diff --git a/.changes/core-navigate-method.md b/.changes/core-navigate-method.md new file mode 100644 index 000000000000..c91eabee6c77 --- /dev/null +++ b/.changes/core-navigate-method.md @@ -0,0 +1,5 @@ +--- +"tauri": minor +--- + +Added `Window::navigate`. diff --git a/.changes/runtime-navigate-method.md b/.changes/runtime-navigate-method.md new file mode 100644 index 000000000000..dfc70d4ee208 --- /dev/null +++ b/.changes/runtime-navigate-method.md @@ -0,0 +1,5 @@ +--- +"tauri-runtime": minor +--- + +Added `navigate` function to `Dispatch` trait. diff --git a/.changes/wry-navigate-method.md b/.changes/wry-navigate-method.md new file mode 100644 index 000000000000..842a7c28f13b --- /dev/null +++ b/.changes/wry-navigate-method.md @@ -0,0 +1,5 @@ +--- +"tauri-runtime-wry": minor +--- + +Implement navigate method diff --git a/core/tauri-runtime-wry/src/lib.rs b/core/tauri-runtime-wry/src/lib.rs index dfb672577503..ccad3b472495 100644 --- a/core/tauri-runtime-wry/src/lib.rs +++ b/core/tauri-runtime-wry/src/lib.rs @@ -1101,6 +1101,7 @@ pub enum WindowMessage { SetMinimizable(bool), SetClosable(bool), SetTitle(String), + Navigate(Url), Maximize, Unmaximize, Minimize, @@ -1449,6 +1450,13 @@ impl Dispatch for WryDispatcher { ) } + fn navigate(&self, url: Url) -> Result<()> { + send_user_message( + &self.context, + Message::Window(self.window_id, WindowMessage::Navigate(url)), + ) + } + fn maximize(&self) -> Result<()> { send_user_message( &self.context, @@ -2422,6 +2430,11 @@ fn handle_user_message( WindowMessage::SetMinimizable(minimizable) => window.set_minimizable(minimizable), WindowMessage::SetClosable(closable) => window.set_closable(closable), WindowMessage::SetTitle(title) => window.set_title(&title), + WindowMessage::Navigate(url) => { + if let WindowHandle::Webview { inner: w, .. } = &window { + w.load_url(url.as_str()) + } + } WindowMessage::Maximize => window.set_maximized(true), WindowMessage::Unmaximize => window.set_maximized(false), WindowMessage::Minimize => window.set_minimized(true), diff --git a/core/tauri-runtime/src/lib.rs b/core/tauri-runtime/src/lib.rs index 5cd05cac3047..20b5a11d5e4b 100644 --- a/core/tauri-runtime/src/lib.rs +++ b/core/tauri-runtime/src/lib.rs @@ -670,6 +670,9 @@ pub trait Dispatch: Debug + Clone + Send + Sync + Sized + 'static /// Updates the window title. fn set_title>(&self, title: S) -> Result<()>; + /// Naviagte to the given URL + fn navigate(&self, url: Url) -> Result<()>; + /// Maximizes the window. fn maximize(&self) -> Result<()>; diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index 788cdba8d6da..bf6aa4490c35 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -1648,8 +1648,14 @@ impl Window { self.current_url.clone() } + /// Navigates the webview to the defined url. + #[cfg(not(test))] + pub fn navigate(&mut self, url: Url) { + self.window.dispatcher.navigate(url).unwrap(); + } + #[cfg(test)] - pub(crate) fn navigate(&mut self, url: Url) { + pub fn navigate(&mut self, url: Url) { self.current_url = url; }