diff --git a/CHANGELOG.md b/CHANGELOG.md index b6d89d1..b536924 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.19.1 + +- Fixed the update button enabling the package + +## 0.19.0 + +- Added diagnostic exports + ## 0.18.3 - Updated Rainycolor's domain・真 diff --git a/rust/src/cmd.rs b/rust/src/cmd.rs index 7f034a1..1d93105 100644 --- a/rust/src/cmd.rs +++ b/rust/src/cmd.rs @@ -125,12 +125,13 @@ pub async fn kill() -> Result<(), String> { pub async fn install_package( state: State<'_, tokio::sync::Mutex>, key: PkgKey, - force: bool + force: bool, + enable: bool ) -> Result { log::debug!("invoke: install_package({})", key); let mut appd = state.lock().await; - appd.pkgs.install_package(&key, force, true) + appd.pkgs.install_package(&key, force, true, enable) .await .map_err(|e| e.to_string()) } diff --git a/rust/src/download_handler.rs b/rust/src/download_handler.rs index 2c1b7a2..316cc33 100644 --- a/rust/src/download_handler.rs +++ b/rust/src/download_handler.rs @@ -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(()) } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 8d1a4c7..5fe1ce6 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -102,16 +102,23 @@ pub async fn run(_args: Vec) { }); app.listen("download-end", closure!(clone apph, |ev| { - let raw = ev.payload(); - log::debug!("download-end triggered: {}", raw); - let key = PkgKey(raw[1..raw.len()-1].to_owned()); - let apph = apph.clone(); - tauri::async_runtime::spawn(async move { - let mutex = apph.state::>(); - let mut appd = mutex.lock().await; - let res = appd.pkgs.install_package(&key, true, false).await; - log::debug!("download-end install {:?}", res); - }); + let payload = serde_json::from_str::(ev.payload()); + match payload { + Ok(payload) => { + log::debug!("download-end triggered: {:?}", payload); + let key = payload.key; + let apph = apph.clone(); + tauri::async_runtime::spawn(async move { + let mutex = apph.state::>(); + let mut appd = mutex.lock().await; + let res = appd.pkgs.install_package(&key, true, false, payload.enable).await; + log::debug!("download-end install {:?}", res); + }); + }, + Err(err) => { + log::error!("invalid download payload: {err}"); + } + } })); app.listen("launch-end", closure!(clone apph, |_| { @@ -134,11 +141,13 @@ pub async fn run(_args: Vec) { tauri::async_runtime::spawn(async move { let mutex = apph.state::>(); let mut appd = mutex.lock().await; - let res = appd.toggle_package(payload.pkg.clone(), ToggleAction::EnableSelf); - log::debug!( - "install-end-prelude toggle {:?}", - res - ); + if payload.enable == true { + let res = appd.toggle_package(payload.pkg.clone(), ToggleAction::EnableSelf); + log::debug!( + "install-end-prelude toggle {:?}", + res + ); + } use tauri::Emitter; let res = apph.emit("install-end", payload); log::debug!("install-end {:?}", res); @@ -273,7 +282,7 @@ fn deep_link(app: AppHandle, args: Vec) { let mut appd = mutex.lock().await; if appd.pkgs.is_offline() { log::warn!("Deep link installation failed: offline"); - } else if let Err(e) = appd.pkgs.install_package(&key, true, true).await { + } else if let Err(e) = appd.pkgs.install_package(&key, true, true, true).await { log::warn!("Deep link installation failed: {}", e.to_string()); } }); diff --git a/rust/src/pkg_store.rs b/rust/src/pkg_store.rs index 6a32860..3301bd5 100644 --- a/rust/src/pkg_store.rs +++ b/rust/src/pkg_store.rs @@ -23,7 +23,8 @@ pub struct PackageStore { #[derive(Clone, Serialize, Deserialize, Debug)] pub struct Payload { - pub pkg: PkgKey + pub pkg: PkgKey, + pub enable: bool, } #[derive(Clone, Copy, Serialize, Deserialize, Debug)] @@ -180,7 +181,13 @@ impl PackageStore { self.offline = false; } - pub async fn install_package(&mut self, key: &PkgKey, force: bool, install_deps: bool) -> Result { + pub async fn install_package( + &mut self, + key: &PkgKey, + force: bool, + install_deps: bool, + enable: bool + ) -> Result { log::info!("installation request: {}/{}/{}", key, force, install_deps); let pkg = self.store.get(key) @@ -193,7 +200,8 @@ impl PackageStore { } self.app.emit("install-start", Payload { - pkg: key.to_owned() + pkg: key.to_owned(), + enable })?; let rmt = pkg.rmt.as_ref() @@ -203,7 +211,7 @@ impl PackageStore { let mut set = HashSet::new(); self.resolve_deps(rmt.clone(), &mut set)?; for dep in set { - Box::pin(self.install_package(&dep, false, false)).await?; + Box::pin(self.install_package(&dep, false, false, enable)).await?; } } @@ -214,7 +222,7 @@ impl PackageStore { let part_path = zip_path.join(".part"); if !zip_path.exists() && !part_path.exists() { - self.dlh.download_zip(&zip_path, &pkg)?; + self.dlh.download_zip(&zip_path, &pkg, enable)?; log::debug!("deferring {}", key); return Ok(InstallResult::Deferred); } @@ -230,7 +238,8 @@ impl PackageStore { self.reload_package(key.to_owned()).await; self.app.emit("install-end-prelude", Payload { - pkg: key.to_owned() + pkg: key.to_owned(), + enable })?; log::info!("installed {}", key); @@ -252,7 +261,8 @@ impl PackageStore { if rv.is_ok() { self.app.emit("install-end-prelude", Payload { - pkg: key.to_owned() + pkg: key.to_owned(), + enable: false })?; log::info!("deleted {}", key); } diff --git a/src/components/App.vue b/src/components/App.vue index fdb38a9..92cee98 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -295,7 +295,7 @@ listen('download-progress', (event) => { pkg.hasAvailableUpdates " icon="pi pi-download" - label="UPDATE ALL" + :label="t('updateAll')" size="small" class="mr-4 m-2.5" @click="pkg.updateAll()" diff --git a/src/components/InstallButton.vue b/src/components/InstallButton.vue index 43ae09f..2b36d07 100644 --- a/src/components/InstallButton.vue +++ b/src/components/InstallButton.vue @@ -53,6 +53,6 @@ const remove = async () => { class="self-center ml-4" style="width: 2rem; height: 2rem" :loading="pkg?.js.downloading" - v-on:click="async () => await pkgs.install(pkg)" + v-on:click="async () => await pkgs.install(pkg, true)" /> diff --git a/src/components/UpdateButton.vue b/src/components/UpdateButton.vue index 0bf24f0..c6d7ccd 100644 --- a/src/components/UpdateButton.vue +++ b/src/components/UpdateButton.vue @@ -17,6 +17,7 @@ const install = async () => { await invoke('install_package', { key: pkgKey(props.pkg), force: true, + enable: false, }); } catch (err) { if (props.pkg !== undefined) { diff --git a/src/i18n/en.ts b/src/i18n/en.ts index 437dea4..efe8a1b 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -9,6 +9,7 @@ export default { skip: 'Skip', close: 'Close', by: 'by {namespace}', + updateAll: 'UPDATE ALL', start: { failed: 'Start check failed', accept: 'Run anyway', diff --git a/src/i18n/pl.ts b/src/i18n/pl.ts index c591498..618beeb 100644 --- a/src/i18n/pl.ts +++ b/src/i18n/pl.ts @@ -9,6 +9,7 @@ export default { skip: 'Pomiń', close: 'Zamknij', by: 'od {namespace}', + updateAll: 'ZAKTUALIZUJ WSZYSTKO', start: { failed: 'Uruchomienie nie powiodło się', accept: 'Uruchom mimo to', diff --git a/src/stores.ts b/src/stores.ts index 9dac0a0..0db6765 100644 --- a/src/stores.ts +++ b/src/stores.ts @@ -189,7 +189,7 @@ export const usePkgStore = defineStore('pkg', { await this.reloadAll(); }, - async install(pkg: Package | undefined) { + async install(pkg: Package | undefined, enable: boolean) { if (pkg === undefined) { return; } @@ -198,6 +198,7 @@ export const usePkgStore = defineStore('pkg', { await invoke('install_package', { key: pkgKey(pkg), force: true, + enable, }); } catch (err) { if (pkg !== undefined) { @@ -211,6 +212,7 @@ export const usePkgStore = defineStore('pkg', { await invoke('install_package', { key, force: true, + enable: false, }); } catch (err) { console.error(err); @@ -221,7 +223,7 @@ export const usePkgStore = defineStore('pkg', { const list = []; for (const pkg of this.allLocal) { if (pkg.rmt && pkg.rmt.version > pkg.loc!.version) { - list.push(this.install(pkg)); + list.push(this.install(pkg, false)); } } await Promise.all(list);