From 60dc40f47f76b4bf6d8be6a8040e7ee282d007d3 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Wed, 19 Jun 2024 15:42:53 +0800 Subject: [PATCH] try hide docker in tao delegate because hide in rustdesk side a bit late so that still seeing it sometimes refactor service to make it restart after login to avoid delegate caught for seconds after login also make main windows Close event restart itself for above case --- Cargo.lock | 4 ++-- src/ipc.rs | 21 +++++++++++++++++---- src/platform/macos.rs | 20 +++++++++----------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ff6e44c2f..4cb4a0634 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6127,7 +6127,7 @@ dependencies = [ [[package]] name = "tao" version = "0.25.0" -source = "git+https://github.com/rustdesk-org/tao?branch=dev#1cad16b200485bbccc67dcee2d339eac6e1c16ad" +source = "git+https://github.com/rustdesk-org/tao?branch=dev#8a014cdb4dd20f35d64bf992374fa40263ee86a4" dependencies = [ "bitflags 1.3.2", "cc", @@ -6167,7 +6167,7 @@ dependencies = [ [[package]] name = "tao-macros" version = "0.1.2" -source = "git+https://github.com/rustdesk-org/tao?branch=dev#1cad16b200485bbccc67dcee2d339eac6e1c16ad" +source = "git+https://github.com/rustdesk-org/tao?branch=dev#8a014cdb4dd20f35d64bf992374fa40263ee86a4" dependencies = [ "proc-macro2 1.0.79", "quote 1.0.35", diff --git a/src/ipc.rs b/src/ipc.rs index 2aff25a15..cae959a19 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -358,14 +358,27 @@ async fn handle(data: Data, stream: &mut Connection) { if is_server() { let _ = privacy_mode::turn_off_privacy(0, Some(PrivacyModeState::OffByPeer)); } - #[cfg(target_os = "linux")] + #[cfg(any(target_os = "macos", target_os = "linux"))] if crate::is_main() { // below part is for main windows can be reopen during rustdesk installation and installing service from UI // this make new ipc server (domain socket) can be created. std::fs::remove_file(&Config::ipc_path("")).ok(); - hbb_common::sleep((crate::platform::SERVICE_INTERVAL * 2) as f32 / 1000.0) - .await; - crate::run_me::<&str>(vec![]).ok(); + #[cfg(target_os = "linux")] + { + hbb_common::sleep((crate::platform::SERVICE_INTERVAL * 2) as f32 / 1000.0) + .await; + crate::run_me::<&str>(vec![]).ok(); + } + #[cfg(target_os = "macos")] + { + // our launchagent interval is 1 second + hbb_common::sleep(1.5).await; + std::process::Command::new("open") + .arg("-n") + .arg(&format!("/Applications/{}.app", crate::get_app_name())) + .spawn() + .ok(); + } } std::process::exit(-1); // to make sure --server luauchagent process can restart because SuccessfulExit used } diff --git a/src/platform/macos.rs b/src/platform/macos.rs index 92991cdcf..0658fb889 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -18,7 +18,6 @@ use core_graphics::{ window::{kCGWindowName, kCGWindowOwnerPID}, }; use hbb_common::{ - allow_err, anyhow::anyhow, bail, log, message_proto::{DisplayInfo, Resolution}, @@ -203,15 +202,6 @@ pub fn is_installed_daemon(prompt: bool) -> bool { .args(&["load", "-w", &agent_plist_file]) .status() .ok(); - std::process::Command::new("sh") - .arg("-c") - .arg(&format!( - "sleep 0.5; open -n /Applications/{}.app", - crate::get_app_name(), - )) - .spawn() - .ok(); - quit_gui(); } } } @@ -516,8 +506,16 @@ pub fn start_os_service() { .unwrap_or_default() as i64; log::info!("Startime: {my_start_time} vs {:?}", server); + let uname = get_active_username(); std::thread::spawn(move || loop { std::thread::sleep(std::time::Duration::from_secs(1)); + let tmp = get_active_username(); + // restart my self after login to make sure --server started earlier + // so that not forbid user start main window because of delegate caught by --service + if uname != tmp { + log::info!("Console user changed from {uname} to {tmp}"); + std::process::exit(-1); + } if server.is_none() { server = get_server_start_time(&mut sys, &path); } @@ -527,7 +525,7 @@ pub fn start_os_service() { log::info!( "Agent start later, {my_start_time} vs {start_time}, will restart --service to make delegate work", ); - std::process::exit(0); + std::process::exit(-1); } // only refresh this pid and check if valid, no need to refresh all processes since refreshing all is expensive, about 10ms on my machine if !sys.refresh_process_specifics(pid, ProcessRefreshKind::new()) {