temp commit

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-03-30 18:16:48 +08:00
parent 34c3615320
commit d82d2471d7
7 changed files with 71 additions and 26 deletions

View File

@ -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 {

View File

@ -224,6 +224,11 @@ pub fn core_main() -> Option<Vec<String>> {
// 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());

View File

@ -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")]

View File

@ -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;
}

View File

@ -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<String> {
if is_gdm_user(&self.seat0_username)
&& self.seat0_display_server == ENV_DESKTOP_PROTOCAL_WAYLAND
&& self.seat0_display_server == DISPLAY_SERVER_WAYLAND
{
None
} else {

View File

@ -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);

View File

@ -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()),