-
Notifications
You must be signed in to change notification settings - Fork 431
feat(window-state): add filter callback for excluding windows from tracking #2330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
2847f11
c8e84f6
4aa8a51
ff66ed3
1368d4a
eca5293
6d8d565
ead110d
20bdfa5
ae08144
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
window-state: patch | ||
window-state-js: patch | ||
--- | ||
|
||
Introduces the ability to use glob patterns in the denylist for windows that shouldn't be tracked and managed. This allows for more flexible window matching, such as ignoring multiple windows that fit a certain naming pattern. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ pub enum Error { | |
Tauri(#[from] tauri::Error), | ||
#[error(transparent)] | ||
SerdeJson(#[from] serde_json::Error), | ||
#[error(transparent)] | ||
Glob(#[from] glob::PatternError), | ||
} | ||
|
||
pub type Result<T> = std::result::Result<T, Error>; | ||
|
@@ -319,7 +321,7 @@ impl<R: Runtime> WindowExtInternal for Window<R> { | |
|
||
#[derive(Default)] | ||
pub struct Builder { | ||
denylist: HashSet<String>, | ||
denylist: Vec<glob::Pattern>, | ||
skip_initial_state: HashSet<String>, | ||
state_flags: StateFlags, | ||
map_label: Option<Box<LabelMapperFn>>, | ||
|
@@ -344,10 +346,16 @@ impl Builder { | |
} | ||
|
||
/// Sets a list of windows that shouldn't be tracked and managed by this plugin | ||
/// for example splash screen windows. | ||
pub fn with_denylist(mut self, denylist: &[&str]) -> Self { | ||
self.denylist = denylist.iter().map(|l| l.to_string()).collect(); | ||
self | ||
/// For example, splash screen windows. It also supports glob patterns for flexible window matching. | ||
pub fn with_denylist(mut self, denylist: &mut [&str]) -> Result<Self> { | ||
|
||
denylist.sort(); | ||
|
||
let mut denylist_patterns = Vec::new(); | ||
for pattern in denylist { | ||
denylist_patterns.push(glob::Pattern::new(pattern)?); | ||
} | ||
self.denylist = denylist_patterns; | ||
Ok(self) | ||
} | ||
|
||
/// Adds the given window label to a list of windows to skip initial state restore. | ||
|
@@ -413,8 +421,10 @@ impl Builder { | |
.map(|map| map(window.label())) | ||
.unwrap_or_else(|| window.label()); | ||
|
||
if self.denylist.contains(label) { | ||
return; | ||
for pattern in &self.denylist { | ||
if pattern.matches(label) { | ||
return; | ||
} | ||
} | ||
|
||
if !self.skip_initial_state.contains(label) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.