diff options
Diffstat (limited to 'src-ui')
-rw-r--r-- | src-ui/src/main.ts | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src-ui/src/main.ts b/src-ui/src/main.ts index 6492a32a..f964a6d5 100644 --- a/src-ui/src/main.ts +++ b/src-ui/src/main.ts @@ -1,35 +1,35 @@ -import { invoke } from '@tauri-apps/api'; -import { Event as TauriEvent, listen } from '@tauri-apps/api/event'; +import { invoke } from "@tauri-apps/api"; +import { listen, Event as TauriEvent } from "@tauri-apps/api/event"; + const $ = document.querySelector.bind(document); document.addEventListener("DOMContentLoaded", async function () { - // get the elements - const helloEl = $("div.hello") as HTMLElement; - const counterButtonEl = $("counter-button") as HTMLElement; - const counterResultEl = $("counter-result") as HTMLElement; - const pingEl = $("backend-ping") as HTMLElement; - - // listen backend-ping event - listen("backend-ping", function (evt: TauriEvent<any>) { - pingEl.classList.add("on"); - setTimeout(function () { - pingEl.classList.remove("on") - }, 500); - }) + // get the elements + const helloEl = $("div.hello")! as HTMLElement; + let counterButtonEl = $("counter-button") as HTMLElement; + let counterResultEl = $("counter-result") as HTMLElement; + let pingEl = $("backend-ping")! as HTMLElement; - // counter button click - counterButtonEl.addEventListener("pointerup", async function () { - const result = await invoke("add_count", { num: 3 }) as string; - counterResultEl.textContent = result; - }); + // listen backend-ping event (from Tauri Rust App) + listen("backend-ping", function (evt: TauriEvent<any>) { + pingEl.classList.add("on"); + setTimeout(function () { + pingEl.classList.remove("on"); + }, 500); + }) - // hello click - helloEl.addEventListener("pointerup", async function () { - const result = await invoke("hello_world") as string; - helloEl.textContent = result; - setTimeout(function () { - helloEl.textContent = "Click again"; - }, 1000); - }); + // counter button click + counterButtonEl.addEventListener("pointerup", async function () { + const result = await invoke("add_count", { num: 1 }) as string; + counterResultEl.textContent = result; + }); -});
\ No newline at end of file + // hello click + helloEl.addEventListener("pointerup", async function () { + const result = await invoke("hello_world") as string; + helloEl.textContent = result; + setTimeout(function () { + helloEl.textContent = "Click again"; + }, 1000); + }) +})
\ No newline at end of file |