looks robust now

This commit is contained in:
rustdesk 2022-04-28 04:22:46 +08:00
parent 8995011d45
commit 0b6155bab8
2 changed files with 28 additions and 22 deletions

View File

@ -137,23 +137,14 @@ pub fn is_installed_daemon(prompt: bool) -> bool {
log::error!("run osascript failed: {}", e); log::error!("run osascript failed: {}", e);
} }
_ => { _ => {
if std::path::Path::new(&agent_plist_file).exists() { let installed = std::path::Path::new(&agent_plist_file).exists();
std::process::Command::new("osascript") log::info!("Agent file {} installed: {}", agent_plist_file, installed);
.arg("-e") if installed {
.arg( log::info!("launch server");
PRIVILEGES_SCRIPTS_DIR std::process::Command::new("launchctl")
.get_file("run.scpt") .args(&["load", "-w", &agent_plist_file])
.unwrap() .status()
.contents_utf8()
.unwrap(),
)
.arg(&format!(
"sleep 0.5; launchctl load -w {};",
agent_plist_file,
))
.spawn()
.ok(); .ok();
std::thread::sleep(std::time::Duration::from_millis(100)); // avoid exit crash
std::process::exit(0); std::process::exit(0);
} }
} }
@ -184,8 +175,18 @@ pub fn uninstall() -> bool {
_ => { _ => {
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);
if !std::path::Path::new(&agent_plist_file).exists() { let uninstalled = !std::path::Path::new(&agent_plist_file).exists();
log::info!(
"Agent file {} uninstalled: {}",
agent_plist_file,
uninstalled
);
if uninstalled {
crate::ipc::set_option("stop-service", "Y"); crate::ipc::set_option("stop-service", "Y");
std::process::Command::new("launchctl")
.args(&["remove", &format!("{}_server", crate::get_full_name())])
.status()
.ok();
std::process::Command::new("osascript") std::process::Command::new("osascript")
.arg("-e") .arg("-e")
.arg( .arg(
@ -196,13 +197,11 @@ pub fn uninstall() -> bool {
.unwrap(), .unwrap(),
) )
.arg(&format!( .arg(&format!(
"sleep 0.5; launchctl remove {}_server; sleep 0.5; open /Applications/{}.app", "sleep 0.5; open /Applications/{}.app",
crate::get_full_name(), crate::get_full_name(),
crate::get_app_name()
)) ))
.spawn() .spawn()
.ok(); .ok();
std::thread::sleep(std::time::Duration::from_millis(100)); // avoid exit crash
std::process::exit(0); std::process::exit(0);
} }
} }
@ -514,7 +513,7 @@ pub fn is_installed() -> bool {
return p return p
.to_str() .to_str()
.unwrap_or_default() .unwrap_or_default()
.contains(&format!("/Applications/{}.app", crate::get_app_name())); .starts_with(&format!("/Applications/{}.app", crate::get_app_name()));
} }
false false
} }

View File

@ -335,7 +335,14 @@ async fn sync_and_watch_config_dir() {
let mut cfg0 = (Config::get(), Config2::get()); let mut cfg0 = (Config::get(), Config2::get());
let mut synced = false; let mut synced = false;
for i in 1..=30 { let tries =
if std::env::args().len() == 2 && std::env::args().nth(1) == Some("--server".to_owned()) {
30
} else {
1
};
log::debug!("#tries of ipc service connection: {}", tries);
for i in 1..=tries {
sleep(i as f32 * 0.3).await; sleep(i as f32 * 0.3).await;
match crate::ipc::connect(1000, "_service").await { match crate::ipc::connect(1000, "_service").await {
Ok(mut conn) => { Ok(mut conn) => {