[desktop] Fix traymenu exit button

This commit is contained in:
Vladimir Stoilov 2024-05-21 11:38:39 +03:00
parent 4ffd5f2079
commit a984032621
No known key found for this signature in database
GPG key ID: 2F190B67A43A81AF
6 changed files with 306 additions and 292 deletions
desktop/tauri/src-tauri

File diff suppressed because it is too large Load diff

View file

@ -12,11 +12,11 @@ rust-version = "1.60"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "2.0.0-beta.13", features = [] }
tauri-build = { version = "2.0.0-beta.15", features = [] }
[dependencies]
# Tauri
tauri = { version = "2.0.0-beta.16", features = ["tray-icon", "image-png", "config-json5"] }
tauri = { version = "2.0.0-beta.19", features = ["tray-icon", "image-png", "config-json5"] }
tauri-plugin-shell = "2.0.0-beta"
tauri-plugin-dialog = "2.0.0-beta"
tauri-plugin-clipboard-manager = "2.0.0-beta"
@ -26,7 +26,7 @@ tauri-plugin-cli = "2.0.0-beta"
tauri-plugin-notification = "2.0.0-beta"
tauri-plugin-log = "2.0.0-beta"
tauri-cli = "2.0.0-beta.13"
tauri-cli = "2.0.0-beta.17"
# General
serde_json = "1.0"

View file

@ -216,9 +216,10 @@ fn main() {
}
}
RunEvent::ExitRequested { api, .. } => {
api.prevent_exit();
}
// TODO(vladimir): why was this needed?
// RunEvent::ExitRequested { api, .. } => {
// api.prevent_exit();
// }
_ => {}
});
}

View file

@ -121,7 +121,6 @@ impl<R: Runtime> PortmasterInterface<R> {
}
handlers.push(Box::new(handler));
debug!("number of registered handlers: {}", handlers.len());
}
}
@ -207,9 +206,8 @@ impl<R: Runtime> PortmasterInterface<R> {
//// Internal functions
fn start_notification_handler(&self) {
if let Some(api) = self.get_api() {
let cli = api.clone();
tauri::async_runtime::spawn(async move {
notifications::notification_handler(cli).await;
notifications::notification_handler(api).await;
});
}
}
@ -221,9 +219,10 @@ impl<R: Runtime> PortmasterInterface<R> {
self.is_reachable.store(true, Ordering::Relaxed);
// store the new api client.
let mut guard = self.api.lock().unwrap();
*guard = Some(api.clone());
drop(guard);
{
let mut guard = self.api.lock().unwrap();
*guard = Some(api.clone());
}
// fire-off the notification handler.
if self.handle_notifications.load(Ordering::Relaxed) {
@ -247,9 +246,10 @@ impl<R: Runtime> PortmasterInterface<R> {
self.is_reachable.store(false, Ordering::Relaxed);
// clear the current api client reference.
let mut guard = self.api.lock().unwrap();
*guard = None;
drop(guard);
{
let mut guard = self.api.lock().unwrap();
*guard = None;
}
if let Ok(mut handlers) = self.handlers.lock() {
for handler in handlers.iter_mut() {

View file

@ -9,7 +9,7 @@ use tauri::{
SubmenuBuilder,
},
tray::{ClickType, TrayIcon, TrayIconBuilder},
Manager, Wry,
Wry,
};
use crate::{
@ -93,7 +93,7 @@ pub fn setup_tray_menu(
.cancel_button_label("No")
.show(move |answer| {
if answer {
let _ = handle.emit("exit-requested", "");
// let _ = handle.emit("exit-requested", "");
handle.exit(0);
}
});

View file

@ -131,7 +131,7 @@ pub fn may_navigate_to_ui(win: &mut WebviewWindow, force: bool) {
return;
}
if force || cfg!(debug_assertions) || win.url().as_str() == "tauri://localhost" {
if force || cfg!(debug_assertions) || win.url().unwrap().as_str() == "tauri://localhost" {
#[cfg(debug_assertions)]
if let Ok(target_url) = std::env::var("TAURI_PM_URL") {
debug!("[tauri] navigating to {}", target_url);
@ -157,7 +157,7 @@ pub fn may_navigate_to_ui(win: &mut WebviewWindow, force: bool) {
} else {
error!(
"not navigating to user interface: current url: {}",
win.url().as_str()
win.url().unwrap().as_str()
);
}
}