From 40b77778f8cd53b4a99e9413c638a98fc5680f0f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 10 Jun 2022 22:38:48 +0100 Subject: [PATCH 1/3] Abstract electron settings properly to avoid boilerplate-hell (#375) (cherry picked from commit 840a69451bf4f9c1c5acb140ec5af62e1e29e8fa) --- src/electron-main.ts | 112 +++++++++++++++++++++++++++---------------- 1 file changed, 71 insertions(+), 41 deletions(-) diff --git a/src/electron-main.ts b/src/electron-main.ts index 57b99df..8256c0f 100644 --- a/src/electron-main.ts +++ b/src/electron-main.ts @@ -389,6 +389,66 @@ ipcMain.on('app_onAction', function(_ev: IpcMainEvent, payload) { } }); +interface Setting { + read(): Promise; + write(value: any): Promise; +} + +const settings: Record = { + "Electron.autoLaunch": { + async read(): Promise { + return launcher.isEnabled(); + }, + async write(value: any): Promise { + if (value) { + return launcher.enable(); + } else { + return launcher.disable(); + } + }, + }, + "Electron.warnBeforeExit": { + async read(): Promise { + return store.get("warnBeforeExit", true); + }, + async write(value: any): Promise { + store.set("warnBeforeExit", value); + }, + }, + "Electron.alwaysShowMenuBar": { // not supported on macOS + async read(): Promise { + return !global.mainWindow.autoHideMenuBar; + }, + async write(value: any): Promise { + store.set('autoHideMenuBar', !value); + global.mainWindow.autoHideMenuBar = !value; + global.mainWindow.setMenuBarVisibility(value); + }, + }, + "Electron.showTrayIcon": { // not supported on macOS + async read(): Promise { + return tray.hasTray(); + }, + async write(value: any): Promise { + if (value) { + // Create trayIcon icon + tray.create(trayConfig); + } else { + tray.destroy(); + } + store.set('minimizeToTray', value); + }, + }, + "Electron.enableHardwareAcceleration": { + async read(): Promise { + return !store.get('disableHardwareAcceleration', false); + }, + async write(value: any): Promise { + store.set('disableHardwareAcceleration', !value); + }, + }, +}; + ipcMain.on('ipcCall', async function(_ev: IpcMainEvent, payload) { if (!mainWindow) return; @@ -399,51 +459,21 @@ ipcMain.on('ipcCall', async function(_ev: IpcMainEvent, payload) { case 'getUpdateFeedUrl': ret = autoUpdater.getFeedURL(); break; - case 'getAutoLaunchEnabled': - ret = await launcher.isEnabled(); + case 'getSettingValue': { + const [settingName] = args; + const setting = settings[settingName]; + ret = await setting.read(); break; - case 'setAutoLaunchEnabled': - if (args[0]) { - launcher.enable(); - } else { - launcher.disable(); - } + } + case 'setSettingValue': { + const [settingName, value] = args; + const setting = settings[settingName]; + await setting.write(value); break; + } case 'setLanguage': appLocalization.setAppLocale(args[0]); break; - case 'shouldWarnBeforeExit': - ret = store.get('warnBeforeExit', true); - break; - case 'setWarnBeforeExit': - store.set('warnBeforeExit', args[0]); - break; - case 'getMinimizeToTrayEnabled': - ret = tray.hasTray(); - break; - case 'setMinimizeToTrayEnabled': - if (args[0]) { - // Create trayIcon icon - tray.create(trayConfig); - } else { - tray.destroy(); - } - store.set('minimizeToTray', args[0]); - break; - case 'getAutoHideMenuBarEnabled': - ret = global.mainWindow.autoHideMenuBar; - break; - case 'setAutoHideMenuBarEnabled': - store.set('autoHideMenuBar', args[0]); - global.mainWindow.autoHideMenuBar = Boolean(args[0]); - global.mainWindow.setMenuBarVisibility(!args[0]); - break; - case 'getDisableHardwareAcceleration': - ret = store.get('disableHardwareAcceleration') === true; - break; - case 'setDisableHardwareAcceleration': - store.set('disableHardwareAcceleration', args[0]); - break; case 'getAppVersion': ret = app.getVersion(); break; @@ -864,7 +894,7 @@ app.enableSandbox(); app.commandLine.appendSwitch('disable-features', 'HardwareMediaKeyHandling,MediaSessionService'); // Disable hardware acceleration if the setting has been set. -if (store.get('disableHardwareAcceleration') === true) { +if (store.get('disableHardwareAcceleration', false) === true) { console.log("Disabling hardware acceleration."); app.disableHardwareAcceleration(); } From 6fa3cb2a3dbf2f1097c4d83cafa1bea70781af71 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 14 Jun 2022 14:58:07 +0100 Subject: [PATCH 2/3] Prepare changelog for v1.10.15 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fe7886..e358e1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Changes in [1.10.15](https://github.com/vector-im/element-desktop/releases/tag/v1.10.15) (2022-06-14) +===================================================================================================== + +## 🐛 Bug Fixes + * Fix missing element desktop preferences ([\#8798](https://github.com/matrix-org/matrix-react-sdk/pull/8798)). Contributed by @t3chguy. + Changes in [1.10.14](https://github.com/vector-im/element-desktop/releases/tag/v1.10.14) (2022-06-07) ===================================================================================================== From 41deac302f7326695cf55a91d16349ce41373189 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 14 Jun 2022 14:58:08 +0100 Subject: [PATCH 3/3] v1.10.15 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ac17d6d..269d928 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "element-desktop", "productName": "Element", "main": "lib/electron-main.js", - "version": "1.10.14", + "version": "1.10.15", "description": "A feature-rich client for Matrix.org", "author": "Element", "repository": {