diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-02-05 22:27:17 +0100 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-02-05 22:27:17 +0100 |
| commit | 45829daa856b376b1ab04d415917110b71b1dec5 (patch) | |
| tree | 8e52daed6897b6f489d455736fe256cb9bd90fef /Hotline/Application-macOS.swift | |
| parent | 5c3ea897d062a47bc8cd6255fb8c36bad2f0733f (diff) | |
Apply formatting
Diffstat (limited to 'Hotline/Application-macOS.swift')
| -rw-r--r-- | Hotline/Application-macOS.swift | 73 |
1 files changed, 41 insertions, 32 deletions
diff --git a/Hotline/Application-macOS.swift b/Hotline/Application-macOS.swift index 36f9aa8..fe9d848 100644 --- a/Hotline/Application-macOS.swift +++ b/Hotline/Application-macOS.swift @@ -1,49 +1,52 @@ -import SwiftUI -import SwiftData import CloudKit +import SwiftData +import SwiftUI import UniformTypeIdentifiers @Observable final class AppLaunchState { static let shared = AppLaunchState() - + enum LaunchState { case loading case launched case terminated } - + var launchState = LaunchState.loading } class AppDelegate: NSObject, NSApplicationDelegate { private var cloudKitObserverToken: Any? = nil - + func applicationDidFinishLaunching(_ notification: Notification) { AppLaunchState.shared.launchState = .launched - + CKContainer.default().accountStatus { status, error in switch status { case .noAccount: print("iCloud Unavailable") - + // We mark CloudKit has available now since we're not waiting on // a server sync or anything. ApplicationState.shared.cloudKitReady = true default: print("iCloud Available") - - self.cloudKitObserverToken = NotificationCenter.default.addObserver(forName: NSPersistentCloudKitContainer.eventChangedNotification, object: nil, queue: OperationQueue.main) { [weak self] note in + + self.cloudKitObserverToken = NotificationCenter.default.addObserver( + forName: NSPersistentCloudKitContainer.eventChangedNotification, object: nil, + queue: OperationQueue.main + ) { [weak self] note in print("iCloud Changed!") ApplicationState.shared.cloudKitReady = true - + guard let token = self?.cloudKitObserverToken else { return } NotificationCenter.default.removeObserver(token) } } } } - + func applicationWillTerminate(_ notification: Notification) { AppLaunchState.shared.launchState = .terminated } @@ -54,28 +57,30 @@ struct Application: App { @Environment(\.scenePhase) private var scenePhase @Environment(\.openWindow) private var openWindow @Environment(\.openURL) private var openURL - + @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate - + @State private var hotlinePanel: HotlinePanel? = nil @State private var selection: Bookmark? = nil @FocusedValue(\.activeHotlineModel) private var activeHotline: Hotline? @FocusedValue(\.activeServerState) private var activeServerState: ServerState? - + private var modelContainer: ModelContainer = { let schema = Schema([ Bookmark.self ]) - let config = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false, cloudKitDatabase: .private("iCloud.pizza.unlimited.hotline")) + let config = ModelConfiguration( + schema: schema, isStoredInMemoryOnly: false, + cloudKitDatabase: .private("iCloud.pizza.unlimited.hotline")) let modelContainer = try! ModelContainer(for: schema, configurations: [config]) - + // Print local SwiftData sqlite file. -// print(modelContainer.configurations.first?.url.path(percentEncoded: false)) - + // print(modelContainer.configurations.first?.url.path(percentEncoded: false)) + return modelContainer }() - + var body: some Scene { // MARK: Tracker Window Window("Servers", id: "servers") { @@ -93,7 +98,7 @@ struct Application: App { } } } - + // MARK: About Box Window("About", id: "about") { AboutView() @@ -103,7 +108,7 @@ struct Application: App { .windowResizability(.contentSize) .windowStyle(.hiddenTitleBar) .defaultPosition(.center) - .commandsRemoved() // Remove About that was automatically added to Window menu. + .commandsRemoved() // Remove About that was automatically added to Window menu. .commands { CommandGroup(replacing: CommandGroupPlacement.appInfo) { Button("About Hotline") { @@ -111,7 +116,7 @@ struct Application: App { } } } - + // MARK: Server Window WindowGroup(id: "server", for: Server.self) { server in ServerView(server: server) @@ -160,7 +165,9 @@ struct Application: App { CommandGroup(after: .help) { Divider() Button("Request Feature...") { - if let url = URL(string: "https://github.com/mierau/hotline/issues/new?labels=enhancement") { + if let url = URL( + string: "https://github.com/mierau/hotline/issues/new?labels=enhancement") + { openURL(url) } } @@ -219,16 +226,19 @@ struct Application: App { Button("Show Accounts") { activeServerState?.selection = .accounts } - .disabled(activeHotline?.status != .loggedIn || activeHotline?.access?.contains(.canOpenUsers) != true ) + .disabled( + activeHotline?.status != .loggedIn + || activeHotline?.access?.contains(.canOpenUsers) != true + ) .keyboardShortcut(.init("5"), modifiers: .command) } } - + // MARK: Settings Window Settings { SettingsView() } - + // MARK: Image Preview Window WindowGroup(id: "preview-image", for: PreviewFileInfo.self) { $info in FilePreviewImageView(info: $info) @@ -238,7 +248,7 @@ struct Application: App { .windowToolbarStyle(.unifiedCompact(showsTitle: true)) .defaultSize(width: 350, height: 150) .defaultPosition(.center) - + // MARK: Text Preview Window WindowGroup(id: "preview-text", for: PreviewFileInfo.self) { $info in FilePreviewTextView(info: $info) @@ -260,23 +270,22 @@ struct Application: App { if hotlinePanel == nil { hotlinePanel = HotlinePanel(HotlinePanelView()) } - + if hotlinePanel?.isVisible == false { hotlinePanel?.orderFront(nil) Prefs.shared.showBannerToolbar = true } } - + func toggleBannerWindow() { if hotlinePanel == nil { hotlinePanel = HotlinePanel(HotlinePanelView()) } - + if hotlinePanel?.isVisible == true { hotlinePanel?.orderOut(nil) Prefs.shared.showBannerToolbar = false - } - else { + } else { hotlinePanel?.orderFront(nil) Prefs.shared.showBannerToolbar = true } |