refactor: update AppHandle usage to use Arc<AppHandle> for improved memory management (#4491)

* refactor: update AppHandle usage to use Arc<AppHandle> for improved memory management

* fix: clippy ci

* fix: ensure default_latency_test is safely accessed with non-null assertion
This commit is contained in:
Tunglies
2025-08-23 00:20:58 +08:00
committed by GitHub
parent c416bd5755
commit 0d070fb934
13 changed files with 140 additions and 96 deletions

View File

@@ -255,7 +255,7 @@ impl NotificationSystem {
#[derive(Debug, Clone)]
pub struct Handle {
pub app_handle: Arc<RwLock<Option<AppHandle>>>,
pub app_handle: Arc<RwLock<Option<Arc<AppHandle>>>>,
pub is_exiting: Arc<RwLock<bool>>,
startup_errors: Arc<RwLock<Vec<ErrorMessage>>>,
startup_completed: Arc<RwLock<bool>>,
@@ -282,10 +282,10 @@ impl Handle {
Self::default()
}
pub fn init(&self, app_handle: &AppHandle) {
pub fn init(&self, app_handle: Arc<AppHandle>) {
{
let mut handle = self.app_handle.write();
*handle = Some(app_handle.clone());
*handle = Some(Arc::clone(&app_handle));
}
let mut system_opt = self.notification_system.write();
@@ -294,8 +294,9 @@ impl Handle {
}
}
pub fn app_handle(&self) -> Option<AppHandle> {
self.app_handle.read().clone()
/// 获取 AppHandle
pub fn app_handle(&self) -> Option<Arc<AppHandle>> {
self.app_handle.read().as_ref().map(Arc::clone)
}
pub fn get_window(&self) -> Option<WebviewWindow> {