fix: restore legacy progress after owned tasks finish

This commit is contained in:
objz committed 2026-10-01 23:01:33 +02:00
1 parent cf9007fa06
commit 615d3fb8fc
2 files changed
+55 -23

No files matched your search

+33 -23
View File
@@ -12,7 +12,7 @@ pub struct ProgressState {
pub progress: Option<(u64, u64)>,
pub sub_action: Option<String>,
tasks: BTreeMap<u64, TaskState>,
legacy_active: bool,
legacy: Option<TaskState>,
}
#[derive(Debug, Clone)]
@@ -28,7 +28,6 @@ static NEXT_TASK_ID: AtomicU64 = AtomicU64::new(1);
pub struct ProgressTask {
id: u64,
finished: bool,
}
#[derive(Clone)]
@@ -53,10 +52,7 @@ impl ProgressTask {
}
tracing::info!("{}", action);
super::request_redraw();
Self {
id,
finished: false,
}
Self { id }
}
pub fn handle(&self) -> ProgressTaskHandle {
@@ -75,15 +71,13 @@ impl ProgressTask {
update_task_progress(self.id, current, total);
}
pub fn finish(mut self) {
self.remove();
self.finished = true;
pub fn finish(self) {
drop(self);
}
pub fn fail(mut self, error: impl std::fmt::Display) {
pub fn fail(self, error: impl std::fmt::Display) {
tracing::debug!("Progress task failed: {error}");
self.remove();
self.finished = true;
drop(self);
}
fn remove(&self) {
@@ -138,18 +132,21 @@ fn update_task_progress(id: u64, current: u64, total: u64) {
impl Drop for ProgressTask {
fn drop(&mut self) {
if !self.finished {
self.remove();
}
self.remove();
}
}
fn refresh_visible(state: &mut ProgressState) {
if let Some((_, task)) = state.tasks.last_key_value() {
if let Some(task) = state
.tasks
.last_key_value()
.map(|(_, task)| task)
.or(state.legacy.as_ref())
{
state.current_action = Some(task.action.clone());
state.sub_action.clone_from(&task.sub_action);
state.progress = task.progress;
} else if !state.legacy_active {
} else {
state.current_action = None;
state.sub_action = None;
state.progress = None;
@@ -160,9 +157,16 @@ pub fn set_action(text: impl Into<String>) {
let text = text.into();
match PROGRESS.lock() {
Ok(mut state) => {
state.legacy_active = true;
state.current_action = Some(text.clone());
state.progress = None;
let sub_action = state
.legacy
.as_ref()
.and_then(|task| task.sub_action.clone());
state.legacy = Some(TaskState {
action: text.clone(),
sub_action,
progress: None,
});
refresh_visible(&mut state);
super::request_redraw();
}
Err(e) => {
@@ -175,7 +179,10 @@ pub fn set_action(text: impl Into<String>) {
pub fn set_progress(current: u64, total: u64) {
match PROGRESS.lock() {
Ok(mut state) => {
state.progress = Some((current, total));
if let Some(task) = state.legacy.as_mut() {
task.progress = Some((current, total));
}
refresh_visible(&mut state);
super::request_redraw();
}
Err(e) => {
@@ -188,7 +195,10 @@ pub fn set_sub_action(text: impl Into<String>) {
let text = text.into();
match PROGRESS.lock() {
Ok(mut state) => {
state.sub_action = Some(text.clone());
if let Some(task) = state.legacy.as_mut() {
task.sub_action = Some(text.clone());
}
refresh_visible(&mut state);
super::request_redraw();
}
Err(e) => {
@@ -201,7 +211,7 @@ pub fn set_sub_action(text: impl Into<String>) {
pub fn clear() {
match PROGRESS.lock() {
Ok(mut state) => {
state.legacy_active = false;
state.legacy = None;
refresh_visible(&mut state);
super::request_redraw();
}