[desktop] Fix traymenu exit button

This commit is contained in:
Vladimir Stoilov
2024-05-21 11:38:39 +03:00
parent 4ffd5f2079
commit a984032621
6 changed files with 306 additions and 292 deletions

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()
);
}
}