Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(main): quit when the hidden countdown overlay is the last window left
EtienneLescot73e9b44b4920
diff --git a/electron/lingeringOverlay.test.ts b/electron/lingeringOverlay.test.tsnew file mode 100644index 000000000..37700033f--- /dev/null+++ b/electron/lingeringOverlay.test.ts@@ -0,0 +1,23 @@+import { describe, expect, it } from "vitest";+import { isOnlyLingeringOverlay } from "./lingeringOverlay";++const window = (destroyed = false) => ({ isDestroyed: () => destroyed });++describe("isOnlyLingeringOverlay", () => {+ it("is true when the hidden overlay is the last window open", () => {+ const overlay = window();+ expect(isOnlyLingeringOverlay([overlay], overlay)).toBe(true);+ expect(isOnlyLingeringOverlay([overlay, window(true)], overlay)).toBe(true);+ });++ it("is false while the HUD or the editor is still open", () => {+ const overlay = window();+ expect(isOnlyLingeringOverlay([window(), overlay], overlay)).toBe(false);+ });++ it("is false without an overlay to close", () => {+ expect(isOnlyLingeringOverlay([], null)).toBe(false);+ const gone = window(true);+ expect(isOnlyLingeringOverlay([gone], gone)).toBe(false);+ });+});diff --git a/electron/lingeringOverlay.ts b/electron/lingeringOverlay.tsnew file mode 100644index 000000000..35d64e64d--- /dev/null+++ b/electron/lingeringOverlay.ts@@ -0,0 +1,18 @@+// The countdown overlay is created on the first take and only hidden between takes, so it is+// ready to paint the next countdown at once. A hidden window still counts for Electron, so+// once the HUD and the editor were gone `window-all-closed` never fired: OpenScreen stayed+// up with no window and only the tray icon left (issue #961). `main.ts` closes the overlay+// when it is the last window standing.++/** The slice of `BrowserWindow` this needs, so the rule can be tested without Electron. */+export type LingeringWindow = { isDestroyed(): boolean };++/** True when `overlay` is the only window still open, so it alone holds the app up. */+export function isOnlyLingeringOverlay(+ open: readonly LingeringWindow[],+ overlay: LingeringWindow | null,+): boolean {+ if (!overlay || overlay.isDestroyed()) return false;+ const alive = open.filter((window) => !window.isDestroyed());+ return alive.length === 1 && alive[0] === overlay;+}diff --git a/electron/main.ts b/electron/main.tsindex 77a94a9d1..e525aa064 100644--- a/electron/main.ts+++ b/electron/main.ts@@ -58,6 +58,7 @@ import {getSelectedDesktopSource,registerIpcHandlers,} from "./ipc/handlers";+import { isOnlyLingeringOverlay } from "./lingeringOverlay";import { installMainProcessErrorGuards } from "./main-process-errors";import { showMessageBoxOver } from "./messageBox";import {@@ -1089,6 +1090,17 @@ if (!cliCommand) {app.on("window-all-closed", () => {app.quit();});+ // The countdown overlay hides between takes instead of closing, so it would keep+ // `window-all-closed` from ever firing (#961). Close it with the last other window. Every+ // HUD/editor switch opens the next window before the previous one's `closed` arrives, so+ // this only fires when the user really closed the last one.+ app.on("browser-window-created", (_, win) => {+ win.once("closed", () => {+ if (isOnlyLingeringOverlay(BrowserWindow.getAllWindows(), countdownOverlayWindow)) {+ countdownOverlayWindow?.close();+ }+ });+ });}app.on("activate", () => {