fix(macos): allow install without existing prefs

- guard optional RustDesk preference copies under set -e\n- keep LaunchAgent bootstrap in the user launchd domain\n- add regression coverage for the install script content

Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
This commit is contained in:
Amirhossein Akhlaghpour 2026-04-08 19:30:51 +03:30
parent ed182b8b54
commit f5ed8f782a
No known key found for this signature in database
GPG key ID: D7A35F11FB70A961
2 changed files with 23 additions and 17 deletions

View file

@ -234,16 +234,12 @@ pub fn is_installed_daemon(prompt: bool) -> bool {
Err(e) => {
log::error!("run osascript failed: {}", e);
}
_ => {
Ok(status) if !status.success() => {
log::warn!("run osascript failed with status: {}", status);
}
Ok(_) => {
let installed = std::path::Path::new(&agent_plist_file).exists();
log::info!("Agent file {} installed: {}", agent_plist_file, installed);
if installed {
log::info!("launch server");
std::process::Command::new("launchctl")
.args(&["load", "-w", &agent_plist_file])
.status()
.ok();
}
}
}
});
@ -334,6 +330,16 @@ mod tests {
|| install.contains("launchctl kickstart -k user/$uid/$agent_label"),
"install script must kickstart the agent after bootstrapping it",
);
assert!(
install.contains("quoted form of user"),
"install script must quote username-derived paths",
);
assert!(
install.contains("test ! -f \"$user_preferences_dir/RustDesk.toml\" || cp -rf")
&& install
.contains("test ! -f \"$user_preferences_dir/RustDesk2.toml\" || cp -rf"),
"install script must treat missing preference files as optional",
);
}
}

View file

@ -6,17 +6,17 @@ on run {daemon_file, agent_file, user}
set sh2 to "echo " & quoted form of agent_file & " > " & agent_plist & " && chown root:wheel " & agent_plist & ";"
set sh3 to "cp -rf /Users/" & user & "/Library/Preferences/com.carriez.RustDesk/RustDesk.toml /var/root/Library/Preferences/com.carriez.RustDesk/;"
set sh3 to "user_preferences_dir=/Users/" & quoted form of user & "/Library/Preferences/com.carriez.RustDesk; root_preferences_dir=/var/root/Library/Preferences/com.carriez.RustDesk; mkdir -p \"$root_preferences_dir\";"
set sh4 to "test ! -f \"$user_preferences_dir/RustDesk.toml\" || cp -rf \"$user_preferences_dir/RustDesk.toml\" \"$root_preferences_dir\";"
set sh5 to "test ! -f \"$user_preferences_dir/RustDesk2.toml\" || cp -rf \"$user_preferences_dir/RustDesk2.toml\" \"$root_preferences_dir\";"
set sh4 to "cp -rf /Users/" & user & "/Library/Preferences/com.carriez.RustDesk/RustDesk2.toml /var/root/Library/Preferences/com.carriez.RustDesk/;"
set sh6 to "uid=$(id -u " & quoted form of user & " 2>/dev/null || true);"
set sh7 to "launchctl load -w " & daemon_plist & ";"
set sh8 to "agent_label=$(basename " & quoted form of agent_plist & " .plist);"
set sh9 to "if [ -n \"$uid\" ]; then launchctl bootstrap gui/$uid " & quoted form of agent_plist & " 2>/dev/null || launchctl bootstrap user/$uid " & quoted form of agent_plist & " 2>/dev/null || launchctl load -w " & quoted form of agent_plist & " || true; else launchctl load -w " & quoted form of agent_plist & " || true; fi;"
set sh10 to "if [ -n \"$uid\" ]; then launchctl kickstart -k gui/$uid/$agent_label 2>/dev/null || launchctl kickstart -k user/$uid/$agent_label 2>/dev/null || true; fi;"
set sh5 to "uid=$(id -u " & quoted form of user & " 2>/dev/null || true);"
set sh6 to "launchctl load -w " & daemon_plist & ";"
set sh7 to "agent_label=$(basename " & quoted form of agent_plist & " .plist);"
set sh8 to "if [ -n \"$uid\" ]; then launchctl bootstrap gui/$uid " & quoted form of agent_plist & " 2>/dev/null || launchctl bootstrap user/$uid " & quoted form of agent_plist & " 2>/dev/null || launchctl load -w " & quoted form of agent_plist & " || true; else launchctl load -w " & quoted form of agent_plist & " || true; fi;"
set sh9 to "if [ -n \"$uid\" ]; then launchctl kickstart -k gui/$uid/$agent_label 2>/dev/null || launchctl kickstart -k user/$uid/$agent_label 2>/dev/null || true; fi;"
set sh to "set -e;" & sh1 & sh2 & sh3 & sh4 & sh5 & sh6 & sh7 & sh8 & sh9
set sh to "set -e;" & sh1 & sh2 & sh3 & sh4 & sh5 & sh6 & sh7 & sh8 & sh9 & sh10
do shell script sh with prompt "RustDesk wants to install daemon and agent" with administrator privileges
end run