fix: update macos (#12578)

* fix: update macos

1. Use `ditto` instead of `cp -r`.
2. Add prompt for extracting dmg.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix: error to err

Signed-off-by: fufesou <linlong1266@gmail.com>

* Refact: Remove "Extracting"

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
Co-authored-by: RustDesk <71636191+rustdesk@users.noreply.github.com>
This commit is contained in:
fufesou
2025-08-07 23:31:31 +08:00
committed by GitHub
parent e85989e9d9
commit 39b91911cb
4 changed files with 96 additions and 30 deletions

View File

@@ -629,7 +629,10 @@ pub fn session_open_terminal(session_id: SessionID, terminal_id: i32, rows: u32,
if let Some(session) = sessions::get_session_by_session_id(&session_id) {
session.open_terminal(terminal_id, rows, cols);
} else {
log::error!("[flutter_ffi] Session not found for session_id: {}", session_id);
log::error!(
"[flutter_ffi] Session not found for session_id: {}",
session_id
);
}
}
@@ -2651,6 +2654,21 @@ pub fn main_set_common(_key: String, _value: String) {
fs::remove_file(f).ok();
}
}
} else if _key == "extract-update-dmg" {
#[cfg(target_os = "macos")]
{
if let Some(new_version_file) = get_download_file_from_url(&_value) {
if let Some(f) = new_version_file.to_str() {
crate::platform::macos::extract_update_dmg(f);
} else {
// unreachable!()
log::error!("Failed to get the new version file path");
}
} else {
// unreachable!()
log::error!("Failed to get the new version file from url: {}", _value);
}
}
}
}

View File

@@ -28,6 +28,7 @@ use objc::rc::autoreleasepool;
use objc::{class, msg_send, sel, sel_impl};
use scrap::{libc::c_void, quartz::ffi::*};
use std::{
collections::HashMap,
os::unix::process::CommandExt,
path::{Path, PathBuf},
process::{Command, Stdio},
@@ -743,7 +744,7 @@ pub fn update_me() -> ResultType<()> {
let update_body = format!(
r#"
do shell script "
pgrep -x 'RustDesk' | grep -v {} | xargs kill -9 && rm -rf /Applications/RustDesk.app && cp -R '{}' /Applications/ && chown -R {}:staff /Applications/RustDesk.app
pgrep -x 'RustDesk' | grep -v {} | xargs kill -9 && rm -rf /Applications/RustDesk.app && ditto '{}' /Applications/RustDesk.app && chown -R {}:staff /Applications/RustDesk.app && xattr -r -d com.apple.quarantine /Applications/RustDesk.app
" with prompt "RustDesk wants to update itself" with administrator privileges
"#,
std::process::id(),
@@ -775,11 +776,26 @@ pgrep -x 'RustDesk' | grep -v {} | xargs kill -9 && rm -rf /Applications/RustDes
}
pub fn update_to(file: &str) -> ResultType<()> {
extract_dmg(file, UPDATE_TEMP_DIR)?;
update_extracted(UPDATE_TEMP_DIR)?;
Ok(())
}
pub fn extract_update_dmg(file: &str) {
let mut evt: HashMap<&str, String> =
HashMap::from([("name", "extract-update-dmg".to_string())]);
match extract_dmg(file, UPDATE_TEMP_DIR) {
Ok(_) => {
log::info!("Extracted dmg file to {}", UPDATE_TEMP_DIR);
}
Err(e) => {
evt.insert("err", e.to_string());
log::error!("Failed to extract dmg file {}: {}", file, e);
}
}
let evt = serde_json::ser::to_string(&evt).unwrap_or("".to_owned());
crate::flutter::push_global_event(crate::flutter::APP_TYPE_MAIN, evt);
}
fn extract_dmg(dmg_path: &str, target_dir: &str) -> ResultType<()> {
let mount_point = "/Volumes/RustDeskUpdate";
let target_path = Path::new(target_dir);
@@ -807,8 +823,8 @@ fn extract_dmg(dmg_path: &str, target_dir: &str) -> ResultType<()> {
let src_path = format!("{}/{}", mount_point, app_name);
let dest_path = format!("{}/{}", target_dir, app_name);
let copy_status = Command::new("cp")
.args(&["-R", &src_path, &dest_path])
let copy_status = Command::new("ditto")
.args(&[&src_path, &dest_path])
.status()?;
if !copy_status.success() {

View File

@@ -4,7 +4,7 @@ on run {daemon_file, agent_file, user, cur_pid, source_dir}
set kill_others to "pgrep -x 'RustDesk' | grep -v " & cur_pid & " | xargs kill -9;"
set copy_files to "rm -rf /Applications/RustDesk.app && cp -r " & source_dir & " /Applications && chown -R " & quoted form of user & ":staff /Applications/RustDesk.app;"
set copy_files to "rm -rf /Applications/RustDesk.app && ditto " & source_dir & " /Applications/RustDesk.app && chown -R " & quoted form of user & ":staff /Applications/RustDesk.app && xattr -r -d com.apple.quarantine /Applications/RustDesk.app;"
set sh1 to "echo " & quoted form of daemon_file & " > /Library/LaunchDaemons/com.carriez.RustDesk_service.plist && chown root:wheel /Library/LaunchDaemons/com.carriez.RustDesk_service.plist;"