@@ -395,7 +395,7 @@ impl<R: Runtime> WindowManager<R> {
395395 & self ,
396396 mut pending : PendingWindow < R > ,
397397 label : & str ,
398- pending_labels : & [ String ] ,
398+ window_labels : & [ String ] ,
399399 app_handle : AppHandle < R > ,
400400 ) -> crate :: Result < PendingWindow < R > > {
401401 let is_init_global = self . inner . config . build . with_global_tauri ;
@@ -422,6 +422,11 @@ impl<R: Runtime> WindowManager<R> {
422422
423423 let mut webview_attributes = pending. webview_attributes ;
424424
425+ let mut window_labels = window_labels. to_vec ( ) ;
426+ let l = label. to_string ( ) ;
427+ if !window_labels. contains ( & l) {
428+ window_labels. push ( l) ;
429+ }
425430 webview_attributes = webview_attributes
426431 . initialization_script ( & self . inner . invoke_initialization_script )
427432 . initialization_script ( & format ! (
@@ -433,7 +438,7 @@ impl<R: Runtime> WindowManager<R> {
433438 }}
434439 }})
435440 "# ,
436- window_labels_array = serde_json:: to_string( pending_labels ) ?,
441+ window_labels_array = serde_json:: to_string( & window_labels ) ?,
437442 current_window_label = serde_json:: to_string( & label) ?,
438443 ) )
439444 . initialization_script ( & self . initialization_script ( & ipc_init, & pattern_init, & plugin_init, is_init_global) ?)
@@ -809,6 +814,9 @@ impl<R: Runtime> WindowManager<R> {
809814 ipc_script : & ' a str ,
810815 #[ raw]
811816 bundle_script : & ' a str ,
817+ // A function to immediately listen to an event.
818+ #[ raw]
819+ listen_function : & ' a str ,
812820 #[ raw]
813821 core_script : & ' a str ,
814822 #[ raw]
@@ -836,6 +844,15 @@ impl<R: Runtime> WindowManager<R> {
836844 pattern_script,
837845 ipc_script,
838846 bundle_script,
847+ listen_function : & format ! (
848+ "function listen(eventName, cb) {{ {} }}" ,
849+ crate :: event:: listen_js(
850+ self . event_listeners_object_name( ) ,
851+ "eventName" . into( ) ,
852+ 0 ,
853+ "window['_' + window.__TAURI__.transformCallback(cb) ]" . into( )
854+ )
855+ ) ,
839856 core_script : include_str ! ( "../scripts/core.js" ) ,
840857 event_initialization_script : & self . event_initialization_script ( ) ,
841858 plugin_initialization_script,
@@ -930,7 +947,7 @@ impl<R: Runtime> WindowManager<R> {
930947 & self ,
931948 app_handle : AppHandle < R > ,
932949 mut pending : PendingWindow < R > ,
933- pending_labels : & [ String ] ,
950+ window_labels : & [ String ] ,
934951 ) -> crate :: Result < PendingWindow < R > > {
935952 if self . windows_lock ( ) . contains_key ( & pending. label ) {
936953 return Err ( crate :: Error :: WindowLabelAlreadyExists ( pending. label ) ) ;
@@ -982,7 +999,7 @@ impl<R: Runtime> WindowManager<R> {
982999
9831000 if is_local {
9841001 let label = pending. label . clone ( ) ;
985- pending = self . prepare_pending_window ( pending, & label, pending_labels , app_handle. clone ( ) ) ?;
1002+ pending = self . prepare_pending_window ( pending, & label, window_labels , app_handle. clone ( ) ) ?;
9861003 pending. ipc_handler = Some ( self . prepare_ipc_handler ( app_handle. clone ( ) ) ) ;
9871004 }
9881005
0 commit comments