summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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);