fix: new updater method changes

This commit is contained in:
PandaDEV 2024-10-07 00:33:35 +10:00
parent f1813c8886
commit b6c962d3f3
No known key found for this signature in database
GPG key ID: 13EFF9BAF70EE75C

View file

@ -1,8 +1,7 @@
use tauri::{AppHandle, async_runtime};
use tauri_plugin_dialog::{DialogExt, MessageDialogKind};
use tauri_plugin_dialog::{DialogExt, MessageDialogKind, MessageDialogButtons};
use tauri_plugin_updater::UpdaterExt;
pub async fn check_for_updates(app: AppHandle) {
println!("Checking for updates...");
@ -22,18 +21,31 @@ pub async fn check_for_updates(app: AppHandle) {
app.dialog()
.message(msg)
.title("Update Available")
.ok_button_label("Install")
.cancel_button_label("Cancel")
.buttons(MessageDialogButtons::OkCancelCustom(String::from("Install"), String::from("Cancel")))
.show(move |response| {
if !response {
return;
}
async_runtime::spawn(async move {
if let Err(e) = update.download_and_install(|_, _| {}, || {}).await {
println!("Error installing new update: {:?}", e);
app.dialog().message(
"Failed to install new update. The new update can be downloaded from Github"
).kind(MessageDialogKind::Error).show(|_| {});
match update.download_and_install(|_, _| {}, || {}).await {
Ok(_) => {
app.dialog()
.message("Update installed successfully. The application needs to restart to apply the changes.")
.title("Update Installed")
.buttons(MessageDialogButtons::OkCancelCustom(String::from("Restart"), String::from("Cancel")))
.show(move |response| {
if response {
app.restart();
}
});
}
Err(e) => {
println!("Error installing new update: {:?}", e);
app.dialog()
.message("Failed to install new update. The new update can be downloaded from Github")
.kind(MessageDialogKind::Error)
.show(|_| {});
}
}
});
});