Skip to content

Commit 9e11c70

Browse files
authored
Merge pull request element-hq#8908 from vector-im/t3chguy/minimize_tray
Allow configuration of whether closing window closes or minimizes to tray
2 parents 5880301 + 5a3b9ae commit 9e11c70

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

electron_app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"author": "New Vector Ltd.",
88
"dependencies": {
99
"auto-launch": "^5.0.1",
10+
"electron-store": "^2.0.0",
1011
"electron-window-state": "^4.1.0",
1112
"minimist": "^1.2.0",
1213
"png-to-ico": "^1.0.2"

electron_app/src/electron-main.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const updater = require('./updater');
3535
const { migrateFromOldOrigin } = require('./originMigrator');
3636

3737
const windowStateKeeper = require('electron-window-state');
38+
const Store = require('electron-store');
3839

3940
// boolean flag set whilst we are doing one-time origin migration
4041
// We only serve the origin migration script while we're actually
@@ -55,8 +56,11 @@ try {
5556
// Continue with the defaults (ie. an empty config)
5657
}
5758

59+
const store = new Store();
60+
5861
let mainWindow = null;
5962
global.appQuitting = false;
63+
global.minimizeToTray = store.get('minimizeToTray', true);
6064

6165

6266
// handle uncaught errors otherwise it displays
@@ -136,6 +140,12 @@ ipcMain.on('ipcCall', async function(ev, payload) {
136140
launcher.disable();
137141
}
138142
break;
143+
case 'getMinimizeToTrayEnabled':
144+
ret = global.minimizeToTray;
145+
break;
146+
case 'setMinimizeToTrayEnabled':
147+
store.set('minimizeToTray', global.minimizeToTray = args[0]);
148+
break;
139149
case 'getAppVersion':
140150
ret = app.getVersion();
141151
break;
@@ -331,7 +341,7 @@ app.on('ready', () => {
331341
mainWindow = global.mainWindow = null;
332342
});
333343
mainWindow.on('close', (e) => {
334-
if (!global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) {
344+
if (global.minimizeToTray && !global.appQuitting && (tray.hasTray() || process.platform === 'darwin')) {
335345
// On Mac, closing the window just hides it
336346
// (this is generally how single-window Mac apps
337347
// behave, eg. Mail.app)

src/vector/platform/ElectronPlatform.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,30 @@ export default class ElectronPlatform extends VectorBasePlatform {
174174
return await this._ipcCall('getAppVersion');
175175
}
176176

177-
supportsAutoLaunch() {
177+
supportsAutoLaunch(): boolean {
178178
return true;
179179
}
180180

181-
async getAutoLaunchEnabled() {
181+
async getAutoLaunchEnabled(): boolean {
182182
return await this._ipcCall('getAutoLaunchEnabled');
183183
}
184184

185-
async setAutoLaunchEnabled(enabled) {
185+
async setAutoLaunchEnabled(enabled: boolean): void {
186186
return await this._ipcCall('setAutoLaunchEnabled', enabled);
187187
}
188188

189+
supportsMinimizeToTray(): boolean {
190+
return true;
191+
}
192+
193+
async getMinimizeToTrayEnabled(): boolean {
194+
return await this._ipcCall('getMinimizeToTrayEnabled');
195+
}
196+
197+
async setMinimizeToTrayEnabled(enabled: boolean): void {
198+
return await this._ipcCall('setMinimizeToTrayEnabled', enabled);
199+
}
200+
189201
async canSelfUpdate(): boolean {
190202
const feedUrl = await this._ipcCall('getUpdateFeedUrl');
191203
return Boolean(feedUrl);

src/vector/platform/VectorBasePlatform.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,6 @@ export default class VectorBasePlatform extends BasePlatform {
8888
this._updateFavicon();
8989
}
9090

91-
supportsAutoLaunch() {
92-
return false;
93-
}
94-
95-
// XXX: Surely this should be a setting like any other?
96-
async getAutoLaunchEnabled() {
97-
return false;
98-
}
99-
100-
async setAutoLaunchEnabled(enabled) {
101-
throw new Error("Unimplemented");
102-
}
103-
10491
/**
10592
* Begin update polling, if applicable
10693
*/

0 commit comments

Comments
 (0)