aboutsummaryrefslogtreecommitdiff
path: root/HoloBar/HoloBarApp.swift
diff options
context:
space:
mode:
Diffstat (limited to 'HoloBar/HoloBarApp.swift')
-rw-r--r--HoloBar/HoloBarApp.swift118
1 files changed, 59 insertions, 59 deletions
diff --git a/HoloBar/HoloBarApp.swift b/HoloBar/HoloBarApp.swift
index eac0acd..650495b 100644
--- a/HoloBar/HoloBarApp.swift
+++ b/HoloBar/HoloBarApp.swift
@@ -2,75 +2,75 @@ import SwiftUI
@main
struct HoloBarApp: App {
- @StateObject private var fetcher = CharacterFetcher()
- @State private var showAvatars = false
+ @StateObject private var fetcher = CharacterFetcher()
+ @State private var showAvatars = false
- var body: some Scene {
- MenuBarExtra {
- VStack {
- if fetcher.characters.isEmpty {
- Text("Loading …")
- } else {
- ForEach(fetcher.characters) { character in
- Button(action: {
- NSWorkspace.shared.open(character.profileURL)
- }) {
- HStack {
- if showAvatars {
- AsyncImage(url: character.avatarURL) { phase in
- if let image = phase.image {
- image
- .resizable()
- .scaledToFill()
- } else if phase.error != nil {
- Image(systemName: "person.crop.circle.badge.exclamationmark")
- .resizable()
- .scaledToFit()
- .foregroundStyle(.gray)
- } else {
- Image(systemName: "person.crop.circle")
- .resizable()
- .scaledToFit()
- .foregroundStyle(.gray)
- }
- }
- }
-
- Text(character.name)
- }
- }
+ var body: some Scene {
+ MenuBarExtra {
+ VStack {
+ if fetcher.characters.isEmpty {
+ Text("Loading …")
+ } else {
+ ForEach(fetcher.characters) { character in
+ Button(action: {
+ NSWorkspace.shared.open(character.profileURL)
+ }) {
+ HStack {
+ if showAvatars {
+ AsyncImage(url: character.avatarURL) { phase in
+ if let image = phase.image {
+ image
+ .resizable()
+ .scaledToFill()
+ } else if phase.error != nil {
+ Image(systemName: "person.crop.circle.badge.exclamationmark")
+ .resizable()
+ .scaledToFit()
+ .foregroundStyle(.gray)
+ } else {
+ Image(systemName: "person.crop.circle")
+ .resizable()
+ .scaledToFit()
+ .foregroundStyle(.gray)
}
+ }
}
- Divider()
+ Text(character.name)
+ }
+ }
+ }
+ }
- #if DEBUG
- Button("Simulate Day Change") {
- NotificationCenter.default.post(name: .NSCalendarDayChanged, object: nil)
- }
- #endif
+ Divider()
- Button("\(showAvatars ? "Hide" : "Show") Avatars") {
- showAvatars.toggle()
- }
+ #if DEBUG
+ Button("Simulate Day Change") {
+ NotificationCenter.default.post(name: .NSCalendarDayChanged, object: nil)
+ }
+ #endif
- Button("Refresh", action: refreshCharacters)
- Button("Quit", action: { NSApplication.shared.terminate(nil) })
- }
- .onReceive(NotificationCenter.default.publisher(for: .NSCalendarDayChanged)) { _ in
- refreshCharacters()
- }
- } label: {
- Text("HL")
+ Button("\(showAvatars ? "Hide" : "Show") Avatars") {
+ showAvatars.toggle()
}
+
+ Button("Refresh", action: refreshCharacters)
+ Button("Quit", action: { 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())
+ 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)
- }
+ if let month = today.month, let day = today.day {
+ fetcher.characters.removeAll()
+ fetcher.fetchCharacters(for: month, day: day)
}
+ }
}