Skip to content

Commit 2e7bbb1

Browse files
committed
fix: RemoveKind is triggered on config updates
1 parent 189b00c commit 2e7bbb1

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

crates/but-settings/src/watch.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::AppSettings;
22
use anyhow::Result;
3-
use notify::{Config, Event, RecommendedWatcher, RecursiveMode, Watcher, event::ModifyKind};
3+
use notify::{
4+
Config, Event, RecommendedWatcher, RecursiveMode, Watcher, event::ModifyKind, event::RemoveKind,
5+
};
46
use std::ops::{Deref, DerefMut};
57
use std::path::Path;
68
use std::{
@@ -130,7 +132,20 @@ impl AppSettingsWithDiskSync {
130132
send_event(update)?;
131133
}
132134
}
133-
135+
Ok(Ok(Event {
136+
kind: notify::event::EventKind::Remove(RemoveKind::File),
137+
..
138+
})) if cfg!(target_os = "linux") => {
139+
let Ok(mut last_seen_settings) = snapshot.write() else {
140+
continue;
141+
};
142+
if let Ok(update) = AppSettings::load(&config_path) {
143+
tracing::info!("settings.json modified; refreshing settings");
144+
*last_seen_settings = update.clone();
145+
watcher.watch(&config_path, RecursiveMode::NonRecursive)?;
146+
send_event(update)?;
147+
}
148+
}
134149
Err(_) => {
135150
tracing::error!(
136151
"Error watching config file {:?} - watcher terminated",

0 commit comments

Comments
 (0)