fix(electron): potential crash on quit (#8855)

This commit is contained in:
Peng Xiao
2024-11-20 14:44:06 +08:00
committed by GitHub
parent b0ca3c6d58
commit 8689465e00
6 changed files with 42 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ import electronWindowState from 'electron-window-state';
import { BehaviorSubject } from 'rxjs';
import { isLinux, isMacOS, isWindows } from '../../shared/utils';
import { beforeAppQuit } from '../cleanup';
import { buildType } from '../config';
import { mainWindowOrigin } from '../constants';
import { ensureHelperProcess } from '../helper-process';
@@ -116,11 +117,17 @@ export class MainWindowManager {
uiSubjects.onFullScreen$.next(mainWindow.isFullScreen());
});
beforeAppQuit(() => {
this.cleanupWindows();
});
mainWindow.on('close', e => {
// TODO(@pengx17): gracefully close the app, for example, ask user to save unsaved changes
e.preventDefault();
if (!isMacOS()) {
closeAllWindows();
this.mainWindowReady = undefined;
this.mainWindow$.next(undefined);
} else {
// hide window on macOS
// application quit will be handled by closing the hidden window