mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-24 12:14:05 +03:00
refactor!(core): return result in Webview/WebviewWindow::url
getter (#9647)
* refactor!(core): return result in `Webview/WebviewWindow::url` getter * clippy * Apply suggestions from code review
This commit is contained in:
parent
d2fc48f0e6
commit
783ef0f2d3
6
.changes/url-result-runtime.md
Normal file
6
.changes/url-result-runtime.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"tauri-runtime": "patch"
|
||||
"tauri-runtime-wry": "patch"
|
||||
---
|
||||
|
||||
Changed `WebviewDispatch::url` getter to return a result.
|
5
.changes/url-result.md
Normal file
5
.changes/url-result.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": "patch:breaking"
|
||||
---
|
||||
|
||||
Changed `WebviewWindow::url` and `Webview::url` getter to return a result.
|
@ -1190,7 +1190,7 @@ pub enum WebviewMessage {
|
||||
SetAutoResize(bool),
|
||||
SetZoom(f64),
|
||||
// Getters
|
||||
Url(Sender<Result<Url>>),
|
||||
Url(Sender<Result<String>>),
|
||||
Bounds(Sender<Result<tauri_runtime::Rect>>),
|
||||
Position(Sender<Result<PhysicalPosition<i32>>>),
|
||||
Size(Sender<Result<PhysicalSize<u32>>>),
|
||||
@ -1305,7 +1305,7 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
|
||||
|
||||
// Getters
|
||||
|
||||
fn url(&self) -> Result<Url> {
|
||||
fn url(&self) -> Result<String> {
|
||||
webview_getter!(self, WebviewMessage::Url)?
|
||||
}
|
||||
|
||||
|
@ -445,7 +445,7 @@ pub trait WebviewDispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + '
|
||||
// GETTERS
|
||||
|
||||
/// Returns the webview's current URL.
|
||||
fn url(&self) -> Result<Url>;
|
||||
fn url(&self) -> Result<String>;
|
||||
|
||||
/// Returns the webview's bounds.
|
||||
fn bounds(&self) -> Result<Rect>;
|
||||
|
@ -502,13 +502,8 @@ impl<T: UserEvent> WebviewDispatch<T> for MockWebviewDispatcher {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn url(&self) -> Result<url::Url> {
|
||||
self
|
||||
.url
|
||||
.lock()
|
||||
.unwrap()
|
||||
.parse()
|
||||
.map_err(|_| Error::FailedToReceiveMessage)
|
||||
fn url(&self) -> Result<String> {
|
||||
Ok(self.url.lock().unwrap().clone())
|
||||
}
|
||||
|
||||
fn bounds(&self) -> Result<tauri_runtime::Rect> {
|
||||
|
@ -1073,9 +1073,12 @@ fn main() {
|
||||
}
|
||||
|
||||
/// Returns the current url of the webview.
|
||||
// TODO: in v2, change this type to Result
|
||||
pub fn url(&self) -> Url {
|
||||
self.webview.dispatcher.url().unwrap()
|
||||
pub fn url(&self) -> crate::Result<Url> {
|
||||
self
|
||||
.webview
|
||||
.dispatcher
|
||||
.url()
|
||||
.map(|url| url.parse().map_err(crate::Error::InvalidUrl))?
|
||||
}
|
||||
|
||||
/// Navigates the webview to the defined url.
|
||||
|
@ -1605,8 +1605,7 @@ impl<R: Runtime> WebviewWindow<R> {
|
||||
}
|
||||
|
||||
/// Returns the current url of the webview.
|
||||
// TODO: in v2, change this type to Result
|
||||
pub fn url(&self) -> Url {
|
||||
pub fn url(&self) -> crate::Result<Url> {
|
||||
self.webview.url()
|
||||
}
|
||||
|
||||
|
22
examples/api/src-tauri/Cargo.lock
generated
22
examples/api/src-tauri/Cargo.lock
generated
@ -4002,6 +4002,17 @@ dependencies = [
|
||||
"syn 2.0.61",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-implement"
|
||||
version = "0.56.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.56.0"
|
||||
@ -4013,6 +4024,17 @@ dependencies = [
|
||||
"syn 2.0.61",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-interface"
|
||||
version = "0.56.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.52",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.1.1"
|
||||
|
Loading…
Reference in New Issue
Block a user