Skip to content

Commit 9c7e86a

Browse files
committed
Access XcodeInspector state through actor
1 parent a82942d commit 9c7e86a

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

Core/Sources/SuggestionWidget/FeatureReducers/WidgetFeature.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public struct WidgetFeature: ReducerProtocol {
100100

101101
case updatePanelStateToMatch(WidgetLocation)
102102
case updateFocusingDocumentURL
103+
case setFocusingDocumentURL(to: URL?)
103104
case updateKeyWindow(WindowCanBecomeKey)
104105

105106
case toastPanel(ToastPanel.Action)
@@ -257,7 +258,8 @@ public struct WidgetFeature: ReducerProtocol {
257258
.notifications(named: NSWorkspace.activeSpaceDidChangeNotification)
258259
for await _ in sequence {
259260
try Task.checkCancellation()
260-
guard let activeXcode = xcodeInspector.activeXcode else { continue }
261+
guard let activeXcode = await xcodeInspector.safe.activeXcode
262+
else { continue }
261263
guard let windowsController,
262264
await windowsController.windows.fullscreenDetector.isOnActiveSpace
263265
else { continue }
@@ -324,7 +326,15 @@ public struct WidgetFeature: ReducerProtocol {
324326
return .none
325327

326328
case .updateFocusingDocumentURL:
327-
state.focusingDocumentURL = xcodeInspector.realtimeActiveDocumentURL
329+
return .run { send in
330+
await send(.setFocusingDocumentURL(
331+
to: await xcodeInspector.safe
332+
.realtimeActiveDocumentURL
333+
))
334+
}
335+
336+
case let .setFocusingDocumentURL(url):
337+
state.focusingDocumentURL = url
328338
return .none
329339

330340
case let .updatePanelStateToMatch(widgetLocation):

Core/Sources/SuggestionWidget/WidgetWindowsController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ actor WidgetWindowsController: NSObject {
9292
try Task.checkCancellation()
9393
let xcodeInspector = self.xcodeInspector
9494
let activeApp = await xcodeInspector.safe.activeApplication
95+
let latestActiveXcode = await xcodeInspector.safe.latestActiveXcode
9596
await MainActor.run {
9697
let state = store.withState { $0 }
9798
let isChatPanelDetached = state.chatPanelState.chatPanelInASeparateWindow
@@ -113,8 +114,7 @@ actor WidgetWindowsController: NSObject {
113114
}
114115
} else if let activeApp, activeApp.isExtensionService {
115116
let noFocus = {
116-
guard let xcode = xcodeInspector.latestActiveXcode
117-
else { return true }
117+
guard let xcode = latestActiveXcode else { return true }
118118
if let window = xcode.appElement.focusedWindow,
119119
window.role == "AXWindow"
120120
{
@@ -341,7 +341,7 @@ private extension WidgetWindowsController {
341341
selectionRangeChange.debounce(for: Duration.milliseconds(500)),
342342
scroll
343343
) {
344-
guard xcodeInspector.latestActiveXcode != nil else { return }
344+
guard await xcodeInspector.safe.latestActiveXcode != nil else { return }
345345
try Task.checkCancellation()
346346

347347
// for better looking
@@ -354,7 +354,7 @@ private extension WidgetWindowsController {
354354
}
355355
} else {
356356
for await notification in merge(selectionRangeChange, scroll) {
357-
guard xcodeInspector.latestActiveXcode != nil else { return }
357+
guard await xcodeInspector.safe.latestActiveXcode != nil else { return }
358358
try Task.checkCancellation()
359359

360360
// for better looking

Pro

Submodule Pro updated from e1d6080 to 9a3fd88

0 commit comments

Comments
 (0)