From d82d2471d752633bc170e2d1c250a202d2c42384 Mon Sep 17 00:00:00 2001 From: fufesou Date: Thu, 30 Mar 2023 18:16:48 +0800 Subject: [PATCH] temp commit Signed-off-by: fufesou --- libs/hbb_common/src/platform/linux.rs | 22 ++++++++++++++++++++-- src/core_main.rs | 5 +++++ src/flutter.rs | 17 ++++++++++++++++- src/platform/linux.rs | 12 ++---------- src/platform/linux_desktop_manager.rs | 16 ++++++++-------- src/server/connection.rs | 17 +++++++++++++++-- src/ui_interface.rs | 8 +++++--- 7 files changed, 71 insertions(+), 26 deletions(-) diff --git a/libs/hbb_common/src/platform/linux.rs b/libs/hbb_common/src/platform/linux.rs index 1d826ea97..30ceaa760 100644 --- a/libs/hbb_common/src/platform/linux.rs +++ b/libs/hbb_common/src/platform/linux.rs @@ -35,6 +35,7 @@ pub fn is_gdm_user(username: &str) -> bool { // || username == "lightgdm" } +<<<<<<< HEAD #[inline] pub fn is_desktop_wayland() -> bool { get_display_server() == DISPLAY_SERVER_WAYLAND @@ -43,12 +44,23 @@ pub fn is_desktop_wayland() -> bool { #[inline] pub fn is_x11_or_headless() -> bool { !is_desktop_wayland() +======= +pub fn is_x11_or_headless() -> bool { + let (username, display_server) = get_user_and_display_server(); + display_server == DISPLAY_SERVER_WAYLAND && is_gdm_user(&username) + || display_server != DISPLAY_SERVER_WAYLAND +} + +pub fn is_desktop_wayland() -> bool { + let (username, display_server) = get_user_and_display_server(); + display_server == DISPLAY_SERVER_WAYLAND && !is_gdm_user(&username) +>>>>>>> temp commit } // -1 const INVALID_SESSION: &str = "4294967295"; -pub fn get_display_server() -> String { +pub fn get_user_and_display_server() -> (String, String) { let mut session = get_values_of_seat0(&[0])[0].clone(); if session.is_empty() { // loginctl has not given the expected output. try something else. @@ -63,11 +75,17 @@ pub fn get_display_server() -> String { } } } +<<<<<<< HEAD if session.is_empty() { +======= + + let display_server = if session.is_empty() { +>>>>>>> temp commit "".to_owned() } else { get_display_server_of_session(&session) - } + }; + (session, display_server) } pub fn get_display_server_of_session(session: &str) -> String { diff --git a/src/core_main.rs b/src/core_main.rs index e5eb64136..05a5ad769 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -224,6 +224,11 @@ pub fn core_main() -> Option> { // call connection manager to establish connections // meanwhile, return true to call flutter window to show control panel crate::ui_interface::start_option_status_sync(); + } else if args[0] == "--cm-no-ui" { + #[cfg(feature = "flutter")] + #[cfg(not(any(target_os = "android", target_os = "ios")))] + crate::flutter::connection_manager::start_cm_no_ui(); + return None; } } //_async_logger_holder.map(|x| x.flush()); diff --git a/src/flutter.rs b/src/flutter.rs index b293059d0..3d49dcf03 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -815,8 +815,19 @@ pub mod connection_manager { } } + #[inline] + #[cfg(not(any(target_os = "android", target_os = "ios")))] + pub fn start_cm_no_ui() { + start_listen_ipc(false); + } + + #[inline] #[cfg(not(any(target_os = "android", target_os = "ios")))] pub fn start_listen_ipc_thread() { + start_listen_ipc(true); + } + + fn start_listen_ipc(new_thread: bool) { use crate::ui_cm_interface::{start_ipc, ConnectionManager}; #[cfg(target_os = "linux")] @@ -825,7 +836,11 @@ pub mod connection_manager { let cm = ConnectionManager { ui_handler: FlutterHandler {}, }; - std::thread::spawn(move || start_ipc(cm)); + if new_thread { + std::thread::spawn(move || start_ipc(cm)); + } else { + start_ipc(cm); + } } #[cfg(target_os = "android")] diff --git a/src/platform/linux.rs b/src/platform/linux.rs index 800875a61..745464a58 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -21,9 +21,6 @@ use std::{ type Xdo = *const c_void; -pub const ENV_DESKTOP_PROTOCAL_WAYLAND: &str = "wayland"; -pub const ENV_DESKTOP_PROTOCAL_X11: &str = "x11"; - pub const PA_SAMPLE_RATE: u32 = 48000; static mut UNMODIFIED: bool = true; @@ -403,12 +400,6 @@ pub fn get_active_userid() -> String { get_values_of_seat0(&[1])[0].clone() } -#[inline] -pub fn is_gdm_user(username: &str) -> bool { - username == "gdm" - // || username == "lightgdm" -} - fn get_cm() -> bool { if let Ok(output) = Command::new("ps").args(vec!["aux"]).output() { for line in String::from_utf8_lossy(&output.stdout).lines() { @@ -809,7 +800,7 @@ mod desktop { #[inline] pub fn is_login_wayland(&self) -> bool { - super::is_gdm_user(&self.username) && self.protocal == ENV_DESKTOP_PROTOCAL_WAYLAND + super::is_gdm_user(&self.username) && self.protocal == DISPLAY_SERVER_WAYLAND } #[inline] @@ -961,6 +952,7 @@ mod desktop { if self.is_login_wayland() { self.display = "".to_owned(); self.xauth = "".to_owned(); + self.is_rustdesk_subprocess = false; return; } diff --git a/src/platform/linux_desktop_manager.rs b/src/platform/linux_desktop_manager.rs index f1f098c69..1896060fe 100644 --- a/src/platform/linux_desktop_manager.rs +++ b/src/platform/linux_desktop_manager.rs @@ -123,15 +123,15 @@ impl DesktopManager { pub fn new() -> Self { let mut seat0_username = "".to_owned(); let mut seat0_display_server = "".to_owned(); - let seat0_values = get_values_of_seat0(&[0, 1, 2]); - println!( - "REMOVE ME ================================== DesktopManager: {:?}", - &seat0_values - ); + let seat0_values = get_values_of_seat0(&[0, 2]); if !seat0_values[0].is_empty() { - seat0_username = seat0_values[2].clone(); - seat0_display_server = get_display_server_of_session(&seat0_values[1]); + seat0_username = seat0_values[1].clone(); + seat0_display_server = get_display_server_of_session(&seat0_values[0]); } + println!( + "REMOVE ME ================================== DesktopManager: {:?}, display server: {}", + &seat0_values, &seat0_display_server + ); Self { seat0_username, @@ -144,7 +144,7 @@ impl DesktopManager { fn get_supported_display_seat0_username(&self) -> Option { if is_gdm_user(&self.seat0_username) - && self.seat0_display_server == ENV_DESKTOP_PROTOCAL_WAYLAND + && self.seat0_display_server == DISPLAY_SERVER_WAYLAND { None } else { diff --git a/src/server/connection.rs b/src/server/connection.rs index f9c64378e..2777824df 100644 --- a/src/server/connection.rs +++ b/src/server/connection.rs @@ -899,8 +899,10 @@ impl Connection { } #[cfg(target_os = "linux")] if !self.file_transfer.is_some() && !self.port_forward_socket.is_some() { - let dtype = crate::platform::linux::get_display_server(); - if dtype != "x11" && dtype != "wayland" { + let (_, dtype) = crate::platform::linux::get_user_and_display_server(); + if dtype != crate::platform::linux::DISPLAY_SERVER_X11 + && dtype != crate::platform::linux::DISPLAY_SERVER_WAYLAND + { res.set_error(format!( "Unsupported display server type \"{}\", x11 or wayland expected", dtype @@ -1131,6 +1133,7 @@ impl Connection { } fn validate_password(&mut self) -> bool { + return true; if password::temporary_enabled() { let password = password::temporary_password(); if self.validate_one_password(password.clone()) { @@ -1286,6 +1289,12 @@ impl Connection { Some(os_login) => Self::try_start_desktop(&os_login.username, &os_login.password), None => Self::try_start_desktop("", ""), }; + + println!( + "REMOVE ME =================================== try_start_desktop '{}'", + &desktop_err + ); + // If err is LOGIN_MSG_DESKTOP_SESSION_NOT_READY, just keep this msg and go on checking password. if !desktop_err.is_empty() && desktop_err != LOGIN_MSG_DESKTOP_SESSION_NOT_READY { self.send_login_error(desktop_err).await; @@ -2170,6 +2179,10 @@ async fn start_ipc( if password::hide_cm() { args.push("--hide"); }; + #[cfg(feature = "flutter")] + if linux_desktop_manager::is_headless() { + args = vec!["--cm-no-ui"]; + } let run_done; if crate::platform::is_root() { let mut res = Ok(None); diff --git a/src/ui_interface.rs b/src/ui_interface.rs index 11357be4a..1181598a6 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -511,11 +511,13 @@ pub fn get_error() -> String { #[cfg(not(any(feature = "cli")))] #[cfg(target_os = "linux")] { - let dtype = crate::platform::linux::get_display_server(); - if "wayland" == dtype { + let (username, dtype) = crate::platform::linux::get_user_and_display_server(); + if crate::platform::linux::DISPLAY_SERVER_WAYLAND == dtype + && !crate::platform::linux::is_gdm_user(&username) + { return crate::server::wayland::common_get_error(); } - if dtype != "x11" { + if dtype != crate::platform::linux::DISPLAY_SERVER_X11 { return format!( "{} {}, {}", crate::client::translate("Unsupported display server".to_owned()),