summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorChristoph Rüßler <christoph.ruessler@mailbox.org>2023-04-29 17:03:43 +0200
committerGitHub <noreply@github.com>2023-04-29 17:03:43 +0200
commit370aff5fcc316bf381c650942065c06ffb5eb76e (patch)
tree52c87b06cf65231a05dddc9039bb697d9ac8e3f5 /src/main.rs
parent836e03c01c9cadc07be0ce0ab7df097688ac34e1 (diff)
Default to tick-based updates (#1657)
* Default to tick-based updates This commit reintroduces code that was previously removed in favor of a notify-based update trigger. It turned out that notify-based updates can cause issues in larger repositories, so tick-based updates seemed like a safer default. https://github.com/extrawurst/gitui/issues/1444 https://github.com/extrawurst/gitui/pull/1310 * Add FAQ entry for --watcher * Remove --poll
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs
index 26e4b5aa..b1c0ed1f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -56,7 +56,7 @@ use asyncgit::{
AsyncGitNotification,
};
use backtrace::Backtrace;
-use crossbeam_channel::{tick, unbounded, Receiver, Select};
+use crossbeam_channel::{never, tick, unbounded, Receiver, Select};
use crossterm::{
terminal::{
disable_raw_mode, enable_raw_mode, EnterAlternateScreen,
@@ -83,11 +83,13 @@ use std::{
use ui::style::Theme;
use watcher::RepoWatcher;
+static TICK_INTERVAL: Duration = Duration::from_secs(5);
static SPINNER_INTERVAL: Duration = Duration::from_millis(80);
///
#[derive(Clone)]
pub enum QueueEvent {
+ Tick,
Notify,
SpinnerUpdate,
AsyncEvent(AsyncNotification),
@@ -114,6 +116,12 @@ pub enum AsyncNotification {
Git(AsyncGitNotification),
}
+#[derive(Clone, Copy, PartialEq)]
+enum Updater {
+ Ticker,
+ NotifyWatcher,
+}
+
fn main() -> Result<()> {
let app_start = Instant::now();
@@ -145,6 +153,12 @@ fn main() -> Result<()> {
let mut repo_path = cliargs.repo_path;
let input = Input::new();
+ let updater = if cliargs.notify_watcher {
+ Updater::NotifyWatcher
+ } else {
+ Updater::Ticker
+ };
+
loop {
let quit_state = run_app(
app_start,
@@ -152,7 +166,7 @@ fn main() -> Result<()> {
theme,
key_config.clone(),
&input,
- cliargs.poll_watcher,
+ updater,
&mut terminal,
)?;
@@ -173,18 +187,24 @@ fn run_app(
theme: Theme,
key_config: KeyConfig,
input: &Input,
- poll_watcher: bool,
+ updater: Updater,
terminal: &mut Terminal<CrosstermBackend<io::Stdout>>,
) -> Result<QuitState, anyhow::Error> {
let (tx_git, rx_git) = unbounded();
let (tx_app, rx_app) = unbounded();
let rx_input = input.receiver();
- let watcher = RepoWatcher::new(
- repo_work_dir(&repo)?.as_str(),
- poll_watcher,
- );
- let rx_watcher = watcher.receiver();
+
+ let (rx_ticker, rx_watcher) = match updater {
+ Updater::NotifyWatcher => {
+ let repo_watcher =
+ RepoWatcher::new(repo_work_dir(&repo)?.as_str());
+
+ (never(), repo_watcher.receiver())
+ }
+ Updater::Ticker => (tick(TICK_INTERVAL), never()),
+ };
+
let spinner_ticker = tick(SPINNER_INTERVAL);
let mut app = App::new(
@@ -210,6 +230,7 @@ fn run_app(
&rx_input,
&rx_git,
&rx_app,
+ &rx_ticker,
&rx_watcher,
&spinner_ticker,
)?
@@ -235,7 +256,9 @@ fn run_app(
}
app.event(ev)?;
}
- QueueEvent::Notify => app.update()?,
+ QueueEvent::Tick | QueueEvent::Notify => {
+ app.update()?;
+ }
QueueEvent::AsyncEvent(ev) => {
if !matches!(
ev,
@@ -309,6 +332,7 @@ fn select_event(
rx_input: &Receiver<InputEvent>,
rx_git: &Receiver<AsyncGitNotification>,
rx_app: &Receiver<AsyncAppNotification>,
+ rx_ticker: &Receiver<Instant>,
rx_notify: &Receiver<()>,
rx_spinner: &Receiver<Instant>,
) -> Result<QueueEvent> {
@@ -317,6 +341,7 @@ fn select_event(
sel.recv(rx_input);
sel.recv(rx_git);
sel.recv(rx_app);
+ sel.recv(rx_ticker);
sel.recv(rx_notify);
sel.recv(rx_spinner);
@@ -331,8 +356,9 @@ fn select_event(
2 => oper.recv(rx_app).map(|e| {
QueueEvent::AsyncEvent(AsyncNotification::App(e))
}),
- 3 => oper.recv(rx_notify).map(|_| QueueEvent::Notify),
- 4 => oper.recv(rx_spinner).map(|_| QueueEvent::SpinnerUpdate),
+ 3 => oper.recv(rx_ticker).map(|_| QueueEvent::Notify),
+ 4 => oper.recv(rx_notify).map(|_| QueueEvent::Notify),
+ 5 => oper.recv(rx_spinner).map(|_| QueueEvent::SpinnerUpdate),
_ => bail!("unknown select source"),
}?;