Skip to content

Commit

Permalink
fix(macos): use BTreeMap for windows map to prevent crash on idle (#8117
Browse files Browse the repository at this point in the history
)

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

* use arc [skip ci]

* add change file
  • Loading branch information
lucasfernog authored Feb 13, 2024
1 parent 510b622 commit 2421073
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/runtime-wry-fix-macos-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-runtime-wry": patch:bug
---

Fixes a crash on macOS when accessing the windows map.
7 changes: 4 additions & 3 deletions core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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"))]
Expand Down

0 comments on commit 2421073

Please sign in to comment.