|
@@ -333,8 +333,8 @@ mod error;
|
|
|
pub use self::error::Error;
|
|
|
|
|
|
use crate::{
|
|
|
- api::dialog::blocking::ask, runtime::EventLoopProxy, utils::config::UpdaterConfig, Env,
|
|
|
- EventLoopMessage, Manager, Runtime, UpdaterEvent, Window,
|
|
|
+ api::dialog::blocking::ask, runtime::EventLoopProxy, utils::config::UpdaterConfig, AppHandle,
|
|
|
+ Env, EventLoopMessage, Manager, Runtime, UpdaterEvent,
|
|
|
};
|
|
|
|
|
|
/// Check for new updates
|
|
@@ -374,14 +374,14 @@ struct UpdateManifest {
|
|
|
pub(crate) async fn check_update_with_dialog<R: Runtime>(
|
|
|
updater_config: UpdaterConfig,
|
|
|
package_info: crate::PackageInfo,
|
|
|
- window: Window<R>,
|
|
|
+ handle: AppHandle<R>,
|
|
|
) {
|
|
|
if let Some(endpoints) = updater_config.endpoints.clone() {
|
|
|
let endpoints = endpoints
|
|
|
.iter()
|
|
|
.map(|e| e.to_string())
|
|
|
.collect::<Vec<String>>();
|
|
|
- let env = window.state::<Env>().inner().clone();
|
|
|
+ let env = handle.state::<Env>().inner().clone();
|
|
|
// check updates
|
|
|
match self::core::builder(env)
|
|
|
.urls(&endpoints[..])
|
|
@@ -395,9 +395,9 @@ pub(crate) async fn check_update_with_dialog<R: Runtime>(
|
|
|
// if dialog enabled only
|
|
|
if updater.should_update && updater_config.dialog {
|
|
|
let body = updater.body.clone().unwrap_or_else(|| String::from(""));
|
|
|
- let window_ = window.clone();
|
|
|
+ let handle_ = handle.clone();
|
|
|
let dialog = prompt_for_install(
|
|
|
- window_,
|
|
|
+ handle_,
|
|
|
&updater.clone(),
|
|
|
&package_info.name,
|
|
|
&body.clone(),
|
|
@@ -406,12 +406,12 @@ pub(crate) async fn check_update_with_dialog<R: Runtime>(
|
|
|
.await;
|
|
|
|
|
|
if let Err(e) = dialog {
|
|
|
- send_status_update(window.clone(), UpdaterEvent::Error(e.to_string()));
|
|
|
+ send_status_update(&handle, UpdaterEvent::Error(e.to_string()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Err(e) => {
|
|
|
- send_status_update(window.clone(), UpdaterEvent::Error(e.to_string()));
|
|
|
+ send_status_update(&handle, UpdaterEvent::Error(e.to_string()));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -422,13 +422,13 @@ pub(crate) async fn check_update_with_dialog<R: Runtime>(
|
|
|
pub(crate) fn listener<R: Runtime>(
|
|
|
updater_config: UpdaterConfig,
|
|
|
package_info: crate::PackageInfo,
|
|
|
- window: &Window<R>,
|
|
|
+ handle: &AppHandle<R>,
|
|
|
) {
|
|
|
- let isolated_window = window.clone();
|
|
|
+ let handle_ = handle.clone();
|
|
|
|
|
|
// Wait to receive the event `"tauri://update"`
|
|
|
- window.listen(EVENT_CHECK_UPDATE, move |_msg| {
|
|
|
- let window = isolated_window.clone();
|
|
|
+ handle.listen_global(EVENT_CHECK_UPDATE, move |_msg| {
|
|
|
+ let handle = handle_.clone();
|
|
|
let package_info = package_info.clone();
|
|
|
|
|
|
// prepare our endpoints
|
|
@@ -444,10 +444,10 @@ pub(crate) fn listener<R: Runtime>(
|
|
|
|
|
|
// check updates
|
|
|
crate::async_runtime::spawn(async move {
|
|
|
- let window = window.clone();
|
|
|
- let window_isolation = window.clone();
|
|
|
+ let handle = handle.clone();
|
|
|
+ let handle_ = handle.clone();
|
|
|
let pubkey = pubkey.clone();
|
|
|
- let env = window.state::<Env>().inner().clone();
|
|
|
+ let env = handle.state::<Env>().inner().clone();
|
|
|
|
|
|
match self::core::builder(env)
|
|
|
.urls(&endpoints[..])
|
|
@@ -461,7 +461,7 @@ pub(crate) fn listener<R: Runtime>(
|
|
|
let body = updater.body.clone().unwrap_or_else(|| String::from(""));
|
|
|
|
|
|
// Emit `tauri://update-available`
|
|
|
- let _ = window.emit(
|
|
|
+ let _ = handle.emit_all(
|
|
|
EVENT_UPDATE_AVAILABLE,
|
|
|
UpdateManifest {
|
|
|
body,
|
|
@@ -469,20 +469,19 @@ pub(crate) fn listener<R: Runtime>(
|
|
|
version: updater.version.clone(),
|
|
|
},
|
|
|
);
|
|
|
- let _ = window
|
|
|
- .app_handle
|
|
|
+ let _ = handle
|
|
|
.create_proxy()
|
|
|
.send_event(EventLoopMessage::Updater(UpdaterEvent::UpdateAvailable));
|
|
|
|
|
|
// Listen for `tauri://update-install`
|
|
|
- window.once(EVENT_INSTALL_UPDATE, move |_msg| {
|
|
|
- let window = window_isolation.clone();
|
|
|
+ handle.once_global(EVENT_INSTALL_UPDATE, move |_msg| {
|
|
|
+ let handle = handle_.clone();
|
|
|
let updater = updater.clone();
|
|
|
|
|
|
// Start installation
|
|
|
crate::async_runtime::spawn(async move {
|
|
|
// emit {"status": "PENDING"}
|
|
|
- send_status_update(window.clone(), UpdaterEvent::Pending);
|
|
|
+ send_status_update(&handle, UpdaterEvent::Pending);
|
|
|
|
|
|
// Launch updater download process
|
|
|
// macOS we display the `Ready to restart dialog` asking to restart
|
|
@@ -492,19 +491,19 @@ pub(crate) fn listener<R: Runtime>(
|
|
|
|
|
|
if let Err(err) = update_result {
|
|
|
// emit {"status": "ERROR", "error": "The error message"}
|
|
|
- send_status_update(window.clone(), UpdaterEvent::Error(err.to_string()));
|
|
|
+ send_status_update(&handle, UpdaterEvent::Error(err.to_string()));
|
|
|
} else {
|
|
|
// emit {"status": "DONE"}
|
|
|
- send_status_update(window.clone(), UpdaterEvent::Updated);
|
|
|
+ send_status_update(&handle, UpdaterEvent::Updated);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
} else {
|
|
|
- send_status_update(window.clone(), UpdaterEvent::AlreadyUpToDate);
|
|
|
+ send_status_update(&handle, UpdaterEvent::AlreadyUpToDate);
|
|
|
}
|
|
|
}
|
|
|
Err(e) => {
|
|
|
- send_status_update(window.clone(), UpdaterEvent::Error(e.to_string()));
|
|
|
+ send_status_update(&handle, UpdaterEvent::Error(e.to_string()));
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -512,8 +511,8 @@ pub(crate) fn listener<R: Runtime>(
|
|
|
}
|
|
|
|
|
|
// Send a status update via `tauri://update-status` event.
|
|
|
-fn send_status_update<R: Runtime>(window: Window<R>, message: UpdaterEvent) {
|
|
|
- let _ = window.emit(
|
|
|
+fn send_status_update<R: Runtime>(handle: &AppHandle<R>, message: UpdaterEvent) {
|
|
|
+ let _ = handle.emit_all(
|
|
|
EVENT_STATUS_UPDATE,
|
|
|
if let UpdaterEvent::Error(error) = &message {
|
|
|
StatusEvent {
|
|
@@ -527,8 +526,7 @@ fn send_status_update<R: Runtime>(window: Window<R>, message: UpdaterEvent) {
|
|
|
}
|
|
|
},
|
|
|
);
|
|
|
- let _ = window
|
|
|
- .app_handle
|
|
|
+ let _ = handle
|
|
|
.create_proxy()
|
|
|
.send_event(EventLoopMessage::Updater(message));
|
|
|
}
|
|
@@ -536,7 +534,7 @@ fn send_status_update<R: Runtime>(window: Window<R>, message: UpdaterEvent) {
|
|
|
// Prompt a dialog asking if the user want to install the new version
|
|
|
// Maybe we should add an option to customize it in future versions.
|
|
|
async fn prompt_for_install<R: Runtime>(
|
|
|
- window: Window<R>,
|
|
|
+ handle: AppHandle<R>,
|
|
|
updater: &self::core::Update,
|
|
|
app_name: &str,
|
|
|
body: &str,
|
|
@@ -544,11 +542,13 @@ async fn prompt_for_install<R: Runtime>(
|
|
|
) -> crate::Result<()> {
|
|
|
// remove single & double quote
|
|
|
let escaped_body = body.replace(&['\"', '\''][..], "");
|
|
|
+ let windows = handle.windows();
|
|
|
+ let parent_window = windows.values().next();
|
|
|
|
|
|
// todo(lemarier): We should review this and make sure we have
|
|
|
// something more conventional.
|
|
|
let should_install = ask(
|
|
|
- Some(&window),
|
|
|
+ parent_window,
|
|
|
format!(r#"A new version of {} is available! "#, app_name),
|
|
|
format!(
|
|
|
r#"{} {} is now available -- you have {}.
|
|
@@ -570,12 +570,12 @@ Release Notes:
|
|
|
|
|
|
// Ask user if we need to restart the application
|
|
|
let should_exit = ask(
|
|
|
- Some(&window),
|
|
|
+ parent_window,
|
|
|
"Ready to Restart",
|
|
|
"The installation was successful, do you want to restart the application now?",
|
|
|
);
|
|
|
if should_exit {
|
|
|
- window.app_handle().restart();
|
|
|
+ handle.restart();
|
|
|
}
|
|
|
}
|
|
|
|