@@ -35,6 +35,8 @@ pub(crate) struct WinitApp {
3535 last_ui_update : Instant ,
3636 avg_frame_time : f32 ,
3737 start_render_sender : SyncSender < ( ) > ,
38+ web_communication_initialized : bool ,
39+ web_communication_startup_buffer : Vec < Vec < u8 > > ,
3840}
3941
4042impl WinitApp {
@@ -61,6 +63,8 @@ impl WinitApp {
6163 last_ui_update : Instant :: now ( ) ,
6264 avg_frame_time : 0. ,
6365 start_render_sender,
66+ web_communication_initialized : false ,
67+ web_communication_startup_buffer : Vec :: new ( ) ,
6468 }
6569 }
6670
@@ -71,7 +75,7 @@ impl WinitApp {
7175 tracing:: error!( "Failed to serialize frontend messages" ) ;
7276 return ;
7377 } ;
74- self . cef_context . send_web_message ( bytes) ;
78+ self . send_or_queue_web_message ( bytes) ;
7579 }
7680 DesktopFrontendMessage :: OpenFileDialog { title, filters, context } => {
7781 let event_loop_proxy = self . event_loop_proxy . clone ( ) ;
@@ -161,6 +165,14 @@ impl WinitApp {
161165 let responses = self . desktop_wrapper . dispatch ( message) ;
162166 self . handle_desktop_frontend_messages ( responses) ;
163167 }
168+
169+ fn send_or_queue_web_message ( & mut self , message : Vec < u8 > ) {
170+ if self . web_communication_initialized {
171+ self . cef_context . send_web_message ( message) ;
172+ } else {
173+ self . web_communication_startup_buffer . push ( message) ;
174+ }
175+ }
164176}
165177
166178impl ApplicationHandler < CustomEvent > for WinitApp {
@@ -215,6 +227,12 @@ impl ApplicationHandler<CustomEvent> for WinitApp {
215227
216228 fn user_event ( & mut self , _: & ActiveEventLoop , event : CustomEvent ) {
217229 match event {
230+ CustomEvent :: WebCommunicationInitialized => {
231+ self . web_communication_initialized = true ;
232+ for message in self . web_communication_startup_buffer . drain ( ..) {
233+ self . cef_context . send_web_message ( message) ;
234+ }
235+ }
218236 CustomEvent :: DesktopWrapperMessage ( message) => self . dispatch_desktop_wrapper_message ( message) ,
219237 CustomEvent :: NodeGraphExecutionResult ( result) => match result {
220238 NodeGraphExecutionResult :: HasRun ( texture) => {
0 commit comments