File tree Expand file tree Collapse file tree 6 files changed +40
-0
lines changed
Expand file tree Collapse file tree 6 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' tauri ' : ' minor:feat'
3+ ' tauri-runtime-wry ' : ' minor:feat'
4+ ---
5+
6+ feat: add ` Webview.reload ` and ` WebviewWindow.reload `
Original file line number Diff line number Diff line change @@ -1303,6 +1303,7 @@ pub enum WebviewMessage {
13031303 WebviewEvent ( WebviewEvent ) ,
13041304 SynthesizedWindowEvent ( SynthesizedWindowEvent ) ,
13051305 Navigate ( Url ) ,
1306+ Reload ,
13061307 Print ,
13071308 Close ,
13081309 Show ,
@@ -1466,6 +1467,17 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
14661467 )
14671468 }
14681469
1470+ fn reload ( & self ) -> Result < ( ) > {
1471+ send_user_message (
1472+ & self . context ,
1473+ Message :: Webview (
1474+ * self . window_id . lock ( ) . unwrap ( ) ,
1475+ self . webview_id ,
1476+ WebviewMessage :: Reload ,
1477+ ) ,
1478+ )
1479+ }
1480+
14691481 fn print ( & self ) -> Result < ( ) > {
14701482 send_user_message (
14711483 & self . context ,
@@ -3307,6 +3319,11 @@ fn handle_user_message<T: UserEvent>(
33073319 log:: error!( "failed to navigate to url {}: {}" , url, e) ;
33083320 }
33093321 }
3322+ WebviewMessage :: Reload => {
3323+ if let Err ( e) = webview. reload ( ) {
3324+ log:: error!( "failed to reload: {e}" ) ;
3325+ }
3326+ }
33103327 WebviewMessage :: Show => {
33113328 if let Err ( e) = webview. set_visible ( true ) {
33123329 log:: error!( "failed to change webview visibility: {e}" ) ;
Original file line number Diff line number Diff line change @@ -486,6 +486,9 @@ pub trait WebviewDispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + '
486486 /// Navigate to the given URL.
487487 fn navigate ( & self , url : Url ) -> Result < ( ) > ;
488488
489+ /// Reloads the current page.
490+ fn reload ( & self ) -> Result < ( ) > ;
491+
489492 /// Opens the dialog to prints the contents of the webview.
490493 fn print ( & self ) -> Result < ( ) > ;
491494
Original file line number Diff line number Diff line change @@ -558,6 +558,10 @@ impl<T: UserEvent> WebviewDispatch<T> for MockWebviewDispatcher {
558558 Ok ( ( ) )
559559 }
560560
561+ fn reload ( & self ) -> Result < ( ) > {
562+ Ok ( ( ) )
563+ }
564+
561565 fn print ( & self ) -> Result < ( ) > {
562566 Ok ( ( ) )
563567 }
Original file line number Diff line number Diff line change @@ -1303,6 +1303,11 @@ fn main() {
13031303 self . webview . dispatcher . navigate ( url) . map_err ( Into :: into)
13041304 }
13051305
1306+ /// Reloads the current page.
1307+ pub fn reload ( & self ) -> crate :: Result < ( ) > {
1308+ self . webview . dispatcher . reload ( ) . map_err ( Into :: into)
1309+ }
1310+
13061311 fn is_local_url ( & self , current_url : & Url ) -> bool {
13071312 let uses_https = current_url. scheme ( ) == "https" ;
13081313
Original file line number Diff line number Diff line change @@ -1898,6 +1898,11 @@ impl<R: Runtime> WebviewWindow<R> {
18981898 self . webview . navigate ( url)
18991899 }
19001900
1901+ /// Reloads the current page.
1902+ pub fn reload ( & self ) -> crate :: Result < ( ) > {
1903+ self . webview . reload ( )
1904+ }
1905+
19011906 /// Handles this window receiving an [`crate::webview::InvokeRequest`].
19021907 pub fn on_message (
19031908 self ,
You can’t perform that action at this time.
0 commit comments