Skip to content

Commit d18b536

Browse files
authored
feat(core): enfore label uniqueness, closes #2067 (#2097)
1 parent fa06fa0 commit d18b536

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

.changes/window-label-unique.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Enfore uniqueness of window label.

core/tauri/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ pub enum Error {
1717
/// Failed to create window.
1818
#[error("failed to create window")]
1919
CreateWindow,
20+
/// Window label must be unique.
21+
#[error("a window with label `{0}` already exists")]
22+
WindowLabelAlreadyExists(String),
2023
/// Can't access webview dispatcher because the webview was closed or not found.
2124
#[error("webview not found: invalid label or it was closed")]
2225
WebviewNotFound,

core/tauri/src/manager.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,11 @@ impl<P: Params> WindowManager<P> {
658658
mut pending: PendingWindow<P>,
659659
pending_labels: &[P::Label],
660660
) -> crate::Result<PendingWindow<P>> {
661+
if self.windows_lock().contains_key(&pending.label) {
662+
return Err(crate::Error::WindowLabelAlreadyExists(
663+
pending.label.to_string(),
664+
));
665+
}
661666
let (is_local, url) = match &pending.webview_attributes.url {
662667
WindowUrl::App(path) => {
663668
let url = self.get_url();

0 commit comments

Comments
 (0)