Sources/Orgstar/OrgstarApp.swift

3959d9c38d34f2d30757a8c9c88309a5328522e5
orgstar/Sources/Orgstar/OrgstarApp.swift history · blame · raw

601 lines · 26056 bytes

  1import AppKit
  2import OrgApp
  3import OrgCore
  4import OrgEditorAppKit
  5import SwiftUI
  6import UserNotifications
  7
  8/// Window-level requests the menu bar makes.
  9@MainActor
 10@Observable
 11final class AppCommands {
 12    var showingQuickOpen = false
 13    var showingFolderPicker = false
 14    var focusSearch = false
 15    var showingConflict = false
 16    var showingPalette = false
 17    /// A location another window asked the main window to show.
 18    private(set) var jumpRequest: (path: String, offset: Int, id: Int)?
 19    private var jumpID = 0
 20    /// The editor showing the open file, for menus and the palette.
 21    var editor: OrgEditor?
 22    /// The pending key prefix, and what can follow it.
 23    var pendingKeys: String?
 24    /// The editor's evil state in the Doom preset.
 25    var editorState: String?
 26    /// The keymap in use, for showing keys in menus and the palette.
 27    var keymap = KeymapPreset.emacs.keymap
 28    var modal = false
 29
 30    /// The keys that run `command`, as menus and the palette show them.
 31    func keyLabel(for command: String) -> String? {
 32        let labels = keymap.keyLabels(for: command, modes: modal ? ["normal", "insert"] : [nil])
 33        return labels.isEmpty ? nil : labels.joined(separator: ", ")
 34    }
 35
 36    /// The editor's selection, for the modeline.
 37    var selection = NSRange(location: 0, length: 0)
 38    var keyHints: [KeyHint] = []
 39    /// A question a command asked, answered in the echo area.
 40    private(set) var prompt: PromptRequest?
 41    /// The last message from a command or the keymap, cleared after a few seconds.
 42    private(set) var message: String?
 43    private var messageID = 0
 44
 45    func ask(_ prompt: Prompt, reply: @escaping (String?) -> Void) {
 46        self.prompt = PromptRequest(prompt: prompt, reply: reply)
 47    }
 48
 49    /// Ends the prompt with an answer, or nil to cancel, and gives the editor the keys back.
 50    func answer(_ text: String?) {
 51        guard let request = prompt else { return }
 52        prompt = nil
 53        if let textView = editor?.textView { textView.window?.makeFirstResponder(textView) }
 54        request.reply(text)
 55    }
 56
 57    /// An app command from a menu, run by the main window.
 58    private(set) var runRequest: (id: String, serial: Int)?
 59    private var runSerial = 0
 60
 61    func run(_ id: String) {
 62        runSerial += 1
 63        runRequest = (id, runSerial)
 64    }
 65
 66    func jump(path: String, offset: Int) {
 67        jumpID += 1
 68        jumpRequest = (path, offset, jumpID)
 69    }
 70
 71    func show(_ text: String) {
 72        messageID += 1
 73        let id = messageID
 74        message = text
 75        Task {
 76            try? await Task.sleep(for: .seconds(4))
 77            if messageID == id { message = nil }
 78        }
 79    }
 80}
 81
 82struct PromptRequest: Identifiable {
 83    let id = UUID()
 84    let prompt: Prompt
 85    let reply: (String?) -> Void
 86}
 87
 88@MainActor
 89final class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDelegate {
 90    var session: DocumentSession?
 91    var commands: AppCommands?
 92
 93    func applicationDidFinishLaunching(_ notification: Notification) {
 94        if SystemReminderCenter.isAvailable { UNUserNotificationCenter.current().delegate = self }
 95    }
 96
 97    /// Reminders show while Orgstar is in front too.
 98    nonisolated func userNotificationCenter(
 99        _ center: UNUserNotificationCenter, willPresent notification: UNNotification
100    ) async -> UNNotificationPresentationOptions {
101        [.banner, .sound, .list]
102    }
103
104    /// Clicking a reminder shows its entry.
105    nonisolated func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async {
106        let info = response.notification.request.content.userInfo
107        guard let path = info["path"] as? String, let offset = info["offset"] as? Int else { return }
108        await MainActor.run {
109            NSApp.activate()
110            commands?.jump(path: path, offset: offset)
111        }
112    }
113
114    func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { true }
115
116    func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
117        guard let session else { return .terminateNow }
118        BufferRestore.save(session)
119        return UnsavedChanges.resolve(session, paths: session.openPaths) ? .terminateNow : .terminateCancel
120    }
121}
122
123/// Unsaved edits when leaving a file or quitting.
124@MainActor
125enum UnsavedChanges {
126    /// Whether the open file can be left: saved in automatic mode, or as the user chooses in
127    /// explicit mode. A save that fails or conflicts keeps the file open.
128    static func resolve(_ session: DocumentSession) -> Bool {
129        guard session.isDirty else { return true }
130        if session.saveMode == .automatic { return session.save() }
131        let alert = NSAlert()
132        alert.messageText = "Save changes to \(session.path.map { ($0 as NSString).lastPathComponent } ?? "this file")?"
133        alert.informativeText = "Your changes will be lost if you don't save them."
134        alert.addButton(withTitle: "Save")
135        alert.addButton(withTitle: "Don't Save")
136        alert.addButton(withTitle: "Cancel")
137        switch alert.runModal() {
138        case .alertFirstButtonReturn: return session.save()
139        case .alertSecondButtonReturn: return true
140        default: return false
141        }
142    }
143
144    /// Whether the buffers of `paths` can be closed: saved in automatic mode, or as the user
145    /// chooses for all of them in explicit mode.
146    static func resolve(_ session: DocumentSession, paths: [String]) -> Bool {
147        let dirty = paths.filter(session.dirtyPaths.contains)
148        guard !dirty.isEmpty else { return true }
149        if session.saveMode == .automatic { return dirty.map(session.save).allSatisfy { $0 } }
150        if dirty == [session.path] { return resolve(session) }
151        let alert = NSAlert()
152        alert.messageText = "Save changes to \(dirty.count) files?"
153        alert.informativeText = dirty.map { ($0 as NSString).lastPathComponent }.joined(separator: ", ")
154        alert.addButton(withTitle: "Save All")
155        alert.addButton(withTitle: "Don't Save")
156        alert.addButton(withTitle: "Cancel")
157        switch alert.runModal() {
158        case .alertFirstButtonReturn: return dirty.map(session.save).allSatisfy { $0 }
159        case .alertSecondButtonReturn: return true
160        default: return false
161        }
162    }
163}
164
165/// The open buffers, their order and carets, kept for the next launch.
166@MainActor
167enum BufferRestore {
168    private static let key = "openBuffers"
169
170    struct State: Codable {
171        var paths: [String]
172        var current: String?
173        var carets: [String: Int]
174    }
175
176    static func save(_ session: DocumentSession, defaults: UserDefaults = .standard) {
177        var carets: [String: Int] = [:]
178        for path in session.openPaths { carets[path] = session.caret(of: path) }
179        let state = State(paths: session.openPaths, current: session.path, carets: carets)
180        if let data = try? JSONEncoder().encode(state) { defaults.set(data, forKey: key) }
181    }
182
183    /// Opens the buffers that were open, in order, and returns the carets to show them at.
184    static func restore(_ session: DocumentSession, defaults: UserDefaults = .standard) -> [String: Int] {
185        guard let data = defaults.data(forKey: key), let state = try? JSONDecoder().decode(State.self, from: data) else { return [:] }
186        let existing = state.paths.filter { FileManager.default.fileExists(atPath: $0) }
187        for path in existing { session.open(path) }
188        if let current = state.current, existing.contains(current) { session.open(current) }
189        return state.carets
190    }
191}
192
193@main
194struct OrgstarApp: App {
195    @NSApplicationDelegateAdaptor private var delegate: AppDelegate
196    @State private var workspace = Result {
197        try WorkspaceModel(directory: WorkspaceModel.defaultDirectory, settings: .with(todoKeywords: Preferences.orgSettings))
198    }
199    @State private var commands = AppCommands()
200    @State private var clock = ClockModel()
201    @State private var scheduler = SystemReminderCenter.isAvailable ? ReminderScheduler(center: SystemReminderCenter()) : nil
202    @State private var session: DocumentSession = {
203        let session = DocumentSession()
204        session.defaults = Preferences.orgSettings
205        return session
206    }()
207
208    var body: some Scene {
209        Window("Orgstar", id: "main") {
210            switch workspace {
211            case .success(let model):
212                ContentView(workspace: model, session: session, commands: commands, scheduler: scheduler, clock: clock)
213                    .environment(\.orgTheme, ConfigSync.shared.theme)
214                    .onAppear {
215                        delegate.session = session
216                        delegate.commands = commands
217                    }
218            case .failure(let error):
219                ContentUnavailableView("Can't open the index", systemImage: "exclamationmark.triangle", description: Text(error.localizedDescription))
220            }
221        }
222        .defaultSize(width: 1280, height: 860)
223        Window("Agenda", id: "agenda") {
224            if case .success(let model) = workspace {
225                AgendaView(workspace: model, session: session, commands: commands, scheduler: scheduler)
226                    .environment(\.orgTheme, ConfigSync.shared.theme)
227            }
228        }
229        .defaultSize(width: 760, height: 720)
230        Window("Board", id: "board") {
231            if case .success(let model) = workspace {
232                BoardView(workspace: model, session: session, commands: commands)
233                    .environment(\.orgTheme, ConfigSync.shared.theme)
234            }
235        }
236        .defaultSize(width: 1100, height: 700)
237        Window("Clock Report", id: "clock-report") {
238            if case .success(let model) = workspace {
239                ClockReportView(workspace: model)
240            }
241        }
242        .defaultSize(width: 860, height: 560)
243        Window("Capture", id: "capture") {
244            if case .success(let model) = workspace {
245                CaptureView(workspace: model, session: session, commands: commands)
246            }
247        }
248        .windowResizability(.contentSize)
249        .windowLevel(.floating)
250        .commands {
251            CommandGroup(after: .newItem) {
252                Button("Add Folder…") { commands.showingFolderPicker = true }
253                    .keyboardShortcut("o", modifiers: [.command, .shift])
254                Button("Quick Open…") { commands.showingQuickOpen = true }
255                    .keyboardShortcut("p")
256                Button("Command Palette…") { commands.showingPalette = true }
257                    .keyboardShortcut("p", modifiers: [.command, .shift])
258            }
259            CommandGroup(after: .saveItem) {
260                Menu("Export") {
261                    ForEach(EditorCommands.all.filter { $0.id.hasPrefix("app.export.") }, id: \.id) { command in
262                        Button(command.title) { commands.run(command.id) }
263                    }
264                }
265                .disabled(session.path == nil)
266            }
267            CommandGroup(replacing: .saveItem) {
268                Button("Close Buffer") {
269                    // ⌘W closes the buffer in the main window, and other windows themselves.
270                    if let key = NSApp.keyWindow, key.identifier?.rawValue.contains("main") != true {
271                        key.performClose(nil)
272                    } else {
273                        commands.run("app.buffer.kill")
274                    }
275                }
276                .keyboardShortcut("w")
277                Button("Close Window") { NSApp.keyWindow?.performClose(nil) }
278                    .keyboardShortcut("w", modifiers: [.command, .shift])
279                Divider()
280                Button("Save") {
281                    if !session.save(), session.conflict != nil { commands.showingConflict = true }
282                }
283                .keyboardShortcut("s")
284                .disabled(session.path == nil || session.isReadOnly)
285                Button("Save All") { commands.run("app.save-all") }
286                    .keyboardShortcut("s", modifiers: [.command, .option])
287                    .disabled(session.dirtyPaths.isEmpty)
288            }
289            CommandGroup(after: .sidebar) {
290                Button("Show or Hide Outline") { commands.run("app.toggle-outline") }
291                    .keyboardShortcut("o", modifiers: [.command, .option])
292                MarkupToggle()
293            }
294            CommandGroup(after: .pasteboard) {
295                Divider()
296                FindMenu(commands: commands)
297            }
298            CommandGroup(after: .textEditing) {
299                Button("Search Notes") { commands.focusSearch = true }
300                    .keyboardShortcut("f", modifiers: [.command, .shift])
301            }
302            CommandGroup(before: .windowList) {
303                AgendaMenuItem()
304                Divider()
305                Button("Switch to Buffer…") { commands.run("app.buffer.switch") }
306                Button("Next Buffer") { commands.run("app.buffer.next") }
307                    .keyboardShortcut("]", modifiers: [.command, .shift])
308                Button("Previous Buffer") { commands.run("app.buffer.previous") }
309                    .keyboardShortcut("[", modifiers: [.command, .shift])
310                Divider()
311            }
312            CommandGroup(after: .newItem) {
313                Button("Capture…") { commands.run("app.capture") }
314                    .keyboardShortcut("n", modifiers: [.command, .shift])
315            }
316        }
317        .commands {
318            CommandMenu("Org") {
319                OrgMenuItems(commands: commands)
320            }
321        }
322        .commands {
323            CommandGroup(after: .appSettings) {
324                Button("Edit Config File") { commands.jump(path: UserConfig.configFile.path, offset: 0) }
325                    .keyboardShortcut(",", modifiers: [.command, .option])
326            }
327        }
328        Settings {
329            SettingsView(commands: commands, workspace: try? workspace.get())
330        }
331    }
332}
333
334/// The Org menu: every org command, with the keys that run it in the current keymap.
335struct OrgMenuItems: View {
336    let commands: AppCommands
337
338    var body: some View {
339        ForEach(EditorCommands.all.filter { $0.id.hasPrefix("org.") }, id: \.id) { command in
340            Button {
341                commands.editor?.run(command.id)
342            } label: {
343                Text(command.title)
344                if let keys = commands.keyLabel(for: command.id) { Text(keys) }
345            }
346            .disabled(commands.editor == nil)
347        }
348    }
349}
350
351/// View ▸ Show Markup (link brackets and targets, emphasis markers) and Show Line Numbers.
352struct MarkupToggle: View {
353    @AppStorage("showTabBar") private var showTabBar = false
354    @AppStorage("showMarkup") private var showMarkup = false
355    @AppStorage("showLineNumbers") private var showLineNumbers = true
356
357    var body: some View {
358        Toggle("Show Markup", isOn: $showMarkup)
359            .keyboardShortcut("m", modifiers: [.command, .shift])
360        Toggle("Show Line Numbers", isOn: $showLineNumbers)
361            .keyboardShortcut("l", modifiers: [.command, .shift])
362        Toggle("Show Tab Bar", isOn: $showTabBar)
363    }
364}
365
366/// Edit ▸ Find: the editor's find bar.
367struct FindMenu: View {
368    let commands: AppCommands
369
370    var body: some View {
371        Menu("Find") {
372            item("Find…", "edit.find", "f")
373            item("Find and Replace…", "edit.replace", "f", [.command, .option])
374            item("Find Next", "edit.find-next", "g")
375            item("Find Previous", "edit.find-previous", "g", [.command, .shift])
376            item("Use Selection for Find", "edit.use-selection-for-find", "e")
377        }
378    }
379
380    private func item(_ title: String, _ id: String, _ key: KeyEquivalent, _ modifiers: EventModifiers = .command) -> some View {
381        Button(title) { commands.editor?.run(id) }
382            .keyboardShortcut(key, modifiers: modifiers)
383            .disabled(commands.editor == nil)
384    }
385}
386
387/// Window ▸ Agenda.
388struct AgendaMenuItem: View {
389    @Environment(\.openWindow) private var openWindow
390
391    var body: some View {
392        Button("Agenda") { openWindow(id: "agenda") }
393            .keyboardShortcut("a", modifiers: [.command, .shift])
394        Button("Board") { openWindow(id: "board") }
395            .keyboardShortcut("b", modifiers: [.command, .shift])
396    }
397}
398
399struct SettingsView: View {
400    let commands: AppCommands
401    let workspace: WorkspaceModel?
402    @State private var importing = false
403    @Environment(\.openWindow) private var openWindow
404    @AppStorage("saveMode") private var saveMode = SaveMode.automatic
405    @AppStorage("keymap") private var preset = KeymapPreset.emacs
406    @AppStorage("optionAsMeta") private var optionAsMeta = OptionAsMeta.left.rawValue
407    @AppStorage("tagsColumn") private var tagsColumn = -77
408    @AppStorage("headingAfterSubtree") private var headingAfterSubtree = true
409    @AppStorage("splitLine") private var splitLine = false
410    @AppStorage("alphabeticalLists") private var alphabeticalLists = true
411    @AppStorage("fillColumn") private var fillColumn = 80
412    @AppStorage("hiddenMarkers") private var hiddenMarkers = true
413    @AppStorage("prettyEntities") private var prettyEntities = true
414    @AppStorage("todoKeywords") private var todoKeywords = Preferences.defaultTodoKeywords
415    @AppStorage("agendaSpan") private var agendaSpan = 10
416    @AppStorage("agendaStartOffset") private var agendaStartOffset = -3
417    @AppStorage("agendaSubfolders") private var agendaSubfolders = false
418    @AppStorage("reminders") private var reminders = true
419    @AppStorage("reminderLead") private var reminderLead = 12
420    @AppStorage("globalCapture") private var globalCapture = true
421    @AppStorage("settingsTab") private var tab = "general"
422    @AppStorage("showHiddenFiles") private var showHiddenFiles = true
423    @AppStorage("themeFont") private var themeFont = ""
424    @AppStorage("themeFontSize") private var themeFontSize = 13
425    @AppStorage("themeLineSpacing") private var themeLineSpacing = 2
426    @AppStorage("themeHeadingStep") private var themeHeadingStep = 1
427
428    /// Installed monospaced font families.
429    private static let monospacedFamilies: [String] = NSFontManager.shared.availableFontFamilies.filter { family in
430        NSFontManager.shared.font(withFamily: family, traits: [], weight: 5, size: 13)?.isFixedPitch == true
431    }
432
433    var body: some View {
434        TabView(selection: $tab) {
435            Tab("General", systemImage: "gearshape", value: "general") { general }
436            Tab("Editing", systemImage: "text.alignleft", value: "editing") { editing }
437            Tab("Appearance", systemImage: "paintpalette", value: "appearance") { appearance }
438            Tab("Agenda", systemImage: "calendar", value: "agenda") { agenda }
439            Tab("Capture", systemImage: "tray.and.arrow.down", value: "capture") { capture }
440        }
441        .frame(width: 600)
442    }
443
444    private func editConfig() {
445        ConfigSync.shared.start()
446        openWindow(id: "main")
447        commands.jump(path: UserConfig.configFile.path, offset: 0)
448    }
449
450    private var general: some View {
451        Form {
452            Section {
453                LabeledContent("config.toml") {
454                    HStack {
455                        Button("Edit in Orgstar") { editConfig() }
456                        Button("Open with Default App") { NSWorkspace.shared.open(UserConfig.configFile) }
457                        Button("Show in Finder") { NSWorkspace.shared.activateFileViewerSelecting([UserConfig.configFile]) }
458                    }
459                }
460                LabeledContent("Emacs") {
461                    Button("Import from Emacs…") { importing = true }
462                }
463            } footer: {
464                Text("Every setting here is also in \(UserConfig.configFile.path), which you can edit, share or keep with your dotfiles. Changes in either place show up in the other.")
465                    .settingsFooter()
466            }
467            Section {
468                Picker("Save files", selection: $saveMode) {
469                    Text("Automatically, when typing stops").tag(SaveMode.automatic)
470                    Text("Only with File ▸ Save (⌘S)").tag(SaveMode.explicit)
471                }
472                .pickerStyle(.radioGroup)
473            }
474            Section {
475                Picker("Keys", selection: $preset) {
476                    ForEach(KeymapPreset.allCases, id: \.self) { Text($0.title).tag($0) }
477                }
478                Toggle("Show hidden files and folders", isOn: $showHiddenFiles)
479                Picker("Option as Meta", selection: $optionAsMeta) {
480                    Text("Left Option").tag(OptionAsMeta.left.rawValue)
481                    Text("Right Option").tag(OptionAsMeta.right.rawValue)
482                    Text("Both").tag(OptionAsMeta([.left, .right]).rawValue)
483                    Text("Neither").tag(0)
484                }
485            } footer: {
486                Text("Your own bindings go in \(KeymapLoader.userFile.path), on top of the preset.")
487                    .settingsFooter()
488            }
489        }
490        .formStyle(.grouped)
491        .frame(height: 330)
492        .sheet(isPresented: $importing) { EmacsImportView(workspace: workspace) }
493    }
494
495    private var editing: some View {
496        Form {
497            Section {
498                Picker("Tags", selection: $tagsColumn) {
499                    Text("Aligned to end at column 77").tag(-77)
500                    Text("One space after the title").tag(0)
501                }
502                Toggle("M-RET adds the new heading after the subtree", isOn: $headingAfterSubtree)
503                Toggle("M-RET splits the line at the caret", isOn: $splitLine)
504                Toggle("Lists can use letters (a. b. c.)", isOn: $alphabeticalLists)
505                Stepper("M-q fills to column \(fillColumn)", value: $fillColumn, in: 40...200)
506            }
507            Section {
508                Toggle("Emacs hides emphasis markers (org-hide-emphasis-markers)", isOn: $hiddenMarkers)
509                Toggle("Emacs shows entities as characters (org-pretty-entities)", isOn: $prettyEntities)
510            } footer: {
511                Text("Tags, tables and M-q measure text as your Emacs displays it, so both write the same file.")
512                    .settingsFooter()
513            }
514            Section {
515                TextField("Default TODO keywords", text: $todoKeywords)
516            } footer: {
517                Text("For files without #+TODO, in #+TODO syntax. Takes effect when Orgstar restarts.")
518                    .settingsFooter()
519            }
520        }
521        .formStyle(.grouped)
522        .frame(height: 450)
523    }
524
525    private var appearance: some View {
526        Form {
527            Section {
528                Picker("Font", selection: $themeFont) {
529                    Text("System monospaced").tag("")
530                    Divider()
531                    ForEach(Self.monospacedFamilies, id: \.self) { Text($0).tag($0) }
532                    if !themeFont.isEmpty, !Self.monospacedFamilies.contains(themeFont) { Text(themeFont).tag(themeFont) }
533                }
534                Stepper("Size: \(themeFontSize) pt", value: $themeFontSize, in: 8...36)
535                Stepper("Line spacing: \(themeLineSpacing) pt", value: $themeLineSpacing, in: 0...16)
536                Stepper("Headings grow by \(themeHeadingStep) pt a level", value: $themeHeadingStep, in: 0...8)
537            } footer: {
538                Text("Tags and tables line up in columns, so a monospaced font keeps them straight.")
539                    .settingsFooter()
540            }
541            Section {
542                LabeledContent("Colors") {
543                    HStack {
544                        Button("Edit in config.toml") { editConfig() }
545                        Button("Show Default Theme") {
546                            openWindow(id: "main")
547                            commands.jump(path: UserConfig.directory.appendingPathComponent("default-theme.toml").path, offset: 0)
548                        }
549                    }
550                }
551            } footer: {
552                Text("Set colors under [theme] (both appearances), [theme.light] or [theme.dark] in config.toml, and TODO keyword colors under [theme.todo]. default-theme.toml lists every color with the default theme's values.")
553                    .settingsFooter()
554            }
555        }
556        .formStyle(.grouped)
557        .frame(height: 380)
558    }
559
560    private var agenda: some View {
561        Form {
562            Section {
563                Stepper("Agenda shows \(agendaSpan) days", value: $agendaSpan, in: 1...31)
564                Stepper(agendaStartOffset == 0 ? "Agenda starts today" : "Agenda starts \(-agendaStartOffset) days before today", value: $agendaStartOffset, in: -14...0)
565                Toggle("Include files in subfolders", isOn: $agendaSubfolders)
566            }
567            Section {
568                Toggle("Notify before timed agenda entries", isOn: $reminders)
569                Stepper("\(reminderLead) minutes before", value: $reminderLead, in: 0...120)
570                    .disabled(!reminders)
571            } footer: {
572                Text("An entry's APPT_WARNTIME property overrides the lead time.")
573                    .settingsFooter()
574            }
575        }
576        .formStyle(.grouped)
577        .frame(height: 290)
578    }
579
580    private var capture: some View {
581        Form {
582            Section {
583                Toggle("⌃⌥Space opens Capture from any app", isOn: $globalCapture)
584            } footer: {
585                Text("Templates go in \(CaptureTemplates.userFile.path).")
586                    .settingsFooter()
587            }
588        }
589        .formStyle(.grouped)
590        .frame(height: 160)
591    }
592}
593
594private extension Text {
595    func settingsFooter() -> some View {
596        font(.caption)
597            .foregroundStyle(.secondary)
598            .textSelection(.enabled)
599            .frame(maxWidth: .infinity, alignment: .leading)
600    }
601}