Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of whether closing window closes or minimizes to tray #8908

Merged
merged 3 commits into from Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions electron_app/package.json
Expand Up @@ -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"
Expand Down
12 changes: 11 additions & 1 deletion electron_app/src/electron-main.js
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions src/vector/platform/ElectronPlatform.js
Expand Up @@ -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);
Expand Down
13 changes: 0 additions & 13 deletions src/vector/platform/VectorBasePlatform.js
Expand Up @@ -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
*/
Expand Down