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(recording): name the last Apple picker pick after a relaunch
EtienneLescot69a79827600c
diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.tsindex 669e3ed25..c0fcabbe4 100644--- a/electron/electron-env.d.ts+++ b/electron/electron-env.d.ts@@ -47,6 +47,8 @@ interface Window {}>;/** Sources are picked in Apple's system picker (macOS 15.2+), not in an app list. */usesSystemSourcePicker?: () => Promise<boolean>;+ /** Name of the last source picked in Apple's picker, for display only: it is not selected. */+ getLastPickedSource?: () => Promise<string | null>;openNotes: () => Promise<{opened: boolean;reason?: string;diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.tsindex c3bd11c01..c892b0be7 100644--- a/electron/ipc/handlers.ts+++ b/electron/ipc/handlers.ts@@ -125,9 +125,11 @@ import {import { patchWebmDurationOnDisk } from "../recording/webm-duration";import { reindexRecordingOnDisk } from "../recording/webm-seek-index";import {+ describeMacPickerSource,describeRecordingSource,enumerationIncludesSourceKind,mergeEnumeratedSources,+ rememberedPickerSourceName,resolveRecordingSource,restoreRecordingSourceAfterEnumeration,shouldEnumerateRecordingSources,@@ -1058,7 +1060,9 @@ async function getMacPickerSession(): Promise<MacPickerSession | null> {return session;}-function selectedSourceFromPick(pick: MacPickerSelection): SelectedSource {+function selectedSourceFromPick(+ pick: MacPickerSelection,+): SelectedSource & { id: string; display_id: string } {const display =pick.displayId !== null? screen.getAllDisplays().find((candidate) => candidate.id === pick.displayId)@@ -2125,8 +2129,15 @@ export function registerIpcHandlers(}return;}- selectedSource = selectedSourceFromPick(pick);+ const picked = selectedSourceFromPick(pick);+ selectedSource = picked;selectedDesktopSource = null;+ // Written only so the next launch can name it: the pick itself dies with the helper.+ try {+ appSettings.setLastSource(describeMacPickerSource(picked, pick.kind));+ } catch (error) {+ console.warn("Failed to persist the picked recording source:", error);+ }broadcastSelectedSource(selectedSource);}@@ -2138,6 +2149,12 @@ export function registerIpcHandlers(// picker they must hand the choice to `open-source-selector` rather than enumerate.ipcMain.handle("uses-system-source-picker", () => macPickerOwnsSources());+ // Named in the HUD and Record mode after a relaunch, while `get-selected-source` still+ // answers null: the pick cannot be restored, so it is never reported as selected.+ ipcMain.handle("get-last-picked-source", () =>+ rememberedPickerSourceName(appSettings.getSnapshot().lastSource, macPickerOwnsSources()),+ );+ipcMain.handle("get-selected-source", async () => {const previousSelectedSource = selectedSource;if (process.platform === "linux" && findPipeWireCursorHelperPath()) {diff --git a/electron/preload.ts b/electron/preload.tsindex 59d54c217..333286bd4 100644--- a/electron/preload.ts+++ b/electron/preload.ts@@ -129,6 +129,9 @@ contextBridge.exposeInMainWorld("electronAPI", {usesSystemSourcePicker: (): Promise<boolean> => {return ipcRenderer.invoke("uses-system-source-picker");},+ getLastPickedSource: (): Promise<string | null> => {+ return ipcRenderer.invoke("get-last-picked-source");+ },openNotes: () => {return ipcRenderer.invoke("open-notes");},diff --git a/electron/recording-source-settings.test.ts b/electron/recording-source-settings.test.tsindex f56a684fa..40aefc588 100644--- a/electron/recording-source-settings.test.ts+++ b/electron/recording-source-settings.test.ts@@ -1,8 +1,10 @@import { describe, expect, it } from "vitest";import {+ describeMacPickerSource,describeRecordingSource,enumerationIncludesSourceKind,mergeEnumeratedSources,+ rememberedPickerSourceName,resolveCurrentRecordingSource,resolveRecordingSource,restoreRecordingSourceAfterEnumeration,@@ -139,3 +141,32 @@ describe("recording source settings", () => {).toEqual(display);});});++describe("the display picked in Apple's picker, kept only to be named", () => {+ const picked = { id: "mac-picker:display:5", name: "Studio Display", display_id: "5" };++ it("describes a display pick as a screen and a window pick as a window", () => {+ expect(describeMacPickerSource(picked, "display")).toEqual({+ platform: "darwin",+ kind: "screen",+ id: "mac-picker:display:5",+ name: "Studio Display",+ displayId: "5",+ });+ // Not derived from the id: `recordingSourceKindFromId` only knows desktopCapturer's+ // `window:` prefix and would call a picked window a screen.+ expect(+ describeMacPickerSource(+ { id: "mac-picker:window:42", name: "Notes", display_id: "" },+ "window",+ ),+ ).toMatchObject({ kind: "window", displayId: null });+ });++ it("names the last pick only where Apple's picker owns the choice", () => {+ const last = describeMacPickerSource(picked, "display");+ expect(rememberedPickerSourceName(last, true)).toBe("Studio Display");+ expect(rememberedPickerSourceName(last, false)).toBeNull();+ expect(rememberedPickerSourceName(null, true)).toBeNull();+ });+});diff --git a/electron/recording-source-settings.ts b/electron/recording-source-settings.tsindex d8d89425b..2480d24a8 100644--- a/electron/recording-source-settings.ts+++ b/electron/recording-source-settings.ts@@ -23,6 +23,36 @@ export function describeRecordingSource(};}+/**+ * What Apple's picker returned, kept only to name it after a relaunch. It is not a+ * restorable descriptor: the filter behind the pick cannot leave the helper, and rebuilding+ * one needs the Screen Recording grant the picker exists to avoid.+ */+export function describeMacPickerSource(+ source: { id: string; name: string; display_id: string },+ kind: "display" | "window",+): RecordingSourceDescriptor {+ return {+ platform: "darwin",+ kind: kind === "window" ? "window" : "screen",+ id: source.id,+ name: source.name,+ displayId: source.display_id || null,+ };+}++/**+ * The name to show for the last pick while nothing is live. Only where Apple's picker owns+ * the choice: everywhere else the descriptor restores a real source, so there is nothing to+ * show in its place.+ */+export function rememberedPickerSourceName(+ lastSource: RecordingSourceDescriptor | null | undefined,+ pickerOwnsSources: boolean,+): string | null {+ return pickerOwnsSources && lastSource ? lastSource.name : null;+}+/*** A screen-only (or window-only) enumeration cannot prove a source of the* other kind is gone. Clearing the live pick in that case is a false negative.diff --git a/src/components/ai-edition/v4/EditorShellV4.module.css b/src/components/ai-edition/v4/EditorShellV4.module.cssindex bed8df50d..11c696b02 100644--- a/src/components/ai-edition/v4/EditorShellV4.module.css+++ b/src/components/ai-edition/v4/EditorShellV4.module.css@@ -978,6 +978,10 @@cursor: pointer;max-width: 220px;}+/* The last pick, not a live one: same button, rest colour. */+.recRowSourceBtnRemembered {+ color: var(--muted);+}.recRowSourceBtn > span,.recRowSourceBtn {white-space: nowrap;diff --git a/src/components/ai-edition/v4/RecStage.test.tsx b/src/components/ai-edition/v4/RecStage.test.tsxindex 0f7a5696c..63fed17ae 100644--- a/src/components/ai-edition/v4/RecStage.test.tsx+++ b/src/components/ai-edition/v4/RecStage.test.tsx@@ -136,6 +136,49 @@ describe("RecStage controls", () => {expect(getSources).not.toHaveBeenCalled();});+ it("names the last pick in the source row only, without selecting it", async () => {+ stubRecordingPrefs({ micEnabled: false });+ const getLastPickedSource = vi.fn(async () => "Studio Display");+ Object.assign(window.electronAPI as unknown as Record<string, unknown>, {+ getLastPickedSource,+ });+ renderRecStage();++ const row = await screen.findByRole("button", { name: "Studio Display" });+ expect(row).toHaveAttribute("data-remembered", "true");+ // Nothing is live: the preview keeps asking what to record.+ expect(screen.getAllByText("rec.selectSource")).toHaveLength(2);+ });++ it("shows a live source in place of the remembered name", async () => {+ stubRecordingPrefs(+ { micEnabled: false },+ { id: "screen:1:0", name: "Display 1", display_id: "1", thumbnail: null, appIcon: null },+ );+ const getLastPickedSource = vi.fn(async () => "Studio Display");+ Object.assign(window.electronAPI as unknown as Record<string, unknown>, {+ getLastPickedSource,+ });+ renderRecStage();++ const row = await screen.findByRole("button", { name: "Display 1" });+ expect(row).not.toHaveAttribute("data-remembered");+ expect(screen.queryByRole("button", { name: "Studio Display" })).toBeNull();+ });++ it("asks to choose when nothing was picked before", async () => {+ stubRecordingPrefs({ micEnabled: false });+ const getLastPickedSource = vi.fn(async () => null);+ Object.assign(window.electronAPI as unknown as Record<string, unknown>, {+ getLastPickedSource,+ });+ renderRecStage();++ await waitFor(() => expect(getLastPickedSource).toHaveBeenCalled());+ const row = screen.getByRole("button", { name: "rec.selectSource" });+ expect(row).not.toHaveAttribute("data-remembered");+ });+it("writes autoZoomEnabled through setRecordingPrefs on click", async () => {const { getRecordingPrefs, setRecordingPrefs } = stubRecordingPrefs({micEnabled: false,diff --git a/src/components/ai-edition/v4/RecStage.tsx b/src/components/ai-edition/v4/RecStage.tsxindex aeb1a99a2..f4f2b2db6 100644--- a/src/components/ai-edition/v4/RecStage.tsx+++ b/src/components/ai-edition/v4/RecStage.tsx@@ -20,6 +20,7 @@ import { useCameraDevices } from "@/hooks/useCameraDevices";import { useCameraPreviewStream } from "@/hooks/useCameraPreviewStream";import { useMicrophoneDevices } from "@/hooks/useMicrophoneDevices";import { usePortalOwnsSource } from "@/hooks/usePortalOwnsSource";+import { useRememberedSourceName } from "@/hooks/useRememberedSourceName";import { canRecordMicrophone, getPlatform } from "@/utils/platformUtils";import styles from "./EditorShellV4.module.css";@@ -196,6 +197,10 @@ export function RecStage({unsubscribe?.();};}, []);+ // Names the last pick in Apple's picker until a new one is made. Only the source row+ // shows it: `source` stays null, so Start recording still opens the picker first and+ // the preview keeps asking what to record.+ const rememberedSourceName = useRememberedSourceName(source !== null);const [sourceModalOpen, setSourceModalOpen] = useState(false);const [sourceTab, setSourceTab] = useState<"screen" | "window">("screen");const [sources, setSources] = useState<ProcessedDesktopSource[]>([]);@@ -262,6 +267,7 @@ export function RecStage({const sourceLabel = portalOwnsSource? t("rec.systemPicker"): (source?.name ?? t("rec.selectSource"));+ const rememberedRow = source === null && rememberedSourceName !== null;return (<div className={styles.recStage}>@@ -335,10 +341,13 @@ export function RecStage({</div><buttontype="button"- className={styles.recRowSourceBtn}+ className={`${styles.recRowSourceBtn}${+ rememberedRow ? ` ${styles.recRowSourceBtnRemembered}` : ""+ }`}+ data-remembered={rememberedRow || undefined}onClick={() => void openSourceModal()}>- {sourceLabel}+ {rememberedRow ? rememberedSourceName : sourceLabel}<ChevronDown size={13} style={{ opacity: 0.6 }} /></button></div>diff --git a/src/components/launch/HudControls.tsx b/src/components/launch/HudControls.tsxindex a84612a8a..b5cfe6284 100644--- a/src/components/launch/HudControls.tsx+++ b/src/components/launch/HudControls.tsx@@ -124,18 +124,24 @@ export const HudTrayLayoutButton = memo(function HudTrayLayoutButton({export const HudSourceButton = memo(function HudSourceButton({vertical,label,+ remembered = false,disabled,onClick,}: {vertical: boolean;label: string;+ /** The label names the last pick, which is not live: same button, rest colour. */+ remembered?: boolean;disabled: boolean;onClick: () => void;}) {return (<buttondata-testid="launch-source-selector-button"- className={`flex h-[34px] shrink-0 items-center gap-[7px] rounded-[10px] border-0 bg-transparent text-[#f5f7fa] transition-all duration-150 hover:bg-white/[0.08] active:scale-[0.97] ${hudDisabledClasses} ${hudFocusClasses} ${+ data-remembered={remembered || undefined}+ className={`flex h-[34px] shrink-0 items-center gap-[7px] rounded-[10px] border-0 bg-transparent ${+ remembered ? "text-[#828c99] hover:text-[#f5f7fa]" : "text-[#f5f7fa]"+ } transition-all duration-150 hover:bg-white/[0.08] active:scale-[0.97] ${hudDisabledClasses} ${hudFocusClasses} ${vertical ? "w-[34px] justify-center px-0" : "pr-3 pl-2.5"} ${styles.electronNoDrag}`}onClick={onClick}diff --git a/src/components/launch/LaunchWindow.test.tsx b/src/components/launch/LaunchWindow.test.tsxindex 6af724a8e..39bd13ea6 100644--- a/src/components/launch/LaunchWindow.test.tsx+++ b/src/components/launch/LaunchWindow.test.tsx@@ -74,6 +74,7 @@ const recorderState = vi.hoisted(() => ({let hudCursorListeners: Array<(x: number, y: number) => void> = [];let selectedSourceChangedListeners: SelectedSourceChangedListener[] = [];let sourceSelectorClosedListeners: Array<() => void> = [];+let lastPickedSourceName: string | null = null;vi.mock("../../hooks/useScreenRecorder", () => ({useScreenRecorder: () => recorderState.value,@@ -233,6 +234,7 @@ function stubElectronAPI(getSelectedSource: Window["electronAPI"]["getSelectedSo...window.electronAPI,getSelectedSource,openSourceSelector: vi.fn(async () => ({ opened: true })),+ getLastPickedSource: vi.fn(async () => lastPickedSourceName),// Follows the platform under test. Pinned to "darwin" before, which was// invisible while only `nativeBridgeClient` was consulted for it — and// silently wrong the moment anything read the platform through here.@@ -334,6 +336,7 @@ function resetLaunchMocks() {hudCursorListeners = [];selectedSourceChangedListeners = [];sourceSelectorClosedListeners = [];+ lastPickedSourceName = null;i18nState.value.systemLocaleSuggestion = null;i18nState.value.acceptSystemLocaleSuggestion.mockClear();i18nState.value.dismissSystemLocaleSuggestion.mockClear();@@ -394,6 +397,50 @@ describe("LaunchWindow record button", () => {expect(screen.getByTestId("launch-record-button")).toHaveAttribute("title", "Display 1");});+ it("names the last pick in Apple's picker without treating it as selected", async () => {+ lastPickedSourceName = "Studio Display";+ renderLaunchWindow();++ const sourceButton = screen.getByTestId("launch-source-selector-button");+ await waitFor(() => expect(sourceButton).toHaveTextContent("Studio Display"));+ expect(sourceButton).toHaveAttribute("data-remembered", "true");+ // Nothing is live, so Record still asks first and only records once a source is chosen.+ expect(screen.getByTestId("launch-record-button")).toHaveAttribute(+ "title",+ "Please select a source to record",+ );+ fireEvent.click(screen.getByTestId("launch-record-button"));+ await waitFor(() => expect(window.electronAPI.openSourceSelector).toHaveBeenCalledTimes(1));+ expect(recorderState.value.toggleRecording).not.toHaveBeenCalled();+ });++ it("shows a live pick in place of the remembered name, and the name again once it is gone", async () => {+ lastPickedSourceName = "Studio Display";+ renderLaunchWindow();+ await waitForSourceSelectionSubscription();+ const sourceButton = screen.getByTestId("launch-source-selector-button");+ await waitFor(() => expect(sourceButton).toHaveTextContent("Studio Display"));++ emitSelectedSourceChanged(displayOneSource);+ await waitFor(() => expect(sourceButton).toHaveTextContent("Display 1"));+ expect(sourceButton).not.toHaveAttribute("data-remembered");++ act(() => {+ selectedSourceChangedListeners.forEach((listener) => listener(null));+ });+ await waitFor(() => expect(sourceButton).toHaveTextContent("Studio Display"));+ expect(sourceButton).toHaveAttribute("data-remembered", "true");+ });++ it("keeps the default name when nothing was picked before", async () => {+ renderLaunchWindow();++ const sourceButton = screen.getByTestId("launch-source-selector-button");+ await waitFor(() => expect(window.electronAPI.getLastPickedSource).toHaveBeenCalled());+ expect(sourceButton).toHaveTextContent("Screen");+ expect(sourceButton).not.toHaveAttribute("data-remembered");+ });+it("does not record after manual source selection", async () => {renderLaunchWindow();await waitForSourceSelectionSubscription();diff --git a/src/components/launch/LaunchWindow.tsx b/src/components/launch/LaunchWindow.tsxindex e72ea2b25..3be181124 100644--- a/src/components/launch/LaunchWindow.tsx+++ b/src/components/launch/LaunchWindow.tsx@@ -12,6 +12,7 @@ import {useMicrophoneDevices,} from "../../hooks/useMicrophoneDevices";import { usePortalOwnsSource } from "../../hooks/usePortalOwnsSource";+import { useRememberedSourceName } from "../../hooks/useRememberedSourceName";import { useScreenRecorder } from "../../hooks/useScreenRecorder";import type { WebcamQualityId } from "../../hooks/webcamCaptureTarget";import { requestCameraAccess } from "../../lib/requestCameraAccess";@@ -612,6 +613,9 @@ export function LaunchWindow() {const defaultSourceName = t("sourceSelector.defaultSourceName");const [selectedSource, setSelectedSource] = useState(defaultSourceName);const [hasSelectedSource, setHasSelectedSource] = useState(false);+ // Names the last pick in Apple's picker until a new one is made. It is only a name:+ // `hasSelectedSource` stays false, so Record still opens the picker first.+ const rememberedSourceName = useRememberedSourceName(hasSelectedSource);const recordAfterSourceSelectionRef = useRef(false);const applySelectedSource = useCallback(@@ -1157,7 +1161,8 @@ export function LaunchWindow() {{!portalOwnsSource && (<HudSourceButtonvertical={isVertical}- label={selectedSource}+ label={hasSelectedSource ? selectedSource : (rememberedSourceName ?? selectedSource)}+ remembered={!hasSelectedSource && rememberedSourceName !== null}disabled={controlsLocked}onClick={openSourceSelector}/>diff --git a/src/hooks/useRememberedSourceName.ts b/src/hooks/useRememberedSourceName.tsnew file mode 100644index 000000000..86b66d276--- /dev/null+++ b/src/hooks/useRememberedSourceName.ts@@ -0,0 +1,35 @@+import { useEffect, useState } from "react";++/**+ * The name of the source picked last time, for a surface that has no live source.+ *+ * Only Apple's picker (macOS 15.2+) answers with a name: its pick cannot be restored after a+ * relaunch, so the main process keeps the name and the selection stays empty. Everywhere else+ * this is `null` and the source restores itself.+ *+ * Asked again whenever the live source goes away, because the name is written when the pick+ * is made, after this surface has already mounted.+ */+export function useRememberedSourceName(hasLiveSource: boolean): string | null {+ const [name, setName] = useState<string | null>(null);++ useEffect(() => {+ if (hasLiveSource) {+ return;+ }+ let active = true;+ void window.electronAPI+ ?.getLastPickedSource?.()+ .then((next) => {+ if (active) {+ setName(next ?? null);+ }+ })+ .catch(() => undefined);+ return () => {+ active = false;+ };+ }, [hasLiveSource]);++ return name;+}