mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 22:40:45 +08:00
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
33 lines
1.3 KiB
Swift
33 lines
1.3 KiB
Swift
import Foundation
|
|
|
|
final class ConfigFileWatcher: @unchecked Sendable, SimpleFileWatcherOwner {
|
|
private let url: URL
|
|
private let watchedDir: URL
|
|
private let targetPath: String
|
|
private let targetName: String
|
|
let watcher: SimpleFileWatcher
|
|
|
|
init(url: URL, onChange: @escaping () -> Void) {
|
|
self.url = url
|
|
self.watchedDir = url.deletingLastPathComponent()
|
|
self.targetPath = url.path
|
|
self.targetName = url.lastPathComponent
|
|
let watchedDirPath = self.watchedDir.path
|
|
let targetPath = self.targetPath
|
|
let targetName = self.targetName
|
|
self.watcher = SimpleFileWatcher(CoalescingFSEventsWatcher(
|
|
paths: [watchedDirPath],
|
|
queueLabel: "ai.openclaw.configwatcher",
|
|
shouldNotify: { _, eventPaths in
|
|
guard let eventPaths else { return true }
|
|
let paths = unsafeBitCast(eventPaths, to: NSArray.self)
|
|
for case let path as String in paths {
|
|
if path == targetPath { return true }
|
|
if path.hasSuffix("/\(targetName)") { return true }
|
|
if path == watchedDirPath { return true }
|
|
}
|
|
return false
|
|
},
|
|
onChange: onChange))
|
|
}
|
|
}
|