prevent frequent loginctl calls
Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com>
This commit is contained in:
		
							parent
							
								
									58bbc33aa6
								
							
						
					
					
						commit
						0931341a7f
					
				@ -183,6 +183,15 @@ pub fn is_active(sid: &str) -> bool {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn is_active_and_seat0(sid: &str) -> bool {
 | 
				
			||||||
 | 
					    if let Ok(output) = run_loginctl(Some(vec!["show-session", sid])) {
 | 
				
			||||||
 | 
					        String::from_utf8_lossy(&output.stdout).contains("State=active")
 | 
				
			||||||
 | 
					            && String::from_utf8_lossy(&output.stdout).contains("Seat=seat0")
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        false
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn run_cmds(cmds: &str) -> ResultType<String> {
 | 
					pub fn run_cmds(cmds: &str) -> ResultType<String> {
 | 
				
			||||||
    let output = std::process::Command::new("sh")
 | 
					    let output = std::process::Command::new("sh")
 | 
				
			||||||
        .args(vec!["-c", cmds])
 | 
					        .args(vec!["-c", cmds])
 | 
				
			||||||
 | 
				
			|||||||
@ -1073,13 +1073,11 @@ mod desktop {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        pub fn refresh(&mut self) {
 | 
					        pub fn refresh(&mut self) {
 | 
				
			||||||
            let seat0_values = get_values_of_seat0(&[0, 1, 2]);
 | 
					            if !self.sid.is_empty() && is_active_and_seat0(&self.sid) {
 | 
				
			||||||
            if !self.sid.is_empty() && is_active(&self.sid) {
 | 
					 | 
				
			||||||
                if self.sid == seat0_values[0] {
 | 
					 | 
				
			||||||
                     return;
 | 
					                     return;
 | 
				
			||||||
                 }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            let seat0_values = get_values_of_seat0(&[0, 1, 2]);
 | 
				
			||||||
            if seat0_values[0].is_empty() {
 | 
					            if seat0_values[0].is_empty() {
 | 
				
			||||||
                *self = Self::default();
 | 
					                *self = Self::default();
 | 
				
			||||||
                self.is_rustdesk_subprocess = false;
 | 
					                self.is_rustdesk_subprocess = false;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user