From 76d1053aaf47724587f0dc208385f9477289d8b4 Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Wed, 16 Sep 2026 03:57:27 -0700 Subject: [PATCH] input-capture: public init for PermissionState (app-engine request 1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cross-lane edit, authorised by the lead. The struct declared two public lets and no init, so the memberwise one was internal and no other target could build a value — `EngineSnapshot.permissions` had to default to `Permissions.preflight()`, i.e. a TCC query, just to have a value to hold. The default is now `PermissionState(listen: false, post: false)`, which is also the honest value before `start()` has read anything. Co-Authored-By: Claude Opus 5 (1M context) --- Sources/MWBMac/Permissions.swift | 11 +++++++++++ Sources/mwb/Engine.swift | 5 +++-- docs/features/input-capture/README.md | 3 ++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Sources/MWBMac/Permissions.swift b/Sources/MWBMac/Permissions.swift index 860ae65..7e2c8b4 100644 --- a/Sources/MWBMac/Permissions.swift +++ b/Sources/MWBMac/Permissions.swift @@ -23,6 +23,17 @@ public struct PermissionState: Equatable, Sendable { /// Accessibility granted. public let post: Bool + /// A state with both grants named explicitly. + /// + /// Public so another target can build one without asking TCC: a menu bar or + /// a snapshot needs a "nothing granted yet" value before `preflight()` has + /// ever run, and `preflight()` is a system query, not a constructor + /// (app-engine request 1, authorised by the lead). + public init(listen: Bool, post: Bool) { + self.listen = listen + self.post = post + } + /// True when both permissions are granted. public var isComplete: Bool { listen && post } } diff --git a/Sources/mwb/Engine.swift b/Sources/mwb/Engine.swift index 42d3164..077ed3a 100644 --- a/Sources/mwb/Engine.swift +++ b/Sources/mwb/Engine.swift @@ -62,8 +62,9 @@ public struct EngineSnapshot: Sendable { public var controlled: String? /// Whether ALL-machines mode is on. public var broadcasting = false - /// Input Monitoring / Accessibility as macOS reports them. - public var permissions = Permissions.preflight() + /// Input Monitoring / Accessibility as macOS reports them. The default is + /// "neither", not a `preflight()`: building a snapshot must not query TCC. + public var permissions = PermissionState(listen: false, post: false) /// Whether the event tap is installed. public var tapRunning = false /// False when the process could not make a `CGEventSource`, so nothing this diff --git a/docs/features/input-capture/README.md b/docs/features/input-capture/README.md index bbffc5d..e8edf67 100644 --- a/docs/features/input-capture/README.md +++ b/docs/features/input-capture/README.md @@ -300,7 +300,8 @@ public final class Cursor: Sendable { var isDecoupled: Bool { get } func restoreEverything() // atexit / signal handler } -public struct PermissionState: Equatable, Sendable { let listen, post: Bool; var isComplete: Bool } +public struct PermissionState: Equatable, Sendable { public init(listen: Bool, post: Bool) + let listen, post: Bool; var isComplete: Bool } public enum Permissions { static let healthCheckInterval: TimeInterval // 5 static func preflight() -> PermissionState