@@ -79,7 +79,7 @@ public struct WidgetFeature: ReducerProtocol {
7979 )
8080 }
8181 }
82-
82+
8383 var lastUpdateWindowOpacityTime = Date ( timeIntervalSince1970: 0 )
8484
8585 public init ( ) { }
@@ -213,10 +213,10 @@ public struct WidgetFeature: ReducerProtocol {
213213
214214 case . observeActiveApplicationChange:
215215 return . run { send in
216- var previousApp : NSRunningApplication ?
217- for await app in activeApplicationMonitor. createStream ( ) {
216+ var previousApp : RunningApplicationInfo ?
217+ for await app in activeApplicationMonitor. createInfoStream ( ) {
218218 try Task . checkCancellation ( )
219- if app != previousApp {
219+ if app? . processIdentifier != previousApp? . processIdentifier {
220220 await send ( . updateActiveApplication)
221221 }
222222 previousApp = app
@@ -311,26 +311,26 @@ public struct WidgetFeature: ReducerProtocol {
311311 case . observeWindowChange:
312312 guard let app = activeApplicationMonitor. activeApplication else { return . none }
313313 guard app. isXcode else { return . none }
314-
314+
315315 let documentURL = state. focusingDocumentURL
316316
317- return . run { [ app] send in
318- await send ( . observeEditorChange)
317+ let notifications = AXNotificationStream (
318+ app: app,
319+ notificationNames:
320+ kAXApplicationActivatedNotification,
321+ kAXMovedNotification,
322+ kAXResizedNotification,
323+ kAXMainWindowChangedNotification,
324+ kAXFocusedWindowChangedNotification,
325+ kAXFocusedUIElementChangedNotification,
326+ kAXWindowMovedNotification,
327+ kAXWindowResizedNotification,
328+ kAXWindowMiniaturizedNotification,
329+ kAXWindowDeminiaturizedNotification
330+ )
319331
320- let notifications = AXNotificationStream (
321- app: app,
322- notificationNames:
323- kAXApplicationActivatedNotification,
324- kAXMovedNotification,
325- kAXResizedNotification,
326- kAXMainWindowChangedNotification,
327- kAXFocusedWindowChangedNotification,
328- kAXFocusedUIElementChangedNotification,
329- kAXWindowMovedNotification,
330- kAXWindowResizedNotification,
331- kAXWindowMiniaturizedNotification,
332- kAXWindowDeminiaturizedNotification
333- )
332+ return . run { send in
333+ await send ( . observeEditorChange)
334334
335335 for await notification in notifications {
336336 try Task . checkCancellation ( )
@@ -369,45 +369,46 @@ public struct WidgetFeature: ReducerProtocol {
369369
370370 case . observeEditorChange:
371371 guard let app = activeApplicationMonitor. activeApplication else { return . none }
372- return . run { send in
373- let appElement = AXUIElementCreateApplication ( app . processIdentifier )
374- if let focusedElement = appElement . focusedElement ,
375- focusedElement . description == " Source Editor " ,
376- let scrollView = focusedElement . parent ,
377- let scrollBar = scrollView . verticalScrollBar
378- {
379- let selectionRangeChange = AXNotificationStream (
380- app: app,
381- element: focusedElement,
382- notificationNames: kAXSelectedTextChangedNotification
383- )
384- let scroll = AXNotificationStream (
385- app: app,
386- element: scrollBar,
387- notificationNames: kAXValueChangedNotification
388- )
372+ let appElement = AXUIElementCreateApplication ( app . processIdentifier )
373+ guard let focusedElement = appElement . focusedElement ,
374+ focusedElement. description == " Source Editor " ,
375+ let scrollView = focusedElement . parent ,
376+ let scrollBar = scrollView . verticalScrollBar
377+ else { return . none }
378+
379+ let selectionRangeChange = AXNotificationStream (
380+ app: app,
381+ element: focusedElement,
382+ notificationNames: kAXSelectedTextChangedNotification
383+ )
384+ let scroll = AXNotificationStream (
385+ app: app,
386+ element: scrollBar,
387+ notificationNames: kAXValueChangedNotification
388+ )
389389
390- if #available ( macOS 13 . 0 , * ) {
391- for await _ in merge (
392- selectionRangeChange . debounce ( for : Duration . milliseconds ( 500 ) ) ,
393- scroll
394- ) {
395- guard activeApplicationMonitor . latestXcode != nil
396- else { return }
397- try Task . checkCancellation ( )
398- await send ( . updateWindowLocation ( animated : false ) )
399- await send ( . updateWindowOpacity )
400- }
401- } else {
402- for await _ in merge ( selectionRangeChange , scroll ) {
403- guard activeApplicationMonitor . latestXcode != nil
404- else { return }
405- try Task . checkCancellation ( )
406- await send ( . updateWindowLocation ( animated : false ) )
407- await send ( . updateWindowOpacity )
408- }
390+ return . run { send in
391+ if #available ( macOS 13 . 0 , * ) {
392+ for await _ in merge (
393+ selectionRangeChange . debounce ( for : Duration . milliseconds ( 500 ) ) ,
394+ scroll
395+ ) {
396+ guard activeApplicationMonitor . latestXcode != nil
397+ else { return }
398+ try Task . checkCancellation ( )
399+ await send ( . updateWindowLocation ( animated : false ) )
400+ await send ( . updateWindowOpacity )
401+ }
402+ } else {
403+ for await _ in merge ( selectionRangeChange , scroll ) {
404+ guard activeApplicationMonitor . latestXcode != nil
405+ else { return }
406+ try Task . checkCancellation ( )
407+ await send ( . updateWindowLocation ( animated : false ) )
408+ await send ( . updateWindowOpacity )
409409 }
410410 }
411+
411412 } . cancellable ( id: CancelID . observeEditorChange, cancelInFlight: true )
412413
413414 case . updateActiveApplication:
@@ -447,7 +448,7 @@ public struct WidgetFeature: ReducerProtocol {
447448 state. panelState. suggestionPanelState. colorScheme = scheme
448449 state. chatPanelState. colorScheme = scheme
449450 return . none
450-
451+
451452 case . updateFocusingDocumentURL:
452453 state. focusingDocumentURL = xcodeInspector. realtimeActiveDocumentURL
453454 return . none
@@ -574,7 +575,7 @@ public struct WidgetFeature: ReducerProtocol {
574575 await send ( . updateWindowOpacityFinished)
575576 }
576577 . cancellable ( id: DebounceKey . updateWindowOpacity, cancelInFlight: true )
577-
578+
578579 case . updateWindowOpacityFinished:
579580 state. lastUpdateWindowOpacityTime = Date ( )
580581 return . none
0 commit comments