File tree 4 files changed +20
-9
lines changed
4 files changed +20
-9
lines changed 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 {
65
65
}
66
66
67
67
#[ command( root = "crate" ) ]
68
- pub fn listen < R : Runtime > (
68
+ pub async fn listen < R : Runtime > (
69
69
webview : Webview < R > ,
70
70
event : EventName ,
71
71
target : EventTarget ,
@@ -75,7 +75,7 @@ pub fn listen<R: Runtime>(
75
75
}
76
76
77
77
#[ command( root = "crate" ) ]
78
- pub fn unlisten < R : Runtime > (
78
+ pub async fn unlisten < R : Runtime > (
79
79
webview : Webview < R > ,
80
80
event : EventName ,
81
81
event_id : EventId ,
@@ -84,7 +84,7 @@ pub fn unlisten<R: Runtime>(
84
84
}
85
85
86
86
#[ command( root = "crate" ) ]
87
- pub fn emit < R : Runtime > (
87
+ pub async fn emit < R : Runtime > (
88
88
app : AppHandle < R > ,
89
89
event : EventName ,
90
90
payload : Option < JsonValue > ,
@@ -93,7 +93,7 @@ pub fn emit<R: Runtime>(
93
93
}
94
94
95
95
#[ command( root = "crate" ) ]
96
- pub fn emit_to < R : Runtime > (
96
+ pub async fn emit_to < R : Runtime > (
97
97
app : AppHandle < R > ,
98
98
target : EventTarget ,
99
99
event : EventName ,
Original file line number Diff line number Diff line change @@ -532,8 +532,14 @@ impl<R: Runtime> AppManager<R> {
532
532
let emit_args = EmitArgs :: new ( event, payload) ?;
533
533
534
534
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) ?;
537
543
listeners. emit ( emit_args) ?;
538
544
539
545
Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -624,9 +624,9 @@ impl<R: Runtime> WebviewManager<R> {
624
624
625
625
pub fn eval_script_all < S : Into < String > > ( & self , script : S ) -> crate :: Result < ( ) > {
626
626
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 ( )
630
630
. try_for_each ( |webview| webview. eval ( & script) )
631
631
}
632
632
You can’t perform that action at this time.
0 commit comments