Fix stale permission display for Screen Recording and Accessibility#17
Merged
Conversation
CGPreflightScreenCaptureAccess() caches its result per-process on macOS 15+, so granting Screen Recording in System Settings while the app runs never flips the UI to "Granted". Fix by polling SCShareableContent.excludingDesktopWindows every 3 s — this call goes through ScreenCaptureKit's own path and is not subject to the same per-process cache. AXIsProcessTrusted() can similarly return stale TCC data. Add a live fallback: attempt AXUIElementCopyAttributeValue on the system-wide element; only kAXErrorAPIDisabled and kAXErrorNotTrusted mean the process lacks permission, all other results (including kAXErrorNoValue for "no focused app") confirm trust. isScreenCaptureGranted and openScreenCaptureSettings are updated to use the same live check so the rest of the app (tap preflight path, status banner) is consistent with the Settings UI.
Extracts the OR-logic from screenCaptureState() and accessibilityState() into public static helpers (screenCapturePermissionState / accessibilityPermissionState) so the decision branches can be exercised without real OS API calls. Tests cover all four boolean combinations for each permission, with explicit regression cases for the macOS 15+ stale-TCC scenario: sync=false/live=true (Screen Recording) and isTrusted=false/liveGranted=true (Accessibility), which were the exact conditions that caused the "always shows not granted" bug.
Static methods on a @mainactor class inherit MainActor isolation in Swift 6, making them uncallable from non-isolated contexts (compile error). The two pure helper functions only operate on plain Bool/PermissionState values and access no actor state, so nonisolated is correct — matching the existing pattern used by MeetingDetector.isTeamsMainApp and cleanWindowTitle.
The AXError C enum does not define kAXErrorNotTrusted — the enum jumps directly from kAXErrorAPIDisabled (-25211) to kAXErrorNoValue (-25212). Removing the non-existent check; kAXErrorAPIDisabled alone correctly identifies the "process not trusted" case. https://claude.ai/code/session_01SLK18VAKHQdk37Mubvyp47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CGPreflightScreenCaptureAccess()andAXIsProcessTrusted()cache their results per-process on macOS 15+; once they returnfalseat launch, they never updateSCShareableContent.excludingDesktopWindowsfor screen capture, andAXUIElementCopyAttributeValuefor accessibility — and show.grantedif either the cached or live check succeedsscreenCapturePermissionState(syncGranted:liveGranted:)andaccessibilityPermissionState(isTrusted:liveGranted:)onPermissionCenter, and added 9 tests inPermissionCenterTests.swiftcovering all boolean combinations including the regression casesnonisolatedto static helpers (Swift 6@MainActorisolation), and removed non-existentAXError.notTrustedmember (onlyAXError.apiDisabledexists in the enum)Test plan
Heard.appvia./scripts/bundle.sh && open build/Heard.appswift run HeardTests— all 9 permission tests pass