From 5190556c37f33d6a479da14856cbd146330d581d Mon Sep 17 00:00:00 2001 From: sawka Date: Mon, 9 Sep 2024 11:49:57 -0700 Subject: [PATCH] always recreate existing window if possible (for the last window only) --- emain/emain.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/emain/emain.ts b/emain/emain.ts index 2e62d0ae1..b10b50364 100644 --- a/emain/emain.ts +++ b/emain/emain.ts @@ -445,7 +445,7 @@ function createBrowserWindow(clientId: string, waveWindow: WaveWindow, fullConfi return; } const numWindows = electron.BrowserWindow.getAllWindows().length; - if ((unamePlatform == "win32" || unamePlatform == "linux") && numWindows == 1) { + if (numWindows == 1) { return; } const choice = electron.dialog.showMessageBoxSync(win, { @@ -463,7 +463,7 @@ function createBrowserWindow(clientId: string, waveWindow: WaveWindow, fullConfi return; } const numWindows = electron.BrowserWindow.getAllWindows().length; - if ((unamePlatform == "win32" || unamePlatform == "linux") && numWindows == 0) { + if (numWindows == 0) { return; } services.WindowService.CloseWindow(waveWindow.oid); @@ -669,9 +669,25 @@ if (unamePlatform !== "darwin") { async function createNewWaveWindow(): Promise { const clientData = await services.ClientService.GetClientData(); - const newWindow = await services.ClientService.MakeWindow(); const fullConfig = await services.FileService.GetFullConfig(); + let recreatedWindow = false; + if (electron.BrowserWindow.getAllWindows().length === 0 && clientData?.windowids?.length >= 1) { + // reopen the first window + const existingWindowId = clientData.windowids[0]; + const existingWindowData = (await services.ObjectService.GetObject("window:" + existingWindowId)) as WaveWindow; + if (existingWindowData != null) { + const win = createBrowserWindow(clientData.oid, existingWindowData, fullConfig); + await win.readyPromise; + win.show(); + recreatedWindow = true; + } + } + if (recreatedWindow) { + return; + } + const newWindow = await services.ClientService.MakeWindow(); const newBrowserWindow = createBrowserWindow(clientData.oid, newWindow, fullConfig); + await newBrowserWindow.readyPromise; newBrowserWindow.show(); }