| 1 | #if os(macOS) && canImport(RastrilloMacUpdates) |
| 2 | import RastrilloMacUpdates |
| 3 | #endif |
| 4 | import CalendarKit |
| 5 | import RastrilloApple |
| 6 | import SwiftUI |
| 7 | #if os(macOS) |
| 8 | import AppKit |
| 9 | #endif |
| 10 | |
| 11 | @main struct CalendarApp: App { |
| 12 | #if os(macOS) && canImport(RastrilloMacUpdates) |
| 13 | @State private var updater = NativeUpdater() |
| 14 | #endif |
| 15 | @StateObject private var connection = NativeConnection(defaultServer: "https://calendar.oficina.works") |
| 16 | @AppStorage("calendar.showMenuBar") private var showMenuBar = true |
| 17 | @State private var model = CalendarModel() |
| 18 | var body: some Scene { |
| 19 | WindowGroup("Calendar", id: "calendar") { |
| 20 | Group { |
| 21 | if let client = connection.client { |
| 22 | CalendarWorkspace(client: client, model: model, accounts: { model.clear(); connection.showAccounts(); model = CalendarModel() }, signOut: { model.clear(); connection.signOut(); model = CalendarModel() }) |
| 23 | } else { |
| 24 | NativeAccountsView("Oficina Calendar", systemImage: "calendar", connection: connection) |
| 25 | } |
| 26 | }.id(connection.activeAccountID).onOpenURL(perform: connection.handleOpenURL).tint(Color(red: 0.78, green: 0.22, blue: 0.29)) |
| 27 | #if os(macOS) |
| 28 | .frame(minWidth: 780, minHeight: 650) |
| 29 | #endif |
| 30 | } |
| 31 | #if os(macOS) |
| 32 | .defaultSize(width: 1080, height: 800) |
| 33 | #if canImport(RastrilloMacUpdates) |
| 34 | .commands { NativeUpdateCommands(updater: updater) } |
| 35 | #endif |
| 36 | #endif |
| 37 | #if os(macOS) |
| 38 | Settings { CalendarSettingsView() } |
| 39 | // MenuBarExtra can echo its current visibility; avoid a UserDefaults update loop. |
| 40 | MenuBarExtra("Oficina Calendar", systemImage: "calendar", isInserted: Binding(get: { showMenuBar }, set: { if showMenuBar != $0 { showMenuBar = $0 } })) { |
| 41 | if let client = connection.client { |
| 42 | CalendarMenuView(client: client, model: model).tint(Color(red: 0.78, green: 0.22, blue: 0.29)) |
| 43 | } else { |
| 44 | NativeAccountsView("Oficina Calendar", systemImage: "calendar", connection: connection) |
| 45 | .frame(width: 380, height: 480) |
| 46 | } |
| 47 | }.menuBarExtraStyle(.window) |
| 48 | #endif |
| 49 | } |
| 50 | } |
| 51 | |