Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(macos): keep the Dock icon, Cmd+Tab and the menu bar

Etienne Lescot5b5627100906
diff --git a/electron/macSpaces.test.ts b/electron/macSpaces.test.ts
new file mode 100644
index 000000000..44e58e44e
--- /dev/null
+++ b/electron/macSpaces.test.ts
@@ -0,0 +1,52 @@
+// Regression cover for the app losing its Dock icon, its Cmd+Tab entry and its menu bar on
+// macOS: see macSpaces.ts for why `skipTransformProcessType` is the whole fix.
+
+import fs from "node:fs";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+import { describe, expect, it, vi } from "vitest";
+import { followAcrossSpaces } from "./macSpaces";
+
+const electronDir = path.dirname(fileURLToPath(import.meta.url));
+
+describe("followAcrossSpaces", () => {
+ it("follows across Spaces on macOS without transforming the process type", () => {
+ const setVisibleOnAllWorkspaces = vi.fn();
+ followAcrossSpaces({ setVisibleOnAllWorkspaces }, "darwin");
+ expect(setVisibleOnAllWorkspaces).toHaveBeenCalledWith(true, {
+ visibleOnFullScreen: true,
+ skipTransformProcessType: true,
+ });
+ });
+
+ it("does nothing elsewhere", () => {
+ const setVisibleOnAllWorkspaces = vi.fn();
+ followAcrossSpaces({ setVisibleOnAllWorkspaces }, "win32");
+ followAcrossSpaces({ setVisibleOnAllWorkspaces }, "linux");
+ expect(setVisibleOnAllWorkspaces).not.toHaveBeenCalled();
+ });
+
+ // The defect was three direct calls, each of which silently called `app.dock.hide()`. A new
+ // window that copies the old one-liner would bring it straight back, so no main-process
+ // source may call the API except through the helper.
+ it("is the only caller of setVisibleOnAllWorkspaces in the main process", () => {
+ const offenders: string[] = [];
+ const walk = (dir: string) => {
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
+ const full = path.join(dir, entry.name);
+ if (entry.isDirectory()) {
+ if (entry.name !== "native" && entry.name !== "node_modules") walk(full);
+ } else if (
+ /\.ts$/.test(entry.name) &&
+ !/\.test\.ts$/.test(entry.name) &&
+ entry.name !== "macSpaces.ts" &&
+ /\.setVisibleOnAllWorkspaces\(/.test(fs.readFileSync(full, "utf8"))
+ ) {
+ offenders.push(path.relative(electronDir, full));
+ }
+ }
+ };
+ walk(electronDir);
+ expect(offenders).toEqual([]);
+ });
+});
diff --git a/electron/macSpaces.ts b/electron/macSpaces.ts
new file mode 100644
index 000000000..1d80c3b3f
--- /dev/null
+++ b/electron/macSpaces.ts
@@ -0,0 +1,40 @@
+// Making a window follow the user across macOS Spaces without demoting the whole app.
+//
+// `setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })` does more than its name
+// says. Unless `skipTransformProcessType` is passed, Electron's darwin implementation calls
+// `app.dock.hide()` on the way through, which switches the process to the *accessory*
+// activation policy (lsappinfo reports `ApplicationType = UIElement`). An accessory app has
+// no Dock icon, is missing from Cmd+Tab, and never owns the menu bar, so the application
+// menu, including "Save Diagnostics", vanished even while the editor had focus (reported on
+// 1.11.0, macOS 26.6.2, while chasing #709).
+//
+// `main.ts` calls `app.dock.show()` on ready specifically to be a regular app, but the HUD
+// is created after that and made the call above, so the policy was reversed the moment the
+// first window opened. The source selector and the countdown overlay did the same.
+//
+// The cost of skipping the transform: an app that stays regular cannot float its windows
+// over ANOTHER app's full-screen Space (AppKit reserves that for accessory apps since
+// 10.14). The HUD still follows across ordinary Spaces, which is what these calls were
+// added for (e7d82e147). The HUD is excluded from capture anyway, and a take can still be
+// stopped from the tray.
+
+/** The slice of `BrowserWindow` this needs, so the rule can be tested without Electron. */
+export type SpacesFollowingWindow = {
+ setVisibleOnAllWorkspaces(
+ visible: boolean,
+ options?: { visibleOnFullScreen?: boolean; skipTransformProcessType?: boolean },
+ ): void;
+};
+
+export function followAcrossSpaces(
+ win: SpacesFollowingWindow,
+ platform: NodeJS.Platform = process.platform,
+): void {
+ if (platform !== "darwin") {
+ return;
+ }
+ win.setVisibleOnAllWorkspaces(true, {
+ visibleOnFullScreen: true,
+ skipTransformProcessType: true,
+ });
+}
diff --git a/electron/windows.ts b/electron/windows.ts
index baa66e4ee..634392755 100644
--- a/electron/windows.ts
+++ b/electron/windows.ts
@@ -18,6 +18,7 @@ import {
parseHudContentRect,
sameRect,
} from "./hudWindowBounds";
+import { followAcrossSpaces } from "./macSpaces";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -410,9 +411,7 @@ export function createHudOverlayWindow(): BrowserWindow {
// Follow the user across macOS Spaces, else the HUD stays pinned to the Space
// it was first opened on.
- if (process.platform === "darwin") {
- win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
- }
+ followAcrossSpaces(win);
// Show only once painted to avoid the black rectangle flash when a transparent
// window is shown before its first paint.
@@ -591,9 +590,7 @@ export function createSourceSelectorWindow(): BrowserWindow {
// Follow the user across macOS Spaces so the selector appears on the active
// desktop regardless of where the HUD was opened.
- if (process.platform === "darwin") {
- win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
- }
+ followAcrossSpaces(win);
if (VITE_DEV_SERVER_URL) {
win.loadURL(VITE_DEV_SERVER_URL + "?windowType=source-selector");
@@ -644,9 +641,7 @@ export function createCountdownOverlayWindow(): BrowserWindow {
win.setIgnoreMouseEvents(true);
- if (process.platform === "darwin") {
- win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
- }
+ followAcrossSpaces(win);
if (VITE_DEV_SERVER_URL) {
win.loadURL(VITE_DEV_SERVER_URL + "?windowType=countdown-overlay");