diff --git a/src/core/tasks/scheduler.rs b/src/core/tasks/scheduler.rs index c108ca86..371ec282 100644 --- a/src/core/tasks/scheduler.rs +++ b/src/core/tasks/scheduler.rs @@ -197,14 +197,14 @@ impl Scheduler { }); let running = self.running.clone(); - let mut last = 100; + let mut last = (100, 0); tokio::spawn(async move { loop { sleep(Duration::from_secs(1)).await; if running.read().is_empty() { - if last != 100 { - last = 100; - emit!(Progress(100, 0)); + if last != (100, 0) { + last = (100, 0); + emit!(Progress(last.0, last.1)); } continue; } @@ -218,19 +218,19 @@ impl Scheduler { progress = (progress.0 + task.done, progress.1 + task.todo); } - let mut new = match progress.1 { + let mut percent = match progress.1 { 0 => 100u8, _ => 100.min(progress.0 * 100 / progress.1) as u8, }; if tasks != 0 { - new = new.min(99); + percent = percent.min(99); left = left.max(1); } - if new != last { - last = new; - emit!(Progress(new, left)); + if last != (percent, left) { + last = (percent, left); + emit!(Progress(last.0, last.1)); } } }); diff --git a/src/core/tasks/tasks.rs b/src/core/tasks/tasks.rs index 090c0f31..777c6fe9 100644 --- a/src/core/tasks/tasks.rs +++ b/src/core/tasks/tasks.rs @@ -212,15 +212,6 @@ impl Tasks { } false } - - pub fn update_progress(&mut self, percent: u8, left: u32) -> bool { - if self.progress.0 == percent { - return false; - } - - self.progress = (percent, left); - true - } } impl Tasks { diff --git a/src/ui/app.rs b/src/ui/app.rs index 71322ea1..d753f1ca 100644 --- a/src/ui/app.rs +++ b/src/ui/app.rs @@ -132,7 +132,7 @@ impl App { self.cx.tasks.file_open(targets); } Event::Progress(percent, left) => { - self.cx.tasks.update_progress(percent, left); + self.cx.tasks.progress = (percent, left); emit!(Render); }