Skip to content

Commit

Permalink
improve download manaager
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDavenport committed Apr 25, 2024
1 parent 3afa862 commit 0aa0e60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
14 changes: 11 additions & 3 deletions gamercade_app/src/modes/arcade_mode/download_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,29 @@ impl DownloadWindow {
let lock = context.task_manager.http.state.blocking_lock();

lock.rom_downloads.iter().for_each(|(key, value)| {
let game_name = context
.directory
.cached_games
.iter()
.find(|game| game.id == *key)
.map(|game| game.title.as_str())
.unwrap_or("Unknown Game");

match value.download_status {
DownloadStatus::Starting => {
ui.label(format!("{key}: Starting..."));
ui.label(format!("{game_name}: Starting..."));
}
DownloadStatus::InProgress {
bytes_downloaded,
total_bytes,
} => {
ui.label(format!(
"{key}: {}",
"{game_name}: {}",
bytes_downloaded as f32 / total_bytes as f32
));
}
DownloadStatus::Done(_) => {
ui.label(format!("{key}: Done"));
ui.label(format!("{game_name}: Done"));
}
}
});
Expand Down
6 changes: 6 additions & 0 deletions gamercade_app/src/task_manager/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ fn download_file(
}
}
Ok(None) => {
// Download is done

// Remove it from the active download list.
let mut lock = state.lock().await;
lock.rom_downloads.remove(&request.game_id);

// Create the directory
let _ = tokio::fs::create_dir_all(GAME_DIR).await;

Expand Down

0 comments on commit 0aa0e60

Please sign in to comment.