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
@@ -0,0 +1,20 @@
import { app } from 'electron';
import { logger } from './logger';
const cleanupRegistry: (() => void)[] = [];
export function beforeAppQuit(fn: () => void) {
cleanupRegistry.push(fn);
}
app.on('before-quit', () => {
cleanupRegistry.forEach(fn => {
// some cleanup functions might throw on quit and crash the app
try {
fn();
} catch (err) {
logger.warn('cleanup error on quit', err);
}
});
});