Skip to content

Commit

Permalink
Merge pull request rustdesk#224 from desertstsung/addfun/relogin_xorg
Browse files Browse the repository at this point in the history
add function
  • Loading branch information
rustdesk authored Sep 9, 2021
2 parents 8138a66 + 1009eab commit c5f1222
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 2 deletions.
67 changes: 67 additions & 0 deletions src/platform/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::{
type Xdo = *const c_void;

pub const PA_SAMPLE_RATE: u32 = 24000;
static mut UNMODIFIED: bool = true;

thread_local! {
static XDO: RefCell<Xdo> = RefCell::new(unsafe { xdo_new(std::ptr::null()) });
Expand Down Expand Up @@ -432,6 +433,72 @@ pub fn fix_login_wayland() {
}
}

pub fn current_is_wayland() -> bool {
let dtype = get_display_server();
return "wayland" == dtype && unsafe{UNMODIFIED};
}

pub fn modify_default_login() -> String {
let dsession = std::env::var("DESKTOP_SESSION").unwrap();
let user_name = std::env::var("USERNAME").unwrap();
if let Ok(Some(x)) = run_cmds("ls /usr/share/* | grep ${DESKTOP_SESSION}-xorg.desktop".to_owned()) {
if x.trim_end().to_string() != "" {
match std::process::Command::new("pkexec")
.args(vec![
"sed",
"-i",
&format!("s/={0}$/={0}-xorg/g", &dsession),
&format!("/var/lib/AccountsService/users/{}", &user_name)
])
.output()
{
Ok(x) => {
let x = String::from_utf8_lossy(&x.stderr);
if !x.is_empty() {
log::error!("modify_default_login failed: {}", x);
return "Fix failed! Please re-login with X server manually".to_owned();
} else {
unsafe {UNMODIFIED = false;}
return "".to_owned();
}
}
Err(err) => {
log::error!("modify_default_login failed: {}", err);
return "Fix failed! Please re-login with X server manually".to_owned();
}
}
} else if let Ok(Some(z)) = run_cmds("ls /usr/share/* | grep ${DESKTOP_SESSION:0:-8}.desktop".to_owned()) {
if z.trim_end().to_string() != "" {
match std::process::Command::new("pkexec")
.args(vec![
"sed",
"-i",
&format!("s/={}$/={}/g", &dsession, &dsession[..dsession.len()-8]),
&format!("/var/lib/AccountsService/users/{}", &user_name)
])
.output()
{
Ok(x) => {
let x = String::from_utf8_lossy(&x.stderr);
if !x.is_empty() {
log::error!("modify_default_login failed: {}", x);
return "Fix failed! Please re-login with X server manually".to_owned();
} else {
unsafe {UNMODIFIED = false;}
return "".to_owned();
}
}
Err(err) => {
log::error!("modify_default_login failed: {}", err);
return "Fix failed! Please re-login with X server manually".to_owned();
}
}
}
}
}
return "Fix failed! Please re-login with X server manually".to_owned();
}

// to-do: test the other display manager
fn _get_display_manager() -> String {
if let Ok(x) = std::fs::read_to_string("/etc/X11/default-display-manager") {
Expand Down
17 changes: 17 additions & 0 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ impl UI {
#[cfg(target_os = "linux")]
{
let dtype = crate::platform::linux::get_display_server();
if "wayland" == dtype {
return "".to_owned();
}
if dtype != "x11" {
return format!("Unsupported display server type {}, x11 expected!", dtype);
}
Expand All @@ -474,6 +477,18 @@ impl UI {
#[cfg(target_os = "linux")]
return crate::platform::linux::fix_login_wayland();
}

fn current_is_wayland(&mut self) -> bool {
#[cfg(target_os = "linux")]
return crate::platform::linux::current_is_wayland();
#[cfg(not(target_os = "linux"))]
return false;
}

fn modify_default_login(&mut self) -> String {
#[cfg(target_os = "linux")]
return crate::platform::linux::modify_default_login();
}

fn get_software_update_url(&self) -> String {
SOFTWARE_UPDATE_URL.lock().unwrap().clone()
Expand Down Expand Up @@ -561,6 +576,8 @@ impl sciter::EventHandler for UI {
fn get_error();
fn is_login_wayland();
fn fix_login_wayland();
fn current_is_wayland();
fn modify_default_login();
fn get_options();
fn get_option(String);
fn get_peer_option(String, String);
Expand Down
22 changes: 20 additions & 2 deletions src/ui/index.tis
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ class App: Reactor.Component
{is_can_screen_recording ? "": <CanScreenRecording />}
{is_can_screen_recording && !handler.is_process_trusted(false) ? <TrustMe /> : ""}
{system_error ? <SystemError /> : ""}
{!system_error && handler.is_login_wayland() ? <FixWayland /> : ""}
{!system_error && handler.is_login_wayland() && !handler.current_is_wayland() ? <FixWayland /> : ""}
{!system_error && handler.current_is_wayland() ? <ModifyDefaultLogin /> : ""}
</div>
<div .right-pane>
<div .right-content>
Expand Down Expand Up @@ -544,7 +545,7 @@ class FixWayland: Reactor.Component {
return <div .trust-me>
<div>Warning</div>
<div>Login screen using Wayland is not supported</div>
<div #fix-wayland .link>Disable it</div>
<div #fix-wayland .link>Fix it</div>
</div>;
}

Expand All @@ -554,6 +555,23 @@ class FixWayland: Reactor.Component {
}
}

class ModifyDefaultLogin: Reactor.Component {
function render() {
return <div .trust-me>
<div>Warning</div>
<div>Current Wayland display server is not supported</div>
<div #modify-default-login .link>Fix it(re-login required)</div>
</div>;
}

event click $(#modify-default-login) {
if (var r = handler.modify_default_login()) {
handler.msgbox("custom-error", "Error", r);
}
app.update();
}
}

function watch_trust() {
// not use TrustMe::update, because it is buggy
var trusted = handler.is_process_trusted(false);
Expand Down

0 comments on commit c5f1222

Please sign in to comment.