EZPPLauncher/preload.js

124 lines
3.5 KiB
JavaScript
Raw Normal View History

2024-01-09 12:10:37 +00:00
const { Titlebar, TitlebarColor } = require("custom-electron-titlebar");
2024-01-11 00:00:43 +00:00
const { ipcRenderer } = require("electron");
2024-01-19 14:04:58 +00:00
const { appName, appVersion } = require("./electron/appInfo");
2024-01-09 12:10:37 +00:00
window.addEventListener("DOMContentLoaded", () => {
const titlebar = new Titlebar({
backgroundColor: TitlebarColor.fromHex("#202020"),
itemBackgroundColor: TitlebarColor.fromHex("#202020"),
menu: null,
enableMnemonics: false,
maximizable: false,
});
2024-01-19 14:04:58 +00:00
titlebar.updateTitle(`${appName} ${appVersion}`);
2024-01-09 12:10:37 +00:00
});
2024-01-11 00:00:43 +00:00
window.addEventListener("login-attempt", async (e) => {
const loginResult = await ipcRenderer.invoke("ezpplauncher:login", {
username: e.detail.username,
password: e.detail.password,
2024-01-11 11:59:52 +00:00
saveCredentials: e.detail.saveCredentials,
2024-01-11 00:00:43 +00:00
});
2024-01-11 11:59:52 +00:00
window.dispatchEvent(
new CustomEvent("login-result", { detail: loginResult }),
);
});
2024-01-18 13:10:47 +00:00
window.addEventListener("autologin-active", async (e) => {
const autologin = await ipcRenderer.invoke(
"ezpplauncher:autologin-active",
);
window.dispatchEvent(
new CustomEvent("autologin-result", { detail: autologin }),
);
});
2024-01-12 13:19:00 +00:00
window.addEventListener("autologin-attempt", async () => {
2024-01-11 11:59:52 +00:00
const loginResult = await ipcRenderer.invoke("ezpplauncher:autologin");
window.dispatchEvent(
new CustomEvent("login-result", { detail: loginResult }),
);
});
2024-01-12 13:19:00 +00:00
window.addEventListener("logout", async () => {
2024-01-11 11:59:52 +00:00
await ipcRenderer.invoke("ezpplauncher:logout");
});
2024-01-12 13:19:00 +00:00
window.addEventListener("guest-login", async () => {
2024-01-11 11:59:52 +00:00
await ipcRenderer.invoke("ezpplauncher:guestlogin");
});
window.addEventListener("launch", async (e) => {
await ipcRenderer.invoke("ezpplauncher:launch", e.detail);
});
2024-01-12 13:19:00 +00:00
window.addEventListener("settings-get", async () => {
const settings = await ipcRenderer.invoke("ezpplauncher:settings");
window.dispatchEvent(
new CustomEvent("settings-result", { detail: settings }),
);
});
2024-01-19 14:04:58 +00:00
window.addEventListener("setting-update", async (e) => {
const detail = e.detail;
await ipcRenderer.invoke("ezpplauncher:setting-update", detail);
});
window.addEventListener("folder-auto", async (e) => {
const result = await ipcRenderer.invoke("ezpplauncher:detect-folder");
window.dispatchEvent(
new CustomEvent("settings-result", { detail: result }),
);
});
2024-01-12 13:19:00 +00:00
window.addEventListener("folder-set", async (e) => {
const result = await ipcRenderer.invoke("ezpplauncher:set-folder");
window.dispatchEvent(
new CustomEvent("settings-result", { detail: result }),
);
});
window.addEventListener("settings-set", async (e) => {
await ipcRenderer.invoke("ezpplauncher:settings-set", e.detail);
});
2024-01-22 11:37:29 +00:00
window.addEventListener("updateExit", async () => {
await ipcRenderer.invoke("ezpplauncher:exitAndUpdate");
});
2024-01-12 15:10:19 +00:00
ipcRenderer.addListener("ezpplauncher:launchabort", (e, args) => {
window.dispatchEvent(
new CustomEvent("launch-abort"),
);
});
2024-01-12 13:19:00 +00:00
ipcRenderer.addListener("ezpplauncher:alert", (e, args) => {
window.dispatchEvent(
new CustomEvent("alert", { detail: args }),
);
});
ipcRenderer.addListener("ezpplauncher:launchstatus", (e, args) => {
window.dispatchEvent(
new CustomEvent("launchStatusUpdate", { detail: args }),
);
});
ipcRenderer.addListener("ezpplauncher:launchprogress", (e, args) => {
window.dispatchEvent(
new CustomEvent("launchProgressUpdate", { detail: args }),
);
});
2024-01-19 15:24:39 +00:00
ipcRenderer.addListener("ezpplauncher:update", (e, args) => {
window.dispatchEvent(
new CustomEvent("update", { detail: args }),
);
});
ipcRenderer.addListener("ezpplauncher:open-settings", (e, args) => {
window.dispatchEvent(
new CustomEvent("open-settings"),
);
});