From d18b5367a91fd53d408510b456897630c70abcca Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sun, 27 Jun 2021 21:05:45 -0300 Subject: [PATCH] feat(core): enfore label uniqueness, closes #2067 (#2097) --- .changes/window-label-unique.md | 5 +++++ core/tauri/src/error.rs | 3 +++ core/tauri/src/manager.rs | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 .changes/window-label-unique.md diff --git a/.changes/window-label-unique.md b/.changes/window-label-unique.md new file mode 100644 index 000000000..27aa3f6ca --- /dev/null +++ b/.changes/window-label-unique.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Enfore uniqueness of window label. diff --git a/core/tauri/src/error.rs b/core/tauri/src/error.rs index 43fbcdb6b..8926e4014 100644 --- a/core/tauri/src/error.rs +++ b/core/tauri/src/error.rs @@ -17,6 +17,9 @@ pub enum Error { /// Failed to create window. #[error("failed to create window")] CreateWindow, + /// Window label must be unique. + #[error("a window with label `{0}` already exists")] + WindowLabelAlreadyExists(String), /// Can't access webview dispatcher because the webview was closed or not found. #[error("webview not found: invalid label or it was closed")] WebviewNotFound, diff --git a/core/tauri/src/manager.rs b/core/tauri/src/manager.rs index b61982561..6d506788b 100644 --- a/core/tauri/src/manager.rs +++ b/core/tauri/src/manager.rs @@ -658,6 +658,11 @@ impl WindowManager

{ mut pending: PendingWindow

, pending_labels: &[P::Label], ) -> crate::Result> { + if self.windows_lock().contains_key(&pending.label) { + return Err(crate::Error::WindowLabelAlreadyExists( + pending.label.to_string(), + )); + } let (is_local, url) = match &pending.webview_attributes.url { WindowUrl::App(path) => { let url = self.get_url();