Claude: Cancel download and disabled back and next button while downloading

This commit is contained in:
Fiery Imp 2025-04-23 17:20:57 -04:00
parent b2fcbbffe1
commit ae06bec3ed
2 changed files with 50 additions and 7 deletions

View File

@ -32,6 +32,7 @@ pub struct DownloadState {
pub completed: bool, pub completed: bool,
pub files: Option<Vec<PathBuf>>, pub files: Option<Vec<PathBuf>>,
pub error: Option<String>, pub error: Option<String>,
pub cancelled: bool,
} }
pub struct SinfarInstallerApp<> { pub struct SinfarInstallerApp<> {
@ -96,9 +97,12 @@ impl<> eframe::App for SinfarInstallerApp<> {
if self.state == InstallerState::Download { if self.state == InstallerState::Download {
if let Ok(state) = self.download_state.lock() { if let Ok(state) = self.download_state.lock() {
// Only update progress if not cancelled
if !state.cancelled {
self.download_progress = state.progress; self.download_progress = state.progress;
self.download_speed = state.speed; self.download_speed = state.speed;
self.estimated_remaining = state.estimated_remaining; self.estimated_remaining = state.estimated_remaining;
}
if let Some(error) = &state.error { if let Some(error) = &state.error {
self.download_error = Some(error.clone()); self.download_error = Some(error.clone());
@ -150,6 +154,13 @@ impl<> eframe::App for SinfarInstallerApp<> {
None => false, None => false,
} }
}, },
InstallerState::Download => {
if let Ok(state) = self.download_state.lock() {
state.completed && state.files.is_some()
} else {
false
}
},
_ => true, _ => true,
}; };
@ -163,10 +174,20 @@ impl<> eframe::App for SinfarInstallerApp<> {
} }
} }
if self.state != InstallerState::GameSelection { let can_go_back = match self.state {
if ui.button("Back").clicked() { InstallerState::Download => {
self.previous_state(); if let Ok(state) = self.download_state.lock() {
state.progress == 0.0 || state.completed || state.error.is_some()
} else {
true
} }
},
InstallerState::GameSelection => false,
_ => true
};
if ui.add_enabled(can_go_back, egui::Button::new("Back")).clicked() {
self.previous_state();
} }
} }
}); });
@ -232,6 +253,19 @@ impl SinfarInstallerApp<> {
}); });
} }
pub fn cancel_download(&mut self) {
if let Ok(mut state) = self.download_state.lock() {
state.error = Some("Download cancelled".to_string());
state.progress = 0.0;
state.cancelled = true;
state.speed = 0.0;
state.estimated_remaining = std::time::Duration::from_secs(0);
}
self.download_progress = 0.0;
self.download_speed = 0.0;
self.estimated_remaining = std::time::Duration::from_secs(0);
}
pub fn start_installation(&mut self) { pub fn start_installation(&mut self) {

View File

@ -44,6 +44,15 @@ pub mod download_progress {
} }
}); });
ui.add_space(10.0);
// Add cancel button during active download
if app.download_progress > 0.0 && app.download_progress < 1.0 {
if ui.button("Cancel Download").clicked() {
app.cancel_download();
}
}
if let Some(error) = &app.download_error { if let Some(error) = &app.download_error {
ui.colored_label(eframe::egui::Color32::RED, format!("Error: {}", error)); ui.colored_label(eframe::egui::Color32::RED, format!("Error: {}", error));
if ui.button("Retry").clicked() { if ui.button("Retry").clicked() {