windows kill flutter main window when --server close (#8077)
Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
		
							parent
							
								
									44d4e13fa7
								
							
						
					
					
						commit
						c2b7810c33
					
				| @ -565,7 +565,7 @@ fn core_main_invoke_new_connection(mut args: std::env::Args) -> Option<Vec<Strin | ||||
|     { | ||||
|         use winapi::um::winuser::WM_USER; | ||||
|         let res = crate::platform::send_message_to_hnwd( | ||||
|             "FLUTTER_RUNNER_WIN32_WINDOW", | ||||
|             &crate::platform::FLUTTER_RUNNER_WIN32_WINDOW_CLASS, | ||||
|             &crate::get_app_name(), | ||||
|             (WM_USER + 2) as _, // referred from unilinks desktop pub
 | ||||
|             uni_links.as_str(), | ||||
|  | ||||
| @ -356,6 +356,8 @@ async fn handle(data: Data, stream: &mut Connection) { | ||||
|                 crate::server::input_service::fix_key_down_timeout_at_exit(); | ||||
|                 if is_server() { | ||||
|                     let _ = privacy_mode::turn_off_privacy(0, Some(PrivacyModeState::OffByPeer)); | ||||
|                     #[cfg(all(windows, feature = "flutter"))] | ||||
|                     crate::platform::kill_flutter_main_window(); | ||||
|                 } | ||||
|                 std::process::exit(0); | ||||
|             } | ||||
|  | ||||
| @ -65,6 +65,8 @@ use windows_service::{ | ||||
| use winreg::enums::*; | ||||
| use winreg::RegKey; | ||||
| 
 | ||||
| pub const FLUTTER_RUNNER_WIN32_WINDOW_CLASS: &'static str = "FLUTTER_RUNNER_WIN32_WINDOW"; | ||||
| 
 | ||||
| pub fn get_focused_display(displays: Vec<DisplayInfo>) -> Option<usize> { | ||||
|     unsafe { | ||||
|         let hWnd = GetForegroundWindow(); | ||||
| @ -2419,3 +2421,33 @@ pub fn is_x64() -> bool { | ||||
|     } | ||||
|     unsafe { sys_info.u.s().wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 } | ||||
| } | ||||
| 
 | ||||
| #[cfg(feature = "flutter")] | ||||
| pub fn kill_flutter_main_window() { | ||||
|     // It is used to kill the hidden flutter main window process, it can also kill the install window process
 | ||||
|     log::info!("kill flutter main window"); | ||||
|     unsafe { | ||||
|         let window_name = wide_string(&crate::get_app_name()); | ||||
|         let class_name = wide_string(FLUTTER_RUNNER_WIN32_WINDOW_CLASS); | ||||
|         let hwnd = FindWindowW(class_name.as_ptr(), window_name.as_ptr()); | ||||
|         if hwnd.is_null() { | ||||
|             return; | ||||
|         } | ||||
|         let mut process_id: u32 = 0; | ||||
|         GetWindowThreadProcessId(hwnd, &mut process_id as *mut u32); | ||||
|         if process_id == 0 { | ||||
|             return; | ||||
|         } | ||||
|         let output = Command::new("taskkill") | ||||
|             .arg("/F") | ||||
|             .arg("/PID") | ||||
|             .arg(process_id.to_string()) | ||||
|             .output() | ||||
|             .expect("Failed to execute command"); | ||||
|         if output.status.success() { | ||||
|             log::info!("kill flutter main window success"); | ||||
|         } else { | ||||
|             log::error!("kill flutter main window failed"); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user