Skip to content

Commit

Permalink
feat(core): enfore label uniqueness, closes #2067 (#2097)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jun 28, 2021
1 parent fa06fa0 commit d18b536
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/window-label-unique.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Enfore uniqueness of window label.
3 changes: 3 additions & 0 deletions core/tauri/src/error.rs
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions core/tauri/src/manager.rs
Expand Up @@ -658,6 +658,11 @@ impl<P: Params> WindowManager<P> {
mut pending: PendingWindow<P>,
pending_labels: &[P::Label],
) -> crate::Result<PendingWindow<P>> {
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();
Expand Down

0 comments on commit d18b536

Please sign in to comment.