mirror of
https://github.com/0PandaDEV/Qopy.git
synced 2025-04-21 21:24:05 +02:00
feat: add 'Check for updates' option to tray menu and improve update handling
This commit is contained in:
parent
e29f2fcfa5
commit
6157eb75a1
4 changed files with 41 additions and 15 deletions
|
@ -23,6 +23,7 @@ pub fn setup(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
|
|||
.build(app)?])
|
||||
.items(&[&MenuItemBuilder::with_id("show", "Show/Hide").build(app)?])
|
||||
.items(&[&MenuItemBuilder::with_id("keybind", "Change keybind").build(app)?])
|
||||
.items(&[&MenuItemBuilder::with_id("check_updates", "Check for updates").build(app)?])
|
||||
.items(&[&MenuItemBuilder::with_id("quit", "Quit").build(app)?])
|
||||
.build()?,
|
||||
)
|
||||
|
@ -48,6 +49,13 @@ pub fn setup(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
|
|||
let _ = _app.track_event("tray_keybind_change", None);
|
||||
window.emit("change_keybind", ()).unwrap();
|
||||
}
|
||||
"check_updates" => {
|
||||
let _ = _app.track_event("tray_check_updates", None);
|
||||
let app_handle = _app.app_handle().clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
crate::api::updater::check_for_updates(app_handle, true).await;
|
||||
});
|
||||
}
|
||||
_ => (),
|
||||
})
|
||||
.icon(icon)
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ fn main() {
|
|||
let _ = app.track_event("app_started", None);
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
api::updater::check_for_updates(app_handle).await;
|
||||
api::updater::check_for_updates(app_handle, false).await;
|
||||
});
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue