diff --git a/privileges_scripts/com.carriez.rustdesk.agent.root.plist b/privileges_scripts/com.carriez.rustdesk.agent.root.plist new file mode 100644 index 000000000..72dbe816e --- /dev/null +++ b/privileges_scripts/com.carriez.rustdesk.agent.root.plist @@ -0,0 +1,30 @@ + + + + + Disable + + Label + com.carriez.rustdesk.agent.root + LimitLoadToSessionType + + LoginWindow + + KeepAlive + + SuccessfulExit + + AfterInitialDemand + + + RunAtLoad + + ProgramArguments + + /Applications/RustDesk.app/Contents/MacOS/rustdesk + --server + + WorkingDirectory + /Applications/RustDesk.app/Contents/MacOS/ + + \ No newline at end of file diff --git a/privileges_scripts/com.carriez.rustdesk.agent.user.plist b/privileges_scripts/com.carriez.rustdesk.agent.user.plist new file mode 100644 index 000000000..1e24769d4 --- /dev/null +++ b/privileges_scripts/com.carriez.rustdesk.agent.user.plist @@ -0,0 +1,30 @@ + + + + + Disable + + Label + com.carriez.rustdesk.agent.root + LimitLoadToSessionType + + Aqua + + KeepAlive + + SuccessfulExit + + AfterInitialDemand + + + RunAtLoad + + ProgramArguments + + /Applications/RustDesk.app/Contents/MacOS/rustdesk + --server + + WorkingDirectory + /Applications/RustDesk.app/Contents/MacOS/ + + \ No newline at end of file diff --git a/privileges_scripts/com.carriez.rustdesk.daemon.plist b/privileges_scripts/com.carriez.rustdesk.daemon.plist new file mode 100644 index 000000000..8d4d1b106 --- /dev/null +++ b/privileges_scripts/com.carriez.rustdesk.daemon.plist @@ -0,0 +1,23 @@ + + + + + Label + com.carriez.rustdesk.daemon + Disabled + + KeepAlive + + Label + com.youqu.todesk.service + ProgramArguments + + /Applications/RustDesk.app/Contents/MacOS/rustdesk + --daemon + + RunAtLoad + + WorkingDirectory + /Applications/RustDesk.app/Contents/MacOS/ + + \ No newline at end of file diff --git a/privileges_scripts/install.scpt b/privileges_scripts/install.scpt new file mode 100644 index 000000000..84937050f --- /dev/null +++ b/privileges_scripts/install.scpt @@ -0,0 +1,9 @@ +set current_dir to POSIX path of ((path to me as text) & "::") + +set sh1 to "cp " & current_dir & "com.carriez.rustdesk.daemon.plist /Library/LaunchDaemons/com.carriez.rustdesk.daemon.plist && chown root:wheel /Library/LaunchDaemons/com.carriez.rustdesk.daemon.plist" +set sh2 to "cp " & current_dir & "com.carriez.rustdesk.agent.root.plist /Library/LaunchAgents/com.carriez.rustdesk.agent.root.plist && chown root:wheel /Library/LaunchAgents/com.carriez.rustdesk.agent.root.plist" +set sh3 to "cp " & current_dir & "com.carriez.rustdesk.agent.user.plist /Library/LaunchAgents/com.carriez.rustdesk.agent.user.plist && chown root:wheel /Library/LaunchAgents/com.carriez.rustdesk.agent.user.plist" + +set sh to sh1 & ";" & sh2 & ";" & sh3 + +do shell script sh with prompt "RustDesk需要安装服务plist" with administrator privileges \ No newline at end of file diff --git a/privileges_scripts/launch_service.scpt b/privileges_scripts/launch_service.scpt new file mode 100644 index 000000000..f0ef31408 --- /dev/null +++ b/privileges_scripts/launch_service.scpt @@ -0,0 +1,10 @@ +set sh to " +launchctl enable system/com.carriez.rustdesk.daemon; +launchctl start system/com.carriez.rustdesk.daemon; +launchctl enable system/com.carriez.rustdesk.agent.root; +launchctl start system/com.carriez.rustdesk.agent.root; +launchctl enable system/com.carriez.rustdesk.agent.user +launchctl start system/com.carriez.rustdesk.agent.user +" + +do shell script sh with prompt "RustDesk需要启动服务" with administrator privileges \ No newline at end of file diff --git a/privileges_scripts/stop_service.scpt b/privileges_scripts/stop_service.scpt new file mode 100644 index 000000000..9a60ec899 --- /dev/null +++ b/privileges_scripts/stop_service.scpt @@ -0,0 +1,10 @@ +set sh to " +launchctl disable system/com.carriez.rustdesk.daemon; +launchctl stop system/com.carriez.rustdesk.daemon; +launchctl disable system/com.carriez.rustdesk.agent.root; +launchctl stop system/com.carriez.rustdesk.agent.root; +launchctl disable system/com.carriez.rustdesk.agent.user +launchctl stop system/com.carriez.rustdesk.agent.user +" + +do shell script sh with prompt "RustDesk需要停止服务" with administrator privileges \ No newline at end of file diff --git a/src/platform/macos.rs b/src/platform/macos.rs index f278fdf9c..85b3e8ea1 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -19,6 +19,7 @@ use core_graphics::{ use hbb_common::{allow_err, bail, log}; use objc::{class, msg_send, sel, sel_impl}; use scrap::{libc::c_void, quartz::ffi::*}; +use std::io::Read; static mut LATEST_SEED: i32 = 0; @@ -98,6 +99,57 @@ pub fn is_can_screen_recording(prompt: bool) -> bool { can_record_screen } +pub fn is_installed_daemon(prompt: bool) -> bool { + if !prompt { + let output = std::process::Command::new("launchctl") + .args(vec!["list", "|", "grep", "com.carriez.rustdesk.daemon"]) + .stdout(std::process::Stdio::piped()) + .output() + .unwrap(); + if output.stdout.len() <= 0{ + return false; + } + + let output = std::process::Command::new("launchctl") + .args(vec!["list", "|", "grep", "com.carriez.rustdesk.agent.root"]) + .stdout(std::process::Stdio::piped()) + .output() + .unwrap(); + if output.stdout.len() <= 0{ + return false; + } + + let output = std::process::Command::new("launchctl") + .args(vec!["list", "|", "grep", "com.carriez.rustdesk.agent.user"]) + .stdout(std::process::Stdio::piped()) + .output() + .unwrap(); + if output.stdout.len() <= 0{ + return false; + } + + return true; + } + + if !std::process::Command::new("osascript") + .arg("./privileges_scripts/install.scpt") + .status() + .unwrap() + .success() { + return false; + } + + if !std::process::Command::new("osascript") + .arg("./privileges_scripts/launch_service.scpt") + .status() + .unwrap() + .success() { + return false; + } + + return true; +} + pub fn get_cursor_pos() -> Option<(i32, i32)> { unsafe { let e = CGEventCreate(0 as _); @@ -334,8 +386,8 @@ pub fn is_installed() -> bool { true } -pub fn start_daemon(){ - log::info!("{}",crate::username()); +pub fn start_daemon() { + log::info!("{}", crate::username()); if let Err(err) = crate::ipc::start("_daemon") { log::error!("Failed to start ipc_daemon: {}", err); std::process::exit(-1); diff --git a/src/ui.rs b/src/ui.rs index 7255c47b7..f12b6dcc5 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -363,6 +363,20 @@ impl UI { options.insert(key, value); } ipc::set_options(options.clone()).ok(); + + #[cfg(macos)] + if key == "stop-service" { + let mut service_script = "./privileges_scripts/stop_service.scpt"; + if value == "Y" { + command = "./privileges_scripts/launch_service.scpt"; + } + + std::process::Command::new("osascript") + .arg(service_script) + .status() + .unwrap() + .success(); + } } fn install_path(&mut self) -> String { @@ -525,6 +539,13 @@ impl UI { return true; } + fn is_installed_daemon(&mut self, _prompt: bool) -> bool { + #[cfg(target_os = "macos")] + return crate::platform::macos::is_installed_daemon(_prompt); + #[cfg(not(target_os = "macos"))] + return true; + } + fn get_error(&mut self) -> String { #[cfg(target_os = "linux")] { @@ -668,6 +689,7 @@ impl sciter::EventHandler for UI { fn goto_install(); fn is_process_trusted(bool); fn is_can_screen_recording(bool); + fn is_installed_daemon(bool); fn get_error(); fn is_login_wayland(); fn fix_login_wayland(); diff --git a/src/ui/index.tis b/src/ui/index.tis index a69e5b014..850a35e62 100644 --- a/src/ui/index.tis +++ b/src/ui/index.tis @@ -307,6 +307,7 @@ class App: Reactor.Component {handler.is_installed() && !software_update_url && handler.is_installed_lower_version() ? : ""} {is_can_screen_recording ? "": } {is_can_screen_recording && !handler.is_process_trusted(false) ? : ""} + {is_can_screen_recording && handler.is_process_trusted(false) && handler.is_installed_daemon(false) ? : ""} {system_error ? : ""} {!system_error && handler.is_login_wayland() && !handler.current_is_wayland() ? : ""} {!system_error && handler.current_is_wayland() ? : ""} @@ -491,6 +492,21 @@ class CanScreenRecording: Reactor.Component { } } +class InstallDaemon: Reactor.Component { + function render() { + return
+
{translate('Configuration Permissions')}
+
{translate('install_daemon')}
+
{translate('Configure')}
+
; + } + + event click $(#install-daemon) { + handler.is_installed_daemon(true); + watch_trust(); + } +} + class FixWayland: Reactor.Component { function render() { return