From 0bc5d5887420ba1eb718254490b7995c771c0447 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Fri, 28 Mar 2025 18:53:49 +0800 Subject: [PATCH] fix(updater): download reuses check's timeout (#2572) * fix(updater): download inherit timeout from check * Add change file --- .changes/updater-download-inherit-check-timeout.md | 6 ++++++ plugins/updater/README.md | 2 +- plugins/updater/guest-js/index.ts | 5 ++++- plugins/updater/src/commands.rs | 2 ++ plugins/updater/src/lib.rs | 5 ++--- plugins/updater/src/updater.rs | 13 +++++-------- 6 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 .changes/updater-download-inherit-check-timeout.md diff --git a/.changes/updater-download-inherit-check-timeout.md b/.changes/updater-download-inherit-check-timeout.md new file mode 100644 index 00000000..ceca443d --- /dev/null +++ b/.changes/updater-download-inherit-check-timeout.md @@ -0,0 +1,6 @@ +--- +"updater": "patch:bug" +"updater-js": "patch:bug" +--- + +Fix `timeout` passed to `check` gets re-used by `download` and `downloadAndinstall` diff --git a/plugins/updater/README.md b/plugins/updater/README.md index f1d91b1c..79fea467 100644 --- a/plugins/updater/README.md +++ b/plugins/updater/README.md @@ -76,7 +76,7 @@ Afterwards all the plugin's APIs are available through the JavaScript guest bind import { check } from '@tauri-apps/plugin-updater' import { relaunch } from '@tauri-apps/plugin-process' const update = await check() -if (update?.available) { +if (update) { await update.downloadAndInstall() await relaunch() } diff --git a/plugins/updater/guest-js/index.ts b/plugins/updater/guest-js/index.ts index dfaaff24..07625eea 100644 --- a/plugins/updater/guest-js/index.ts +++ b/plugins/updater/guest-js/index.ts @@ -133,7 +133,10 @@ async function check(options?: CheckOptions): Promise { return await invoke('plugin:updater|check', { ...options - }).then((meta) => (meta.available ? new Update(meta) : null)) + }).then((meta) => + // TODO: Handle this in the rust side + meta.available ? new Update(meta) : null + ) } export type { CheckOptions, DownloadOptions, DownloadEvent } diff --git a/plugins/updater/src/commands.rs b/plugins/updater/src/commands.rs index eed3cd77..55d504bb 100644 --- a/plugins/updater/src/commands.rs +++ b/plugins/updater/src/commands.rs @@ -40,6 +40,8 @@ pub(crate) struct Metadata { struct DownloadedBytes(pub Vec); impl Resource for DownloadedBytes {} +// TODO: Align this with the result of `updater.check` to Result> +// and remove `available` instead of handling this in the js side #[tauri::command] pub(crate) async fn check( webview: Webview, diff --git a/plugins/updater/src/lib.rs b/plugins/updater/src/lib.rs index 75b014bc..fb059e43 100644 --- a/plugins/updater/src/lib.rs +++ b/plugins/updater/src/lib.rs @@ -153,8 +153,7 @@ impl Builder { I: IntoIterator, S: Into, { - let args = args.into_iter().map(|a| a.into()).collect::>(); - self.installer_args.extend_from_slice(&args); + self.installer_args.extend(args.into_iter().map(Into::into)); self } @@ -214,7 +213,7 @@ impl Builder { config.pubkey = pubkey; } if let Some(windows) = &mut config.windows { - windows.installer_args.extend_from_slice(&installer_args); + windows.installer_args.extend(installer_args); } app.manage(UpdaterState { target, diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index 1ae2cfe9..b59272e4 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -124,8 +124,7 @@ pub struct UpdaterBuilder { impl UpdaterBuilder { pub(crate) fn new(app: &AppHandle, config: crate::Config) -> Self { let app_ = app.clone(); - let run_on_main_thread = - move |f: Box| app_.run_on_main_thread(f); + let run_on_main_thread = move |f| app_.run_on_main_thread(f); Self { run_on_main_thread: Box::new(run_on_main_thread), installer_args: config @@ -230,8 +229,7 @@ impl UpdaterBuilder { I: IntoIterator, S: Into, { - let args = args.into_iter().map(|a| a.into()).collect::>(); - self.installer_args.extend_from_slice(&args); + self.installer_args.extend(args.into_iter().map(Into::into)); self } @@ -312,8 +310,7 @@ impl UpdaterBuilder { I: IntoIterator, S: Into, { - let args = args.into_iter().map(|a| a.into()).collect::>(); - self.current_exe_args.extend_from_slice(&args); + self.installer_args.extend(args.into_iter().map(Into::into)); self } } @@ -478,10 +475,10 @@ impl Updater { version: release.version.to_string(), date: release.pub_date, download_url: release.download_url(&self.json_target)?.to_owned(), - body: release.notes.clone(), signature: release.signature(&self.json_target)?.to_owned(), + body: release.notes, raw_json: raw_json.unwrap(), - timeout: self.timeout, + timeout: None, proxy: self.proxy.clone(), headers: self.headers.clone(), installer_args: self.installer_args.clone(),