From 70708b34cc1e1ffcf21b0eaf1fcdad2d8f1858ab Mon Sep 17 00:00:00 2001 From: fanyang Date: Mon, 14 Oct 2024 21:33:48 +0800 Subject: [PATCH] Fix app not displayed when click on the dock icon under macOS (#424) --- easytier-gui/src-tauri/src/lib.rs | 18 +++++++++++++--- easytier/src/common/stun.rs | 6 ++++-- easytier/src/gateway/tokio_smoltcp/device.rs | 12 +++++++---- easytier/src/launcher.rs | 1 - tauri-plugin-vpnservice/src/error.rs | 22 ++++++++++---------- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/easytier-gui/src-tauri/src/lib.rs b/easytier-gui/src-tauri/src/lib.rs index 7ef603a..64156d0 100644 --- a/easytier-gui/src-tauri/src/lib.rs +++ b/easytier-gui/src-tauri/src/lib.rs @@ -16,6 +16,7 @@ use easytier::{ use serde::{Deserialize, Serialize}; use tauri::Manager as _; +use tauri::RunEvent; pub const AUTOSTART_ARG: &str = "--autostart"; @@ -335,7 +336,7 @@ pub fn run() { .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_vpnservice::init()); - builder + let mut app = builder .setup(|app| { // for logging config let Ok(log_dir) = app.path().app_log_dir() else { @@ -394,6 +395,17 @@ pub fn run() { } _ => {} }) - .run(tauri::generate_context!()) - .expect("error while running tauri application"); + .build(tauri::generate_context!()) + .unwrap(); + + #[cfg(not(target_os = "macos"))] + app.run(|_app, _event| {}); + + #[cfg(target_os = "macos")] + app.run(|app, event| match event { + RunEvent::Reopen { .. } => { + toggle_window_visibility(app); + } + _ => {} + }); } diff --git a/easytier/src/common/stun.rs b/easytier/src/common/stun.rs index 86b957e..36aafb7 100644 --- a/easytier/src/common/stun.rs +++ b/easytier/src/common/stun.rs @@ -56,8 +56,10 @@ impl HostResolverIter { self.ips = ips .filter(|x| x.is_ipv4()) .choose_multiple(&mut rand::thread_rng(), self.max_ip_per_domain as usize); - - if self.ips.is_empty() {return self.next().await;} + + if self.ips.is_empty() { + return self.next().await; + } } Err(e) => { tracing::warn!(?host, ?e, "lookup host for stun failed"); diff --git a/easytier/src/gateway/tokio_smoltcp/device.rs b/easytier/src/gateway/tokio_smoltcp/device.rs index c424984..987b3d1 100644 --- a/easytier/src/gateway/tokio_smoltcp/device.rs +++ b/easytier/src/gateway/tokio_smoltcp/device.rs @@ -69,10 +69,14 @@ impl<'d> TxToken for BufferTxToken<'d> { } impl Device for BufferDevice { - type RxToken<'a> = BufferRxToken - where Self:'a; - type TxToken<'a> = BufferTxToken<'a> - where Self:'a; + type RxToken<'a> + = BufferRxToken + where + Self: 'a; + type TxToken<'a> + = BufferTxToken<'a> + where + Self: 'a; fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { match self.recv_queue.pop_front() { diff --git a/easytier/src/launcher.rs b/easytier/src/launcher.rs index 615093d..341548e 100644 --- a/easytier/src/launcher.rs +++ b/easytier/src/launcher.rs @@ -137,7 +137,6 @@ impl EasyTierLauncher { let vpn_portal = instance.get_vpn_portal_inst(); tasks.spawn(async move { loop { - // Update TUN Device Name *data_c.tun_dev_name.write().unwrap() = global_ctx_c.get_flags().dev_name.clone(); diff --git a/tauri-plugin-vpnservice/src/error.rs b/tauri-plugin-vpnservice/src/error.rs index 895220d..177e8c2 100644 --- a/tauri-plugin-vpnservice/src/error.rs +++ b/tauri-plugin-vpnservice/src/error.rs @@ -4,18 +4,18 @@ pub type Result = std::result::Result; #[derive(Debug, thiserror::Error)] pub enum Error { - #[error(transparent)] - Io(#[from] std::io::Error), - #[cfg(mobile)] - #[error(transparent)] - PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError), + #[error(transparent)] + Io(#[from] std::io::Error), + #[cfg(mobile)] + #[error(transparent)] + PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError), } impl Serialize for Error { - fn serialize(&self, serializer: S) -> std::result::Result - where - S: Serializer, - { - serializer.serialize_str(self.to_string().as_ref()) - } + fn serialize(&self, serializer: S) -> std::result::Result + where + S: Serializer, + { + serializer.serialize_str(self.to_string().as_ref()) + } }