Skip to content

Commit 257c025

Browse files
committed
Update to activate extension app when using hotkey to show widgets
1 parent fa7dc18 commit 257c025

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Core/Sources/Service/Service.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import AppKit
12
import Combine
23
import Dependencies
34
import Foundation
@@ -83,14 +84,28 @@ final class GlobalShortcutManager {
8384
setupShortcutIfNeeded()
8485

8586
KeyboardShortcuts.onKeyUp(for: .showHideWidget) { [guiController] in
86-
if XcodeInspector.shared.activeXcode == nil,
87+
let isXCodeActive = XcodeInspector.shared.activeXcode != nil
88+
let isExtensionActive = NSApplication.shared.isActive
89+
90+
if !isXCodeActive,
8791
!guiController.viewStore.state.suggestionWidgetState.chatPanelState.isPanelDisplayed,
8892
UserDefaults.shared.value(for: \.showHideWidgetShortcutGlobally)
8993
{
9094
guiController.viewStore.send(.openChatPanel(forceDetach: true))
9195
} else {
9296
guiController.viewStore.send(.suggestionWidget(.circularWidget(.widgetClicked)))
9397
}
98+
99+
if !isExtensionActive {
100+
Task {
101+
try await Task.sleep(nanoseconds: 150_000_000)
102+
NSApplication.shared.activate(ignoringOtherApps: true)
103+
}
104+
} else if let previous = XcodeInspector.shared.previousActiveApplication,
105+
!previous.isActive
106+
{
107+
previous.runningApplication.activate()
108+
}
94109
}
95110

96111
XcodeInspector.shared.$activeApplication.sink { app in

Tool/Sources/XcodeInspector/XcodeInspector.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public final class XcodeInspector: ObservableObject {
1414
private var activeXcodeCancellable = Set<AnyCancellable>()
1515

1616
@Published public internal(set) var activeApplication: AppInstanceInspector?
17+
@Published public internal(set) var previousActiveApplication: AppInstanceInspector?
1718
@Published public internal(set) var activeXcode: XcodeAppInstanceInspector?
1819
@Published public internal(set) var latestActiveXcode: XcodeAppInstanceInspector?
1920
@Published public internal(set) var xcodes: [XcodeAppInstanceInspector] = []
@@ -110,6 +111,7 @@ public final class XcodeInspector: ObservableObject {
110111
setActiveXcode(new)
111112
}
112113
} else {
114+
previousActiveApplication = activeApplication
113115
activeApplication = AppInstanceInspector(runningApplication: app)
114116
}
115117
}
@@ -145,6 +147,7 @@ public final class XcodeInspector: ObservableObject {
145147

146148
@MainActor
147149
func setActiveXcode(_ xcode: XcodeAppInstanceInspector) {
150+
previousActiveApplication = activeApplication
148151
activeApplication = xcode
149152
xcode.refresh()
150153
for task in activeXcodeObservations { task.cancel() }

0 commit comments

Comments
 (0)