CI / ci (push) Canceled after 0s
Neo triage input: continuous spell checking off by default, on when asked — markdown on disk already carries the spelling; squiggles are a presentation choice, per-launch with no persistence. Edit ▸ Check Spelling While Typing binds AppGateState.spellChecking and applies it to the live NSTextView in makeNSView/updateNSView. Commands views take gate as a plain property — @Environment lookups trap at launch there (crash-verified). Verified in-app: toggle -> live view flag true -> squiggles render. (The initial "does nothing" report was a machine-level kill switch: NSAllowContinuousSpellChecking=0 in the global defaults domain, since deleted; no app code change was needed for that part.) Closes #77 follow-up.
183 lines
6.1 KiB
Swift
183 lines
6.1 KiB
Swift
//
|
|
// MuseionApp.swift
|
|
// Museion
|
|
//
|
|
// Created by Alexander Kucera on 26.08.26.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
/// App-scoped gate state — raised once per app-launch, first window only (ticket #41).
|
|
/// The model is shared so ⌘N during the gate can't start a second concurrent check.
|
|
@MainActor
|
|
@Observable
|
|
final class AppGateState {
|
|
var gateRaised = true
|
|
/// True once the gate sheet's onDismiss fired (dismissal completion, #48) —
|
|
/// the provisioning failure card presents only after this.
|
|
var gateDismissed = false
|
|
let gateModel = EngineGateModel()
|
|
let provisioning = ProvisioningModel()
|
|
/// #50: daily backup pass, sequenced after provisioning finishes.
|
|
let backup = BackupModel()
|
|
/// #14: the app-scoped mentor bridge — the pane renders it; quit tears it down.
|
|
let mentor = MentorSessionModel()
|
|
/// #18: the app-scoped Posts state — FSEvents watcher + lifecycle ops.
|
|
let posts = PostsModel()
|
|
/// #77 (Neo triage input): spellcheck posture — off by default, on when
|
|
/// asked via Edit ▸ Check Spelling While Typing. Per-launch only, no
|
|
/// persistence; markdown on disk already carries the spelling.
|
|
var spellChecking = false
|
|
/// #17: the Museion Home — repoint-only (ADR-0004). Defaults to
|
|
/// `~/Documents/Museion`; UserDefaults is the persistence floor: a Home is
|
|
/// a plain folder, nothing app-owned to put in a database. Non-file URLs
|
|
/// read back as nil (the default wins) — the Home is always a folder.
|
|
var museionHome: URL {
|
|
didSet { UserDefaults.standard.set(museionHome.absoluteString, forKey: "museionHome") }
|
|
}
|
|
|
|
init() {
|
|
// Explicit init: `Self` in a stored-property initializer trips
|
|
// @ObservationTracked's macro expansion (covariant Self).
|
|
museionHome = UserDefaults.standard.string(forKey: "museionHome")
|
|
.flatMap(URL.init(string:))
|
|
.flatMap { $0.isFileURL ? $0 : nil }
|
|
?? Self.defaultMuseionHome
|
|
// #70: the six prose-typography slot defaults.
|
|
}
|
|
|
|
/// The default Home, absent a stored override — `~/Documents/Museion`
|
|
/// (b3daac9: Documents, not the account root; TCC note in ADR-0004).
|
|
nonisolated static let defaultMuseionHome = FileManager.default.homeDirectoryForCurrentUser
|
|
.appendingPathComponent("Documents/Museion", isDirectory: true)
|
|
}
|
|
|
|
@main
|
|
struct MuseionApp: App {
|
|
@State private var gate = AppGateState()
|
|
|
|
var body: some Scene {
|
|
WindowGroup {
|
|
ContentView()
|
|
.environment(gate)
|
|
// #14: app quit tears down the engine child cleanly (map
|
|
// decision: child lifecycle). willTerminate is the real quit
|
|
// signal on macOS — scenePhase .inactive also fires on plain
|
|
// focus loss, which would kill the engine on every app switch.
|
|
.onReceive(NotificationCenter.default.publisher(for: NSApplication.willTerminateNotification)) { _ in
|
|
gate.mentor.shutdown()
|
|
gate.posts.shutdown()
|
|
}
|
|
}
|
|
Window("About \(AppMetadata.name)", id: "about") {
|
|
AboutEngineView()
|
|
}
|
|
.windowResizability(.contentSize)
|
|
.commands {
|
|
// SwiftUI has no About scene on macOS; replace the stock panel with our window.
|
|
CommandGroup(replacing: .appInfo) {
|
|
OpenAboutButton()
|
|
}
|
|
// #77: spellcheck posture — Edit ▸ Check Spelling While Typing,
|
|
// default off (Neo posture: on when asked). Explicit rather than
|
|
// relying on the stock submenu's presence in a WindowGroup app.
|
|
CommandGroup(after: .textEditing) {
|
|
EditSpellingToggle(gate: gate)
|
|
}
|
|
// #68: View menu reading toggle — reaches the visible editor.
|
|
CommandMenu("View") {
|
|
Button("Toggle Reading Mode") {
|
|
NotificationCenter.default.post(name: .toggleReadingMode, object: nil)
|
|
}
|
|
.keyboardShortcut("r", modifiers: .command)
|
|
}
|
|
// #50: reveal the snapshots folder in Finder (restore = manual
|
|
// copy-back, documented in the bundled help doc).
|
|
CommandMenu("Help") {
|
|
OpenBackupFolderButton()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct OpenAboutButton: View {
|
|
@Environment(\.openWindow) private var openWindow
|
|
|
|
var body: some View {
|
|
Button("About \(AppMetadata.name)") { openWindow(id: "about") }
|
|
}
|
|
}
|
|
|
|
/// #77: the spellcheck posture toggle — binds the app-scoped bool the editor
|
|
/// surface reads on every update pass. Takes `gate` as a plain property:
|
|
/// commands views don't inherit the window environment (@Environment lookup
|
|
/// traps at launch — crash-verified), but observation tracking still works.
|
|
private struct EditSpellingToggle: View {
|
|
let gate: AppGateState
|
|
|
|
var body: some View {
|
|
Toggle("Check Spelling While Typing", isOn: Binding(
|
|
get: { gate.spellChecking },
|
|
set: { gate.spellChecking = $0 },
|
|
))
|
|
}
|
|
}
|
|
|
|
/// #50: reveals `~/Library/Application Support/Museion/Backups` in Finder —
|
|
/// restore is manual Finder copy-back in v1 (help doc describes it).
|
|
private struct OpenBackupFolderButton: View {
|
|
var body: some View {
|
|
Button("Open Backup Folder") {
|
|
NSWorkspace.shared.open(URL(fileURLWithPath: ProfileBackup.defaultBackupsRoot()))
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Read-only mirror of the last completed check's state.json record (ticket #39).
|
|
/// Reads the file when opened; never triggers a check; no re-check button.
|
|
struct AboutEngineView: View {
|
|
@State private var record: EngineProbe.StateRecord?
|
|
|
|
var body: some View {
|
|
VStack(spacing: 12) {
|
|
Image(systemName: "books.vertical")
|
|
.font(.largeTitle)
|
|
Text(AppMetadata.name)
|
|
.font(.title)
|
|
.bold()
|
|
Text(AppMetadata.tagline)
|
|
.foregroundStyle(.secondary)
|
|
|
|
Divider()
|
|
|
|
if let record {
|
|
VStack(alignment: .leading, spacing: 6) {
|
|
aboutRow("Engine", record.status == "pass" ? "Ready" : "Unavailable")
|
|
aboutRow("Engine version", record.engineVersion ?? "—")
|
|
aboutRow("Last checked", record.checkedAt)
|
|
aboutRow("Binary path", record.binaryPath ?? "—")
|
|
}
|
|
} else {
|
|
Text("No engine check recorded yet.")
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
.padding(20)
|
|
.frame(width: 380)
|
|
.onAppear { record = EngineProbe.readStateRecord() }
|
|
}
|
|
|
|
private func aboutRow(_ label: String, _ value: String) -> some View {
|
|
HStack(alignment: .firstTextBaseline) {
|
|
Text(label)
|
|
.foregroundStyle(.secondary)
|
|
Spacer(minLength: 12)
|
|
Text(value)
|
|
.textSelection(.enabled)
|
|
.lineLimit(1)
|
|
.truncationMode(.middle)
|
|
}
|
|
.font(.callout)
|
|
}
|
|
}
|