Skip to content

Commit 0e8e4c9

Browse files
committed
Display accessibility permission in general view
1 parent d6a31b7 commit 0e8e4c9

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

Core/Sources/Client/AsyncXPCService.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ public struct AsyncXPCService {
2020
}
2121
}
2222
}
23+
24+
public func getXPCServiceAccessibilityPermission() async throws -> Bool {
25+
try await withXPCServiceConnected(connection: connection) {
26+
service, continuation in
27+
service.getXPCServiceAccessibilityPermission { isGranted in
28+
continuation.resume(isGranted)
29+
}
30+
}
31+
}
2332

2433
public func getSuggestedCode(editorContent: EditorContent) async throws -> UpdatedContent? {
2534
try await suggestionRequest(

Core/Sources/HostApp/GeneralView.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ struct AppInfoView: View {
7272
struct ExtensionServiceView: View {
7373
@Environment(\.toast) var toast
7474
@State var xpcServiceVersion: String?
75-
@State var accessibilityPermissionGranted: Bool?
75+
@State var isAccessibilityPermissionGranted: Bool?
7676
@State var isRunningAction = false
7777

7878
var body: some View {
7979
VStack(alignment: .leading) {
8080
Text("Extension Service Version: \(xpcServiceVersion ?? "Loading..")")
8181
let grantedStatus: String = {
82-
guard let accessibilityPermissionGranted else { return "Loading.." }
83-
return accessibilityPermissionGranted ? "Granted" : "Not Granted"
82+
guard let isAccessibilityPermissionGranted else { return "Loading.." }
83+
return isAccessibilityPermissionGranted ? "Granted" : "Not Granted"
8484
}()
8585
Text("Accessibility Permission: \(grantedStatus)")
8686

@@ -119,6 +119,8 @@ struct ExtensionServiceView: View {
119119
do {
120120
let service = try getService()
121121
xpcServiceVersion = try await service.getXPCServiceVersion().version
122+
isAccessibilityPermissionGranted = try await service
123+
.getXPCServiceAccessibilityPermission()
122124
} catch {
123125
toast(Text(error.localizedDescription), .error)
124126
}

Core/Sources/Service/XPCService.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public class XPCService: NSObject, XPCServiceProtocol {
2929
)
3030
}
3131

32+
public func getXPCServiceAccessibilityPermission(withReply reply: @escaping (Bool) -> Void) {
33+
reply(AXIsProcessTrusted())
34+
}
35+
3236
// MARK: - Suggestion
3337

3438
@discardableResult

Core/Sources/XPCShared/XPCServiceProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ public protocol XPCServiceProtocol {
4949
)
5050

5151
func getXPCServiceVersion(withReply reply: @escaping (String, String) -> Void)
52+
func getXPCServiceAccessibilityPermission(withReply reply: @escaping (Bool) -> Void)
5253
}

0 commit comments

Comments
 (0)