Fix: showing config file changed notice after remote config update
This commit is contained in:
parent
19e6986345
commit
520735a5a4
|
@ -12,11 +12,22 @@ import Yams
|
||||||
|
|
||||||
class ConfigFileManager {
|
class ConfigFileManager {
|
||||||
static let shared = ConfigFileManager()
|
static let shared = ConfigFileManager()
|
||||||
var witness:Witness?
|
private var witness:Witness?
|
||||||
|
private var pause = false
|
||||||
|
|
||||||
|
func pauseForNextChange() {
|
||||||
|
pause = true
|
||||||
|
}
|
||||||
|
|
||||||
func watchConfigFile(configName:String) {
|
func watchConfigFile(configName:String) {
|
||||||
let path = "\(kConfigFolderPath)\(configName).yaml"
|
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 {
|
for event in events {
|
||||||
if event.flags.contains(.ItemModified){
|
if event.flags.contains(.ItemModified){
|
||||||
NSUserNotificationCenter.default
|
NSUserNotificationCenter.default
|
||||||
|
|
|
@ -153,10 +153,14 @@ class RemoteConfigManager {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let savePath = kConfigFolderPath.appending(config.name).appending(".yaml")
|
let savePath = kConfigFolderPath.appending(config.name).appending(".yaml")
|
||||||
let fm = FileManager.default
|
|
||||||
|
if config.name == ConfigManager.selectConfigName {
|
||||||
|
ConfigFileManager.shared.pauseForNextChange()
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if fm.fileExists(atPath: savePath) {
|
if FileManager.default.fileExists(atPath: savePath) {
|
||||||
try fm.removeItem(atPath: savePath)
|
try FileManager.default.removeItem(atPath: savePath)
|
||||||
}
|
}
|
||||||
try newData.write(to: URL(fileURLWithPath: savePath))
|
try newData.write(to: URL(fileURLWithPath: savePath))
|
||||||
complete?(nil)
|
complete?(nil)
|
||||||
|
|
Loading…
Reference in New Issue