blob: f96779387807ad097f4d5ad8b8e55b7c3bb1f106 (
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
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;
let counterButtonEl = $("counter-button") as HTMLElement;
let counterResultEl = $("counter-result") as HTMLElement;
let pingEl = $("backend-ping")! as HTMLElement;
let panicButtonEl = $("panic-button") as HTMLElement;
let installLocationHolderEl = $("install-location-holder") as HTMLElement;
let versionNumberHolderEl = $("version-number-holder") as HTMLElement;
let omniButtonEl = document.getElementById("omni-button") as HTMLElement;
// 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);
})
// counter button click
counterButtonEl.addEventListener("pointerup", async function () {
const result = await invoke("add_count", { num: 1 }) 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);
})
// panic button click
panicButtonEl.addEventListener("pointerup", async function () {
await invoke("force_panic");
alert("Never should have been able to get here!");
});
// Run the following on initial page load
// Get version number
let version_number_string = await invoke("get_version_number") as string;
versionNumberHolderEl.textContent = version_number_string;
// Get install location
let install_location = await invoke("find_game_install_location") as string;
// Change omni-button content based on whether game install was found
if (install_location && install_location.length > 0) {
omniButtonEl.textContent = "Install";
installLocationHolderEl.textContent = install_location;
}
else {
omniButtonEl.textContent = "Find Titanfall2 install location";
}
})
|