Commit 0e58e1b1ae
Verified · cmc
Layout: unified · split
Sources/OrgApp/ConfigSync.swift +7 −2
| @@ -62,8 +62,11 @@ public final class ConfigSync { | ||
| 62 | 62 | MainActor.assumeIsolated { self?.writeBack() } |
| 63 | 63 | } |
| 64 | 64 | guard watch else { return } |
| 65 | let directory = url.deletingLastPathComponent() | |
| 66 | watcher = FSEventsWatcher(roots: [directory.resolvingSymlinksInPath()]) { [weak self] events in | |
| 65 | let directory = url.deletingLastPathComponent().resolvingSymlinksInPath() | |
| 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 | 70 | let changed = Set(events.compactMap { event -> URL? in |
| 68 | 71 | if case .changed(let url) = event { return url } |
| 69 | 72 | return nil |
| @@ -71,6 +74,8 @@ public final class ConfigSync { | ||
| 71 | 74 | Task { @MainActor [weak self] in |
| 72 | 75 | guard let self else { return } |
| 73 | 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 | 79 | let name = file.lastPathComponent |
| 75 | 80 | if name == self.url.lastPathComponent { self.reload() } |
| 76 | 81 | if self.isThemeFile(file) { self.readTheme() } |
Sources/OrgApp/UserConfig.swift +6 −2
| @@ -23,12 +23,16 @@ public enum UserConfig { | ||
| 23 | 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 | 31 | /// A file of the configuration folder; one that exists only where earlier versions kept |
| 27 | 32 | /// it (Application Support) is still read from there. |
| 28 | 33 | public static func file(_ name: String) -> URL { |
| 29 | 34 | let url = directory.appendingPathComponent(name) |
| 30 | let legacy = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0] | |
| 31 | .appendingPathComponent("Orgstar").appendingPathComponent(name) | |
| 35 | let legacy = legacyDirectory.appendingPathComponent(name) | |
| 32 | 36 | let manager = FileManager.default |
| 33 | 37 | if !manager.fileExists(atPath: url.path), manager.fileExists(atPath: legacy.path) { return legacy } |
| 34 | 38 | return url |