Skip to content

Commit 9712ed1

Browse files
authored
feat(updater): add Downloaded status event (#3804)
1 parent 9b70f82 commit 9712ed1

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Add updater `Downloaded` status event.

core/tauri/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ pub enum UpdaterEvent {
252252
/// The total
253253
content_length: Option<u64>,
254254
},
255+
/// The update has been download and is now about to be installed.
256+
Downloaded,
255257
/// The update has been applied and the app is now up to date.
256258
Updated,
257259
/// The app is already up to date.
@@ -265,6 +267,7 @@ impl UpdaterEvent {
265267
pub(crate) fn status_message(self) -> &'static str {
266268
match self {
267269
Self::Pending => updater::EVENT_STATUS_PENDING,
270+
Self::Downloaded => updater::EVENT_STATUS_DOWNLOADED,
268271
Self::Updated => updater::EVENT_STATUS_SUCCESS,
269272
Self::AlreadyUpToDate => updater::EVENT_STATUS_UPTODATE,
270273
Self::Error(_) => updater::EVENT_STATUS_ERROR,

core/tauri/src/updater/core.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,11 @@ impl<R: Runtime> Clone for Update<R> {
476476
impl<R: Runtime> Update<R> {
477477
// Download and install our update
478478
// @todo(lemarier): Split into download and install (two step) but need to be thread safe
479-
pub(crate) async fn download_and_install<F: Fn(usize, Option<u64>)>(
479+
pub(crate) async fn download_and_install<C: Fn(usize, Option<u64>), D: FnOnce()>(
480480
&self,
481481
pub_key: String,
482-
on_chunk: F,
482+
on_chunk: C,
483+
on_download_finish: D,
483484
) -> Result {
484485
// make sure we can install the update on linux
485486
// We fail here because later we can add more linux support
@@ -551,6 +552,8 @@ impl<R: Runtime> Update<R> {
551552
}
552553
}
553554

555+
on_download_finish();
556+
554557
// create memory buffer from our archive (Seek + Read)
555558
let mut archive_buffer = Cursor::new(buffer);
556559

@@ -1522,7 +1525,7 @@ mod test {
15221525
assert_eq!(updater.version, "2.0.1");
15231526

15241527
// download, install and validate signature
1525-
let install_process = block!(updater.download_and_install(pubkey, |_, _| ()));
1528+
let install_process = block!(updater.download_and_install(pubkey, |_, _| (), || ()));
15261529
assert!(install_process.is_ok());
15271530

15281531
// make sure the extraction went well (it should have skipped the main app.app folder)

core/tauri/src/updater/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@
230230
//!
231231
//! **Pending** is emitted when the download is started and **Done** when the install is complete. You can then ask to restart the application.
232232
//!
233+
//! **Downloaded** is emitted when the download has finished.
234+
//!
233235
//! **UpToDate** is emitted when the app already has the latest version installed and an update is not needed.
234236
//!
235237
//! **Error** is emitted when there is an error with the updater. We suggest to listen to this event even if the dialog is enabled.
@@ -249,6 +251,9 @@
249251
//! tauri::UpdaterEvent::Pending => {
250252
//! println!("update is pending!");
251253
//! }
254+
//! tauri::UpdaterEvent::Downloaded => {
255+
//! println!("update has been downloaded!");
256+
//! }
252257
//! tauri::UpdaterEvent::Updated => {
253258
//! println!("app has been updated");
254259
//! }
@@ -465,6 +470,8 @@ pub const EVENT_STATUS_PENDING: &str = "PENDING";
465470
/// When you got this status, something went wrong
466471
/// you can find the error message inside the `error` field.
467472
pub const EVENT_STATUS_ERROR: &str = "ERROR";
473+
/// The update has been downloaded.
474+
pub const EVENT_STATUS_DOWNLOADED: &str = "DOWNLOADED";
468475
/// When you receive this status, you should ask the user to restart
469476
pub const EVENT_STATUS_SUCCESS: &str = "DONE";
470477
/// When you receive this status, this is because the application is running last version
@@ -712,6 +719,7 @@ pub(crate) async fn download_and_install<R: Runtime>(update: core::Update<R>) ->
712719
send_status_update(&update.app, UpdaterEvent::Pending);
713720

714721
let handle = update.app.clone();
722+
let handle_ = handle.clone();
715723

716724
// Launch updater download process
717725
// macOS we display the `Ready to restart dialog` asking to restart
@@ -723,6 +731,9 @@ pub(crate) async fn download_and_install<R: Runtime>(update: core::Update<R>) ->
723731
move |chunk_length, content_length| {
724732
send_download_progress_event(&handle, chunk_length, content_length);
725733
},
734+
move || {
735+
send_status_update(&handle_, UpdaterEvent::Downloaded);
736+
},
726737
)
727738
.await;
728739

@@ -840,7 +851,7 @@ Release Notes:
840851
// Windows is closing the current App and launch the downloaded MSI when ready (the process stop here)
841852
// 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)
842853
update
843-
.download_and_install(pubkey.clone(), |_, _| ())
854+
.download_and_install(pubkey.clone(), |_, _| (), || ())
844855
.await?;
845856

846857
// Ask user if we need to restart the application

0 commit comments

Comments
 (0)