Skip to content

Commit 012b4f9

Browse files
committed
Make activateXcode optional
1 parent dd95c9a commit 012b4f9

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Pro

Submodule Pro updated from b49fbf2 to 1d6bb19

Tool/Sources/XcodeInspector/XcodeInspector.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -549,15 +549,16 @@ extension XcodeAppInstanceInspector {
549549
// MARK: - Triggering Command
550550

551551
public extension XcodeAppInstanceInspector {
552-
func triggerCopilotCommand(name: String) async throws {
552+
func triggerCopilotCommand(name: String, activateXcode: Bool = true) async throws {
553553
let bundleName = Bundle.main
554554
.object(forInfoDictionaryKey: "EXTENSION_BUNDLE_NAME") as! String
555-
try await triggerMenuItem(path: ["Editor", bundleName, name])
555+
try await triggerMenuItem(path: ["Editor", bundleName, name], activateXcode: activateXcode)
556556
}
557557
}
558558

559559
public extension AppInstanceInspector {
560-
func triggerMenuItem(path: [String]) async throws {
560+
@MainActor
561+
func triggerMenuItem(path: [String], activateXcode: Bool) async throws {
561562
guard !path.isEmpty else { return }
562563

563564
struct CantRunCommand: Error, LocalizedError {
@@ -567,7 +568,17 @@ public extension AppInstanceInspector {
567568
}
568569
}
569570

570-
if !runningApplication.isActive { runningApplication.activate() }
571+
if activateXcode {
572+
if !runningApplication.activate() {
573+
throw CantRunCommand(path: path)
574+
}
575+
} else {
576+
if !runningApplication.isActive {
577+
throw CantRunCommand(path: path)
578+
}
579+
}
580+
581+
await Task.yield()
571582

572583
if UserDefaults.shared.value(for: \.triggerActionWithAccessibilityAPI) {
573584
let app = AXUIElementCreateApplication(runningApplication.processIdentifier)
@@ -617,7 +628,6 @@ public extension AppInstanceInspector {
617628
set theprocs to every process whose unix id is \
618629
\(runningApplication.processIdentifier)
619630
repeat with proc in theprocs
620-
set the frontmost of proc to true
621631
tell proc
622632
repeat with theMenu in menus of menu bar 1
623633
set theValue to value of attribute "AXVisibleChildren" of theMenu

0 commit comments

Comments
 (0)