Revert "feat: macos, update dmg (#13539)"

This reverts commit a6571e71e4.
This commit is contained in:
RustDesk
2025-11-20 23:17:48 +08:00
committed by GitHub
parent 3787b45b49
commit 1920da5478
3 changed files with 19 additions and 82 deletions

View File

@@ -115,10 +115,6 @@ pub fn global_init() -> bool {
crate::server::wayland::init(); crate::server::wayland::init();
} }
} }
#[cfg(target_os = "macos")]
{
crate::platform::macos::try_remove_temp_update_dir(None);
}
true true
} }

View File

@@ -300,35 +300,14 @@ pub fn core_main() -> Option<Vec<String>> {
{ {
use crate::platform; use crate::platform;
if args[0] == "--update" { if args[0] == "--update" {
if args.len() > 1 && args[1].ends_with(".dmg") { let _text = match platform::update_me() {
// Version check is unnecessary unless downgrading to an older version Ok(_) => {
// that lacks "update dmg" support. This is a special case since we cannot log::info!("{}", translate("Update successfully!".to_string()));
// detect the version before extracting the DMG, so we skip the check.
let dmg_path = &args[1];
println!("Updating from DMG: {}", dmg_path);
match platform::update_from_dmg(dmg_path) {
Ok(_) => {
println!("Update process from DMG started successfully.");
// The new process will handle the rest. We can exit.
}
Err(err) => {
eprintln!("Failed to start update from DMG: {}", err);
}
} }
} else { Err(err) => {
println!("Starting update process..."); log::error!("Update failed with error: {err}");
log::info!("Starting update process..."); }
let _text = match platform::update_me() { };
Ok(_) => {
println!("{}", translate("Update successfully!".to_string()));
log::info!("Update successfully!");
}
Err(err) => {
eprintln!("Update failed with error: {}", err);
log::error!("Update failed with error: {err}");
}
};
}
return None; return None;
} }
} }

View File

@@ -38,8 +38,6 @@ static PRIVILEGES_SCRIPTS_DIR: Dir =
include_dir!("$CARGO_MANIFEST_DIR/src/platform/privileges_scripts"); include_dir!("$CARGO_MANIFEST_DIR/src/platform/privileges_scripts");
static mut LATEST_SEED: i32 = 0; static mut LATEST_SEED: i32 = 0;
// Using a fixed temporary directory for updates is preferable to
// using one that includes the custom client name.
const UPDATE_TEMP_DIR: &str = "/tmp/.rustdeskupdate"; const UPDATE_TEMP_DIR: &str = "/tmp/.rustdeskupdate";
extern "C" { extern "C" {
@@ -716,14 +714,6 @@ pub fn quit_gui() {
}; };
} }
#[inline]
pub fn try_remove_temp_update_dir(dir: Option<&str>) {
let target_path = Path::new(dir.unwrap_or(UPDATE_TEMP_DIR));
if target_path.exists() {
std::fs::remove_dir_all(target_path).ok();
}
}
pub fn update_me() -> ResultType<()> { pub fn update_me() -> ResultType<()> {
let is_installed_daemon = is_installed_daemon(false); let is_installed_daemon = is_installed_daemon(false);
let option_stop_service = "stop-service"; let option_stop_service = "stop-service";
@@ -743,7 +733,6 @@ pub fn update_me() -> ResultType<()> {
bail!("Unknown app directory of current exe file: {:?}", cmd); bail!("Unknown app directory of current exe file: {:?}", cmd);
}; };
let app_name = crate::get_app_name();
if is_installed_daemon && !is_service_stopped { if is_installed_daemon && !is_service_stopped {
let agent = format!("{}_server.plist", crate::get_full_name()); let agent = format!("{}_server.plist", crate::get_full_name());
let agent_plist_file = format!("/Library/LaunchAgents/{}", agent); let agent_plist_file = format!("/Library/LaunchAgents/{}", agent);
@@ -760,13 +749,12 @@ pub fn update_me() -> ResultType<()> {
let update_body = format!( let update_body = format!(
r#" r#"
do shell script " do shell script "
pgrep -x '{app_name}' | grep -v {pid} | xargs kill -9 && rm -rf '/Applications/{app_name}.app' && ditto '{app_dir}' '/Applications/{app_name}.app' && chown -R {user}:staff '/Applications/{app_name}.app' && xattr -r -d com.apple.quarantine '/Applications/{app_name}.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 "{app_name} wants to update itself" with administrator privileges " with prompt "RustDesk wants to update itself" with administrator privileges
"#, "#,
app_name = app_name, std::process::id(),
pid = std::process::id(), app_dir,
app_dir = app_dir, get_active_username()
user = get_active_username()
); );
match Command::new("osascript") match Command::new("osascript")
.arg("-e") .arg("-e")
@@ -784,7 +772,7 @@ pgrep -x '{app_name}' | grep -v {pid} | xargs kill -9 && rm -rf '/Applications/{
} }
std::process::Command::new("open") std::process::Command::new("open")
.arg("-n") .arg("-n")
.arg(&format!("/Applications/{}.app", app_name)) .arg(&format!("/Applications/{}.app", crate::get_app_name()))
.spawn() .spawn()
.ok(); .ok();
// leave open a little time // leave open a little time
@@ -792,15 +780,6 @@ pgrep -x '{app_name}' | grep -v {pid} | xargs kill -9 && rm -rf '/Applications/{
Ok(()) Ok(())
} }
pub fn update_from_dmg(dmg_path: &str) -> ResultType<()> {
println!("Starting update from DMG: {}", dmg_path);
extract_dmg(dmg_path, UPDATE_TEMP_DIR)?;
println!("DMG extracted");
update_extracted(UPDATE_TEMP_DIR)?;
println!("Update process started");
Ok(())
}
pub fn update_to(_file: &str) -> ResultType<()> { pub fn update_to(_file: &str) -> ResultType<()> {
update_extracted(UPDATE_TEMP_DIR)?; update_extracted(UPDATE_TEMP_DIR)?;
Ok(()) Ok(())
@@ -832,14 +811,10 @@ fn extract_dmg(dmg_path: &str, target_dir: &str) -> ResultType<()> {
} }
std::fs::create_dir_all(target_path)?; std::fs::create_dir_all(target_path)?;
let status = Command::new("hdiutil") Command::new("hdiutil")
.args(&["attach", "-nobrowse", "-mountpoint", mount_point, dmg_path]) .args(&["attach", "-nobrowse", "-mountpoint", mount_point, dmg_path])
.status()?; .status()?;
if !status.success() {
bail!("Failed to attach DMG image at {}: {:?}", dmg_path, status);
}
struct DmgGuard(&'static str); struct DmgGuard(&'static str);
impl Drop for DmgGuard { impl Drop for DmgGuard {
fn drop(&mut self) { fn drop(&mut self) {
@@ -850,7 +825,7 @@ fn extract_dmg(dmg_path: &str, target_dir: &str) -> ResultType<()> {
} }
let _guard = DmgGuard(mount_point); let _guard = DmgGuard(mount_point);
let app_name = format!("{}.app", crate::get_app_name()); let app_name = "RustDesk.app";
let src_path = format!("{}/{}", mount_point, app_name); let src_path = format!("{}/{}", mount_point, app_name);
let dest_path = format!("{}/{}", target_dir, app_name); let dest_path = format!("{}/{}", target_dir, app_name);
@@ -859,12 +834,7 @@ fn extract_dmg(dmg_path: &str, target_dir: &str) -> ResultType<()> {
.status()?; .status()?;
if !copy_status.success() { if !copy_status.success() {
bail!( bail!("Failed to copy application {:?}", copy_status);
"Failed to copy application from {} to {}: {:?}",
src_path,
dest_path,
copy_status
);
} }
if !Path::new(&dest_path).exists() { if !Path::new(&dest_path).exists() {
@@ -878,13 +848,9 @@ fn extract_dmg(dmg_path: &str, target_dir: &str) -> ResultType<()> {
} }
fn update_extracted(target_dir: &str) -> ResultType<()> { fn update_extracted(target_dir: &str) -> ResultType<()> {
let app_name = crate::get_app_name(); let exe_path = format!("{}/RustDesk.app/Contents/MacOS/RustDesk", target_dir);
let exe_path = format!(
"{}/{}.app/Contents/MacOS/{}",
target_dir, app_name, app_name
);
let _child = unsafe { let _child = unsafe {
if let Err(e) = Command::new(&exe_path) Command::new(&exe_path)
.arg("--update") .arg("--update")
.stdin(Stdio::null()) .stdin(Stdio::null())
.stdout(Stdio::null()) .stdout(Stdio::null())
@@ -893,11 +859,7 @@ fn update_extracted(target_dir: &str) -> ResultType<()> {
hbb_common::libc::setsid(); hbb_common::libc::setsid();
Ok(()) Ok(())
}) })
.spawn() .spawn()?
{
try_remove_temp_update_dir(Some(target_dir));
bail!(e);
}
}; };
Ok(()) Ok(())
} }