Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
01a6f16
Merge tag '0.30.3' into develop
intitni Feb 7, 2024
c3d4dff
Update issue templates
intitni Feb 7, 2024
73cf3ab
Add WindowsController
intitni Feb 13, 2024
78ce489
Make WidgetLocation Equatable
intitni Feb 13, 2024
3c9dfc4
Move windows to WindowsController
intitni Feb 13, 2024
163f8d5
Update the dependency to hold a WindowsController instead
intitni Feb 13, 2024
eabb647
Remove useless actions
intitni Feb 13, 2024
f3275a1
Update windows getter
intitni Feb 13, 2024
e280dbd
Merge branch 'feature/improve-performance-of-widgets' into develop
intitni Feb 14, 2024
098e7e3
Make focusedEditorContent a function marked as expensive
intitni Feb 14, 2024
342ab60
Rename WindowsController to WidgetWindowsController
intitni Feb 14, 2024
6d65d57
Fix that a task is not stored
intitni Feb 14, 2024
a78ed53
Add throttler to RealtimeSuggestionController
intitni Feb 14, 2024
20bdfbd
Throttle location generation
intitni Feb 14, 2024
9a7ce06
Bump version to 0.30.4
intitni Feb 14, 2024
578802a
Merge tag '0.30.4.beta.1' into develop
intitni Feb 14, 2024
250bdf9
Remove scroll event throttle
intitni Feb 15, 2024
10f2a93
Add DebounceFunction and ThrottleFunction
intitni Feb 15, 2024
12ff573
Remove some use of MainActor
intitni Feb 15, 2024
3a1f4c3
Update circular widget implementation
intitni Feb 15, 2024
d480527
Update
intitni Feb 15, 2024
02ab5ca
Update signpost API
intitni Feb 15, 2024
72a8565
Fix dependecy
intitni Feb 15, 2024
7c5c105
Bump build number
intitni Feb 15, 2024
d1d118e
Tweak widget behavior
intitni Feb 15, 2024
060e08c
Make WidgetWindowsController an actor
intitni Feb 15, 2024
df7ad31
Bring back some main actors
intitni Feb 15, 2024
cbe4ec7
Merge tag '0.30.4.beta.2' into develop
intitni Feb 15, 2024
1973c99
Adjust widget transition when switching apps
intitni Feb 16, 2024
919c7ad
Bump version
intitni Feb 17, 2024
653459c
Update appcast.xml
intitni Feb 17, 2024
0cc2e7a
Merge branch 'release/0.30.4'
intitni Feb 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make WidgetWindowsController an actor
  • Loading branch information
intitni committed Feb 15, 2024
commit 060e08c1aa3357dfa11e1c58ac34e25b9600a7b4
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public final class SuggestionWidgetController: NSObject {
dependency.windowsController = windowsController

store.send(.startup)
windowsController.start()
Task {
await windowsController.start()
}
}
}

Expand Down
43 changes: 16 additions & 27 deletions Core/Sources/SuggestionWidget/WidgetWindowsController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Foundation
import SwiftUI
import XcodeInspector

final class WidgetWindowsController: NSObject {
actor WidgetWindowsController: NSObject {
let userDefaultsObservers = WidgetUserDefaultsObservers()
var xcodeInspector: XcodeInspector { .shared }

Expand Down Expand Up @@ -90,11 +90,9 @@ final class WidgetWindowsController: NSObject {

let isChatPanelDetached = state.chatPanelState.chatPanelInASeparateWindow
let hasChat = !state.chatPanelState.chatTabGroup.tabInfo.isEmpty
let shouldDebounce = await MainActor.run {
defer { lastUpdateWindowOpacityTime = Date() }
return !immediately &&
!(Date().timeIntervalSince(lastUpdateWindowOpacityTime) > 5)
}
let shouldDebounce = !immediately &&
!(Date().timeIntervalSince(lastUpdateWindowOpacityTime) > 5)
lastUpdateWindowOpacityTime = Date()
let activeApp = xcodeInspector.activeApplication

updateWindowOpacityTask?.cancel()
Expand Down Expand Up @@ -169,7 +167,7 @@ final class WidgetWindowsController: NSObject {
func update() async {
let state = store.withState { $0 }
let isChatPanelDetached = state.chatPanelState.chatPanelInASeparateWindow
guard let widgetLocation = generateWidgetLocation() else { return }
guard let widgetLocation = await generateWidgetLocation() else { return }
await updatePanelState(widgetLocation)

windows.widgetWindow.setFrame(
Expand Down Expand Up @@ -208,10 +206,8 @@ final class WidgetWindowsController: NSObject {
}

let now = Date()
let shouldThrottle = await MainActor.run {
!immediately &&
!(now.timeIntervalSince(lastUpdateWindowLocationTime) > 5)
}
let shouldThrottle = !immediately &&
!(now.timeIntervalSince(lastUpdateWindowLocationTime) > 5)

updateWindowLocationTask?.cancel()
let interval: TimeInterval = 0.1
Expand All @@ -222,14 +218,11 @@ final class WidgetWindowsController: NSObject {
interval - now.timeIntervalSince(lastUpdateWindowLocationTime)
)

let task = Task {
updateWindowLocationTask = Task {
try await Task.sleep(nanoseconds: UInt64(delay * 1_000_000_000))
try Task.checkCancellation()
await update()
}
await MainActor.run {
updateWindowLocationTask = task
}
} else {
Task {
await update()
Expand Down Expand Up @@ -272,13 +265,13 @@ extension WidgetWindowsController: NSWindowDelegate {
}

private extension WidgetWindowsController {
func activate(_ app: AppInstanceInspector) async {
func activate(_ app: AppInstanceInspector) {
guard currentApplicationProcessIdentifier != app.processIdentifier else { return }
currentApplicationProcessIdentifier = app.processIdentifier
await observe(to: app)
observe(to: app)
}

func observe(to app: AppInstanceInspector) async {
func observe(to app: AppInstanceInspector) {
Task {
await updateWindowLocation(animated: false, immediately: true)
await updateWindowOpacity(immediately: true)
Expand All @@ -287,7 +280,8 @@ private extension WidgetWindowsController {
return
}
let notifications = app.axNotifications
let task = Task {
observeToAppTask?.cancel()
observeToAppTask = Task {
await windows.orderFront()

let documentURL = await MainActor.run { store.withState { $0.focusingDocumentURL } }
Expand Down Expand Up @@ -335,13 +329,11 @@ private extension WidgetWindowsController {
}
}
}

observeToAppTask?.cancel()
observeToAppTask = task
}

func observe(to editor: SourceEditor) async {
let task = Task {
func observe(to editor: SourceEditor) {
observeToFocusedEditorTask?.cancel()
observeToFocusedEditorTask = Task {
let selectionRangeChange = editor.axNotifications
.filter { $0.kind == .selectedTextChanged }
let scroll = editor.axNotifications
Expand Down Expand Up @@ -378,9 +370,6 @@ private extension WidgetWindowsController {
}
}
}

observeToFocusedEditorTask?.cancel()
observeToFocusedEditorTask = task
}
}

Expand Down