瀏覽代碼

fix(macos): use BTreeMap for windows map to prevent crash on idle (#8117)

* fix(macos): use BTreeMap for windows map to prevent crash on idle

* use arc [skip ci]

* add change file
Lucas Fernandes Nogueira 1 年之前
父節點
當前提交
2421073576
共有 2 個文件被更改,包括 9 次插入3 次删除
  1. 5 0
      .changes/runtime-wry-fix-macos-crash.md
  2. 4 3
      core/tauri-runtime-wry/src/lib.rs

+ 5 - 0
.changes/runtime-wry-fix-macos-crash.md

@@ -0,0 +1,5 @@
+---
+"tauri-runtime-wry": patch:bug
+---
+
+Fixes a crash on macOS when accessing the windows map.

+ 4 - 3
core/tauri-runtime-wry/src/lib.rs

@@ -5,7 +5,7 @@
 //! The [`wry`] Tauri [`Runtime`].
 
 use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle};
-use std::rc::Rc;
+use std::{collections::BTreeMap, rc::Rc};
 use tauri_runtime::{
   http::{header::CONTENT_TYPE, Request as HttpRequest, RequestParts, Response as HttpResponse},
   menu::{AboutMetadata, CustomMenuItem, Menu, MenuEntry, MenuHash, MenuId, MenuItem, MenuUpdate},
@@ -269,7 +269,7 @@ pub enum ActiveTracingSpan {
 }
 
 #[derive(Debug)]
-pub struct WindowsStore(RefCell<HashMap<WebviewId, WindowWrapper>>);
+pub struct WindowsStore(RefCell<BTreeMap<WebviewId, WindowWrapper>>);
 
 // SAFETY: we ensure this type is only used on the main thread.
 #[allow(clippy::non_send_fields_in_send_ty)]
@@ -1985,7 +1985,8 @@ impl<T: UserEvent> Wry<T> {
     #[cfg(all(desktop, feature = "global-shortcut"))]
     let global_shortcut_manager = Rc::new(Mutex::new(WryShortcutManager::new(&event_loop)));
 
-    let windows = Arc::new(WindowsStore(RefCell::new(HashMap::default())));
+    let windows = Arc::new(WindowsStore(RefCell::new(BTreeMap::default())));
+
     let webview_id_map = WebviewIdStore::default();
 
     #[cfg(all(desktop, feature = "system-tray"))]