diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-08-07 08:47:30 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-08-07 08:47:30 -0300 |
| commit | b1924ac4c419f1d55ae4bbd06be96ac0e2db54d4 (patch) | |
| tree | 214d98807ba8890d36c9640cde2482f741b0a9d8 | |
| parent | 858ded2aa27ab9c86ecf79c1702ef07a2bdf60fe (diff) | |
| parent | 567e0bdf92f30946a48d0fd6cee522355b0aef03 (diff) | |
| download | mullvadvpn-b1924ac4c419f1d55ae4bbd06be96ac0e2db54d4.tar.xz mullvadvpn-b1924ac4c419f1d55ae4bbd06be96ac0e2db54d4.zip | |
Merge branch 'handle-window-close-on-linux'
| -rw-r--r-- | app/main.js | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/app/main.js b/app/main.js index 5b242a644c..b852557c22 100644 --- a/app/main.js +++ b/app/main.js @@ -20,6 +20,7 @@ const ApplicationMain = { _logFilePath: '', _oldLogFilePath: (null: ?string), _connectionFilePollInterval: (null: ?IntervalID), + _shouldQuit: false, run() { if (this._ensureSingleInstance()) { @@ -31,8 +32,10 @@ const ApplicationMain = { log.info(`Running version ${app.getVersion()}`); + app.on('activate', () => this._onActivate()); app.on('ready', () => this._onReady()); app.on('window-all-closed', () => app.quit()); + app.on('before-quit', () => this._onBeforeQuit()); }, _ensureSingleInstance() { @@ -119,6 +122,26 @@ const ApplicationMain = { } }, + _onActivate() { + const windowController = this._windowController; + if (windowController) { + windowController.show(); + } + }, + + _onBeforeQuit() { + this._shouldQuit = true; + + if (process.env.NODE_ENV === 'development') { + const windowController = this._windowController; + if (windowController) { + windowController.window.closeDevTools(); + } + } + + return true; + }, + async _onReady() { const window = this._createWindow(); const tray = this._createTray(); @@ -137,8 +160,6 @@ const ApplicationMain = { if (process.env.NODE_ENV === 'development') { await this._installDevTools(); - - window.on('close', () => window.closeDevTools()); window.openDevTools({ mode: 'detach' }); } @@ -149,11 +170,12 @@ const ApplicationMain = { case 'darwin': this._installMacOsMenubarAppWindowHandlers(tray, windowController); break; + case 'linux': + this._installGenericMenubarAppWindowHandlers(tray, windowController); + this._installLinuxWindowCloseHandler(windowController); + break; default: - tray.on('click', () => { - windowController.toggle(); - }); - windowController.show(); + this._installGenericMenubarAppWindowHandlers(tray, windowController); break; } @@ -457,6 +479,25 @@ const ApplicationMain = { window.on('hide', () => macEventMonitor.stop()); tray.on('click', () => windowController.toggle()); }, + + _installGenericMenubarAppWindowHandlers(tray: Tray, windowController: WindowController) { + tray.on('click', () => { + windowController.toggle(); + }); + windowController.show(); + }, + + _installLinuxWindowCloseHandler(windowController: WindowController) { + windowController.window.on('close', (closeEvent) => { + if (process.platform === 'linux' && !this._shouldQuit) { + closeEvent.preventDefault(); + windowController.hide(); + return false; + } else { + return true; + } + }); + }, }; ApplicationMain.run(); |
