quit cm process if ipc connection to ipc server closed (#9292)
Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
		
							parent
							
								
									c8cd564e69
								
							
						
					
					
						commit
						993862c103
					
				@ -84,6 +84,7 @@ lazy_static::lazy_static! {
 | 
				
			|||||||
    // Is server logic running. The server code can invoked to run by the main process if --server is not running.
 | 
					    // Is server logic running. The server code can invoked to run by the main process if --server is not running.
 | 
				
			||||||
    static ref SERVER_RUNNING: Arc<RwLock<bool>> = Default::default();
 | 
					    static ref SERVER_RUNNING: Arc<RwLock<bool>> = Default::default();
 | 
				
			||||||
    static ref IS_MAIN: bool = std::env::args().nth(1).map_or(true, |arg| !arg.starts_with("--"));
 | 
					    static ref IS_MAIN: bool = std::env::args().nth(1).map_or(true, |arg| !arg.starts_with("--"));
 | 
				
			||||||
 | 
					    static ref IS_CM: bool = std::env::args().nth(1) == Some("--cm".to_owned()) || std::env::args().nth(1) == Some("--cm-no-ui".to_owned());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct SimpleCallOnReturn {
 | 
					pub struct SimpleCallOnReturn {
 | 
				
			||||||
@ -137,6 +138,11 @@ pub fn is_main() -> bool {
 | 
				
			|||||||
    *IS_MAIN
 | 
					    *IS_MAIN
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[inline]
 | 
				
			||||||
 | 
					pub fn is_cm() -> bool {
 | 
				
			||||||
 | 
					    *IS_CM
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Is server logic running.
 | 
					// Is server logic running.
 | 
				
			||||||
#[inline]
 | 
					#[inline]
 | 
				
			||||||
pub fn is_server_running() -> bool {
 | 
					pub fn is_server_running() -> bool {
 | 
				
			||||||
 | 
				
			|||||||
@ -477,7 +477,10 @@ pub fn core_main() -> Option<Vec<String>> {
 | 
				
			|||||||
        } else if args[0] == "--cm-no-ui" {
 | 
					        } else if args[0] == "--cm-no-ui" {
 | 
				
			||||||
            #[cfg(feature = "flutter")]
 | 
					            #[cfg(feature = "flutter")]
 | 
				
			||||||
            #[cfg(not(any(target_os = "android", target_os = "ios", target_os = "windows")))]
 | 
					            #[cfg(not(any(target_os = "android", target_os = "ios", target_os = "windows")))]
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                crate::ui_interface::start_option_status_sync();
 | 
				
			||||||
                crate::flutter::connection_manager::start_cm_no_ui();
 | 
					                crate::flutter::connection_manager::start_cm_no_ui();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            return None;
 | 
					            return None;
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            #[cfg(all(feature = "flutter", feature = "plugin_framework"))]
 | 
					            #[cfg(all(feature = "flutter", feature = "plugin_framework"))]
 | 
				
			||||||
 | 
				
			|||||||
@ -625,7 +625,6 @@ pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
 | 
				
			|||||||
        OPTION_ENABLE_FILE_TRANSFER,
 | 
					        OPTION_ENABLE_FILE_TRANSFER,
 | 
				
			||||||
        &Config::get_option(OPTION_ENABLE_FILE_TRANSFER),
 | 
					        &Config::get_option(OPTION_ENABLE_FILE_TRANSFER),
 | 
				
			||||||
    ));
 | 
					    ));
 | 
				
			||||||
 | 
					 | 
				
			||||||
    match ipc::new_listener("_cm").await {
 | 
					    match ipc::new_listener("_cm").await {
 | 
				
			||||||
        Ok(mut incoming) => {
 | 
					        Ok(mut incoming) => {
 | 
				
			||||||
            while let Some(result) = incoming.next().await {
 | 
					            while let Some(result) = incoming.next().await {
 | 
				
			||||||
@ -647,7 +646,7 @@ pub async fn start_ipc<T: InvokeUiCM>(cm: ConnectionManager<T>) {
 | 
				
			|||||||
            log::error!("Failed to start cm ipc server: {}", err);
 | 
					            log::error!("Failed to start cm ipc server: {}", err);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    crate::platform::quit_gui();
 | 
					    quit_cm();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(target_os = "android")]
 | 
					#[cfg(target_os = "android")]
 | 
				
			||||||
@ -1042,3 +1041,11 @@ pub fn close_voice_call(id: i32) {
 | 
				
			|||||||
        allow_err!(client.tx.send(Data::CloseVoiceCall("".to_owned())));
 | 
					        allow_err!(client.tx.send(Data::CloseVoiceCall("".to_owned())));
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[cfg(not(any(target_os = "android", target_os = "ios")))]
 | 
				
			||||||
 | 
					pub fn quit_cm() {
 | 
				
			||||||
 | 
					    // in case of std::process::exit not work
 | 
				
			||||||
 | 
					    log::info!("quit cm");
 | 
				
			||||||
 | 
					    CLIENTS.write().unwrap().clear();
 | 
				
			||||||
 | 
					    crate::platform::quit_gui();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1138,6 +1138,7 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
 | 
				
			|||||||
        )
 | 
					        )
 | 
				
			||||||
    ))]
 | 
					    ))]
 | 
				
			||||||
    let mut enable_file_transfer = "".to_owned();
 | 
					    let mut enable_file_transfer = "".to_owned();
 | 
				
			||||||
 | 
					    let is_cm = crate::common::is_cm();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    loop {
 | 
					    loop {
 | 
				
			||||||
        if let Ok(mut c) = ipc::connect(1000, "").await {
 | 
					        if let Ok(mut c) = ipc::connect(1000, "").await {
 | 
				
			||||||
@ -1148,6 +1149,9 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
 | 
				
			|||||||
                        match res {
 | 
					                        match res {
 | 
				
			||||||
                            Err(err) => {
 | 
					                            Err(err) => {
 | 
				
			||||||
                                log::error!("ipc connection closed: {}", err);
 | 
					                                log::error!("ipc connection closed: {}", err);
 | 
				
			||||||
 | 
					                                if is_cm {
 | 
				
			||||||
 | 
					                                    crate::ui_cm_interface::quit_cm();
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
                                break;
 | 
					                                break;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            #[cfg(not(any(target_os = "android", target_os = "ios")))]
 | 
					                            #[cfg(not(any(target_os = "android", target_os = "ios")))]
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user