portable service: fix clean shared memory, at_exit not called at flutter

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2022-11-18 17:07:03 +08:00
parent 0199770454
commit f986236a61
3 changed files with 15 additions and 3 deletions

View File

@ -90,6 +90,9 @@ class _ConnectionPageState extends State<ConnectionPage>
Get.forceAppUpdate(); Get.forceAppUpdate();
} }
isWindowMinisized = false; isWindowMinisized = false;
} else if (eventName == 'close') {
// called more then one time
bind.mainOnMainWindowClose();
} }
} }

View File

@ -619,7 +619,11 @@ pub fn main_set_peer_option_sync(id: String, key: String, value: String) -> Sync
} }
pub fn main_set_peer_alias(id: String, alias: String) { pub fn main_set_peer_alias(id: String, alias: String) {
main_broadcast_message(&HashMap::from([("name", "alias"), ("id", &id), ("alias", &alias)])); main_broadcast_message(&HashMap::from([
("name", "alias"),
("id", &id),
("alias", &alias),
]));
set_peer_option(id, "alias".to_owned(), alias) set_peer_option(id, "alias".to_owned(), alias)
} }
@ -1173,6 +1177,11 @@ pub fn main_account_auth_result() -> String {
account_auth_result() account_auth_result()
} }
pub fn main_on_main_window_close() {
#[cfg(windows)]
crate::portable_service::client::drop_portable_service_shared_memory();
}
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
pub mod server_side { pub mod server_side {
use jni::{ use jni::{

View File

@ -487,7 +487,7 @@ pub mod client {
crate::portable_service::SHMEM_NAME, crate::portable_service::SHMEM_NAME,
shmem_size, shmem_size,
)?); )?);
shutdown_hooks::add_shutdown_hook(drop_shmem); shutdown_hooks::add_shutdown_hook(drop_portable_service_shared_memory);
} }
let mut option = SHMEM.lock().unwrap(); let mut option = SHMEM.lock().unwrap();
let shmem = option.as_mut().unwrap(); let shmem = option.as_mut().unwrap();
@ -507,7 +507,7 @@ pub mod client {
Ok(()) Ok(())
} }
extern "C" fn drop_shmem() { pub extern "C" fn drop_portable_service_shared_memory() {
log::info!("drop shared memory"); log::info!("drop shared memory");
*SHMEM.lock().unwrap() = None; *SHMEM.lock().unwrap() = None;
} }