Claude: Cancel download and disabled back and next button while downloading
This commit is contained in:
parent
b2fcbbffe1
commit
ae06bec3ed
@ -32,6 +32,7 @@ pub struct DownloadState {
|
||||
pub completed: bool,
|
||||
pub files: Option<Vec<PathBuf>>,
|
||||
pub error: Option<String>,
|
||||
pub cancelled: bool,
|
||||
}
|
||||
|
||||
pub struct SinfarInstallerApp<> {
|
||||
@ -96,9 +97,12 @@ impl<> eframe::App for SinfarInstallerApp<> {
|
||||
|
||||
if self.state == InstallerState::Download {
|
||||
if let Ok(state) = self.download_state.lock() {
|
||||
self.download_progress = state.progress;
|
||||
self.download_speed = state.speed;
|
||||
self.estimated_remaining = state.estimated_remaining;
|
||||
// Only update progress if not cancelled
|
||||
if !state.cancelled {
|
||||
self.download_progress = state.progress;
|
||||
self.download_speed = state.speed;
|
||||
self.estimated_remaining = state.estimated_remaining;
|
||||
}
|
||||
|
||||
if let Some(error) = &state.error {
|
||||
self.download_error = Some(error.clone());
|
||||
@ -150,6 +154,13 @@ impl<> eframe::App for SinfarInstallerApp<> {
|
||||
None => false,
|
||||
}
|
||||
},
|
||||
InstallerState::Download => {
|
||||
if let Ok(state) = self.download_state.lock() {
|
||||
state.completed && state.files.is_some()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
_ => true,
|
||||
};
|
||||
|
||||
@ -163,10 +174,20 @@ impl<> eframe::App for SinfarInstallerApp<> {
|
||||
}
|
||||
}
|
||||
|
||||
if self.state != InstallerState::GameSelection {
|
||||
if ui.button("Back").clicked() {
|
||||
self.previous_state();
|
||||
}
|
||||
let can_go_back = match self.state {
|
||||
InstallerState::Download => {
|
||||
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) {
|
||||
|
||||
|
||||
|
@ -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 {
|
||||
ui.colored_label(eframe::egui::Color32::RED, format!("Error: {}", error));
|
||||
if ui.button("Retry").clicked() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user