From 22a5399588980387874b0393e31633a5eb4ffa20 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Fri, 9 Jun 2023 13:35:03 +0800 Subject: [PATCH] fix config sync when uninstall service --- src/platform/linux.rs | 24 +++++++++++++++--------- src/server.rs | 7 +++++-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/platform/linux.rs b/src/platform/linux.rs index 1b69db547..65e8d4226 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -1119,13 +1119,25 @@ pub fn run_me_with(secs: u32) { .ok(); } +fn switch_service(stop: bool) -> String { + let home = std::env::var("HOME").unwrap_or_default(); + Config::set_option("stop-service".into(), if stop { "Y" } else { "" }.into()); + if home != "/root" && !Config::get().is_empty() { + format!("cp -f {home}/.config/rustdesk/RustDesk.toml /root/.config/rustdesk/; cp -f {home}/.config/rustdesk/RustDesk2.toml /root/.config/rustdesk/;") + } else { + "".to_owned() + } +} + pub fn uninstall_service(show_new_window: bool) -> bool { if !has_cmd("systemctl") { return false; } log::info!("Uninstalling service..."); - Config::set_option("stop-service".into(), "Y".into()); - if !run_cmds_pkexec("systemctl disable rustdesk; systemctl stop rustdesk") { + let cp = switch_service(true); + if !run_cmds_pkexec(&format!( + "{cp} systemctl disable rustdesk; systemctl stop rustdesk" + )) { Config::set_option("stop-service".into(), "".into()); return true; } @@ -1140,13 +1152,7 @@ pub fn install_service() -> bool { return false; } log::info!("Installing service..."); - let home = std::env::var("HOME").unwrap_or_default(); - let cp = if home != "/root" && !Config::get().is_empty() { - format!("cp -f {home}/.config/rustdesk/RustDesk.toml /root/.config/rustdesk/; cp -f {home}/.config/rustdesk/RustDesk2.toml /root/.config/rustdesk/;") - } else { - "".to_owned() - }; - Config::set_option("stop-service".into(), "".into()); + let cp = switch_service(false); if !run_cmds_pkexec(&format!( "{cp}systemctl enable rustdesk; systemctl start rustdesk" )) { diff --git a/src/server.rs b/src/server.rs index 896c40e1e..545f81e3c 100644 --- a/src/server.rs +++ b/src/server.rs @@ -62,6 +62,9 @@ pub mod video_service; pub type Childs = Arc>>; type ConnMap = HashMap; +#[cfg(any(target_os = "macos", target_os = "linux"))] +const CONFIG_SYNC_INTERVAL_SECS: f32 = 0.3; + lazy_static::lazy_static! { pub static ref CHILD_PROCESS: Childs = Default::default(); pub static ref CONN_COUNT: Arc> = Default::default(); @@ -477,7 +480,7 @@ async fn sync_and_watch_config_dir() { log::debug!("#tries of ipc service connection: {}", tries); use hbb_common::sleep; for i in 1..=tries { - sleep(i as f32 * 0.3).await; + sleep(i as f32 * CONFIG_SYNC_INTERVAL_SECS).await; match crate::ipc::connect(1000, "_service").await { Ok(mut conn) => { if !synced { @@ -508,7 +511,7 @@ async fn sync_and_watch_config_dir() { } loop { - sleep(0.3).await; + sleep(CONFIG_SYNC_INTERVAL_SECS).await; let cfg = (Config::get(), Config2::get()); if cfg != cfg0 { log::info!("config updated, sync to root");