|
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+//
|
|
|
2
|
+// LoadingView.swift
|
|
|
3
|
+// App for Indeed
|
|
|
4
|
+//
|
|
|
5
|
+
|
|
|
6
|
+import Cocoa
|
|
|
7
|
+import QuartzCore
|
|
|
8
|
+
|
|
|
9
|
+final class LoadingView: NSView {
|
|
|
10
|
+ private enum Theme {
|
|
|
11
|
+ static let brandBlue = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
|
|
|
12
|
+ static let brandBlueLight = NSColor(srgbRed: 54 / 255, green: 110 / 255, blue: 198 / 255, alpha: 1)
|
|
|
13
|
+ static let pageBackgroundTop = NSColor(srgbRed: 252 / 255, green: 253 / 255, blue: 255 / 255, alpha: 1)
|
|
|
14
|
+ static let pageBackgroundBottom = NSColor(srgbRed: 241 / 255, green: 245 / 255, blue: 252 / 255, alpha: 1)
|
|
|
15
|
+ static let iconWell = NSColor(srgbRed: 239 / 255, green: 246 / 255, blue: 255 / 255, alpha: 1)
|
|
|
16
|
+ static let headingBlue = NSColor(srgbRed: 0, green: 82 / 255, blue: 204 / 255, alpha: 1)
|
|
|
17
|
+ static let subtitleText = NSColor(srgbRed: 51 / 255, green: 65 / 255, blue: 85 / 255, alpha: 1)
|
|
|
18
|
+ static let statusText = NSColor(srgbRed: 118 / 255, green: 118 / 255, blue: 118 / 255, alpha: 1)
|
|
|
19
|
+ static let waveTint = NSColor(srgbRed: 186 / 255, green: 210 / 255, blue: 253 / 255, alpha: 1)
|
|
|
20
|
+ static let badgeFill = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 0.1)
|
|
|
21
|
+ static let badgeText = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
|
|
|
22
|
+ }
|
|
|
23
|
+
|
|
|
24
|
+ private let backgroundGradientHost = NSView()
|
|
|
25
|
+ private let heroBackground = LoadingSplashBackgroundView()
|
|
|
26
|
+ private let iconWell = NSView()
|
|
|
27
|
+ private let iconView = NSImageView()
|
|
|
28
|
+ private let aiBadgeHost = NSView()
|
|
|
29
|
+ private let aiBadgeLabel = NSTextField(labelWithString: "AI-POWERED")
|
|
|
30
|
+ private let titleLabel = NSTextField(labelWithString: "App for Indeed")
|
|
|
31
|
+ private let subtitleLabel = NSTextField(labelWithString: "Find your perfect job with the power of AI.")
|
|
|
32
|
+ private let statusLabel = NSTextField(labelWithString: "Starting up…")
|
|
|
33
|
+ private let progressBar = LoadingProgressBarView()
|
|
|
34
|
+ private let thinkingIndicator = ChatThinkingIndicatorView(
|
|
|
35
|
+ compact: false,
|
|
|
36
|
+ accessibilityLabel: "Loading App for Indeed"
|
|
|
37
|
+ )
|
|
|
38
|
+
|
|
|
39
|
+ override init(frame frameRect: NSRect) {
|
|
|
40
|
+ super.init(frame: frameRect)
|
|
|
41
|
+ setUp()
|
|
|
42
|
+ }
|
|
|
43
|
+
|
|
|
44
|
+ @available(*, unavailable)
|
|
|
45
|
+ required init?(coder: NSCoder) {
|
|
|
46
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
47
|
+ }
|
|
|
48
|
+
|
|
|
49
|
+ override func layout() {
|
|
|
50
|
+ super.layout()
|
|
|
51
|
+ backgroundGradientHost.layer?.sublayers?
|
|
|
52
|
+ .filter { $0.name == "pageGradient" }
|
|
|
53
|
+ .forEach { $0.frame = backgroundGradientHost.bounds }
|
|
|
54
|
+ progressBar.layoutProgressFill(animated: false)
|
|
|
55
|
+ }
|
|
|
56
|
+
|
|
|
57
|
+ override func viewDidMoveToWindow() {
|
|
|
58
|
+ super.viewDidMoveToWindow()
|
|
|
59
|
+ if window != nil {
|
|
|
60
|
+ startAnimating()
|
|
|
61
|
+ } else {
|
|
|
62
|
+ stopAnimating()
|
|
|
63
|
+ }
|
|
|
64
|
+ }
|
|
|
65
|
+
|
|
|
66
|
+ func setStatus(_ message: String, progress: CGFloat) {
|
|
|
67
|
+ statusLabel.stringValue = message
|
|
|
68
|
+ progressBar.setProgress(progress, animated: true)
|
|
|
69
|
+ setAccessibilityLabel("Loading App for Indeed. \(message)")
|
|
|
70
|
+ }
|
|
|
71
|
+
|
|
|
72
|
+ func startAnimating() {
|
|
|
73
|
+ thinkingIndicator.startAnimatingIfNeeded()
|
|
|
74
|
+ progressBar.startShimmerIfNeeded()
|
|
|
75
|
+ heroBackground.startAmbientAnimationIfNeeded()
|
|
|
76
|
+ }
|
|
|
77
|
+
|
|
|
78
|
+ func stopAnimating() {
|
|
|
79
|
+ thinkingIndicator.stopAnimating()
|
|
|
80
|
+ progressBar.stopShimmer()
|
|
|
81
|
+ heroBackground.stopAmbientAnimation()
|
|
|
82
|
+ }
|
|
|
83
|
+
|
|
|
84
|
+ private func setUp() {
|
|
|
85
|
+ wantsLayer = true
|
|
|
86
|
+
|
|
|
87
|
+ backgroundGradientHost.translatesAutoresizingMaskIntoConstraints = false
|
|
|
88
|
+ backgroundGradientHost.wantsLayer = true
|
|
|
89
|
+
|
|
|
90
|
+ heroBackground.translatesAutoresizingMaskIntoConstraints = false
|
|
|
91
|
+ heroBackground.waveTint = Theme.waveTint
|
|
|
92
|
+
|
|
|
93
|
+ iconWell.translatesAutoresizingMaskIntoConstraints = false
|
|
|
94
|
+ iconWell.wantsLayer = true
|
|
|
95
|
+ iconWell.layer?.backgroundColor = Theme.iconWell.cgColor
|
|
|
96
|
+ iconWell.layer?.cornerRadius = 28
|
|
|
97
|
+ if #available(macOS 11.0, *) {
|
|
|
98
|
+ iconWell.layer?.cornerCurve = .continuous
|
|
|
99
|
+ }
|
|
|
100
|
+ iconWell.layer?.masksToBounds = true
|
|
|
101
|
+ iconWell.layer?.borderColor = NSColor.white.cgColor
|
|
|
102
|
+ iconWell.layer?.borderWidth = 3
|
|
|
103
|
+ iconWell.layer?.shadowColor = NSColor.black.cgColor
|
|
|
104
|
+ iconWell.layer?.shadowOpacity = 0.08
|
|
|
105
|
+ iconWell.layer?.shadowRadius = 16
|
|
|
106
|
+ iconWell.layer?.shadowOffset = CGSize(width: 0, height: -4)
|
|
|
107
|
+
|
|
|
108
|
+ iconView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
109
|
+ iconView.imageScaling = .scaleProportionallyUpOrDown
|
|
|
110
|
+ iconView.image = NSApp.applicationIconImage
|
|
|
111
|
+
|
|
|
112
|
+ aiBadgeHost.translatesAutoresizingMaskIntoConstraints = false
|
|
|
113
|
+ aiBadgeHost.wantsLayer = true
|
|
|
114
|
+ aiBadgeHost.layer?.backgroundColor = Theme.badgeFill.cgColor
|
|
|
115
|
+ aiBadgeHost.layer?.cornerRadius = 10
|
|
|
116
|
+ if #available(macOS 11.0, *) {
|
|
|
117
|
+ aiBadgeHost.layer?.cornerCurve = .continuous
|
|
|
118
|
+ }
|
|
|
119
|
+
|
|
|
120
|
+ aiBadgeLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
|
121
|
+ aiBadgeLabel.font = .systemFont(ofSize: 11, weight: .bold)
|
|
|
122
|
+ aiBadgeLabel.textColor = Theme.badgeText
|
|
|
123
|
+ aiBadgeLabel.alignment = .center
|
|
|
124
|
+ aiBadgeLabel.isEditable = false
|
|
|
125
|
+ aiBadgeLabel.isSelectable = false
|
|
|
126
|
+ aiBadgeLabel.isBezeled = false
|
|
|
127
|
+ aiBadgeLabel.drawsBackground = false
|
|
|
128
|
+
|
|
|
129
|
+ titleLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
|
130
|
+ titleLabel.font = .systemFont(ofSize: 44, weight: .bold)
|
|
|
131
|
+ titleLabel.textColor = Theme.headingBlue
|
|
|
132
|
+ titleLabel.alignment = .center
|
|
|
133
|
+
|
|
|
134
|
+ subtitleLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
|
135
|
+ subtitleLabel.font = .systemFont(ofSize: 18, weight: .regular)
|
|
|
136
|
+ subtitleLabel.textColor = Theme.subtitleText
|
|
|
137
|
+ subtitleLabel.alignment = .center
|
|
|
138
|
+ subtitleLabel.maximumNumberOfLines = 2
|
|
|
139
|
+ subtitleLabel.lineBreakMode = .byWordWrapping
|
|
|
140
|
+
|
|
|
141
|
+ statusLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
|
142
|
+ statusLabel.font = .systemFont(ofSize: 15, weight: .medium)
|
|
|
143
|
+ statusLabel.textColor = Theme.statusText
|
|
|
144
|
+ statusLabel.alignment = .center
|
|
|
145
|
+ statusLabel.maximumNumberOfLines = 2
|
|
|
146
|
+ statusLabel.lineBreakMode = .byTruncatingTail
|
|
|
147
|
+
|
|
|
148
|
+ progressBar.translatesAutoresizingMaskIntoConstraints = false
|
|
|
149
|
+
|
|
|
150
|
+ thinkingIndicator.translatesAutoresizingMaskIntoConstraints = false
|
|
|
151
|
+
|
|
|
152
|
+ iconWell.addSubview(iconView)
|
|
|
153
|
+ aiBadgeHost.addSubview(aiBadgeLabel)
|
|
|
154
|
+
|
|
|
155
|
+ let heroStack = NSStackView(views: [
|
|
|
156
|
+ iconWell,
|
|
|
157
|
+ aiBadgeHost,
|
|
|
158
|
+ titleLabel,
|
|
|
159
|
+ subtitleLabel,
|
|
|
160
|
+ statusLabel
|
|
|
161
|
+ ])
|
|
|
162
|
+ heroStack.orientation = .vertical
|
|
|
163
|
+ heroStack.alignment = .centerX
|
|
|
164
|
+ heroStack.spacing = 18
|
|
|
165
|
+ heroStack.setCustomSpacing(28, after: iconWell)
|
|
|
166
|
+ heroStack.setCustomSpacing(12, after: aiBadgeHost)
|
|
|
167
|
+ heroStack.setCustomSpacing(10, after: titleLabel)
|
|
|
168
|
+ heroStack.setCustomSpacing(28, after: subtitleLabel)
|
|
|
169
|
+ heroStack.translatesAutoresizingMaskIntoConstraints = false
|
|
|
170
|
+
|
|
|
171
|
+ addSubview(backgroundGradientHost)
|
|
|
172
|
+ addSubview(heroBackground)
|
|
|
173
|
+ addSubview(heroStack)
|
|
|
174
|
+ addSubview(thinkingIndicator)
|
|
|
175
|
+ addSubview(progressBar)
|
|
|
176
|
+
|
|
|
177
|
+ NSLayoutConstraint.activate([
|
|
|
178
|
+ backgroundGradientHost.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
|
179
|
+ backgroundGradientHost.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
|
180
|
+ backgroundGradientHost.topAnchor.constraint(equalTo: topAnchor),
|
|
|
181
|
+ backgroundGradientHost.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
|
182
|
+
|
|
|
183
|
+ heroBackground.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
|
184
|
+ heroBackground.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
|
185
|
+ heroBackground.topAnchor.constraint(equalTo: topAnchor),
|
|
|
186
|
+ heroBackground.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
|
187
|
+
|
|
|
188
|
+ iconWell.widthAnchor.constraint(equalToConstant: 128),
|
|
|
189
|
+ iconWell.heightAnchor.constraint(equalToConstant: 128),
|
|
|
190
|
+
|
|
|
191
|
+ iconView.centerXAnchor.constraint(equalTo: iconWell.centerXAnchor),
|
|
|
192
|
+ iconView.centerYAnchor.constraint(equalTo: iconWell.centerYAnchor),
|
|
|
193
|
+ iconView.widthAnchor.constraint(equalToConstant: 88),
|
|
|
194
|
+ iconView.heightAnchor.constraint(equalToConstant: 88),
|
|
|
195
|
+
|
|
|
196
|
+ aiBadgeHost.heightAnchor.constraint(equalToConstant: 26),
|
|
|
197
|
+ aiBadgeLabel.leadingAnchor.constraint(equalTo: aiBadgeHost.leadingAnchor, constant: 14),
|
|
|
198
|
+ aiBadgeLabel.trailingAnchor.constraint(equalTo: aiBadgeHost.trailingAnchor, constant: -14),
|
|
|
199
|
+ aiBadgeLabel.centerYAnchor.constraint(equalTo: aiBadgeHost.centerYAnchor),
|
|
|
200
|
+
|
|
|
201
|
+ heroStack.centerXAnchor.constraint(equalTo: centerXAnchor),
|
|
|
202
|
+ heroStack.centerYAnchor.constraint(equalTo: centerYAnchor, constant: -48),
|
|
|
203
|
+ heroStack.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor, constant: 48),
|
|
|
204
|
+ heroStack.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor, constant: -48),
|
|
|
205
|
+ heroStack.widthAnchor.constraint(lessThanOrEqualToConstant: 720),
|
|
|
206
|
+
|
|
|
207
|
+ subtitleLabel.widthAnchor.constraint(lessThanOrEqualTo: heroStack.widthAnchor),
|
|
|
208
|
+ statusLabel.widthAnchor.constraint(lessThanOrEqualTo: heroStack.widthAnchor),
|
|
|
209
|
+
|
|
|
210
|
+ progressBar.centerXAnchor.constraint(equalTo: centerXAnchor),
|
|
|
211
|
+ progressBar.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor, constant: 72),
|
|
|
212
|
+ progressBar.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor, constant: -72),
|
|
|
213
|
+ progressBar.widthAnchor.constraint(lessThanOrEqualToConstant: 560),
|
|
|
214
|
+ progressBar.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.52),
|
|
|
215
|
+ progressBar.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -64),
|
|
|
216
|
+
|
|
|
217
|
+ thinkingIndicator.centerXAnchor.constraint(equalTo: centerXAnchor),
|
|
|
218
|
+ thinkingIndicator.bottomAnchor.constraint(equalTo: progressBar.topAnchor, constant: -24)
|
|
|
219
|
+ ])
|
|
|
220
|
+
|
|
|
221
|
+ installPageGradient()
|
|
|
222
|
+ setAccessibilityElement(true)
|
|
|
223
|
+ setAccessibilityRole(.group)
|
|
|
224
|
+ setAccessibilityLabel("Loading App for Indeed")
|
|
|
225
|
+ }
|
|
|
226
|
+
|
|
|
227
|
+ private func installPageGradient() {
|
|
|
228
|
+ let gradient = CAGradientLayer()
|
|
|
229
|
+ gradient.name = "pageGradient"
|
|
|
230
|
+ gradient.colors = [
|
|
|
231
|
+ Theme.pageBackgroundTop.cgColor,
|
|
|
232
|
+ Theme.pageBackgroundBottom.cgColor
|
|
|
233
|
+ ]
|
|
|
234
|
+ gradient.startPoint = CGPoint(x: 0.5, y: 1)
|
|
|
235
|
+ gradient.endPoint = CGPoint(x: 0.5, y: 0)
|
|
|
236
|
+ gradient.frame = backgroundGradientHost.bounds
|
|
|
237
|
+ backgroundGradientHost.layer?.addSublayer(gradient)
|
|
|
238
|
+ }
|
|
|
239
|
+
|
|
|
240
|
+}
|
|
|
241
|
+
|
|
|
242
|
+// MARK: - Loading progress bar
|
|
|
243
|
+
|
|
|
244
|
+private final class LoadingProgressBarView: NSView {
|
|
|
245
|
+ private enum Theme {
|
|
|
246
|
+ static let brandBlue = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
|
|
|
247
|
+ static let brandBlueLight = NSColor(srgbRed: 54 / 255, green: 110 / 255, blue: 198 / 255, alpha: 1)
|
|
|
248
|
+ static let trackFill = NSColor(srgbRed: 228 / 255, green: 233 / 255, blue: 242 / 255, alpha: 1)
|
|
|
249
|
+ static let trackBorder = NSColor(srgbRed: 212 / 255, green: 218 / 255, blue: 230 / 255, alpha: 1)
|
|
|
250
|
+ static let percentText = NSColor(srgbRed: 37 / 255, green: 87 / 255, blue: 167 / 255, alpha: 1)
|
|
|
251
|
+ }
|
|
|
252
|
+
|
|
|
253
|
+ private let track = NSView()
|
|
|
254
|
+ private let fill = NSView()
|
|
|
255
|
+ private let percentLabel = NSTextField(labelWithString: "0%")
|
|
|
256
|
+ private var fillWidthConstraint: NSLayoutConstraint?
|
|
|
257
|
+ private var fillGradientLayer: CAGradientLayer?
|
|
|
258
|
+ private var shimmerLayer: CAGradientLayer?
|
|
|
259
|
+ private var targetProgress: CGFloat = 0.04
|
|
|
260
|
+
|
|
|
261
|
+ override var intrinsicContentSize: NSSize {
|
|
|
262
|
+ NSSize(width: 420, height: 44)
|
|
|
263
|
+ }
|
|
|
264
|
+
|
|
|
265
|
+ override init(frame frameRect: NSRect) {
|
|
|
266
|
+ super.init(frame: frameRect)
|
|
|
267
|
+ setUp()
|
|
|
268
|
+ }
|
|
|
269
|
+
|
|
|
270
|
+ @available(*, unavailable)
|
|
|
271
|
+ required init?(coder: NSCoder) {
|
|
|
272
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
273
|
+ }
|
|
|
274
|
+
|
|
|
275
|
+ override func layout() {
|
|
|
276
|
+ super.layout()
|
|
|
277
|
+ layoutProgressFill(animated: false)
|
|
|
278
|
+ }
|
|
|
279
|
+
|
|
|
280
|
+ func setProgress(_ progress: CGFloat, animated: Bool) {
|
|
|
281
|
+ targetProgress = min(max(progress, 0), 1)
|
|
|
282
|
+ let percent = Int((targetProgress * 100).rounded())
|
|
|
283
|
+ percentLabel.stringValue = "\(percent)%"
|
|
|
284
|
+ layoutProgressFill(animated: animated)
|
|
|
285
|
+ }
|
|
|
286
|
+
|
|
|
287
|
+ func layoutProgressFill(animated: Bool) {
|
|
|
288
|
+ layoutSubtreeIfNeeded()
|
|
|
289
|
+ let trackWidth = track.bounds.width
|
|
|
290
|
+ guard trackWidth > 1 else { return }
|
|
|
291
|
+ let width = max(trackWidth * max(targetProgress, 0.03), 12)
|
|
|
292
|
+ fillWidthConstraint?.constant = width
|
|
|
293
|
+
|
|
|
294
|
+ guard animated else {
|
|
|
295
|
+ fillGradientLayer?.frame = fill.bounds
|
|
|
296
|
+ shimmerLayer?.frame = fill.bounds
|
|
|
297
|
+ return
|
|
|
298
|
+ }
|
|
|
299
|
+ NSAnimationContext.runAnimationGroup { context in
|
|
|
300
|
+ context.duration = 0.45
|
|
|
301
|
+ context.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
|
|
|
302
|
+ context.allowsImplicitAnimation = true
|
|
|
303
|
+ fill.animator().layoutSubtreeIfNeeded()
|
|
|
304
|
+ } completionHandler: { [weak self] in
|
|
|
305
|
+ guard let self else { return }
|
|
|
306
|
+ self.fillGradientLayer?.frame = self.fill.bounds
|
|
|
307
|
+ self.shimmerLayer?.frame = self.fill.bounds
|
|
|
308
|
+ }
|
|
|
309
|
+ }
|
|
|
310
|
+
|
|
|
311
|
+ func startShimmerIfNeeded() {
|
|
|
312
|
+ guard !NSWorkspace.shared.accessibilityDisplayShouldReduceMotion,
|
|
|
313
|
+ let shimmerLayer else { return }
|
|
|
314
|
+ shimmerLayer.removeAnimation(forKey: "shimmer")
|
|
|
315
|
+ let move = CABasicAnimation(keyPath: "transform.translation.x")
|
|
|
316
|
+ move.fromValue = -fill.bounds.width * 0.6
|
|
|
317
|
+ move.toValue = fill.bounds.width * 0.6
|
|
|
318
|
+ move.duration = 1.35
|
|
|
319
|
+ move.repeatCount = .greatestFiniteMagnitude
|
|
|
320
|
+ move.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
|
|
|
321
|
+ shimmerLayer.add(move, forKey: "shimmer")
|
|
|
322
|
+ }
|
|
|
323
|
+
|
|
|
324
|
+ func stopShimmer() {
|
|
|
325
|
+ shimmerLayer?.removeAnimation(forKey: "shimmer")
|
|
|
326
|
+ }
|
|
|
327
|
+
|
|
|
328
|
+ private func setUp() {
|
|
|
329
|
+ translatesAutoresizingMaskIntoConstraints = false
|
|
|
330
|
+
|
|
|
331
|
+ track.translatesAutoresizingMaskIntoConstraints = false
|
|
|
332
|
+ track.wantsLayer = true
|
|
|
333
|
+ track.layer?.backgroundColor = Theme.trackFill.cgColor
|
|
|
334
|
+ track.layer?.borderColor = Theme.trackBorder.cgColor
|
|
|
335
|
+ track.layer?.borderWidth = 1
|
|
|
336
|
+ track.layer?.cornerRadius = 7
|
|
|
337
|
+ if #available(macOS 11.0, *) {
|
|
|
338
|
+ track.layer?.cornerCurve = .continuous
|
|
|
339
|
+ }
|
|
|
340
|
+ track.layer?.masksToBounds = true
|
|
|
341
|
+ track.setContentHuggingPriority(.defaultLow, for: .horizontal)
|
|
|
342
|
+ track.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
|
|
|
343
|
+
|
|
|
344
|
+ fill.translatesAutoresizingMaskIntoConstraints = false
|
|
|
345
|
+ fill.wantsLayer = true
|
|
|
346
|
+ fill.layer?.cornerRadius = 7
|
|
|
347
|
+ if #available(macOS 11.0, *) {
|
|
|
348
|
+ fill.layer?.cornerCurve = .continuous
|
|
|
349
|
+ }
|
|
|
350
|
+ fill.layer?.masksToBounds = true
|
|
|
351
|
+
|
|
|
352
|
+ let fillGradient = CAGradientLayer()
|
|
|
353
|
+ fillGradient.colors = [
|
|
|
354
|
+ Theme.brandBlueLight.cgColor,
|
|
|
355
|
+ Theme.brandBlue.cgColor
|
|
|
356
|
+ ]
|
|
|
357
|
+ fillGradient.startPoint = CGPoint(x: 0, y: 0.5)
|
|
|
358
|
+ fillGradient.endPoint = CGPoint(x: 1, y: 0.5)
|
|
|
359
|
+ fillGradient.cornerRadius = 7
|
|
|
360
|
+ fill.layer?.addSublayer(fillGradient)
|
|
|
361
|
+ fillGradientLayer = fillGradient
|
|
|
362
|
+
|
|
|
363
|
+ let shimmer = CAGradientLayer()
|
|
|
364
|
+ shimmer.colors = [
|
|
|
365
|
+ NSColor.white.withAlphaComponent(0).cgColor,
|
|
|
366
|
+ NSColor.white.withAlphaComponent(0.45).cgColor,
|
|
|
367
|
+ NSColor.white.withAlphaComponent(0).cgColor
|
|
|
368
|
+ ]
|
|
|
369
|
+ shimmer.startPoint = CGPoint(x: 0, y: 0.5)
|
|
|
370
|
+ shimmer.endPoint = CGPoint(x: 1, y: 0.5)
|
|
|
371
|
+ shimmer.locations = [0, 0.5, 1]
|
|
|
372
|
+ fill.layer?.addSublayer(shimmer)
|
|
|
373
|
+ shimmerLayer = shimmer
|
|
|
374
|
+
|
|
|
375
|
+ percentLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
|
376
|
+ percentLabel.font = .monospacedDigitSystemFont(ofSize: 13, weight: .semibold)
|
|
|
377
|
+ percentLabel.textColor = Theme.percentText
|
|
|
378
|
+ percentLabel.alignment = .right
|
|
|
379
|
+ percentLabel.setContentHuggingPriority(.required, for: .horizontal)
|
|
|
380
|
+
|
|
|
381
|
+ track.addSubview(fill)
|
|
|
382
|
+
|
|
|
383
|
+ let row = NSStackView(views: [track, percentLabel])
|
|
|
384
|
+ row.orientation = .horizontal
|
|
|
385
|
+ row.spacing = 14
|
|
|
386
|
+ row.alignment = .centerY
|
|
|
387
|
+ row.translatesAutoresizingMaskIntoConstraints = false
|
|
|
388
|
+ addSubview(row)
|
|
|
389
|
+
|
|
|
390
|
+ fillWidthConstraint = fill.widthAnchor.constraint(equalToConstant: 12)
|
|
|
391
|
+ fillWidthConstraint?.isActive = true
|
|
|
392
|
+
|
|
|
393
|
+ NSLayoutConstraint.activate([
|
|
|
394
|
+ row.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
|
395
|
+ row.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
|
396
|
+ row.topAnchor.constraint(equalTo: topAnchor),
|
|
|
397
|
+ row.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
|
398
|
+
|
|
|
399
|
+ track.heightAnchor.constraint(equalToConstant: 14),
|
|
|
400
|
+
|
|
|
401
|
+ fill.leadingAnchor.constraint(equalTo: track.leadingAnchor),
|
|
|
402
|
+ fill.topAnchor.constraint(equalTo: track.topAnchor),
|
|
|
403
|
+ fill.bottomAnchor.constraint(equalTo: track.bottomAnchor),
|
|
|
404
|
+
|
|
|
405
|
+ percentLabel.widthAnchor.constraint(equalToConstant: 44)
|
|
|
406
|
+ ])
|
|
|
407
|
+
|
|
|
408
|
+ setAccessibilityElement(true)
|
|
|
409
|
+ setAccessibilityRole(.progressIndicator)
|
|
|
410
|
+ setAccessibilityLabel("Loading progress")
|
|
|
411
|
+ }
|
|
|
412
|
+}
|
|
|
413
|
+
|
|
|
414
|
+// MARK: - Full-page decorative background (matches dashboard welcome hero)
|
|
|
415
|
+
|
|
|
416
|
+private final class LoadingSplashBackgroundView: NSView {
|
|
|
417
|
+ var waveTint = NSColor(srgbRed: 186 / 255, green: 210 / 255, blue: 253 / 255, alpha: 1)
|
|
|
418
|
+
|
|
|
419
|
+ override var isFlipped: Bool { true }
|
|
|
420
|
+
|
|
|
421
|
+ override func draw(_ dirtyRect: NSRect) {
|
|
|
422
|
+ NSColor.clear.setFill()
|
|
|
423
|
+ bounds.fill()
|
|
|
424
|
+ guard bounds.width > 24, bounds.height > 24 else { return }
|
|
|
425
|
+ drawSideWaves(in: bounds, isLeft: true)
|
|
|
426
|
+ drawSideWaves(in: bounds, isLeft: false)
|
|
|
427
|
+ drawAmbientSparkles(in: bounds)
|
|
|
428
|
+ }
|
|
|
429
|
+
|
|
|
430
|
+ func startAmbientAnimationIfNeeded() {
|
|
|
431
|
+ guard !NSWorkspace.shared.accessibilityDisplayShouldReduceMotion else { return }
|
|
|
432
|
+ let anim = CABasicAnimation(keyPath: "opacity")
|
|
|
433
|
+ anim.fromValue = 0.92
|
|
|
434
|
+ anim.toValue = 1
|
|
|
435
|
+ anim.duration = 2.4
|
|
|
436
|
+ anim.autoreverses = true
|
|
|
437
|
+ anim.repeatCount = .greatestFiniteMagnitude
|
|
|
438
|
+ layer?.add(anim, forKey: "ambientPulse")
|
|
|
439
|
+ }
|
|
|
440
|
+
|
|
|
441
|
+ func stopAmbientAnimation() {
|
|
|
442
|
+ layer?.removeAnimation(forKey: "ambientPulse")
|
|
|
443
|
+ }
|
|
|
444
|
+
|
|
|
445
|
+ private func drawSideWaves(in bounds: NSRect, isLeft: Bool) {
|
|
|
446
|
+ for i in 0..<12 {
|
|
|
447
|
+ let path = NSBezierPath()
|
|
|
448
|
+ path.lineWidth = 1.2
|
|
|
449
|
+ path.lineCapStyle = .round
|
|
|
450
|
+ let phase = CGFloat(i) * 0.88
|
|
|
451
|
+ let base = CGFloat(i + 1) * 14 + 8
|
|
|
452
|
+ var first = true
|
|
|
453
|
+ for y in stride(from: CGFloat(0), through: bounds.height, by: 2.4) {
|
|
|
454
|
+ let wobble = sin(y * 0.042 + phase) * (5 + CGFloat(i % 5))
|
|
|
455
|
+ let x = isLeft ? (base + wobble) : (bounds.width - base - wobble)
|
|
|
456
|
+ let point = NSPoint(x: x, y: y)
|
|
|
457
|
+ if first {
|
|
|
458
|
+ path.move(to: point)
|
|
|
459
|
+ first = false
|
|
|
460
|
+ } else {
|
|
|
461
|
+ path.line(to: point)
|
|
|
462
|
+ }
|
|
|
463
|
+ }
|
|
|
464
|
+ let fade = 1 - CGFloat(i) / 13
|
|
|
465
|
+ waveTint.withAlphaComponent((0.1 + CGFloat(i % 3) * 0.024) * fade).setStroke()
|
|
|
466
|
+ path.stroke()
|
|
|
467
|
+ }
|
|
|
468
|
+ }
|
|
|
469
|
+
|
|
|
470
|
+ private func drawAmbientSparkles(in bounds: NSRect) {
|
|
|
471
|
+ let accent = NSColor(srgbRed: 0, green: 82 / 255, blue: 204 / 255, alpha: 1)
|
|
|
472
|
+ let specs: [(CGFloat, CGFloat, CGFloat, CGFloat)] = [
|
|
|
473
|
+ (0.06, 0.1, 12, 0.32),
|
|
|
474
|
+ (0.94, 0.08, 14, 0.36),
|
|
|
475
|
+ (0.12, 0.38, 7, 0.22),
|
|
|
476
|
+ (0.88, 0.36, 8, 0.24),
|
|
|
477
|
+ (0.5, 0.05, 10, 0.18),
|
|
|
478
|
+ (0.22, 0.72, 6, 0.16),
|
|
|
479
|
+ (0.78, 0.68, 9, 0.2),
|
|
|
480
|
+ (0.04, 0.55, 5, 0.14),
|
|
|
481
|
+ (0.96, 0.52, 6, 0.15)
|
|
|
482
|
+ ]
|
|
|
483
|
+ for (nx, ny, size, a) in specs {
|
|
|
484
|
+ let center = NSPoint(x: bounds.width * nx, y: bounds.height * ny)
|
|
|
485
|
+ fillFourPointStar(center: center, radius: size, color: accent.withAlphaComponent(a))
|
|
|
486
|
+ }
|
|
|
487
|
+ }
|
|
|
488
|
+
|
|
|
489
|
+ private func fillFourPointStar(center: NSPoint, radius: CGFloat, color: NSColor) {
|
|
|
490
|
+ let path = NSBezierPath()
|
|
|
491
|
+ for i in 0..<4 {
|
|
|
492
|
+ let angle = CGFloat(i) * .pi / 2 - .pi / 2
|
|
|
493
|
+ let point = NSPoint(
|
|
|
494
|
+ x: center.x + cos(angle) * radius,
|
|
|
495
|
+ y: center.y + sin(angle) * radius
|
|
|
496
|
+ )
|
|
|
497
|
+ if i == 0 {
|
|
|
498
|
+ path.move(to: point)
|
|
|
499
|
+ } else {
|
|
|
500
|
+ path.line(to: point)
|
|
|
501
|
+ }
|
|
|
502
|
+ }
|
|
|
503
|
+ path.close()
|
|
|
504
|
+ color.setFill()
|
|
|
505
|
+ path.fill()
|
|
|
506
|
+ }
|
|
|
507
|
+}
|