-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathWidgetWindowsController+NES.swift
More file actions
122 lines (102 loc) · 3.73 KB
/
WidgetWindowsController+NES.swift
File metadata and controls
122 lines (102 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import AppKit
import GitHubCopilotService
extension WidgetWindowsController {
func setupNESSuggestionPanelObservers() {
Task { @MainActor in
let nesContentPublisher = store.publisher
.map(\.panelState.nesSuggestionPanelState.nesContent)
.removeDuplicates()
.sink { [weak self] _ in
Task { [weak self] in
await self?.updateWindowLocation(animated: false, immediately: true)
}
}
await self.storeCancellables([nesContentPublisher])
}
}
@MainActor
func applyOpacityForNESWindows(by noFocus: Bool) {
guard !noFocus, isNESFeatureFlagEnabled
else {
hideAllNESWindows()
return
}
displayAllNESWindows()
}
@MainActor
func hideAllNESWindows() {
windows.nesMenuWindow.alphaValue = 0
windows.nesDiffWindow.setIsVisible(false)
hideNESDiffWindow()
windows.nesNotificationWindow.alphaValue = 0
windows.nesNotificationWindow.setIsVisible(false)
}
@MainActor
func displayAllNESWindows() {
windows.nesMenuWindow.alphaValue = 1
windows.nesDiffWindow.setIsVisible(true)
windows.nesDiffWindow.alphaValue = 1
windows.nesDiffWindow.setIsVisible(true)
windows.nesNotificationWindow.alphaValue = 1
windows.nesNotificationWindow.setIsVisible(true)
}
@MainActor
func hideNESDiffWindow() {
NSAnimationContext.runAnimationGroup { context in
context.duration = 0.2
windows.nesDiffWindow.animator().alphaValue = 0
windows.nesDiffWindow.setIsVisible(false)
}
}
@MainActor
func updateNESDiffWindowFrame(
_ location: WidgetLocation.NESPanelLocation,
animated: Bool,
trigger: WidgetLocation.LocationTrigger
) async {
windows.nesDiffWindow.layoutIfNeeded()
guard let contentView = windows.nesDiffWindow.contentView
else {
return
}
let effectiveSize: NSSize? = {
let fittingSize = contentView.fittingSize
if fittingSize.width > 0 && fittingSize.height > 0 {
return fittingSize
}
let intrinsicSize = contentView.intrinsicContentSize
if intrinsicSize.width > 0 && intrinsicSize.height > 0 {
return intrinsicSize
}
return nil
}()
guard let contentSize = effectiveSize,
contentSize.width.isFinite,
contentSize.height.isFinite,
let frame = location.calcDiffViewFrame(contentSize: contentSize)
else {
return
}
windows.nesDiffWindow.setFrame(
frame,
display: false,
animate: animated
)
}
@MainActor
func updateNESNotificationWindowFrame(
_ location: WidgetLocation.NESPanelLocation,
animated: Bool
) async {
var notificationWindowFrame = windows.nesNotificationWindow.frame
let scrollViewFrame = location.scrollViewFrame
let screenFrame = location.screenFrame
notificationWindowFrame.origin.x = scrollViewFrame.minX + scrollViewFrame.width / 2 - notificationWindowFrame.width / 2
notificationWindowFrame.origin.y = screenFrame.height - scrollViewFrame.maxY + Style.nesSuggestionMenuLeadingPadding * 2
windows.nesNotificationWindow.setFrame(
notificationWindowFrame,
display: false,
animate: animated
)
}
}