diff --git a/electron_app/package.json b/electron_app/package.json index 8481db77a..f80f3ad34 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 12203e790..6da7182cc 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 6e600cfc8..fcab36ac3 100644 --- a/src/vector/platform/ElectronPlatform.js +++ b/src/vector/platform/ElectronPlatform.js @@ -174,18 +174,30 @@ 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'); } - async setAutoLaunchEnabled(enabled) { + async setAutoLaunchEnabled(enabled: boolean): void { return await this._ipcCall('setAutoLaunchEnabled', enabled); } + supportsMinimizeToTray(): boolean { + return true; + } + + async getMinimizeToTrayEnabled(): boolean { + return await this._ipcCall('getMinimizeToTrayEnabled'); + } + + async setMinimizeToTrayEnabled(enabled: boolean): void { + 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 602a0c27c..cfdeeacbe 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 */