Skip to content

Commit 15619b4

Browse files
committed
refactor
1 parent ba727e8 commit 15619b4

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

crates/but-settings/src/persistence.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ impl AppSettings {
2020

2121
// merge customizations from disk into the defaults to get a complete set of settings.
2222
let customizations = serde_json_lenient::from_str(&std::fs::read_to_string(config_path)?)?;
23-
2423
let mut settings: serde_json::Value = serde_json_lenient::from_str(DEFAULTS)?;
2524

2625
merge_non_null_json_value(customizations, &mut settings);

crates/but-settings/src/watch.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::AppSettings;
22
use anyhow::Result;
3-
use notify::{
4-
Config, Event, RecommendedWatcher, RecursiveMode, Watcher, event::ModifyKind, event::RemoveKind,
5-
};
3+
use notify::event::RemoveKind;
4+
use notify::{Config, Event, RecommendedWatcher, RecursiveMode, Watcher, event::ModifyKind};
65
use std::ops::{Deref, DerefMut};
76
use std::path::Path;
87
use std::{
@@ -132,6 +131,10 @@ impl AppSettingsWithDiskSync {
132131
send_event(update)?;
133132
}
134133
}
134+
// On linux (maybe even other platforms) Modify doesn't trigger as we replace
135+
// the original file with a new one when writing.
136+
// On Linux, the watcher then also doesn't keep watching the new file, despite being
137+
// at the same path.
135138
Ok(Ok(Event {
136139
kind: notify::event::EventKind::Remove(RemoveKind::File),
137140
..
@@ -140,9 +143,11 @@ impl AppSettingsWithDiskSync {
140143
continue;
141144
};
142145
if let Ok(update) = AppSettings::load(&config_path) {
143-
tracing::info!("settings.json modified; refreshing settings");
144-
*last_seen_settings = update.clone();
146+
tracing::info!("settings.json replaced; refreshing settings");
147+
// Have to rewatch the path here as the watcher loses track.
145148
watcher.watch(&config_path, RecursiveMode::NonRecursive)?;
149+
150+
*last_seen_settings = update.clone();
146151
send_event(update)?;
147152
}
148153
}

0 commit comments

Comments
 (0)