Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

improve https://github.com/rustdesk/rustdesk/discussions/5631#discussioncomment-8916273

rustdesk85f387bfb9ec
diff --git a/res/mac-tray-dark-x2.png b/res/mac-tray-dark-x2.png
index d1ba59123..8b838cb5e 100644
Binary files a/res/mac-tray-dark-x2.png and b/res/mac-tray-dark-x2.png differ
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<Vec<String>> {
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<Vec<String>> {
#[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<Vec<String>> {
// 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 @@
<true/>
<key>ProgramArguments</key>
<array>
- <string>/Applications/RustDesk.app/Contents/MacOS/RustDesk</string>
- <string>--service</string>
+ <string>/bin/sh</string>
+ <string>-c</string>
+ <string>sleep 1.5; /Applications/RustDesk.app/Contents/MacOS/RustDesk --service</string>
</array>
<key>RunAtLoad</key>
<true/>
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 {