Merge pull request #8908 from vector-im/t3chguy/minimize_tray

Allow configuration of whether closing window closes or minimizes to tray
This commit is contained in:
Travis Ralston 2019-02-24 17:33:14 -07:00 committed by GitHub
commit 9e11c70416
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 17 deletions

View file

@ -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"

View file

@ -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)

View file

@ -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);

View file

@ -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
*/