feat: add 'Check for updates' option to tray menu and improve update handling

This commit is contained in:
PandaDEV 2025-01-01 18:26:37 +10:00
parent e29f2fcfa5
commit 6157eb75a1
No known key found for this signature in database
GPG key ID: 13EFF9BAF70EE75C
4 changed files with 41 additions and 15 deletions

View file

@ -1,8 +1,9 @@
use tauri::Manager;
use tauri::{async_runtime, AppHandle};
use tauri_plugin_dialog::{DialogExt, MessageDialogButtons, MessageDialogKind};
use tauri_plugin_updater::UpdaterExt;
pub async fn check_for_updates(app: AppHandle) {
pub async fn check_for_updates(app: AppHandle, prompted: bool) {
println!("Checking for updates...");
let updater = app.updater().unwrap();
@ -18,6 +19,10 @@ pub async fn check_for_updates(app: AppHandle) {
"Would you like to install it now?",
]);
let window = app.get_webview_window("main").unwrap();
window.show().unwrap();
window.set_focus().unwrap();
app.dialog()
.message(msg)
.title("Qopy Update Available")
@ -31,7 +36,7 @@ pub async fn check_for_updates(app: AppHandle) {
Ok(_) => {
app.dialog()
.message("Update installed successfully. The application needs to restart to apply the changes.")
.title("Qopy Update Installed")
.title("Qopy Needs to Restart")
.buttons(MessageDialogButtons::OkCancelCustom(String::from("Restart"), String::from("Cancel")))
.show(move |response| {
if response {
@ -50,9 +55,22 @@ pub async fn check_for_updates(app: AppHandle) {
});
});
}
Ok(None) => println!("No updates available."),
Ok(None) => {
println!("No updates available.");
}
Err(e) => {
println!("Failed to check for updates: {:?}", e);
if prompted {
let window = app.get_webview_window("main").unwrap();
window.show().unwrap();
window.set_focus().unwrap();
app.dialog()
.message("No updates available.")
.title("Qopy Update Check")
.show(|_| {});
}
println!("No updates available. {}", e.to_string());
}
}
}