mirror of
https://github.com/element-hq/element-desktop.git
synced 2025-12-23 23:59:16 -05:00
Small step in tidying the IPCs
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
33
src/ipc.ts
33
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);
|
||||
|
||||
@@ -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<string, boolean>;
|
||||
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<void> {
|
||||
|
||||
@@ -91,6 +91,14 @@ const Settings: Record<string, Setting> = {
|
||||
Store.instance?.set("enableContentProtection", value);
|
||||
},
|
||||
},
|
||||
"locale": {
|
||||
async read(): Promise<any> {
|
||||
return Store.instance?.get("locale");
|
||||
},
|
||||
async write(value: any): Promise<void> {
|
||||
global.appLocalization.setAppLocale(value);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
ipcMain.handle("getSupportedSettings", async () => {
|
||||
|
||||
Reference in New Issue
Block a user