blob: a3b45e78dc1135e26677d0a06a797e54d7b05c42 (
plain) (
blame)
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
|
import SwiftUI
@main
struct HoloBarApp: App {
@StateObject private var fetcher = CharacterFetcher()
var body: some Scene {
MenuBarExtra {
VStack {
if fetcher.characters.isEmpty {
Text("Loading …")
} else {
ForEach(fetcher.characters) { character in
Button(character.name) {
NSWorkspace.shared.open(character.profileURL)
}
}
}
Divider()
#if DEBUG
Button("Simulate Day Change") {
NotificationCenter.default.post(name: .NSCalendarDayChanged, object: nil)
}
#endif
Button("Refresh") {
refreshCharacters()
}
Button("Quit") {
NSApplication.shared.terminate(nil)
}
}
.onReceive(NotificationCenter.default.publisher(for: .NSCalendarDayChanged)) { _ in
refreshCharacters()
}
} label: {
Text("HL")
}
}
private func refreshCharacters() {
let today = Calendar.current.dateComponents([.month, .day], from: Date())
if let month = today.month, let day = today.day {
fetcher.characters.removeAll()
fetcher.fetchCharacters(for: month, day: day)
}
}
}
|