| 1 | #if os(macOS) && canImport(RastrilloMacUpdates) |
| 2 | import RastrilloMacUpdates |
| 3 | #endif |
| 4 | import RastrilloApple |
| 5 | import SheetsKit |
| 6 | import SwiftUI |
| 7 | |
| 8 | @main struct SheetsApp: App { |
| 9 | #if os(macOS) && canImport(RastrilloMacUpdates) |
| 10 | // Quiet, as Calls: a scheduled check never opens a window; an update |
| 11 | // downloads in the background and installs on quit. Needs "install": |
| 12 | // "automatic" in mac-updates.json too (rastrillo/native docs/mac-updates.md). |
| 13 | @State private var updater = NativeUpdater(policy: .quiet) |
| 14 | #endif |
| 15 | #if os(macOS) |
| 16 | @State private var windows = SheetsWindows() |
| 17 | @NSApplicationDelegateAdaptor(SheetsApplicationDelegate.self) private var appDelegate |
| 18 | #endif |
| 19 | /// One Oficina ID model for the whole app (slice A: one identity), read |
| 20 | /// from the keychain once at launch, whichever window asks first. |
| 21 | @StateObject private var oficina = SheetsOficinaSession.live() |
| 22 | init() { |
| 23 | #if os(macOS) |
| 24 | // The launch gate (spec §13): run the signed executable with this |
| 25 | // argument before any Sparkle publish. |
| 26 | if CommandLine.arguments.contains(SheetsOficinaLaunchCheck.argument) { |
| 27 | let result = SheetsOficinaLaunchCheck.run() |
| 28 | result.lines.forEach { print($0) } |
| 29 | exit(result.passed ? 0 : 1) |
| 30 | } |
| 31 | #endif |
| 32 | } |
| 33 | var body: some Scene { |
| 34 | #if os(macOS) |
| 35 | Window(sheetsMacString("Home"), id: "home") { |
| 36 | SheetsAccountWindow(oficina: oficina, windows: windows) |
| 37 | #if canImport(RastrilloMacUpdates) |
| 38 | // The quiet updater's one line, only while an update is pending: where |
| 39 | // an update that needs the person (automatic downloads off) shows up. |
| 40 | .safeAreaInset(edge: .bottom) { |
| 41 | if updater.canInstallPendingUpdate { NativeUpdateNotice(updater: updater).padding(.bottom, 12) } |
| 42 | } |
| 43 | #endif |
| 44 | } |
| 45 | .defaultSize(width: 1000, height: 760) |
| 46 | .commands { |
| 47 | // First: it replaces the About/Hide/Quit/Help groups with items in the |
| 48 | // plain name ("Quit Sheets", not "Quit Oficina Sheets"); declared later |
| 49 | // it would drop Check for Updates (after .appInfo) with them. |
| 50 | PlainAppNameCommands() |
| 51 | // Home is a NavigationSplitView. The Help group PlainAppNameCommands |
| 52 | // replaces carried SwiftUI's hidden ⌥⌘S Toggle Sidebar; this restores |
| 53 | // View ▸ Show/Hide Sidebar (⌃⌘S). |
| 54 | SidebarCommands() |
| 55 | SheetsWindowCommands(windows: windows) |
| 56 | SheetsEditorCommands() |
| 57 | #if canImport(RastrilloMacUpdates) |
| 58 | NativeUpdateCommands(updater: updater) |
| 59 | #endif |
| 60 | } |
| 61 | WindowGroup("Sheets", id: "document", for: UUID.self) { $id in |
| 62 | SheetsDocumentWindow(windows: windows, id: id) |
| 63 | } |
| 64 | .defaultSize(width: 1120, height: 820) |
| 65 | .restorationBehavior(.disabled) |
| 66 | #else |
| 67 | WindowGroup { SheetsAccountWindow(oficina: oficina) } |
| 68 | #endif |
| 69 | } |
| 70 | } |
| 71 | |