Skip to content

Commit 479a2c7

Browse files
authored
fix(desktop): recreate window on second-instance relaunch (#701)
1 parent c4d45d1 commit 479a2c7

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

apps/desktop/main/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,11 @@ function focusMainWindow(): void {
753753
}
754754

755755
app.on("second-instance", () => {
756+
if (!mainWindow || mainWindow.isDestroyed()) {
757+
createMainWindow();
758+
return;
759+
}
760+
756761
focusMainWindow();
757762
});
758763

tests/desktop/dev-toolchain-invariants.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,25 @@ describe("Shutdown safety", () => {
321321
});
322322

323323
// -----------------------------------------------------------------------
324-
// 18. dev-launchd.sh stop sends SIGTERM before SIGKILL
324+
// 18. second-instance recreates the main window when none exists
325+
// -----------------------------------------------------------------------
326+
it("index.ts recreates the main window on second-instance when none exists", () => {
327+
const indexTs = readFile("apps/desktop/main/index.ts");
328+
const secondInstanceStart = indexTs.indexOf('app.on("second-instance"');
329+
const secondInstanceBlock = indexTs.slice(
330+
secondInstanceStart,
331+
secondInstanceStart + 300,
332+
);
333+
334+
expect(secondInstanceBlock).toContain(
335+
"!mainWindow || mainWindow.isDestroyed()",
336+
);
337+
expect(secondInstanceBlock).toContain("createMainWindow()");
338+
expect(secondInstanceBlock).toContain("focusMainWindow()");
339+
});
340+
341+
// -----------------------------------------------------------------------
342+
// 19. dev-launchd.sh stop sends SIGTERM before SIGKILL
325343
// -----------------------------------------------------------------------
326344
it("dev-launchd.sh stop_services sends SIGTERM before SIGKILL", () => {
327345
const devLaunchdSh = readFile("scripts/dev-launchd.sh");

0 commit comments

Comments
 (0)