From 1dd4c218dcf32389a465078c9112ec08fb7f905b Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Wed, 12 Feb 2025 14:31:28 +0000 Subject: [PATCH] Release 0.31.0 --- .../AXNotificationStream.swift | 9 +++++-- ...tinExtensionTelemetryServiceProvider.swift | 4 +-- .../XcodeInspector+TriggerCommand.swift | 25 +++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Tool/Sources/AXNotificationStream/AXNotificationStream.swift b/Tool/Sources/AXNotificationStream/AXNotificationStream.swift index 2a7fa16..7354ef2 100644 --- a/Tool/Sources/AXNotificationStream/AXNotificationStream.swift +++ b/Tool/Sources/AXNotificationStream/AXNotificationStream.swift @@ -110,6 +110,7 @@ public final class AXNotificationStream: AsyncSequence { ) var pendingRegistrationNames = Set(notificationNames) var retry = 0 + var shouldLogAXDisabledEvent: Bool = true while !pendingRegistrationNames.isEmpty, retry < 100 { guard let self else { return } retry += 1 @@ -125,14 +126,18 @@ public final class AXNotificationStream: AsyncSequence { } switch e { case .success: + shouldLogAXDisabledEvent = true pendingRegistrationNames.remove(name) await Status.shared.updateAXStatus(.granted) case .actionUnsupported: Logger.service.error("AXObserver: Action unsupported: \(name)") pendingRegistrationNames.remove(name) case .apiDisabled: - Logger.service - .error("AXObserver: Accessibility API disabled, will try again later") + if shouldLogAXDisabledEvent { // Avoid keeping log AX disabled too many times + shouldLogAXDisabledEvent = false + Logger.service + .error("AXObserver: Accessibility API disabled, will try again later") + } retry -= 1 await Status.shared.updateAXStatus(.notGranted) case .invalidUIElement: diff --git a/Tool/Sources/BuiltinExtension/BuiltinExtensionTelemetryServiceProvider.swift b/Tool/Sources/BuiltinExtension/BuiltinExtensionTelemetryServiceProvider.swift index c78899e..df7a390 100644 --- a/Tool/Sources/BuiltinExtension/BuiltinExtensionTelemetryServiceProvider.swift +++ b/Tool/Sources/BuiltinExtension/BuiltinExtensionTelemetryServiceProvider.swift @@ -43,11 +43,11 @@ public final class BuiltinExtensionTelemetryServiceProvider< public func sendError(_ request: TelemetryExceptionRequest) async throws { guard let telemetryService else { - Logger.service.error("Builtin telemetry service not found.") + print("Builtin telemetry service not found.") throw BuiltinExtensionTelemetryServiceNotFoundError() } guard let workspaceInfo = await activeWorkspace() else { - Logger.service.error("Builtin active workspace info not found.") + print("Builtin active workspace info not found.") throw BuiltinExtensionActiveWorkspaceInfoNotFoundError() } diff --git a/Tool/Sources/XcodeInspector/XcodeInspector+TriggerCommand.swift b/Tool/Sources/XcodeInspector/XcodeInspector+TriggerCommand.swift index e6ea06e..a3dcba6 100644 --- a/Tool/Sources/XcodeInspector/XcodeInspector+TriggerCommand.swift +++ b/Tool/Sources/XcodeInspector/XcodeInspector+TriggerCommand.swift @@ -7,8 +7,33 @@ public extension XcodeAppInstanceInspector { func triggerCopilotCommand(name: String, activateXcode: Bool = true) async throws { let bundleName = Bundle.main .object(forInfoDictionaryKey: "EXTENSION_BUNDLE_NAME") as! String + + guard await isBundleEnabled(bundleName: bundleName) else { + print("Bundle \(bundleName) is not enabled") + return + } + try await triggerMenuItem(path: ["Editor", bundleName, name], activateApp: activateXcode) } + + private func isBundleEnabled(bundleName: String) async -> Bool { + let app = AXUIElementCreateApplication(runningApplication.processIdentifier) + + guard let menuBar = app.menuBar, + let editorMenu = menuBar.child(title: "Editor") else { + return false + } + + if let bundleMenuItem = editorMenu.child(title: bundleName, role: "AXMenuItem") { + var enabled: CFTypeRef? + let error = AXUIElementCopyAttributeValue(bundleMenuItem, kAXEnabledAttribute as CFString, &enabled) + if error == .success, let isEnabled = enabled as? Bool { + return isEnabled + } + } + + return false + } } public extension AppInstanceInspector {