Mac: fix permission prompt crash
This commit is contained in:
@@ -8,7 +8,6 @@ import Speech
|
|||||||
import UserNotifications
|
import UserNotifications
|
||||||
|
|
||||||
enum PermissionManager {
|
enum PermissionManager {
|
||||||
@MainActor
|
|
||||||
static func ensure(_ caps: [Capability], interactive: Bool) async -> [Capability: Bool] {
|
static func ensure(_ caps: [Capability], interactive: Bool) async -> [Capability: Bool] {
|
||||||
var results: [Capability: Bool] = [:]
|
var results: [Capability: Bool] = [:]
|
||||||
for cap in caps {
|
for cap in caps {
|
||||||
@@ -43,11 +42,13 @@ enum PermissionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case .accessibility:
|
case .accessibility:
|
||||||
let trusted = AXIsProcessTrusted()
|
let trusted = await MainActor.run { AXIsProcessTrusted() }
|
||||||
results[cap] = trusted
|
results[cap] = trusted
|
||||||
if interactive, !trusted {
|
if interactive, !trusted {
|
||||||
let opts: NSDictionary = ["AXTrustedCheckOptionPrompt": true]
|
await MainActor.run {
|
||||||
_ = AXIsProcessTrustedWithOptions(opts)
|
let opts: NSDictionary = ["AXTrustedCheckOptionPrompt": true]
|
||||||
|
_ = AXIsProcessTrustedWithOptions(opts)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case .screenRecording:
|
case .screenRecording:
|
||||||
@@ -81,7 +82,6 @@ enum PermissionManager {
|
|||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
@MainActor
|
|
||||||
static func status(_ caps: [Capability] = Capability.allCases) async -> [Capability: Bool] {
|
static func status(_ caps: [Capability] = Capability.allCases) async -> [Capability: Bool] {
|
||||||
var results: [Capability: Bool] = [:]
|
var results: [Capability: Bool] = [:]
|
||||||
for cap in caps {
|
for cap in caps {
|
||||||
@@ -93,7 +93,7 @@ enum PermissionManager {
|
|||||||
|| settings.authorizationStatus == .provisional
|
|| settings.authorizationStatus == .provisional
|
||||||
|
|
||||||
case .accessibility:
|
case .accessibility:
|
||||||
results[cap] = AXIsProcessTrusted()
|
results[cap] = await MainActor.run { AXIsProcessTrusted() }
|
||||||
|
|
||||||
case .screenRecording:
|
case .screenRecording:
|
||||||
if #available(macOS 10.15, *) {
|
if #available(macOS 10.15, *) {
|
||||||
@@ -184,12 +184,12 @@ final class PermissionMonitor: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.isChecking = true
|
self.isChecking = true
|
||||||
self.lastCheck = now
|
|
||||||
|
|
||||||
let latest = await PermissionManager.status()
|
let latest = await PermissionManager.status()
|
||||||
if latest != self.status {
|
if latest != self.status {
|
||||||
self.status = latest
|
self.status = latest
|
||||||
}
|
}
|
||||||
|
self.lastCheck = Date()
|
||||||
|
|
||||||
self.isChecking = false
|
self.isChecking = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ final class ClawdisXPCService: NSObject, ClawdisXPCProtocol {
|
|||||||
|
|
||||||
func handle(_ data: Data, withReply reply: @escaping @Sendable (Data?, Error?) -> Void) {
|
func handle(_ data: Data, withReply reply: @escaping @Sendable (Data?, Error?) -> Void) {
|
||||||
let logger = logger
|
let logger = logger
|
||||||
Task.detached(priority: nil) { @Sendable in
|
Task.detached { @Sendable in
|
||||||
do {
|
do {
|
||||||
let request = try JSONDecoder().decode(Request.self, from: data)
|
let request = try JSONDecoder().decode(Request.self, from: data)
|
||||||
let response = try await Self.process(request: request, notifier: NotificationManager(), logger: logger)
|
let response = try await Self.process(request: request, notifier: NotificationManager(), logger: logger)
|
||||||
let encoded = try JSONEncoder().encode(response)
|
let encoded = try JSONEncoder().encode(response)
|
||||||
reply(encoded, nil)
|
await MainActor.run { reply(encoded, nil) }
|
||||||
} catch {
|
} catch {
|
||||||
logger.error("Failed to handle XPC request: \(error.localizedDescription, privacy: .public)")
|
logger.error("Failed to handle XPC request: \(error.localizedDescription, privacy: .public)")
|
||||||
let resp = Response(ok: false, message: "decode/handle error: \(error.localizedDescription)")
|
let resp = Response(ok: false, message: "decode/handle error: \(error.localizedDescription)")
|
||||||
reply(try? JSONEncoder().encode(resp), error)
|
await MainActor.run { reply(try? JSONEncoder().encode(resp), error) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user