Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into 578-nf-hangs_after_quit
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/main.ts
  • Loading branch information
forman authored and forman committed Mar 22, 2018
2 parents 1ecb2ee + d176693 commit a14651c
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class CateDesktopApp {
private mainWindow: electron.BrowserWindow = null;
private splashWindow: electron.BrowserWindow = null;

private quitRequested = false;
private quitConfirmed = false;

get webAPIConfig(): any {
Expand Down Expand Up @@ -173,6 +174,11 @@ class CateDesktopApp {
});
});

// Emitted before the application starts closing its windows.
electron.app.on('before-quit', () => {
this.quitRequested = true;
});

// Emitted when all windows have been closed and the application will quit.
electron.app.on('quit', () => {
log.info('Quit.');
Expand Down Expand Up @@ -384,7 +390,7 @@ class CateDesktopApp {
{...this.webAPIProcessOptions, timeout: 1000 * this.webAPIStopTimeout});
if (processData.status !== 0 || processData.error) {
log.error(`Failed to stop Cate service. Status: ${processData.status}, ${processData.error}`);
log.error(`Killing it (pid=${this.webAPIProcess.pid})...`);
log.warn(`Killing it (pid=${this.webAPIProcess.pid})...`);
this.webAPIProcess.kill(this.webAPIKillSignal);
this.webAPIProcess = null;
//sleep(10000);
Expand Down Expand Up @@ -431,6 +437,7 @@ class CateDesktopApp {
const suppressQuitConfirm = this.preferences.get('suppressQuitConfirm', false);
if (suppressQuitConfirm) {
this.quitConfirmed = true;
this.forceQuit();
} else {
// Prevent default behavior, which is closing the main window.
event.preventDefault();
Expand All @@ -442,8 +449,11 @@ class CateDesktopApp {
// Force window close, so app can quit after all windows closed.
// We must call destroy() here, calling close() seems to have no effect on Mac (Electron 1.8.2).
this.mainWindow.destroy();
this.forceQuit();
});
}
} else {
this.forceQuit();
}
});

Expand All @@ -454,6 +464,14 @@ class CateDesktopApp {
});
}

private forceQuit() {
if (!this.quitRequested) {
// Force quit on Mac
log.warn("Forcing quit.");
electron.app.quit();
}
}

private confirmQuit(callback: (suppressQuitConfirm: boolean) => void) {
const quitName = process.platform === 'darwin' ? 'Quit' : 'Exit';
const options = {
Expand Down

0 comments on commit a14651c

Please sign in to comment.