Skip to content

Commit 1973c99

Browse files
committed
Adjust widget transition when switching apps
1 parent cbe4ec7 commit 1973c99

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

Core/Sources/SuggestionWidget/WidgetWindowsController.swift

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ actor WidgetWindowsController: NSObject {
5353
guard let app else { return }
5454
Task { [weak self] in await self?.activate(app) }
5555
}.store(in: &cancellable)
56-
56+
5757
xcodeInspector.$focusedEditor.sink { [weak self] editor in
5858
guard let editor else { return }
5959
Task { [weak self] in await self?.observe(to: editor) }
@@ -91,7 +91,7 @@ actor WidgetWindowsController: NSObject {
9191
let isChatPanelDetached = state.chatPanelState.chatPanelInASeparateWindow
9292
let hasChat = !state.chatPanelState.chatTabGroup.tabInfo.isEmpty
9393
let shouldDebounce = !immediately &&
94-
!(Date().timeIntervalSince(lastUpdateWindowOpacityTime) > 5)
94+
!(Date().timeIntervalSince(lastUpdateWindowOpacityTime) > 5)
9595
lastUpdateWindowOpacityTime = Date()
9696
let activeApp = xcodeInspector.activeApplication
9797

@@ -207,7 +207,7 @@ actor WidgetWindowsController: NSObject {
207207

208208
let now = Date()
209209
let shouldThrottle = !immediately &&
210-
!(now.timeIntervalSince(lastUpdateWindowLocationTime) > 5)
210+
!(now.timeIntervalSince(lastUpdateWindowLocationTime) > 5)
211211

212212
updateWindowLocationTask?.cancel()
213213
let interval: TimeInterval = 0.1
@@ -266,19 +266,22 @@ extension WidgetWindowsController: NSWindowDelegate {
266266

267267
private extension WidgetWindowsController {
268268
func activate(_ app: AppInstanceInspector) {
269+
Task {
270+
if app.isXcode {
271+
await updateWindowLocation(animated: false, immediately: true)
272+
await updateWindowOpacity(immediately: false)
273+
} else {
274+
await updateWindowOpacity(immediately: true)
275+
await updateWindowLocation(animated: false, immediately: false)
276+
}
277+
}
269278
guard currentApplicationProcessIdentifier != app.processIdentifier else { return }
270279
currentApplicationProcessIdentifier = app.processIdentifier
271280
observe(to: app)
272281
}
273282

274283
func observe(to app: AppInstanceInspector) {
275-
Task {
276-
await updateWindowLocation(animated: false, immediately: true)
277-
await updateWindowOpacity(immediately: true)
278-
}
279-
guard let app = app as? XcodeAppInstanceInspector else {
280-
return
281-
}
284+
guard let app = app as? XcodeAppInstanceInspector else { return }
282285
let notifications = app.axNotifications
283286
observeToAppTask?.cancel()
284287
observeToAppTask = Task {
@@ -346,25 +349,25 @@ private extension WidgetWindowsController {
346349
) {
347350
guard xcodeInspector.latestActiveXcode != nil else { return }
348351
try Task.checkCancellation()
349-
352+
350353
// for better looking
351354
if notification.kind == .scrollPositionChanged {
352355
await hideSuggestionPanelWindow()
353356
}
354-
357+
355358
await updateWindowLocation(animated: false, immediately: false)
356359
await updateWindowOpacity(immediately: false)
357360
}
358361
} else {
359362
for await notification in merge(selectionRangeChange, scroll) {
360363
guard xcodeInspector.latestActiveXcode != nil else { return }
361364
try Task.checkCancellation()
362-
365+
363366
// for better looking
364367
if notification.kind == .scrollPositionChanged {
365368
await hideSuggestionPanelWindow()
366369
}
367-
370+
368371
await updateWindowLocation(animated: false, immediately: false)
369372
await updateWindowOpacity(immediately: false)
370373
}
@@ -379,7 +382,7 @@ extension WidgetWindowsController {
379382
windows.sharedPanelWindow.alphaValue = 0
380383
windows.suggestionPanelWindow.alphaValue = 0
381384
}
382-
385+
383386
@MainActor
384387
func hideSuggestionPanelWindow() {
385388
windows.suggestionPanelWindow.alphaValue = 0

0 commit comments

Comments
 (0)