Skip to content

Commit 4782e04

Browse files
committed
Small step in tidying the IPCs
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 0061966 commit 4782e04

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

src/ipc.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,15 @@ ipcMain.on("loudNotification", function (): void {
3939
});
4040

4141
let powerSaveBlockerId: number | null = null;
42-
ipcMain.on("app_onAction", function (_ev: IpcMainEvent, payload) {
43-
switch (payload.action) {
44-
case "call_state": {
45-
if (powerSaveBlockerId !== null && powerSaveBlocker.isStarted(powerSaveBlockerId)) {
46-
if (payload.state === "ended") {
47-
powerSaveBlocker.stop(powerSaveBlockerId);
48-
powerSaveBlockerId = null;
49-
}
50-
} else {
51-
if (powerSaveBlockerId === null && payload.state === "connected") {
52-
powerSaveBlockerId = powerSaveBlocker.start("prevent-display-sleep");
53-
}
54-
}
55-
break;
42+
ipcMain.on("callState", function (_ev: IpcMainEvent, state) {
43+
if (powerSaveBlockerId !== null && powerSaveBlocker.isStarted(powerSaveBlockerId)) {
44+
if (state === "ended") {
45+
powerSaveBlocker.stop(powerSaveBlockerId);
46+
powerSaveBlockerId = null;
47+
}
48+
} else {
49+
if (powerSaveBlockerId === null && state === "connected") {
50+
powerSaveBlockerId = powerSaveBlocker.start("prevent-display-sleep");
5651
}
5752
}
5853
});
@@ -65,15 +60,9 @@ ipcMain.on("ipcCall", async function (_ev: IpcMainEvent, payload) {
6560
let ret: any;
6661

6762
switch (payload.name) {
68-
case "getUpdateFeedUrl":
69-
ret = autoUpdater.getFeedURL();
70-
break;
7163
case "setLanguage":
7264
global.appLocalization.setAppLocale(args[0]);
7365
break;
74-
case "getAppVersion":
75-
ret = app.getVersion();
76-
break;
7766
case "focusWindow":
7867
if (global.mainWindow.isMinimized()) {
7968
global.mainWindow.restore();
@@ -229,4 +218,8 @@ ipcMain.on("ipcCall", async function (_ev: IpcMainEvent, payload) {
229218
});
230219
});
231220

221+
ipcMain.handle("getCanSelfUpdate", () => !!autoUpdater.getFeedURL());
222+
223+
ipcMain.handle("getVersion", () => app.getVersion());
224+
232225
ipcMain.handle("getConfig", () => global.vectorConfig);

src/preload.cts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { ipcRenderer, contextBridge, IpcRendererEvent } from "electron";
1414
// handing out generalised messaging access.
1515

1616
const CHANNELS = [
17-
"app_onAction",
1817
"before-quit",
1918
"check_updates",
2019
"install_update",
@@ -51,17 +50,21 @@ contextBridge.exposeInMainWorld("electron", {
5150
},
5251

5352
async initialise(): Promise<{
53+
version: string;
5454
protocol: string;
5555
sessionId: string;
5656
config: IConfigOptions;
5757
supportedSettings: Record<string, boolean>;
58+
canSelfUpdate: boolean;
5859
}> {
59-
const [{ protocol, sessionId }, config, supportedSettings] = await Promise.all([
60+
const [{ protocol, sessionId }, config, supportedSettings, version, canSelfUpdate] = await Promise.all([
6061
ipcRenderer.invoke("getProtocol"),
6162
ipcRenderer.invoke("getConfig"),
6263
ipcRenderer.invoke("getSupportedSettings"),
64+
ipcRenderer.invoke("getVersion"),
65+
ipcRenderer.invoke("canSelfUpdate"),
6366
]);
64-
return { protocol, sessionId, config, supportedSettings };
67+
return { protocol, sessionId, config, supportedSettings, version, canSelfUpdate };
6568
},
6669

6770
async setSettingValue(settingName: string, value: any): Promise<void> {

src/settings.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ const Settings: Record<string, Setting> = {
9191
Store.instance?.set("enableContentProtection", value);
9292
},
9393
},
94+
"locale": {
95+
async read(): Promise<any> {
96+
return Store.instance?.get("locale");
97+
},
98+
async write(value: any): Promise<void> {
99+
global.appLocalization.setAppLocale(value);
100+
},
101+
},
94102
};
95103

96104
ipcMain.handle("getSupportedSettings", async () => {

0 commit comments

Comments
 (0)