From 85f387bfb9ec2a8067d3273829a21b1deb07efd4 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Wed, 27 Mar 2024 00:38:13 +0800 Subject: [PATCH] improve https://github.com/rustdesk/rustdesk/discussions/5631#discussioncomment-8916273 --- res/mac-tray-dark-x2.png | Bin 651 -> 612 bytes src/core_main.rs | 5 +++-- src/platform/linux.rs | 2 +- src/platform/macos.rs | 13 +++++++++---- src/platform/privileges_scripts/daemon.plist | 5 +++-- src/platform/windows.rs | 2 +- src/tray.rs | 2 +- src/ui_interface.rs | 4 ++-- 8 files changed, 20 insertions(+), 13 deletions(-) diff --git a/res/mac-tray-dark-x2.png b/res/mac-tray-dark-x2.png index d1ba59123b927422433b2da3a2dbb4d2631df9b2..8b838cb5ea16f38e4d788589a33fe72570f4c394 100644 GIT binary patch literal 612 zcmeAS@N?(olHy`uVBq!ia0vp^HXzKw3=&b&bO2Hb0X`wFKw3&lN=8NoNQ#S#OM(HA zjSL`y5)u+X2C_Ju4HTD^m4$GnrKREGKn7=o$sM2_@+Coj!3AlpcXf)#j|)1_>)u9euRkoSVAR!AZu@x7!!`AF^ItM6sQHJ# zDk-XU&-&_dob%gH&A(1}j<4gIeXjHF9J{#1J;CppwhQ-kXDo{3;F7Npf4KFF>Wi5L z#^QTLlcVNOt&TUkc-uSX#R{=EcRyBS#m~5NP^d%D@ZHbI33EO=&MAL4FFWm7hmY`g zn`E>7^Zf)L#k*gS`RJ+X^yi7;CVj@sMH_wM?r-~&yPjX?YvbDZRkI?roO?t953ad4 zPg3aZ%9r{b?*amqGt(a*GUIFhA8%n6x306&d&TFUEj~KWuAlALrT(oZ zExWoqGPU_y*<9h1#aTP#n~lZ%eur==uAeUBZqlTxJCUvJt=_l%9j32WH5I@8md*L4 z>ABbLvkK2PI80f)EnePw>(@uOt`&Wqy3<8x@|_G-yFa$~A78Eve7->slx!G0UHx3v IIVCg!0Cqa~IRF3v literal 651 zcmV;60(AX}P)u_VkvZ5<>Hr^kDqUT!LGDkb9 zZZ-V~>Hnnf)rftHGtNi}eKkre=Z2LY-)UeF=w;#1@tNLlBEaA|xqnJ3{EPRh@98nZ z=RMWODgSQrxTs#X)z(IDa{6=e<>ldMEWqg(B5w4#&F?Xz{_CY!0fRezZb{J@ohkKx zV@Yoc`bP`%Eh@+fjIBHpmhU{l)c=`S0u$CZ?Uv{yj*A@V&QqW2|v zz>-YM6oEKEM@;SoG1XBAU_%aw1p$=`&zj!Qks%;r=hn-J8Bad5Vn?<@>${Bk|MMz2 zM>{n&4L+0TsHoq2FYrO63RolKqR--Ygt1hhb>+y=ZXt1_SN)d*+f}LG7vABS9!7s5 zib?X<_tSiY><|{-Rfz}g^a(1mdqqQ3wmoyF?u6C zum0*M?Ah7-&|-+PwuA(S0Yj(I>}hH_5L!NFub8>~N=RywFO+h;#&v{UDfv!E70PS# lJEth!3l7*~j-Za;e*skNj%Z*=Q6c~U002ovPDHLkV1ln#C&2&! diff --git a/src/core_main.rs b/src/core_main.rs index 3b241abe1..caac2ca99 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -265,7 +265,8 @@ pub fn core_main() -> Option> { return None; } else if args[0] == "--uninstall-service" { log::info!("start --uninstall-service"); - crate::platform::uninstall_service(false); + crate::platform::uninstall_service(false, true); + return None; } else if args[0] == "--service" { log::info!("start --service"); crate::start_os_service(); @@ -277,7 +278,6 @@ pub fn core_main() -> Option> { #[cfg(any(target_os = "linux", target_os = "windows"))] { crate::start_server(true); - return None; } #[cfg(target_os = "macos")] { @@ -286,6 +286,7 @@ pub fn core_main() -> Option> { // prevent server exit when encountering errors from tray hbb_common::allow_err!(handler.join()); } + return None; } else if args[0] == "--import-config" { if args.len() == 2 { let filepath; diff --git a/src/platform/linux.rs b/src/platform/linux.rs index 78e539923..7a1eac0ca 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -1275,7 +1275,7 @@ fn switch_service(stop: bool) -> String { } } -pub fn uninstall_service(show_new_window: bool) -> bool { +pub fn uninstall_service(show_new_window: bool, _: bool) -> bool { if !has_cmd("systemctl") { return false; } diff --git a/src/platform/macos.rs b/src/platform/macos.rs index ec2aac681..b8fae77cb 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -219,7 +219,7 @@ fn correct_app_name(s: &str) -> String { s } -pub fn uninstall_service(show_new_window: bool) -> bool { +pub fn uninstall_service(show_new_window: bool, sync: bool) -> bool { // to-do: do together with win/linux about refactory start/stop service if !is_installed_daemon(false) { return false; @@ -232,7 +232,7 @@ pub fn uninstall_service(show_new_window: bool) -> bool { return false; }; - std::thread::spawn(move || { + let func = move || { match std::process::Command::new("osascript") .arg("-e") .arg(script_body) @@ -275,7 +275,12 @@ pub fn uninstall_service(show_new_window: bool) -> bool { } } } - }); + }; + if sync { + func(); + } else { + std::thread::spawn(func); + } true } @@ -515,7 +520,7 @@ pub fn start_os_service() { // https://emorydunn.github.io/LaunchAgent/Classes/LaunchAgent.html#/s:11LaunchAgentAAC16throttleIntervalSiSgvp, // by default, ThrottleInterval = 10, we changed it to 1 if dt >= 0 { - std::thread::sleep(std::time::Duration::from_secs(dt.clamp(3, 30) as _)); + std::thread::sleep(std::time::Duration::from_secs(dt.clamp(0, 15) as _)); } log::info!("The others killed"); std::process::exit(0); diff --git a/src/platform/privileges_scripts/daemon.plist b/src/platform/privileges_scripts/daemon.plist index 84e9f0598..82e082347 100644 --- a/src/platform/privileges_scripts/daemon.plist +++ b/src/platform/privileges_scripts/daemon.plist @@ -8,8 +8,9 @@ ProgramArguments - /Applications/RustDesk.app/Contents/MacOS/RustDesk - --service + /bin/sh + -c + sleep 1.5; /Applications/RustDesk.app/Contents/MacOS/RustDesk --service RunAtLoad diff --git a/src/platform/windows.rs b/src/platform/windows.rs index b24b1bcc0..0659422ef 100644 --- a/src/platform/windows.rs +++ b/src/platform/windows.rs @@ -2302,7 +2302,7 @@ impl Drop for WakeLock { } } -pub fn uninstall_service(show_new_window: bool) -> bool { +pub fn uninstall_service(show_new_window: bool, _: bool) -> bool { log::info!("Uninstalling service..."); let filter = format!(" /FI \"PID ne {}\"", get_current_pid()); Config::set_option("stop-service".into(), "Y".into()); diff --git a/src/tray.rs b/src/tray.rs index 96f9ca2b7..0f625df48 100644 --- a/src/tray.rs +++ b/src/tray.rs @@ -131,7 +131,7 @@ pub fn make_tray() -> hbb_common::ResultType<()> { return; } */ - if !crate::platform::uninstall_service(false) { + if !crate::platform::uninstall_service(false, false) { *control_flow = ControlFlow::Exit; } } else if event.id == open_i.id() { diff --git a/src/ui_interface.rs b/src/ui_interface.rs index 25a11b45e..1c285947e 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -348,7 +348,7 @@ pub fn set_option(key: String, value: String) { #[cfg(target_os = "macos")] { let is_stop = value == "Y"; - if is_stop && crate::platform::macos::uninstall_service(true) { + if is_stop && crate::platform::uninstall_service(true, false) { return; } } @@ -356,7 +356,7 @@ pub fn set_option(key: String, value: String) { { if crate::platform::is_installed() { if value == "Y" { - if crate::platform::uninstall_service(true) { + if crate::platform::uninstall_service(true, false) { return; } } else {