From e7d11467941e74cab76a87a45fe2c0ea75a6e156 Mon Sep 17 00:00:00 2001 From: Sean Billig Date: Tue, 14 Jan 2025 22:10:04 -0800 Subject: [PATCH] config: add `refresh_on_file_change` bool to en/disable file watcher --- src/config.rs | 1 + src/default_config.toml | 1 + src/lib.rs | 13 +++++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/config.rs b/src/config.rs index 513e8bcb07..625931db6c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,6 +22,7 @@ pub(crate) struct Config { pub struct GeneralConfig { pub always_show_help: BoolConfigEntry, pub confirm_quit: BoolConfigEntry, + pub refresh_on_file_change: BoolConfigEntry, pub collapsed_sections: Vec, } diff --git a/src/default_config.toml b/src/default_config.toml index db88c791db..eaf97e74b1 100644 --- a/src/default_config.toml +++ b/src/default_config.toml @@ -8,6 +8,7 @@ confirm_quit.enabled = false # Sets initially collapsed sections in the editor. e.g.: # collapsed_sections = ["untracked", "recent_commits", "branch_status"] collapsed_sections = [] +refresh_on_file_change.enabled = true [style] # fg / bg can be either of: diff --git a/src/lib.rs b/src/lib.rs index 022dda6b30..9a335e8495 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,10 +87,10 @@ pub fn run(args: &cli::Args, term: &mut Term) -> Res<()> { repo.set_workdir(&dir, false)?; log::debug!("Initializing config"); - let config = config::init_config()?; + let config = Rc::new(config::init_config()?); log::debug!("Creating initial state"); - let mut state = state::State::create(Rc::new(repo), term.size()?, args, Rc::new(config), true)?; + let mut state = state::State::create(Rc::new(repo), term.size()?, args, config.clone(), true)?; log::debug!("Initial update"); state.update(term, &[GituEvent::Term(Event::FocusGained)])?; @@ -106,7 +106,12 @@ pub fn run(args: &cli::Args, term: &mut Term) -> Res<()> { handle_initial_send_keys(&keys, &mut state, term)?; } - let watcher = FileWatcher::new(&dir)?; + let watcher = config + .general + .refresh_on_file_change + .enabled + .then(|| FileWatcher::new(&dir)) + .transpose()?; while !state.quit { let mut events = if event::poll(Duration::from_millis(100))? { @@ -115,7 +120,7 @@ pub fn run(args: &cli::Args, term: &mut Term) -> Res<()> { vec![] }; - if watcher.pending_updates() { + if watcher.as_ref().is_some_and(|w| w.pending_updates()) { events.push(GituEvent::FileUpdate); } state.update(term, &events)?;