Skip to content

Commit fe56fa2

Browse files
heyitsR1claude
andcommitted
fix(macos): raise the Screen Recording prompt on first run
`requestScreenAccess` only raised the TCC prompt when `getMediaAccessStatus("screen")` returned "not-determined", which macOS never reports. Chromium resolves that permission through `CGPreflightScreenCaptureAccess()`, a bool, so a machine that has never been asked is indistinguishable from an explicit refusal and both arrive as "denied". A first run therefore fell straight through to the "open System Settings" dialog without macOS ever being asked, leaving a manual toggle as the only way to grant. The renderer's retry loop in openSourceSelectorFlow arms on the same status and never ran either. Decide from whether this launch has already asked instead. The first ask raises the prompt and reports "not-determined" so the retry loop arms; later asks report the real status so the Settings dialog still reaches a user who genuinely refused, without re-prompting on every click. Verified on macOS 26.2: with no TCC screen-capture row for the bundle, getMediaAccessStatus("screen") returns "denied" while getMediaAccessStatus("camera") returns "not-determined". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent df4e00a commit fe56fa2

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

‎electron/ipc/handlers.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import { patchWebmDurationOnDisk } from "../recording/webm-duration";
7979
import { reindexRecordingOnDisk } from "../recording/webm-seek-index";
8080
import { registerNativeBridgeHandlers } from "./nativeBridge";
8181
import { RecordingStreamRegistry, registerRecordingStreamHandlers } from "./recordingStream";
82+
import { shouldPromptForScreenAccess } from "./screenAccessPrompt";
8283

8384
const PROJECT_FILE_EXTENSION = "openscreen";
8485
export const SHORTCUTS_FILE = path.join(app.getPath("userData"), "shortcuts.json");
@@ -455,6 +456,8 @@ type AttachNativeMacWebcamRecordingInput = {
455456

456457
let selectedSource: SelectedSource | null = null;
457458
let selectedDesktopSource: DesktopCapturerSource | null = null;
459+
/** macOS raises its Screen Recording prompt once per launch. */
460+
let hasPromptedForScreenAccess = false;
458461
let lastEnumeratedSources = new Map<string, DesktopCapturerSource>();
459462
let currentProjectPath: string | null = null;
460463
let currentRecordingSession: RecordingSession | null = null;
@@ -1674,7 +1677,14 @@ export function registerIpcHandlers(
16741677

16751678
// Screen recording has no askForMediaAccess equivalent, so trigger the
16761679
// TCC prompt without opening OpenScreen's source selector above it.
1677-
if (status === "not-determined") {
1680+
// macOS reports a never-asked machine as "denied", so the decision has to
1681+
// come from shouldPromptForScreenAccess rather than the status alone.
1682+
//
1683+
// Report "not-determined" while that prompt is up: it is the status the
1684+
// renderer's retry loop polls on, and macOS keeps answering "denied"
1685+
// until the user actually accepts.
1686+
if (shouldPromptForScreenAccess(status, hasPromptedForScreenAccess)) {
1687+
hasPromptedForScreenAccess = true;
16781688
const mainWin = getMainWindow();
16791689
if (mainWin && !mainWin.isDestroyed()) {
16801690
if (!mainWin.isVisible()) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it } from "vitest";
2+
import { shouldPromptForScreenAccess } from "./screenAccessPrompt";
3+
4+
describe("shouldPromptForScreenAccess", () => {
5+
it("never prompts once the permission is granted", () => {
6+
expect(shouldPromptForScreenAccess("granted", false)).toBe(false);
7+
expect(shouldPromptForScreenAccess("granted", true)).toBe(false);
8+
});
9+
10+
it("prompts on the first ask of a launch even though macOS reports denied", () => {
11+
// The regression this guards: macOS collapses "never asked" into "denied",
12+
// so a first run used to skip the prompt entirely.
13+
expect(shouldPromptForScreenAccess("denied", false)).toBe(true);
14+
});
15+
16+
it("stops prompting after this launch has already asked", () => {
17+
// Lets the caller report the real status so the Settings dialog takes over
18+
// instead of re-prompting on every click.
19+
expect(shouldPromptForScreenAccess("denied", true)).toBe(false);
20+
expect(shouldPromptForScreenAccess("restricted", true)).toBe(false);
21+
});
22+
23+
it("still prompts on not-determined, whatever this launch has already asked", () => {
24+
expect(shouldPromptForScreenAccess("not-determined", false)).toBe(true);
25+
expect(shouldPromptForScreenAccess("not-determined", true)).toBe(true);
26+
});
27+
});

‎electron/ipc/screenAccessPrompt.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Decides whether to raise macOS' own Screen Recording prompt.
3+
*
4+
* `systemPreferences.getMediaAccessStatus("screen")` cannot answer
5+
* "not-determined" on macOS. Chromium resolves that permission through
6+
* `CGPreflightScreenCaptureAccess()`, a bool, so a machine that has never been
7+
* asked is reported exactly like an explicit refusal — both arrive as "denied".
8+
* Gating the prompt on `status === "not-determined"` therefore never fires: a
9+
* fresh install falls straight through to the "open System Settings" dialog and
10+
* macOS is never given the chance to ask, so the only way to grant is a manual
11+
* toggle. The renderer's permission-retry loop arms on the same status and is
12+
* dead for the same reason.
13+
*
14+
* Drive the first prompt off whether this launch has already asked instead.
15+
* Asking once per launch keeps a genuine refusal from re-prompting on every
16+
* click, and lets the next call report the real status so the Settings dialog
17+
* still reaches a user who said no.
18+
*/
19+
export function shouldPromptForScreenAccess(
20+
status: string,
21+
hasPromptedThisLaunch: boolean,
22+
): boolean {
23+
if (status === "granted") {
24+
return false;
25+
}
26+
27+
return status === "not-determined" || !hasPromptedThisLaunch;
28+
}

0 commit comments

Comments
 (0)