Files
orca/native/computer-use-macos/Sources/OrcaComputerUseMacOSCore/SessionLockProbe.swift
T
Jinwoo Hong aaa61af50a fix(computer): report a locked screen instead of missing Accessibility (#42277)
* fix(computer): report a locked screen instead of missing Accessibility

Behind the lock screen (display sleep, screen saver or a manual lock) macOS reports Accessibility as untrusted. Orca read that as a missing permission, and its recovery hint led agents to open System Settings. Check the session lock first and return screen_locked; permission setup refuses while locked.

* fix(computer): recheck the lock under the provider lock and at setup launch

* fix(computer): read the lock fresh for setup and keep locked status reads out of the cache

* refactor(computer): drop the extra lock read at setup; the status and setup helper already check it
2026-11-14 02:43:37 -05:00

20 lines
983 B
Swift

import CoreGraphics
import Foundation
// Why: display sleep, the screen saver and a manual lock all put the session behind the lock screen, where macOS
// reports Accessibility as untrusted and hides app windows; without this check that reads as a missing permission.
public enum SessionLockProbe {
public static let screenIsLockedKey = "CGSSessionScreenIsLocked"
public static let lockedMessage = "The Mac's screen is locked or asleep, so Orca can't see or control windows. Wake and unlock the Mac, then retry."
/// Read fresh on every call: the lock can start or end at any moment.
public static func isLocked() -> Bool {
isLocked(session: CGSessionCopyCurrentDictionary() as? [String: Any])
}
/// No session dictionary (no window-server session) or no key is how an unlocked session reports itself.
public static func isLocked(session: [String: Any]?) -> Bool {
(session?[screenIsLockedKey] as? NSNumber)?.boolValue ?? false
}
}