Skip to content

Commit 2847f11

Browse files
committed
feat(window-state): Add glob pattern support to denylist for flexible window management
1 parent 406e6f4 commit 2847f11

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/window-state/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ serde_json = { workspace = true }
2929
tauri = { workspace = true }
3030
log = { workspace = true }
3131
thiserror = { workspace = true }
32+
glob = { workspace = true }
3233
bitflags = "2"

plugins/window-state/src/lib.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub enum Error {
4141
Tauri(#[from] tauri::Error),
4242
#[error(transparent)]
4343
SerdeJson(#[from] serde_json::Error),
44+
#[error(transparent)]
45+
Glob(#[from] glob::PatternError),
4446
}
4547

4648
pub type Result<T> = std::result::Result<T, Error>;
@@ -319,7 +321,7 @@ impl<R: Runtime> WindowExtInternal for Window<R> {
319321

320322
#[derive(Default)]
321323
pub struct Builder {
322-
denylist: HashSet<String>,
324+
denylist: Vec<glob::Pattern>,
323325
skip_initial_state: HashSet<String>,
324326
state_flags: StateFlags,
325327
map_label: Option<Box<LabelMapperFn>>,
@@ -344,10 +346,16 @@ impl Builder {
344346
}
345347

346348
/// Sets a list of windows that shouldn't be tracked and managed by this plugin
347-
/// for example splash screen windows.
348-
pub fn with_denylist(mut self, denylist: &[&str]) -> Self {
349-
self.denylist = denylist.iter().map(|l| l.to_string()).collect();
350-
self
349+
/// For example, splash screen windows. It also supports glob patterns for flexible window matching.
350+
pub fn with_denylist(mut self, denylist: &mut [&str]) -> Result<Self> {
351+
denylist.sort();
352+
353+
let mut denylist_patterns = Vec::new();
354+
for pattern in denylist {
355+
denylist_patterns.push(glob::Pattern::new(&pattern)?);
356+
}
357+
self.denylist = denylist_patterns;
358+
Ok(self)
351359
}
352360

353361
/// Adds the given window label to a list of windows to skip initial state restore.
@@ -413,8 +421,11 @@ impl Builder {
413421
.map(|map| map(window.label()))
414422
.unwrap_or_else(|| window.label());
415423

416-
if self.denylist.contains(label) {
417-
return;
424+
425+
for pattern in &self.denylist {
426+
if pattern.matches(label) {
427+
return;
428+
}
418429
}
419430

420431
if !self.skip_initial_state.contains(label) {

0 commit comments

Comments
 (0)