krz/orgstar

A native macOS editor for org-mode files. editor org-mode swift

Commit 0e58e1b1ae

0e58e1b1ae285390762ec1b8bf93c882ecc94a02

parent: 68b118ae7a

Verified · cmc

cmc <hello@cleberg.net> · 2026-10-08 03:40 UTC

Watch the legacy Application Support folder for config edits

A keymap.toml (or other config file) read from the folder earlier
versions used now reloads when edited there.

Layout: unified · split

Sources/OrgApp/ConfigSync.swift +7 −2
@@ -62,8 +62,11 @@ public final class ConfigSync {
62 MainActor.assumeIsolated { self?.writeBack() } 62 MainActor.assumeIsolated { self?.writeBack() }
63 } 63 }
64 guard watch else { return } 64 guard watch else { return }
65 let directory = url.deletingLastPathComponent() 65 let directory = url.deletingLastPathComponent().resolvingSymlinksInPath()
66 watcher = FSEventsWatcher(roots: [directory.resolvingSymlinksInPath()]) { [weak self] events in 66 // Files still read from where earlier versions kept them reload when edited there too.
67 let legacy = UserConfig.legacyDirectory.resolvingSymlinksInPath()
68 let watchesLegacy = legacy.path != directory.path && FileManager.default.fileExists(atPath: legacy.path)
69 watcher = FSEventsWatcher(roots: [directory] + (watchesLegacy ? [legacy] : [])) { [weak self] events in
67 let changed = Set(events.compactMap { event -> URL? in 70 let changed = Set(events.compactMap { event -> URL? in
68 if case .changed(let url) = event { return url } 71 if case .changed(let url) = event { return url }
69 return nil 72 return nil
@@ -71,6 +74,8 @@ public final class ConfigSync {
71 Task { @MainActor [weak self] in 74 Task { @MainActor [weak self] in
72 guard let self else { return } 75 guard let self else { return }
73 for file in changed.sorted(by: { $0.path < $1.path }) { 76 for file in changed.sorted(by: { $0.path < $1.path }) {
77 if !file.path.hasPrefix(directory.path + "/"),
78 UserConfig.file(file.lastPathComponent).resolvingSymlinksInPath().path != file.resolvingSymlinksInPath().path { continue }
74 let name = file.lastPathComponent 79 let name = file.lastPathComponent
75 if name == self.url.lastPathComponent { self.reload() } 80 if name == self.url.lastPathComponent { self.reload() }
76 if self.isThemeFile(file) { self.readTheme() } 81 if self.isThemeFile(file) { self.readTheme() }
Sources/OrgApp/UserConfig.swift +6 −2
@@ -23,12 +23,16 @@ public enum UserConfig {
23 return URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent(".config/orgstar") 23 return URL(fileURLWithPath: NSHomeDirectory()).appendingPathComponent(".config/orgstar")
24 } 24 }
25 25
26 /// Where earlier versions kept the configuration files.
27 public static var legacyDirectory: URL {
28 FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0].appendingPathComponent("Orgstar")
29 }
30
26 /// A file of the configuration folder; one that exists only where earlier versions kept 31 /// A file of the configuration folder; one that exists only where earlier versions kept
27 /// it (Application Support) is still read from there. 32 /// it (Application Support) is still read from there.
28 public static func file(_ name: String) -> URL { 33 public static func file(_ name: String) -> URL {
29 let url = directory.appendingPathComponent(name) 34 let url = directory.appendingPathComponent(name)
30 let legacy = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0] 35 let legacy = legacyDirectory.appendingPathComponent(name)
31 .appendingPathComponent("Orgstar").appendingPathComponent(name)
32 let manager = FileManager.default 36 let manager = FileManager.default
33 if !manager.fileExists(atPath: url.path), manager.fileExists(atPath: legacy.path) { return legacy } 37 if !manager.fileExists(atPath: url.path), manager.fileExists(atPath: legacy.path) { return legacy }
34 return url 38 return url