From 9388ab4f24b2af9289411d799fa9e9872fd93274 Mon Sep 17 00:00:00 2001 From: Valentin Perrelle <valentin.perrelle@cea.fr> Date: Thu, 27 Apr 2023 20:30:47 +0200 Subject: [PATCH] Revert "[ivette] Wait for all listener to terminate before actually closing the main window" This reverts commit 385a2ff48f203a180fd8e8bdfcaa7b36265be05b. --- ivette/src/dome/main/dome.ts | 14 +------------- ivette/src/dome/misc/system.ts | 26 ++++++++++---------------- ivette/src/dome/renderer/dome.tsx | 7 ++----- 3 files changed, 13 insertions(+), 34 deletions(-) diff --git a/ivette/src/dome/main/dome.ts b/ivette/src/dome/main/dome.ts index 4528aae3982..7c5db4f83c0 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 d3c6f8e5a7f..0896e771210 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 00fb869ac04..4410ed078d7 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); } -- GitLab