#if os(macOS) && canImport(RastrilloMacUpdates) import RastrilloMacUpdates #endif import CalendarKit import RastrilloApple import SwiftUI #if os(macOS) import AppKit #endif @main struct CalendarApp: App { #if os(macOS) && canImport(RastrilloMacUpdates) @State private var updater = NativeUpdater() #endif @StateObject private var connection = NativeConnection(defaultServer: "https://calendar.oficina.works") @AppStorage("calendar.showMenuBar") private var showMenuBar = true @State private var model = CalendarModel() var body: some Scene { WindowGroup("Calendar", id: "calendar") { Group { if let client = connection.client { CalendarWorkspace(client: client, model: model, accounts: { model.clear(); connection.showAccounts(); model = CalendarModel() }, signOut: { model.clear(); connection.signOut(); model = CalendarModel() }) } else { NativeAccountsView("Oficina Calendar", systemImage: "calendar", connection: connection) } }.id(connection.activeAccountID).onOpenURL(perform: connection.handleOpenURL).tint(Color(red: 0.78, green: 0.22, blue: 0.29)) #if os(macOS) .frame(minWidth: 780, minHeight: 650) #endif } #if os(macOS) .defaultSize(width: 1080, height: 800) #if canImport(RastrilloMacUpdates) .commands { NativeUpdateCommands(updater: updater) } #endif #endif #if os(macOS) Settings { CalendarSettingsView() } // MenuBarExtra can echo its current visibility; avoid a UserDefaults update loop. MenuBarExtra("Oficina Calendar", systemImage: "calendar", isInserted: Binding(get: { showMenuBar }, set: { if showMenuBar != $0 { showMenuBar = $0 } })) { if let client = connection.client { CalendarMenuView(client: client, model: model).tint(Color(red: 0.78, green: 0.22, blue: 0.29)) } else { NativeAccountsView("Oficina Calendar", systemImage: "calendar", connection: connection) .frame(width: 380, height: 480) } }.menuBarExtraStyle(.window) #endif } }