@@ -3,11 +3,12 @@ use blitz_shell::{BlitzApplication, View};
33use blitz_traits:: { navigation:: NavigationProvider , net:: NetProvider } ;
44use dioxus_core:: { provide_context, ScopeId } ;
55use dioxus_history:: { History , MemoryHistory } ;
6+ use futures_channel:: oneshot;
67use std:: any:: Any ;
78use std:: rc:: Rc ;
89use std:: sync:: Arc ;
9- use tokio:: sync:: oneshot;
1010use winit:: application:: ApplicationHandler ;
11+
1112use winit:: event:: { StartCause , WindowEvent } ;
1213use winit:: event_loop:: { ActiveEventLoop , EventLoopProxy } ;
1314use winit:: window:: Window ;
@@ -44,20 +45,29 @@ impl<T: ?Sized> OpaquePtr<T> {
4445}
4546
4647#[ doc( hidden) ]
47- pub struct UnsafeBox < T : ?Sized > ( Box < T > ) ;
48+ pub struct UnsafeBox < T : ?Sized > {
49+ value : Box < T > ,
50+ owner : std:: thread:: ThreadId ,
51+ }
4852
49- // Safety: this wrapper exists solely to satisfy the `Send + Sync` bound imposed by the embedder
50- // event channel. The payloads are only ever created and consumed on the event loop thread.
5153unsafe impl < T : ?Sized > Send for UnsafeBox < T > { }
5254unsafe impl < T : ?Sized > Sync for UnsafeBox < T > { }
5355
5456impl < T : ?Sized > UnsafeBox < T > {
5557 pub fn new ( value : Box < T > ) -> Self {
56- Self ( value)
58+ Self {
59+ value,
60+ owner : std:: thread:: current ( ) . id ( ) ,
61+ }
5762 }
5863
5964 pub fn into_inner ( self ) -> Box < T > {
60- self . 0
65+ assert_eq ! (
66+ self . owner,
67+ std:: thread:: current( ) . id( ) ,
68+ "UnsafeBox accessed from a different thread" ,
69+ ) ;
70+ self . value
6171 }
6272}
6373
@@ -142,6 +152,14 @@ impl DioxusNativeProvider {
142152 receiver
143153 }
144154
155+ pub fn new_window (
156+ & self ,
157+ vdom : dioxus_core:: VirtualDom ,
158+ attributes : winit:: window:: WindowAttributes ,
159+ ) -> oneshot:: Receiver < ( WindowId , Arc < Window > ) > {
160+ self . create_document_window ( vdom, attributes)
161+ }
162+
145163 pub fn get_window ( & self , window_id : WindowId ) -> oneshot:: Receiver < Option < Arc < Window > > > {
146164 let ( sender, receiver) = oneshot:: channel ( ) ;
147165 let reply = UnsafeBox :: new ( Box :: new ( sender) ) ;
@@ -207,7 +225,7 @@ impl DioxusNativeApplication {
207225 provide_context ( shared) ;
208226 } ) ;
209227
210- let shell_provider = doc. as_ref ( ) . shell_provider . clone ( ) ;
228+ let shell_provider = doc. inner . borrow ( ) . shell_provider . clone ( ) ;
211229 doc. vdom
212230 . in_scope ( ScopeId :: ROOT , move || provide_context ( shell_provider) ) ;
213231
@@ -287,7 +305,7 @@ impl DioxusNativeApplication {
287305 // Reload changed assets
288306 for asset_path in & hotreload_message. assets {
289307 if let Some ( url) = asset_path. to_str ( ) {
290- doc. reload_resource_by_href ( url) ;
308+ doc. inner . borrow_mut ( ) . reload_resource_by_href ( url) ;
291309 }
292310 }
293311
0 commit comments