From 1009eabdfec534a19ba2293c1853daafb1437f1b Mon Sep 17 00:00:00 2001 From: desertstsung Date: Thu, 9 Sep 2021 15:07:09 +0800 Subject: [PATCH] add function relogin required if current is wayland --- src/platform/linux.rs | 67 +++++++++++++++++++++++++++++++++++++++++++ src/ui.rs | 17 +++++++++++ src/ui/index.tis | 22 ++++++++++++-- 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/src/platform/linux.rs b/src/platform/linux.rs index 8ebd62f7f..9b68c3656 100644 --- a/src/platform/linux.rs +++ b/src/platform/linux.rs @@ -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 = RefCell::new(unsafe { xdo_new(std::ptr::null()) }); @@ -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") { diff --git a/src/ui.rs b/src/ui.rs index 311939f22..5c4085970 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -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); } @@ -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() @@ -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); diff --git a/src/ui/index.tis b/src/ui/index.tis index 81489192f..ea48bacdc 100644 --- a/src/ui/index.tis +++ b/src/ui/index.tis @@ -360,7 +360,8 @@ class App: Reactor.Component {is_can_screen_recording ? "": } {is_can_screen_recording && !handler.is_process_trusted(false) ? : ""} {system_error ? : ""} - {!system_error && handler.is_login_wayland() ? : ""} + {!system_error && handler.is_login_wayland() && !handler.current_is_wayland() ? : ""} + {!system_error && handler.current_is_wayland() ? : ""}
@@ -544,7 +545,7 @@ class FixWayland: Reactor.Component { return
Warning
Login screen using Wayland is not supported
-
Disable it
+
Fix it
; } @@ -554,6 +555,23 @@ class FixWayland: Reactor.Component { } } +class ModifyDefaultLogin: Reactor.Component { + function render() { + return
+
Warning
+
Current Wayland display server is not supported
+
Fix it(re-login required)
+
; + } + + 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);