diff --git a/ivette/src/dome/main/dome.ts b/ivette/src/dome/main/dome.ts index 4528aae39829f29a839a0bac5bfd70b134c01d53..7c5db4f83c027748e0124a3c1199518063151880 100644 --- a/ivette/src/dome/main/dome.ts +++ b/ivette/src/dome/main/dome.ts @@ -477,22 +477,10 @@ function createBrowserWindow( }); // Emitted when the window want's to close. - const closeHandler = function (event: Event): void { - // Do not call this handler in a cycle; the next close event will forcibly - // close the window - theWindow.off('close', closeHandler); - // Do not close the window yet - event.preventDefault(); - + theWindow.on('close', () => { handle.frame = theWindow.getBounds(); handle.devtools = webContents.isDevToolsOpened(); webContents.send('dome.ipc.closing'); - }; - - theWindow.on('close', closeHandler); - - ipcMain.on('dome-ipc.done-closing', () => { - theWindow.close(); }); // Keep track of frame positions (in DEVEL) diff --git a/ivette/src/dome/misc/system.ts b/ivette/src/dome/misc/system.ts index d3c6f8e5a7f6c01cfae4946ba67ec25d644d47d4..0896e7712106c082ab1ad4a2db4d1da4354e55fa 100644 --- a/ivette/src/dome/misc/system.ts +++ b/ivette/src/dome/misc/system.ts @@ -114,7 +114,7 @@ emitter.setMaxListeners(250); // --- At Exit // -------------------------------------------------------------------------- -export type Callback = () => (void | Promise<void>); +export type Callback = () => void; const exitJobs: Callback[] = []; @@ -128,14 +128,11 @@ export function atExit(callback: Callback): void { } /** Execute all pending exit jobs (and flush the list). */ -export async function doExit(): Promise<void> { - await Promise.all(exitJobs.map(async (fn) => { - try { - const promise = fn(); - promise && await promise; - } +export function doExit(): void { + exitJobs.forEach((fn) => { + try { fn(); } catch (err) { D.error('atExit:', err); } - })); + }); exitJobs.length = 0; } @@ -468,16 +465,13 @@ export function rename(oldPath: string, newPath: string): Promise<void> { const childprocess = new Map<number, Exec.ChildProcess>(); -atExit(async () => { - await Promise.all(Array.from(childprocess.values()).map(async (process) => { - try { - process.kill(); - await new Promise(resolve => process.on('exit', resolve)); - } +atExit(() => { + childprocess.forEach((process, pid) => { + try { process.kill(); } catch (err) { - D.warn('killing process', process.pid, err); + D.warn('killing process', pid, err); } - })); + }); }); export type StdPipe = { path?: string | undefined; mode?: number; pipe?: boolean }; diff --git a/ivette/src/dome/renderer/dome.tsx b/ivette/src/dome/renderer/dome.tsx index 00fb869ac04c3ef09186ff64d47002e6f673ea79..4410ed078d74224ccab45073213737b933e9c243 100644 --- a/ivette/src/dome/renderer/dome.tsx +++ b/ivette/src/dome/renderer/dome.tsx @@ -251,13 +251,10 @@ export const globalSettings = new Event(Settings.global); // --- Closing // -------------------------------------------------------------------------- -ipcRenderer.on('dome.ipc.closing', async () => { - await System.doExit(); - ipcRenderer.send('dome-ipc.done-closing'); - }); +ipcRenderer.on('dome.ipc.closing', System.doExit); /** Register a callback to be executed when the window is closing. */ -export function atExit(callback: () => (void | Promise<void>)): void { +export function atExit(callback: () => void): void { System.atExit(callback); }