add function
relogin required if current is wayland
This commit is contained in:
		
							parent
							
								
									d369955790
								
							
						
					
					
						commit
						1009eabdfe
					
				| @ -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()) }); | ||||
| @ -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") { | ||||
|  | ||||
							
								
								
									
										17
									
								
								src/ui.rs
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								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); | ||||
|  | ||||
| @ -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> | ||||
| @ -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>; | ||||
|     } | ||||
| 
 | ||||
| @ -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); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user