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,10 +1,10 @@
$primary: #2E2D2B; $primary: #2e2d2b;
$accent: #FEB453; $accent: #feb453;
$divider: #ffffff0d; $divider: #ffffff0d;
$text: #E5DFD5; $text: #e5dfd5;
$text2: #ADA9A1; $text2: #ada9a1;
$mutedtext: #78756F; $mutedtext: #78756f;
.bg { .bg {
width: 750px; width: 750px;
@ -25,7 +25,7 @@ $mutedtext: #78756F;
gap: 8px; gap: 8px;
align-items: center; align-items: center;
img{ img {
background-color: $divider; background-color: $divider;
border-radius: 6px; border-radius: 6px;
padding: 8px 6px; padding: 8px 6px;
@ -123,7 +123,7 @@ $mutedtext: #78756F;
background-color: $divider; background-color: $divider;
margin-left: 8px; margin-left: 8px;
margin-right: 4px; margin-right: 4px;
transition: all .2s; transition: all 0.2s;
} }
.actions { .actions {
@ -134,7 +134,7 @@ $mutedtext: #78756F;
gap: 8px; gap: 8px;
border-radius: 7px; border-radius: 7px;
background-color: transparent; background-color: transparent;
transition: all .2s; transition: all 0.2s;
cursor: pointer; cursor: pointer;
} }
@ -142,7 +142,7 @@ $mutedtext: #78756F;
background-color: $divider; background-color: $divider;
} }
&:hover .actions:hover~.divider { &:hover .actions:hover ~ .divider {
opacity: 0; opacity: 0;
} }
} }

View file

@ -23,6 +23,7 @@ pub fn setup(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
.build(app)?]) .build(app)?])
.items(&[&MenuItemBuilder::with_id("show", "Show/Hide").build(app)?]) .items(&[&MenuItemBuilder::with_id("show", "Show/Hide").build(app)?])
.items(&[&MenuItemBuilder::with_id("keybind", "Change keybind").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)?]) .items(&[&MenuItemBuilder::with_id("quit", "Quit").build(app)?])
.build()?, .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); let _ = _app.track_event("tray_keybind_change", None);
window.emit("change_keybind", ()).unwrap(); 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) .icon(icon)

View file

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

View file

@ -96,7 +96,7 @@ fn main() {
let _ = app.track_event("app_started", None); let _ = app.track_event("app_started", None);
tauri::async_runtime::spawn(async move { tauri::async_runtime::spawn(async move {
api::updater::check_for_updates(app_handle).await; api::updater::check_for_updates(app_handle, false).await;
}); });
Ok(()) Ok(())