1- import AppKit
2- import Combine
31import Dependencies
42import Foundation
5- import KeyboardShortcuts
63import Workspace
74import WorkspaceSuggestionService
85import XcodeInspector
@@ -16,10 +13,6 @@ import ProService
1613 public static let shared = TheActor ( )
1714}
1815
19- extension KeyboardShortcuts . Name {
20- static let showHideWidget = Self ( " ShowHideWidget " )
21- }
22-
2316/// The running extension service.
2417public final class Service {
2518 public static let shared = Service ( )
@@ -70,68 +63,3 @@ public final class Service {
7063 }
7164}
7265
73- @MainActor
74- final class GlobalShortcutManager {
75- let guiController : GraphicalUserInterfaceController
76- private var cancellable = Set < AnyCancellable > ( )
77-
78- nonisolated init ( guiController: GraphicalUserInterfaceController ) {
79- self . guiController = guiController
80- }
81-
82- func start( ) {
83- KeyboardShortcuts . userDefaults = . shared
84- setupShortcutIfNeeded ( )
85-
86- KeyboardShortcuts . onKeyUp ( for: . showHideWidget) { [ guiController] in
87- let isXCodeActive = XcodeInspector . shared. activeXcode != nil
88- let isExtensionActive = NSApplication . shared. isActive
89-
90- if !isXCodeActive,
91- !guiController. viewStore. state. suggestionWidgetState. chatPanelState. isPanelDisplayed,
92- UserDefaults . shared. value ( for: \. showHideWidgetShortcutGlobally)
93- {
94- guiController. viewStore. send ( . openChatPanel( forceDetach: true ) )
95- } else {
96- guiController. viewStore. send ( . suggestionWidget( . circularWidget( . widgetClicked) ) )
97- }
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- }
109- }
110-
111- XcodeInspector . shared. $activeApplication. sink { app in
112- if !UserDefaults. shared. value ( for: \. showHideWidgetShortcutGlobally) {
113- let shouldBeEnabled = if let app, app. isXcode || app. isExtensionService {
114- true
115- } else {
116- false
117- }
118- if shouldBeEnabled {
119- self . setupShortcutIfNeeded ( )
120- } else {
121- self . removeShortcutIfNeeded ( )
122- }
123- } else {
124- self . setupShortcutIfNeeded ( )
125- }
126- } . store ( in: & cancellable)
127- }
128-
129- func setupShortcutIfNeeded( ) {
130- KeyboardShortcuts . enable ( . showHideWidget)
131- }
132-
133- func removeShortcutIfNeeded( ) {
134- KeyboardShortcuts . disable ( . showHideWidget)
135- }
136- }
137-
0 commit comments