SPB Git

Repository Public

SPNotesApp.swift 2.6 KB 50 lines swift

1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: App/SPNotesApp.swift3// Description: Application entry point: main windows (multi-window, restorable), one window per note, Settings, optional menu bar extra, menu commands.4import SwiftUI5import SPNotesDesign67@main8struct SPNotesApp: App {9    @NSApplicationDelegateAdaptor(AppDelegate.self) private var delegate10    @State private var env: AppEnvironment1112    init() {13        let env = AppEnvironment()14        _env = State(initialValue: env)15        AppDelegate.environment = env16    }1718    var body: some Scene {19        WindowGroup("SP Notes", id: "main") {20            MainWindow(initialNote: nil).environment(env).modifier(NoteWindowOpener())21        }22        .defaultSize(width: 1180, height: 760)23        .commands { AppCommands(env: env) }2425        // « Ouvrir dans une nouvelle fenêtre » : one window per note id, restored by the system at next launch26        WindowGroup("Note", id: "note", for: String.self) { $id in27            MainWindow(initialNote: id).environment(env).modifier(NoteWindowOpener())28        }29        .defaultSize(width: 980, height: 720)3031        Settings { SettingsView().environment(env).tint(NVColor.accent).preferredColorScheme(env.preferences.appearance.colorScheme) }3233        MenuBarExtra("SP Notes", systemImage: "note.text", isInserted: Binding(get: { env.preferences.showMenuBarIcon }, set: { env.preferences.showMenuBarIcon = $0 })) {34            Button("Capture rapide (\(env.preferences.quickNoteShortcut.display))") { AppDelegate.shared?.toggleQuickNote() }35            Button("Capturer le presse-papiers dans la boîte de réception") { Task { let m = QuickNoteModel(env: env); if m.accept(pasteboard: .general) { await m.save() } } }.disabled(env.isBlocked)36            Divider()37            Button("Boîte de réception" + (env.library.counts.inbox > 0 ? " (\(env.library.counts.inbox))" : "")) { MainWindowOpener.open?(); env.show(.inbox); NSApp.activate(ignoringOtherApps: true) }38            Button("Tâches" + (env.tasks.openCount > 0 ? " (\(env.tasks.openCount))" : "")) { MainWindowOpener.open?(); env.show(.tasks); NSApp.activate(ignoringOtherApps: true) }39            Button("Ouvrir SP Notes") { MainWindowOpener.open?(); NSApp.activate(ignoringOtherApps: true) }40            Divider()41            Button("Quitter") { NSApp.terminate(nil) }42        }43    }44}4546private struct NoteWindowOpener: ViewModifier {47    @Environment(\.openWindow) private var openWindow48    func body(content: Content) -> some View { content.onAppear { OpenNoteWindow.open = { id in openWindow(id: "note", value: id) } } }49}50
Files main
Menu

Theme