-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountdownPanel.swift
More file actions
92 lines (75 loc) · 2.54 KB
/
Copy pathCountdownPanel.swift
File metadata and controls
92 lines (75 loc) · 2.54 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
import SwiftUI
import AppKit
// MARK: - Countdown Floating Panel
/// Click-through, invisible to recording. Shows large countdown number centered on target screen.
final class CountdownFloatingPanel: NSPanel {
init() {
super.init(
contentRect: NSRect(x: 0, y: 0, width: 200, height: 200),
styleMask: [.nonactivatingPanel, .borderless],
backing: .buffered,
defer: false
)
isReleasedWhenClosed = false
level = .floating
sharingType = .none
hidesOnDeactivate = false
isOpaque = false
backgroundColor = .clear
hasShadow = false
animationBehavior = .none
collectionBehavior = [.canJoinAllSpaces, .stationary]
ignoresMouseEvents = true
}
override var canBecomeKey: Bool { false }
override var canBecomeMain: Bool { false }
}
// MARK: - Countdown Model
@Observable
final class CountdownModel {
var count: Int = 3
}
// MARK: - Countdown Panel Manager
/// Manages the lifecycle of the floating countdown overlay.
final class CountdownPanelManager {
private var panel: CountdownFloatingPanel?
private let model = CountdownModel()
func show(on screen: NSScreen) {
let view = CountdownOverlayView(model: model)
let hosting = NSHostingView(rootView: view)
hosting.frame = NSRect(x: 0, y: 0, width: 200, height: 200)
let p = CountdownFloatingPanel()
p.contentView = hosting
let screenFrame = screen.frame
let x = screenFrame.midX - 100
let y = screenFrame.midY - 100
p.setFrame(NSRect(x: x, y: y, width: 200, height: 200), display: true)
p.orderFrontRegardless()
panel = p
}
func updateCount(_ count: Int) {
model.count = count
}
func dismiss() {
panel?.close()
panel = nil
}
}
// MARK: - Countdown Overlay View
struct CountdownOverlayView: View {
var model: CountdownModel
var body: some View {
ZStack {
Circle()
.fill(SB.Colors.surfaceOverlay)
.frame(width: SB.Layout.countdownBackdropSize, height: SB.Layout.countdownBackdropSize)
.blur(radius: 25)
Text("\(model.count)")
.font(SB.Typo.countdown)
.foregroundStyle(SB.Colors.textPrimary)
.contentTransition(.numericText())
.animation(SB.Anim.countTick, value: model.count)
}
.frame(width: SB.Layout.countdownFrameSize, height: SB.Layout.countdownFrameSize)
}
}