diff --git a/libs/hbb_common b/libs/hbb_common index 57c8a23ab..bb2d6fa6b 160000 --- a/libs/hbb_common +++ b/libs/hbb_common @@ -1 +1 @@ -Subproject commit 57c8a23ab970587ea6380943b04dc354020bbe7c +Subproject commit bb2d6fa6bdf097f23b891a10f439d747e5acb15f diff --git a/src/platform/macos.rs b/src/platform/macos.rs index f0ff5cb58..f17365a02 100644 --- a/src/platform/macos.rs +++ b/src/platform/macos.rs @@ -25,7 +25,7 @@ use hbb_common::{ }; use include_dir::{include_dir, Dir}; use objc::rc::autoreleasepool; -use objc::{class, msg_send, sel, sel_impl}; +use objc::{class, msg_send, runtime::Object, sel, sel_impl}; use scrap::{libc::c_void, quartz::ffi::*}; use std::{ collections::HashMap, @@ -171,6 +171,7 @@ pub fn is_installed_daemon(prompt: bool) -> bool { let agent = format!("{}_server.plist", crate::get_full_name()); let agent_plist_file = format!("/Library/LaunchAgents/{}", agent); if !prompt { + // in macos 13, there is new way to check if they are running or enabled, https://developer.apple.com/documentation/servicemanagement/updating-helper-executables-from-earlier-versions-of-macos#Respond-to-changes-in-System-Settings if !std::path::Path::new(&format!("/Library/LaunchDaemons/{}", daemon)).exists() { return false; } @@ -296,6 +297,9 @@ fn update_daemon_agent(agent_plist_file: String, update_source_dir: String, sync fn correct_app_name(s: &str) -> String { let s = s.replace("rustdesk", &crate::get_app_name().to_lowercase()); let s = s.replace("RustDesk", &crate::get_app_name()); + if let Some(bundleid) = get_bundle_id() { + let s = s.replace("com.carriez.rustdesk", &bundleid); + } s } @@ -1052,3 +1056,27 @@ impl WakeLock { .ok_or(anyhow!("no AwakeHandle"))? } } + +fn get_bundle_id() -> Option { + unsafe { + let bundle: id = msg_send![class!(NSBundle), mainBundle]; + if bundle.is_null() { + return None; + } + + let bundle_id: id = msg_send![bundle, bundleIdentifier]; + if bundle_id.is_null() { + return None; + } + + let c_str: *const std::os::raw::c_char = msg_send![bundle_id, UTF8String]; + if c_str.is_null() { + return None; + } + + let bundle_id_str = std::ffi::CStr::from_ptr(c_str) + .to_string_lossy() + .to_string(); + Some(bundle_id_str) + } +} diff --git a/src/platform/privileges_scripts/agent.plist b/src/platform/privileges_scripts/agent.plist index 5ff786a49..71cf0cc3d 100644 --- a/src/platform/privileges_scripts/agent.plist +++ b/src/platform/privileges_scripts/agent.plist @@ -4,6 +4,10 @@ Label com.carriez.RustDesk_server + + AssociatedBundleIdentifiers + com.carriez.rustdesk + LimitLoadToSessionType LoginWindow diff --git a/src/platform/privileges_scripts/daemon.plist b/src/platform/privileges_scripts/daemon.plist index 59f103a31..c003ea2be 100644 --- a/src/platform/privileges_scripts/daemon.plist +++ b/src/platform/privileges_scripts/daemon.plist @@ -4,6 +4,10 @@ Label com.carriez.RustDesk_service + + AssociatedBundleIdentifiers + com.carriez.rustdesk + KeepAlive ThrottleInterval