fix: update button enabling its package

This commit is contained in:
2025-05-01 16:32:10 +00:00
parent 2e17e0ae75
commit 9b86af282e
11 changed files with 81 additions and 33 deletions

View File

@ -17,6 +17,12 @@ pub struct DownloadTick {
ratio: f32,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct DownloadEndPayload {
pub key: PkgKey,
pub enable: bool
}
impl DownloadHandler {
pub fn new(app: AppHandle) -> DownloadHandler {
DownloadHandler {
@ -25,7 +31,7 @@ impl DownloadHandler {
}
}
pub fn download_zip(&mut self, zip_path: &PathBuf, pkg: &Package) -> Result<()> {
pub fn download_zip(&mut self, zip_path: &PathBuf, pkg: &Package, enable: bool) -> Result<()> {
let rmt = pkg.rmt.as_ref()
.ok_or_else(|| anyhow!("Attempted to download a package without remote data"))?
.clone();
@ -34,12 +40,18 @@ impl DownloadHandler {
} else {
// TODO clear cache button should clear this
self.paths.insert(zip_path.clone());
tauri::async_runtime::spawn(Self::download_zip_proc(self.app.clone(), zip_path.clone(), pkg.key(), rmt));
tauri::async_runtime::spawn(Self::download_zip_proc(self.app.clone(), zip_path.clone(), pkg.key(), rmt, enable));
Ok(())
}
}
async fn download_zip_proc(app: AppHandle, zip_path: PathBuf, pkg_key: PkgKey, rmt: Remote) -> Result<()> {
async fn download_zip_proc(
app: AppHandle,
zip_path: PathBuf,
pkg_key: PkgKey,
rmt: Remote,
enable: bool
) -> Result<()> {
use futures::StreamExt;
use tokio::io::AsyncWriteExt;
@ -66,7 +78,10 @@ impl DownloadHandler {
log::debug!("downloaded to {:?}", zip_path);
app.emit("download-end", pkg_key)?;
app.emit("download-end", DownloadEndPayload {
key: pkg_key,
enable
})?;
Ok(())
}