File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " tauri " : patch:enhance
3+ ---
4+
5+ Mark the event commands as async so they do not block the main thread.
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ impl<'de> Deserialize<'de> for WebviewLabel {
6565}
6666
6767#[ command( root = "crate" ) ]
68- pub fn listen < R : Runtime > (
68+ pub async fn listen < R : Runtime > (
6969 webview : Webview < R > ,
7070 event : EventName ,
7171 target : EventTarget ,
@@ -75,7 +75,7 @@ pub fn listen<R: Runtime>(
7575}
7676
7777#[ command( root = "crate" ) ]
78- pub fn unlisten < R : Runtime > (
78+ pub async fn unlisten < R : Runtime > (
7979 webview : Webview < R > ,
8080 event : EventName ,
8181 event_id : EventId ,
@@ -84,7 +84,7 @@ pub fn unlisten<R: Runtime>(
8484}
8585
8686#[ command( root = "crate" ) ]
87- pub fn emit < R : Runtime > (
87+ pub async fn emit < R : Runtime > (
8888 app : AppHandle < R > ,
8989 event : EventName ,
9090 payload : Option < JsonValue > ,
@@ -93,7 +93,7 @@ pub fn emit<R: Runtime>(
9393}
9494
9595#[ command( root = "crate" ) ]
96- pub fn emit_to < R : Runtime > (
96+ pub async fn emit_to < R : Runtime > (
9797 app : AppHandle < R > ,
9898 target : EventTarget ,
9999 event : EventName ,
Original file line number Diff line number Diff line change @@ -532,8 +532,14 @@ impl<R: Runtime> AppManager<R> {
532532 let emit_args = EmitArgs :: new ( event, payload) ?;
533533
534534 let listeners = self . listeners ( ) ;
535-
536- listeners. emit_js ( self . webview . webviews_lock ( ) . values ( ) , event, & emit_args) ?;
535+ let webviews = self
536+ . webview
537+ . webviews_lock ( )
538+ . values ( )
539+ . cloned ( )
540+ . collect :: < Vec < _ > > ( ) ;
541+
542+ listeners. emit_js ( webviews. iter ( ) , event, & emit_args) ?;
537543 listeners. emit ( emit_args) ?;
538544
539545 Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -624,9 +624,9 @@ impl<R: Runtime> WebviewManager<R> {
624624
625625 pub fn eval_script_all < S : Into < String > > ( & self , script : S ) -> crate :: Result < ( ) > {
626626 let script = script. into ( ) ;
627- self
628- . webviews_lock ( )
629- . values ( )
627+ let webviews = self . webviews_lock ( ) . values ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
628+ webviews
629+ . iter ( )
630630 . try_for_each ( |webview| webview. eval ( & script) )
631631 }
632632
You can’t perform that action at this time.
0 commit comments