summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorEmīls Piņķis <emils@mullvad.net>2018-05-03 11:01:41 +0100
committerEmīls Piņķis <emils@mullvad.net>2018-05-03 11:01:41 +0100
commit217ea838b3b85574af36856475d5951fb0b14a30 (patch)
tree8f98e8e05aad5a8752636d41356c543ba0c518da
parent1b514f646bbb1bb73ae8e4db3365d9c1cc5b4b9e (diff)
parent0b30e5e5f4d118a05507f0303870f83d1ecda7a7 (diff)
downloadmullvadvpn-217ea838b3b85574af36856475d5951fb0b14a30.tar.xz
mullvadvpn-217ea838b3b85574af36856475d5951fb0b14a30.zip
Merge branch 'bugfix-disconnect-tunnel-on-app-shutdown'
-rw-r--r--app/app.js13
-rw-r--r--app/main.js26
2 files changed, 26 insertions, 13 deletions
diff --git a/app/app.js b/app/app.js
index 13a5c75f59..429c7e39cd 100644
--- a/app/app.js
+++ b/app/app.js
@@ -55,6 +55,19 @@ ipcRenderer.on('disconnect', () => {
log.warn('Unable to disconnect the tunnel', e.message);
});
});
+
+ipcRenderer.on('app-shutdown', () => {
+ log.info('Been told by the renderer process that the app is shutting down');
+ // The shutdown behaviour may have to be different on mobile platforms
+ const shutdown_func = process.platform === 'darwin' ? () => backend.shutdown() : () => backend.disconnect();
+ shutdown_func().catch( e => {
+ log.error('Failed to shutdown tunnel: ', e);
+ });
+
+ // no matter what, don't block the frontend from shutting down, I guess.
+ ipcRenderer.send('daemon-shutdown', true);
+});
+
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
diff --git a/app/main.js b/app/main.js
index 1321f05219..bfc7bcfdf2 100644
--- a/app/main.js
+++ b/app/main.js
@@ -30,6 +30,7 @@ const appDelegate = {
_window: (null: ?BrowserWindow),
_tray: (null: ?Tray),
_logFileLocation: '',
+ _readyToQuit: false,
connectionFilePollInterval: (null: ?IntervalID),
setup: () => {
@@ -87,6 +88,11 @@ const appDelegate = {
}
},
+ onTunnelShutdown: (isTunnelDown: boolean) => {
+ appDelegate._readyToQuit = isTunnelDown;
+ app.quit();
+ },
+
onReady: async () => {
const window = appDelegate._window = appDelegate._createWindow();
@@ -97,22 +103,16 @@ const appDelegate = {
ipcMain.on('show-window', () => appDelegate._showWindow(window, appDelegate._tray));
ipcMain.on('hide-window', () => window.hide());
+ ipcMain.on('daemon-shutdown', appDelegate.onTunnelShutdown);
window.loadURL('file://' + path.join(__dirname, 'index.html'));
- // Since macOS still runs the daemon manually it has to shut it down.
- // On other platforms closing the app only disconnects the tunnel.
- if (process.platform === 'darwin') {
- window.on('close', () => {
- log.debug('The browser window is closing, shutting down the daemon...');
- window.webContents.send('shutdown');
- });
- } else {
- window.on('close', () => {
- log.debug('The browser window is closing, shutting down the tunnel...');
- window.webContents.send('disconnect');
- });
- }
+ app.on('before-quit', (event) => {
+ if (!appDelegate._readyToQuit) {
+ event.preventDefault();
+ window.webContents.send('app-shutdown');
+ }
+ });
ipcMain.on('collect-logs', (event, id, toRedact) => {
log.info('Collecting logs in', appDelegate._logFileLocation);