filter foreground window to avoid frequent prompts
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
		
							parent
							
								
									e1a9cfcf7f
								
							
						
					
					
						commit
						cf3ddb2a18
					
				| @ -11,6 +11,7 @@ use std::io::prelude::*; | |||||||
| use std::{ | use std::{ | ||||||
|     ffi::OsString, |     ffi::OsString, | ||||||
|     fs, io, mem, |     fs, io, mem, | ||||||
|  |     os::windows::process::CommandExt, | ||||||
|     path::PathBuf, |     path::PathBuf, | ||||||
|     sync::{Arc, Mutex}, |     sync::{Arc, Mutex}, | ||||||
|     time::{Duration, Instant}, |     time::{Duration, Instant}, | ||||||
| @ -1644,6 +1645,29 @@ pub fn is_elevated(process_id: Option<DWORD>) -> ResultType<bool> { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | #[inline] | ||||||
|  | fn filter_foreground_window(process_id: DWORD) -> ResultType<bool> { | ||||||
|  |     if let Ok(output) = std::process::Command::new("tasklist") | ||||||
|  |         .args(vec![ | ||||||
|  |             "/SVC", | ||||||
|  |             "/NH", | ||||||
|  |             "/FI", | ||||||
|  |             &format!("PID eq {}", process_id), | ||||||
|  |         ]) | ||||||
|  |         .creation_flags(CREATE_NO_WINDOW) | ||||||
|  |         .output() | ||||||
|  |     { | ||||||
|  |         let s = String::from_utf8_lossy(&output.stdout) | ||||||
|  |             .to_string() | ||||||
|  |             .to_lowercase(); | ||||||
|  |         Ok(["Taskmgr", "mmc", "regedit"] | ||||||
|  |             .iter() | ||||||
|  |             .any(|name| s.contains(&name.to_string().to_lowercase()))) | ||||||
|  |     } else { | ||||||
|  |         bail!("run tasklist failed"); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| pub fn is_foreground_window_elevated() -> ResultType<bool> { | pub fn is_foreground_window_elevated() -> ResultType<bool> { | ||||||
|     unsafe { |     unsafe { | ||||||
|         let mut process_id: DWORD = 0; |         let mut process_id: DWORD = 0; | ||||||
| @ -1651,7 +1675,12 @@ pub fn is_foreground_window_elevated() -> ResultType<bool> { | |||||||
|         if process_id == 0 { |         if process_id == 0 { | ||||||
|             bail!("Failed to get processId, errno {}", GetLastError()) |             bail!("Failed to get processId, errno {}", GetLastError()) | ||||||
|         } |         } | ||||||
|         is_elevated(Some(process_id)) |         let elevated = is_elevated(Some(process_id))?; | ||||||
|  |         if elevated { | ||||||
|  |             filter_foreground_window(process_id) | ||||||
|  |         } else { | ||||||
|  |             Ok(false) | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -954,10 +954,7 @@ pub fn get_current_display() -> ResultType<(usize, usize, Display)> { | |||||||
| fn start_uac_elevation_check() { | fn start_uac_elevation_check() { | ||||||
|     static START: Once = Once::new(); |     static START: Once = Once::new(); | ||||||
|     START.call_once(|| { |     START.call_once(|| { | ||||||
|         if !crate::platform::is_installed() |         if !crate::platform::is_installed() && !crate::platform::is_root() { | ||||||
|             && !crate::platform::is_root() |  | ||||||
|             && !crate::portable_service::client::running() |  | ||||||
|         { |  | ||||||
|             std::thread::spawn(|| loop { |             std::thread::spawn(|| loop { | ||||||
|                 std::thread::sleep(std::time::Duration::from_secs(1)); |                 std::thread::sleep(std::time::Duration::from_secs(1)); | ||||||
|                 if let Ok(uac) = crate::ui::win_privacy::is_process_consent_running() { |                 if let Ok(uac) = crate::ui::win_privacy::is_process_consent_running() { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user