Skip to content

Commit 1dd4c21

Browse files
committed
Release 0.31.0
1 parent c933346 commit 1dd4c21

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

Tool/Sources/AXNotificationStream/AXNotificationStream.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public final class AXNotificationStream: AsyncSequence {
110110
)
111111
var pendingRegistrationNames = Set(notificationNames)
112112
var retry = 0
113+
var shouldLogAXDisabledEvent: Bool = true
113114
while !pendingRegistrationNames.isEmpty, retry < 100 {
114115
guard let self else { return }
115116
retry += 1
@@ -125,14 +126,18 @@ public final class AXNotificationStream: AsyncSequence {
125126
}
126127
switch e {
127128
case .success:
129+
shouldLogAXDisabledEvent = true
128130
pendingRegistrationNames.remove(name)
129131
await Status.shared.updateAXStatus(.granted)
130132
case .actionUnsupported:
131133
Logger.service.error("AXObserver: Action unsupported: \(name)")
132134
pendingRegistrationNames.remove(name)
133135
case .apiDisabled:
134-
Logger.service
135-
.error("AXObserver: Accessibility API disabled, will try again later")
136+
if shouldLogAXDisabledEvent { // Avoid keeping log AX disabled too many times
137+
shouldLogAXDisabledEvent = false
138+
Logger.service
139+
.error("AXObserver: Accessibility API disabled, will try again later")
140+
}
136141
retry -= 1
137142
await Status.shared.updateAXStatus(.notGranted)
138143
case .invalidUIElement:

Tool/Sources/BuiltinExtension/BuiltinExtensionTelemetryServiceProvider.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ public final class BuiltinExtensionTelemetryServiceProvider<
4343

4444
public func sendError(_ request: TelemetryExceptionRequest) async throws {
4545
guard let telemetryService else {
46-
Logger.service.error("Builtin telemetry service not found.")
46+
print("Builtin telemetry service not found.")
4747
throw BuiltinExtensionTelemetryServiceNotFoundError()
4848
}
4949
guard let workspaceInfo = await activeWorkspace() else {
50-
Logger.service.error("Builtin active workspace info not found.")
50+
print("Builtin active workspace info not found.")
5151
throw BuiltinExtensionActiveWorkspaceInfoNotFoundError()
5252
}
5353

Tool/Sources/XcodeInspector/XcodeInspector+TriggerCommand.swift

+25
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,33 @@ public extension XcodeAppInstanceInspector {
77
func triggerCopilotCommand(name: String, activateXcode: Bool = true) async throws {
88
let bundleName = Bundle.main
99
.object(forInfoDictionaryKey: "EXTENSION_BUNDLE_NAME") as! String
10+
11+
guard await isBundleEnabled(bundleName: bundleName) else {
12+
print("Bundle \(bundleName) is not enabled")
13+
return
14+
}
15+
1016
try await triggerMenuItem(path: ["Editor", bundleName, name], activateApp: activateXcode)
1117
}
18+
19+
private func isBundleEnabled(bundleName: String) async -> Bool {
20+
let app = AXUIElementCreateApplication(runningApplication.processIdentifier)
21+
22+
guard let menuBar = app.menuBar,
23+
let editorMenu = menuBar.child(title: "Editor") else {
24+
return false
25+
}
26+
27+
if let bundleMenuItem = editorMenu.child(title: bundleName, role: "AXMenuItem") {
28+
var enabled: CFTypeRef?
29+
let error = AXUIElementCopyAttributeValue(bundleMenuItem, kAXEnabledAttribute as CFString, &enabled)
30+
if error == .success, let isEnabled = enabled as? Bool {
31+
return isEnabled
32+
}
33+
}
34+
35+
return false
36+
}
1237
}
1338

1439
public extension AppInstanceInspector {

0 commit comments

Comments
 (0)