blob: 6492a32aeb0862c015b00789a880de668a0c9f15 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import { invoke } from '@tauri-apps/api';
import { Event as TauriEvent, listen } 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);
})
// counter button click
counterButtonEl.addEventListener("pointerup", async function () {
const result = await invoke("add_count", { num: 3 }) as string;
counterResultEl.textContent = result;
});
// 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);
});
});
|