--no-server parameter to avoid server ipc occupied by ui (#9272)
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
parent
aa3402b44a
commit
f0ca4b9fee
@ -39,6 +39,7 @@ pub fn core_main() -> Option<Vec<String>> {
|
|||||||
let mut _is_run_as_system = false;
|
let mut _is_run_as_system = false;
|
||||||
let mut _is_quick_support = false;
|
let mut _is_quick_support = false;
|
||||||
let mut _is_flutter_invoke_new_connection = false;
|
let mut _is_flutter_invoke_new_connection = false;
|
||||||
|
let mut no_server = false;
|
||||||
let mut arg_exe = Default::default();
|
let mut arg_exe = Default::default();
|
||||||
for arg in std::env::args() {
|
for arg in std::env::args() {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
@ -62,6 +63,8 @@ pub fn core_main() -> Option<Vec<String>> {
|
|||||||
_is_run_as_system = true;
|
_is_run_as_system = true;
|
||||||
} else if arg == "--quick_support" {
|
} else if arg == "--quick_support" {
|
||||||
_is_quick_support = true;
|
_is_quick_support = true;
|
||||||
|
} else if arg == "--no-server" {
|
||||||
|
no_server = true;
|
||||||
} else {
|
} else {
|
||||||
args.push(arg);
|
args.push(arg);
|
||||||
}
|
}
|
||||||
@ -134,6 +137,7 @@ pub fn core_main() -> Option<Vec<String>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
hbb_common::init_log(false, &log_name);
|
hbb_common::init_log(false, &log_name);
|
||||||
|
log::info!("main start args: {:?}, env: {:?}", args, std::env::args());
|
||||||
|
|
||||||
// linux uni (url) go here.
|
// linux uni (url) go here.
|
||||||
#[cfg(all(target_os = "linux", feature = "flutter"))]
|
#[cfg(all(target_os = "linux", feature = "flutter"))]
|
||||||
@ -161,9 +165,8 @@ pub fn core_main() -> Option<Vec<String>> {
|
|||||||
#[cfg(all(feature = "flutter", feature = "plugin_framework"))]
|
#[cfg(all(feature = "flutter", feature = "plugin_framework"))]
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
init_plugins(&args);
|
init_plugins(&args);
|
||||||
log::info!("main start args:{:?}", args);
|
|
||||||
if args.is_empty() || crate::common::is_empty_uni_link(&args[0]) {
|
if args.is_empty() || crate::common::is_empty_uni_link(&args[0]) {
|
||||||
std::thread::spawn(move || crate::start_server(false));
|
std::thread::spawn(move || crate::start_server(false, no_server));
|
||||||
} else {
|
} else {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
@ -279,11 +282,11 @@ pub fn core_main() -> Option<Vec<String>> {
|
|||||||
crate::privacy_mode::restore_reg_connectivity(true);
|
crate::privacy_mode::restore_reg_connectivity(true);
|
||||||
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||||
{
|
{
|
||||||
crate::start_server(true);
|
crate::start_server(true, false);
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
let handler = std::thread::spawn(move || crate::start_server(true));
|
let handler = std::thread::spawn(move || crate::start_server(true, false));
|
||||||
crate::tray::start_tray();
|
crate::tray::start_tray();
|
||||||
// prevent server exit when encountering errors from tray
|
// prevent server exit when encountering errors from tray
|
||||||
hbb_common::allow_err!(handler.join());
|
hbb_common::allow_err!(handler.join());
|
||||||
|
@ -401,10 +401,10 @@ async fn handle(data: Data, stream: &mut Connection) {
|
|||||||
std::fs::remove_file(&Config::ipc_path("")).ok();
|
std::fs::remove_file(&Config::ipc_path("")).ok();
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
// https://github.com/rustdesk/rustdesk/discussions/9254, slow on some machines
|
hbb_common::sleep((crate::platform::SERVICE_INTERVAL * 2) as f32 / 1000.0)
|
||||||
hbb_common::sleep((crate::platform::SERVICE_INTERVAL * 2) as f32 / 1000.0 + 1.2)
|
|
||||||
.await;
|
.await;
|
||||||
crate::run_me::<&str>(vec![]).ok();
|
// https://github.com/rustdesk/rustdesk/discussions/9254
|
||||||
|
crate::run_me::<&str>(vec!["--no-server"]).ok();
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
|
@ -102,7 +102,7 @@ fn main() {
|
|||||||
cli::connect_test(p, key, token);
|
cli::connect_test(p, key, token);
|
||||||
} else if let Some(p) = matches.value_of("server") {
|
} else if let Some(p) = matches.value_of("server") {
|
||||||
log::info!("id={}", hbb_common::config::Config::get_id());
|
log::info!("id={}", hbb_common::config::Config::get_id());
|
||||||
crate::start_server(true);
|
crate::start_server(true, false);
|
||||||
}
|
}
|
||||||
common::global_clean();
|
common::global_clean();
|
||||||
}
|
}
|
||||||
|
@ -1378,6 +1378,7 @@ pub fn uninstall_service(show_new_window: bool, _: bool) -> bool {
|
|||||||
Config::set_option("stop-service".into(), "".into());
|
Config::set_option("stop-service".into(), "".into());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// systemctl stop will kill child processes, below may not be executed.
|
||||||
if show_new_window {
|
if show_new_window {
|
||||||
run_me_with(2);
|
run_me_with(2);
|
||||||
}
|
}
|
||||||
|
@ -456,16 +456,21 @@ pub async fn start_server(_is_server: bool) {
|
|||||||
/// * `is_server` - Whether the current client is definitely the server.
|
/// * `is_server` - Whether the current client is definitely the server.
|
||||||
/// If true, the server will be started.
|
/// If true, the server will be started.
|
||||||
/// Otherwise, client will check if there's already a server and start one if not.
|
/// Otherwise, client will check if there's already a server and start one if not.
|
||||||
|
/// * `no_server` - If `is_server` is false, whether to start a server if not found.
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
pub async fn start_server(is_server: bool) {
|
pub async fn start_server(is_server: bool, no_server: bool) {
|
||||||
#[cfg(target_os = "linux")]
|
use std::sync::Once;
|
||||||
{
|
static ONCE: Once = Once::new();
|
||||||
log::info!("DISPLAY={:?}", std::env::var("DISPLAY"));
|
ONCE.call_once(|| {
|
||||||
log::info!("XAUTHORITY={:?}", std::env::var("XAUTHORITY"));
|
#[cfg(target_os = "linux")]
|
||||||
}
|
{
|
||||||
#[cfg(windows)]
|
log::info!("DISPLAY={:?}", std::env::var("DISPLAY"));
|
||||||
hbb_common::platform::windows::start_cpu_performance_monitor();
|
log::info!("XAUTHORITY={:?}", std::env::var("XAUTHORITY"));
|
||||||
|
}
|
||||||
|
#[cfg(windows)]
|
||||||
|
hbb_common::platform::windows::start_cpu_performance_monitor();
|
||||||
|
});
|
||||||
|
|
||||||
if is_server {
|
if is_server {
|
||||||
crate::common::set_server_running(true);
|
crate::common::set_server_running(true);
|
||||||
@ -516,8 +521,14 @@ pub async fn start_server(is_server: bool) {
|
|||||||
crate::ipc::client_get_hwcodec_config_thread(0);
|
crate::ipc::client_get_hwcodec_config_thread(0);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::info!("server not started (will try to start): {}", err);
|
log::info!("server not started: {err:?}, no_server: {no_server}");
|
||||||
std::thread::spawn(|| start_server(true));
|
if no_server {
|
||||||
|
hbb_common::sleep(1.0).await;
|
||||||
|
std::thread::spawn(|| start_server(false, true));
|
||||||
|
} else {
|
||||||
|
log::info!("try start server");
|
||||||
|
std::thread::spawn(|| start_server(true, false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user