Skip to content

Commit 579c7e2

Browse files
authored
refactor: move unsafe send sync impl up to Context (#14805)
* fix(tauri-runtime-wry): redraw Sync/non-Sync boundaries * fix(tauri-runtime-wry): redraw Send/non-Send boundaries * add change file * fix: clippy * address review
1 parent 2a88bf9 commit 579c7e2

2 files changed

Lines changed: 9 additions & 16 deletions

File tree

.changes/fix-send-sync.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-runtime-wry": minor:breaking
3+
---
4+
5+
`WindowsStore` and `DispatcherMainThreadContext` are no longer `Send` and `Sync`, and unsafe impl has been moved to `Context` directly.

crates/tauri-runtime-wry/src/lib.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ pub struct Context<T: UserEvent> {
263263
webview_runtime_installed: bool,
264264
}
265265

266+
unsafe impl<T: UserEvent> Send for Context<T> {}
267+
unsafe impl<T: UserEvent> Sync for Context<T> {}
268+
266269
impl<T: UserEvent> Context<T> {
267270
pub fn run_threaded<R, F>(&self, f: F) -> R
268271
where
@@ -432,14 +435,6 @@ pub enum ActiveTracingSpan {
432435
#[derive(Debug)]
433436
pub struct WindowsStore(pub RefCell<BTreeMap<WindowId, WindowWrapper>>);
434437

435-
// SAFETY: we ensure this type is only used on the main thread.
436-
#[allow(clippy::non_send_fields_in_send_ty)]
437-
unsafe impl Send for WindowsStore {}
438-
439-
// SAFETY: we ensure this type is only used on the main thread.
440-
#[allow(clippy::non_send_fields_in_send_ty)]
441-
unsafe impl Sync for WindowsStore {}
442-
443438
#[derive(Debug, Clone)]
444439
pub struct DispatcherMainThreadContext<T: UserEvent> {
445440
pub window_target: EventLoopWindowTarget<Message<T>>,
@@ -450,14 +445,6 @@ pub struct DispatcherMainThreadContext<T: UserEvent> {
450445
pub active_tracing_spans: ActiveTraceSpanStore,
451446
}
452447

453-
// SAFETY: we ensure this type is only used on the main thread.
454-
#[allow(clippy::non_send_fields_in_send_ty)]
455-
unsafe impl<T: UserEvent> Send for DispatcherMainThreadContext<T> {}
456-
457-
// SAFETY: we ensure this type is only used on the main thread.
458-
#[allow(clippy::non_send_fields_in_send_ty)]
459-
unsafe impl<T: UserEvent> Sync for DispatcherMainThreadContext<T> {}
460-
461448
impl<T: UserEvent> fmt::Debug for Context<T> {
462449
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
463450
f.debug_struct("Context")
@@ -2843,6 +2830,7 @@ impl<T: UserEvent> Wry<T> {
28432830
let main_thread_id = current_thread().id();
28442831
let web_context = WebContextStore::default();
28452832

2833+
#[allow(clippy::arc_with_non_send_sync)]
28462834
let windows = Arc::new(WindowsStore(RefCell::new(BTreeMap::default())));
28472835
let window_id_map = WindowIdStore::default();
28482836

0 commit comments

Comments
 (0)