Fix: showing config file changed notice after remote config update

This commit is contained in:
yichengchen 2019-07-29 19:01:07 +08:00
parent 19e6986345
commit 520735a5a4
2 changed files with 20 additions and 5 deletions

View File

@ -12,11 +12,22 @@ import Yams
class ConfigFileManager {
static let shared = ConfigFileManager()
var witness:Witness?
private var witness:Witness?
private var pause = false
func pauseForNextChange() {
pause = true
}
func watchConfigFile(configName:String) {
let path = "\(kConfigFolderPath)\(configName).yaml"
witness = Witness(paths: [path], flags: .FileEvents, latency: 0.3) { events in
witness = Witness(paths: [path], flags: .FileEvents, latency: 0.3) {
[weak self] events in
guard let self = self else {return}
guard !self.pause else {
self.pause = false
return
}
for event in events {
if event.flags.contains(.ItemModified){
NSUserNotificationCenter.default

View File

@ -153,10 +153,14 @@ class RemoteConfigManager {
return
}
let savePath = kConfigFolderPath.appending(config.name).appending(".yaml")
let fm = FileManager.default
if config.name == ConfigManager.selectConfigName {
ConfigFileManager.shared.pauseForNextChange()
}
do {
if fm.fileExists(atPath: savePath) {
try fm.removeItem(atPath: savePath)
if FileManager.default.fileExists(atPath: savePath) {
try FileManager.default.removeItem(atPath: savePath)
}
try newData.write(to: URL(fileURLWithPath: savePath))
complete?(nil)