diff options
| author | Fuwn <[email protected]> | 2025-02-12 23:25:10 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-02-12 23:25:10 -0800 |
| commit | ee6cc230c73a4bad1df711a0cd0352af7e4baced (patch) | |
| tree | ceb5f14e3d30292af7cc501039738874c5374b39 /HoloBar/HoloBarApp.swift | |
| parent | feat(HoloBarApp): Add more avatar fallback levels (diff) | |
| download | holobar-ui.tar.xz holobar-ui.zip | |
feat: Add a UI windowui
Diffstat (limited to 'HoloBar/HoloBarApp.swift')
| -rw-r--r-- | HoloBar/HoloBarApp.swift | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/HoloBar/HoloBarApp.swift b/HoloBar/HoloBarApp.swift index eac0acd..3fadf0c 100644 --- a/HoloBar/HoloBarApp.swift +++ b/HoloBar/HoloBarApp.swift @@ -1,11 +1,17 @@ import SwiftUI +#Preview { ContentView().environmentObject(CharacterFetcher()) } + @main struct HoloBarApp: App { @StateObject private var fetcher = CharacterFetcher() @State private var showAvatars = false var body: some Scene { + Window("HoloBar", id: "main") { + ContentView().environmentObject(fetcher) + } + MenuBarExtra { VStack { if fetcher.characters.isEmpty { @@ -50,27 +56,28 @@ struct HoloBarApp: App { } #endif + Button("Show UI") { + for window in NSApp.windows { + if window.identifier?.rawValue == "main" { + window.makeKeyAndOrderFront(nil) + + return + } + } + } + Button("\(showAvatars ? "Hide" : "Show") Avatars") { showAvatars.toggle() } - Button("Refresh", action: refreshCharacters) + Button("Refresh", action: fetcher.refreshCharactersForToday) Button("Quit", action: { NSApplication.shared.terminate(nil) }) } .onReceive(NotificationCenter.default.publisher(for: .NSCalendarDayChanged)) { _ in - refreshCharacters() + fetcher.refreshCharactersForToday() } } 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) - } - } } |