Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions src/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
});
Expand All @@ -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();
Expand Down Expand Up @@ -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);
9 changes: 6 additions & 3 deletions src/preload.cts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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> {
Expand Down
8 changes: 8 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Loading