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