diff --git a/src/ipc.ts b/src/ipc.ts index 3b3d3cce9c..f914dbbd32 100644 --- a/src/ipc.ts +++ b/src/ipc.ts @@ -39,20 +39,15 @@ ipcMain.on("loudNotification", function (): void { }); let powerSaveBlockerId: number | null = null; -ipcMain.on("app_onAction", function (_ev: IpcMainEvent, payload) { - switch (payload.action) { - case "call_state": { - if (powerSaveBlockerId !== null && powerSaveBlocker.isStarted(powerSaveBlockerId)) { - if (payload.state === "ended") { - powerSaveBlocker.stop(powerSaveBlockerId); - powerSaveBlockerId = null; - } - } else { - if (powerSaveBlockerId === null && payload.state === "connected") { - powerSaveBlockerId = powerSaveBlocker.start("prevent-display-sleep"); - } - } - break; +ipcMain.on("callState", function (_ev: IpcMainEvent, state) { + if (powerSaveBlockerId !== null && powerSaveBlocker.isStarted(powerSaveBlockerId)) { + if (state === "ended") { + powerSaveBlocker.stop(powerSaveBlockerId); + powerSaveBlockerId = null; + } + } else { + if (powerSaveBlockerId === null && state === "connected") { + powerSaveBlockerId = powerSaveBlocker.start("prevent-display-sleep"); } } }); @@ -65,15 +60,9 @@ ipcMain.on("ipcCall", async function (_ev: IpcMainEvent, payload) { let ret: any; switch (payload.name) { - case "getUpdateFeedUrl": - ret = autoUpdater.getFeedURL(); - break; case "setLanguage": global.appLocalization.setAppLocale(args[0]); break; - case "getAppVersion": - ret = app.getVersion(); - break; case "focusWindow": if (global.mainWindow.isMinimized()) { global.mainWindow.restore(); @@ -229,4 +218,8 @@ ipcMain.on("ipcCall", async function (_ev: IpcMainEvent, payload) { }); }); +ipcMain.handle("getCanSelfUpdate", () => !!autoUpdater.getFeedURL()); + +ipcMain.handle("getVersion", () => app.getVersion()); + ipcMain.handle("getConfig", () => global.vectorConfig); diff --git a/src/preload.cts b/src/preload.cts index f8922ab632..226c0610f6 100644 --- a/src/preload.cts +++ b/src/preload.cts @@ -14,7 +14,6 @@ import { ipcRenderer, contextBridge, IpcRendererEvent } from "electron"; // handing out generalised messaging access. const CHANNELS = [ - "app_onAction", "before-quit", "check_updates", "install_update", @@ -51,17 +50,21 @@ contextBridge.exposeInMainWorld("electron", { }, async initialise(): Promise<{ + version: string; protocol: string; sessionId: string; config: IConfigOptions; supportedSettings: Record; + canSelfUpdate: boolean; }> { - const [{ protocol, sessionId }, config, supportedSettings] = await Promise.all([ + const [{ protocol, sessionId }, config, supportedSettings, version, canSelfUpdate] = await Promise.all([ ipcRenderer.invoke("getProtocol"), ipcRenderer.invoke("getConfig"), ipcRenderer.invoke("getSupportedSettings"), + ipcRenderer.invoke("getVersion"), + ipcRenderer.invoke("canSelfUpdate"), ]); - return { protocol, sessionId, config, supportedSettings }; + return { protocol, sessionId, config, supportedSettings, version, canSelfUpdate }; }, async setSettingValue(settingName: string, value: any): Promise { diff --git a/src/settings.ts b/src/settings.ts index 7c97aeca5d..ab25243486 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -91,6 +91,14 @@ const Settings: Record = { Store.instance?.set("enableContentProtection", value); }, }, + "locale": { + async read(): Promise { + return Store.instance?.get("locale"); + }, + async write(value: any): Promise { + global.appLocalization.setAppLocale(value); + }, + }, }; ipcMain.handle("getSupportedSettings", async () => {