Skip to content

Commit c4066ab

Browse files
authored
Merge pull request #10379 from TheGB0077/revert
fix(settings): Enhance settings file observability
2 parents cb26e4e + 15619b4 commit c4066ab

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

crates/but-path/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn app_config_dir() -> anyhow::Result<PathBuf> {
1313
if let Ok(test_dir) = std::env::var("E2E_TEST_APP_DATA_DIR") {
1414
return Ok(PathBuf::from(test_dir).join("gitbutler"));
1515
}
16-
dirs::data_dir()
16+
dirs::config_dir()
1717
.ok_or(anyhow::anyhow!("Could not get app data dir"))
1818
.map(|dir| dir.join("gitbutler"))
1919
}

crates/but-settings/src/watch.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::AppSettings;
22
use anyhow::Result;
3+
use notify::event::RemoveKind;
34
use notify::{Config, Event, RecommendedWatcher, RecursiveMode, Watcher, event::ModifyKind};
45
use std::ops::{Deref, DerefMut};
56
use std::path::Path;
@@ -130,7 +131,26 @@ impl AppSettingsWithDiskSync {
130131
send_event(update)?;
131132
}
132133
}
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.
138+
Ok(Ok(Event {
139+
kind: notify::event::EventKind::Remove(RemoveKind::File),
140+
..
141+
})) if cfg!(target_os = "linux") => {
142+
let Ok(mut last_seen_settings) = snapshot.write() else {
143+
continue;
144+
};
145+
if let Ok(update) = AppSettings::load(&config_path) {
146+
tracing::info!("settings.json replaced; refreshing settings");
147+
// Have to rewatch the path here as the watcher loses track.
148+
watcher.watch(&config_path, RecursiveMode::NonRecursive)?;
133149

150+
*last_seen_settings = update.clone();
151+
send_event(update)?;
152+
}
153+
}
134154
Err(_) => {
135155
tracing::error!(
136156
"Error watching config file {:?} - watcher terminated",

crates/gitbutler-tauri/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ fn main() {
3737
let mut tauri_context = generate_context!();
3838
gitbutler_secret::secret::set_application_namespace(&tauri_context.config().identifier);
3939

40-
let config_dir = but_path::app_config_dir()
41-
.expect("missing config dir")
42-
.join("gitbutler");
40+
let config_dir = but_path::app_config_dir().expect("missing config dir");
4341
std::fs::create_dir_all(&config_dir).expect("failed to create config dir");
4442
let mut app_settings =
4543
AppSettingsWithDiskSync::new(config_dir.clone()).expect("failed to create app settings");

0 commit comments

Comments
 (0)