瀏覽代碼

fix(core): Send updater status events when default dialog is enabled, closes #7128 (#7157)

Fabian-Lars 2 年之前
父節點
當前提交
5d85d0990c
共有 2 個文件被更改,包括 24 次插入3 次删除
  1. 5 0
      .changes/updater-dialog-events.md
  2. 19 3
      core/tauri/src/updater/mod.rs

+ 5 - 0
.changes/updater-dialog-events.md

@@ -0,0 +1,5 @@
+---
+tauri: patch:enhance
+---
+
+Send updater status events even if default dialog is enabled.

+ 19 - 3
core/tauri/src/updater/mod.rs

@@ -423,8 +423,10 @@ pub(crate) async fn check_update_with_dialog<R: Runtime>(handle: AppHandle<R>) {
       Ok(updater) => {
         let pubkey = updater_config.pubkey.clone();
 
-        // if dialog enabled only
-        if updater.should_update && updater_config.dialog {
+        if !updater.should_update {
+          send_status_update(&handle, UpdaterEvent::AlreadyUpToDate);
+        } else if updater_config.dialog {
+          // if dialog enabled only
           let body = updater.body.clone().unwrap_or_else(|| String::from(""));
           let dialog =
             prompt_for_install(&updater.clone(), &package_info.name, &body.clone(), pubkey).await;
@@ -591,14 +593,28 @@ Release Notes:
   );
 
   if should_install {
+    let handle = update.app.clone();
+    let handle_ = handle.clone();
+
     // Launch updater download process
     // macOS we display the `Ready to restart dialog` asking to restart
     // Windows is closing the current App and launch the downloaded MSI when ready (the process stop here)
     // Linux we replace the AppImage by launching a new install, it start a new AppImage instance, so we're closing the previous. (the process stop here)
     update
-      .download_and_install(pubkey.clone(), |_, _| (), || ())
+      .download_and_install(
+        pubkey.clone(),
+        move |chunk_length, content_length| {
+          send_download_progress_event(&handle, chunk_length, content_length);
+        },
+        move || {
+          send_status_update(&handle_, UpdaterEvent::Downloaded);
+        },
+      )
       .await?;
 
+    // emit {"status": "DONE"}
+    send_status_update(&update.app, UpdaterEvent::Updated);
+
     // Ask user if we need to restart the application
     let should_exit = ask(
       parent_window,