From 714570443d2213587d6266377ed9cecc9efe7c69 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sun, 24 Feb 2019 01:08:01 +0000 Subject: [PATCH 1/3] Allow configuration of whether closing window closes or minimizes to tray Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- electron_app/package.json | 1 + electron_app/src/electron-main.js | 12 +++++++++++- src/vector/platform/ElectronPlatform.js | 14 +++++++++++++- src/vector/platform/VectorBasePlatform.js | 13 ------------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/electron_app/package.json b/electron_app/package.json index 8481db77a7..f80f3ad341 100644 --- a/electron_app/package.json +++ b/electron_app/package.json @@ -7,6 +7,7 @@ "author": "New Vector Ltd.", "dependencies": { "auto-launch": "^5.0.1", + "electron-store": "^2.0.0", "electron-window-state": "^4.1.0", "minimist": "^1.2.0", "png-to-ico": "^1.0.2" diff --git a/electron_app/src/electron-main.js b/electron_app/src/electron-main.js index 12203e7906..6da7182cc7 100644 --- a/electron_app/src/electron-main.js +++ b/electron_app/src/electron-main.js @@ -35,6 +35,7 @@ const updater = require('./updater'); const { migrateFromOldOrigin } = require('./originMigrator'); const windowStateKeeper = require('electron-window-state'); +const Store = require('electron-store'); // boolean flag set whilst we are doing one-time origin migration // We only serve the origin migration script while we're actually @@ -55,8 +56,11 @@ try { // Continue with the defaults (ie. an empty config) } +const store = new Store(); + let mainWindow = null; global.appQuitting = false; +global.minimizeToTray = store.get('minimizeToTray', true); // handle uncaught errors otherwise it displays @@ -136,6 +140,12 @@ ipcMain.on('ipcCall', async function(ev, payload) { launcher.disable(); } break; + case 'getMinimizeToTrayEnabled': + ret = global.minimizeToTray; + break; + case 'setMinimizeToTrayEnabled': + store.set('minimizeToTray', global.minimizeToTray = args[0]); + break; case 'getAppVersion': ret = app.getVersion(); break; @@ -331,7 +341,7 @@ app.on('ready', () => { mainWindow = global.mainWindow = null; }); mainWindow.on('close', (e) => { - if (!global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) { + if (global.minimizeToTray && !global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) { // On Mac, closing the window just hides it // (this is generally how single-window Mac apps // behave, eg. Mail.app) diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js index 6e600cfc85..13140a2d1e 100644 --- a/src/vector/platform/ElectronPlatform.js +++ b/src/vector/platform/ElectronPlatform.js @@ -182,10 +182,22 @@ export default class ElectronPlatform extends VectorBasePlatform { return await this._ipcCall('getAutoLaunchEnabled'); } - async setAutoLaunchEnabled(enabled) { + async setAutoLaunchEnabled(enabled: boolean) { return await this._ipcCall('setAutoLaunchEnabled', enabled); } + supportsMinimizeToTray() { + return true; + } + + async getMinimizeToTrayEnabled() { + return await this._ipcCall('getMinimizeToTrayEnabled'); + } + + async setMinimizeToTrayEnabled(enabled: boolean) { + return await this._ipcCall('setMinimizeToTrayEnabled', enabled); + } + async canSelfUpdate(): boolean { const feedUrl = await this._ipcCall('getUpdateFeedUrl'); return Boolean(feedUrl); diff --git a/src/vector/platform/VectorBasePlatform.js b/src/vector/platform/VectorBasePlatform.js index 602a0c27c9..cfdeeacbe4 100644 --- a/src/vector/platform/VectorBasePlatform.js +++ b/src/vector/platform/VectorBasePlatform.js @@ -88,19 +88,6 @@ export default class VectorBasePlatform extends BasePlatform { this._updateFavicon(); } - supportsAutoLaunch() { - return false; - } - - // XXX: Surely this should be a setting like any other? - async getAutoLaunchEnabled() { - return false; - } - - async setAutoLaunchEnabled(enabled) { - throw new Error("Unimplemented"); - } - /** * Begin update polling, if applicable */ From 717495c4e0219ab7d1c0a49734162692665c7aa9 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sun, 24 Feb 2019 01:21:18 +0000 Subject: [PATCH 2/3] specify return types to match superclass Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/platform/ElectronPlatform.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js index 13140a2d1e..f2dd6cb782 100644 --- a/src/vector/platform/ElectronPlatform.js +++ b/src/vector/platform/ElectronPlatform.js @@ -174,11 +174,11 @@ export default class ElectronPlatform extends VectorBasePlatform { return await this._ipcCall('getAppVersion'); } - supportsAutoLaunch() { + supportsAutoLaunch(): boolean { return true; } - async getAutoLaunchEnabled() { + async getAutoLaunchEnabled(): boolean { return await this._ipcCall('getAutoLaunchEnabled'); } @@ -186,11 +186,11 @@ export default class ElectronPlatform extends VectorBasePlatform { return await this._ipcCall('setAutoLaunchEnabled', enabled); } - supportsMinimizeToTray() { + supportsMinimizeToTray(): boolean { return true; } - async getMinimizeToTrayEnabled() { + async getMinimizeToTrayEnabled(): boolean { return await this._ipcCall('getMinimizeToTrayEnabled'); } From 5a3b9ae4542a3673cf2de5e6d6ce2e5de1730894 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sun, 24 Feb 2019 01:38:21 +0000 Subject: [PATCH 3/3] more matching Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/platform/ElectronPlatform.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vector/platform/ElectronPlatform.js b/src/vector/platform/ElectronPlatform.js index f2dd6cb782..fcab36ac39 100644 --- a/src/vector/platform/ElectronPlatform.js +++ b/src/vector/platform/ElectronPlatform.js @@ -182,7 +182,7 @@ export default class ElectronPlatform extends VectorBasePlatform { return await this._ipcCall('getAutoLaunchEnabled'); } - async setAutoLaunchEnabled(enabled: boolean) { + async setAutoLaunchEnabled(enabled: boolean): void { return await this._ipcCall('setAutoLaunchEnabled', enabled); } @@ -194,7 +194,7 @@ export default class ElectronPlatform extends VectorBasePlatform { return await this._ipcCall('getMinimizeToTrayEnabled'); } - async setMinimizeToTrayEnabled(enabled: boolean) { + async setMinimizeToTrayEnabled(enabled: boolean): void { return await this._ipcCall('setMinimizeToTrayEnabled', enabled); }