From 5a740e891e38dd8dcd5d0d280d24a788785f3fbb Mon Sep 17 00:00:00 2001 From: rustdesk Date: Wed, 19 Jun 2024 09:27:29 +0800 Subject: [PATCH] make main window can be reopen if killed by --server for creating ipc --- src/common.rs | 6 ++++++ src/ipc.rs | 12 ++++++++++-- src/platform/mod.rs | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/common.rs b/src/common.rs index 60cbd06b3..9be677e18 100644 --- a/src/common.rs +++ b/src/common.rs @@ -197,6 +197,7 @@ lazy_static::lazy_static! { static ref IS_SERVER: bool = std::env::args().nth(1) == Some("--server".to_owned()); // Is server logic running. The server code can invoked to run by the main process if --server is not running. static ref SERVER_RUNNING: Arc> = Default::default(); + static ref IS_MAIN: bool = std::env::args().nth(1).map_or(true, |arg| !arg.starts_with("--")); } #[cfg(not(any(target_os = "android", target_os = "ios")))] @@ -250,6 +251,11 @@ pub fn is_server() -> bool { *IS_SERVER } +#[inline] +pub fn is_main() -> bool { + *IS_MAIN +} + // Is server logic running. #[inline] pub fn is_server_running() -> bool { diff --git a/src/ipc.rs b/src/ipc.rs index d76f51820..2e566feff 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -358,7 +358,15 @@ async fn handle(data: Data, stream: &mut Connection) { if is_server() { let _ = privacy_mode::turn_off_privacy(0, Some(PrivacyModeState::OffByPeer)); } - std::process::exit(-1); // to make sure --server luauchagent process can restart because SuccessfulExit used + #[cfg(target_os = "linux")] + if crate::is_main() { + // below part is for main windows can be reopen during rustdesk installation and installing service from UI + // this make new ipc server (domain socket) can be created. + std::fs::remove_file(&Config::ipc_path("")).ok(); + hbb_common::sleep(crate::platform::SERVICE_INTERVAL * 2 as _).await; + crate::run_me::<&str>(vec![]).ok(); + } + std::process::exit(-1); // to make sure --server luauchagent process can restart because SuccessfulExit used } } Data::OnlineStatus(_) => { @@ -700,7 +708,7 @@ async fn check_pid(postfix: &str) { } } // if not remove old ipc file, the new ipc creation will fail - // if we remove a ipc file, but the old ipc process is still running, + // if we remove a ipc file, but the old ipc process is still running, // new connection to the ipc will connect to new ipc, old connection to old ipc still keep alive std::fs::remove_file(&Config::ipc_path(postfix)).ok(); } diff --git a/src/platform/mod.rs b/src/platform/mod.rs index a01362872..65d047cff 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -27,7 +27,7 @@ pub mod linux_desktop_manager; use hbb_common::{message_proto::CursorData, ResultType}; use std::sync::{Arc, Mutex}; #[cfg(not(any(target_os = "macos", target_os = "android", target_os = "ios")))] -const SERVICE_INTERVAL: u64 = 300; +pub const SERVICE_INTERVAL: u64 = 300; lazy_static::lazy_static! { static ref INSTALLING_SERVICE: Arc>= Default::default();