@@ -27,6 +27,7 @@ use std::{
27
27
mod cmd;
28
28
29
29
type LabelMapperFn = dyn Fn ( & str ) -> & str + Send + Sync ;
30
+ type FilterCallbackFn = dyn Fn ( & str ) -> bool + Send + Sync ;
30
31
31
32
/// Default filename used to store window state.
32
33
///
@@ -320,6 +321,7 @@ impl<R: Runtime> WindowExtInternal for Window<R> {
320
321
#[ derive( Default ) ]
321
322
pub struct Builder {
322
323
denylist : HashSet < String > ,
324
+ filter_callback : Option < Box < FilterCallbackFn > > ,
323
325
skip_initial_state : HashSet < String > ,
324
326
state_flags : StateFlags ,
325
327
map_label : Option < Box < LabelMapperFn > > ,
@@ -344,12 +346,22 @@ impl Builder {
344
346
}
345
347
346
348
/// Sets a list of windows that shouldn't be tracked and managed by this plugin
347
- /// for example splash screen windows.
349
+ /// For example, splash screen windows.
348
350
pub fn with_denylist ( mut self , denylist : & [ & str ] ) -> Self {
349
351
self . denylist = denylist. iter ( ) . map ( |l| l. to_string ( ) ) . collect ( ) ;
350
352
self
351
353
}
352
354
355
+ /// Sets a filter callback to exclude specific windows from being tracked.
356
+ /// Return `true` to save the state, or `false` to skip and not save it.
357
+ pub fn with_filter < F > ( mut self , filter_callback : F ) -> Self
358
+ where
359
+ F : Fn ( & str ) -> bool + Send + Sync + ' static ,
360
+ {
361
+ self . filter_callback = Some ( Box :: new ( filter_callback) ) ;
362
+ self
363
+ }
364
+
353
365
/// Adds the given window label to a list of windows to skip initial state restore.
354
366
pub fn skip_initial_state ( mut self , label : & str ) -> Self {
355
367
self . skip_initial_state . insert ( label. into ( ) ) ;
@@ -413,10 +425,19 @@ impl Builder {
413
425
. map ( |map| map ( window. label ( ) ) )
414
426
. unwrap_or_else ( || window. label ( ) ) ;
415
427
428
+ // Check deny list names
416
429
if self . denylist . contains ( label) {
417
430
return ;
418
431
}
419
432
433
+ // Check deny list callback
434
+ if let Some ( filter_callback) = & self . filter_callback {
435
+ // Don't save the state if the callback returns false
436
+ if !filter_callback ( label) {
437
+ return ;
438
+ }
439
+ }
440
+
420
441
if !self . skip_initial_state . contains ( label) {
421
442
let _ = window. restore_state ( self . state_flags ) ;
422
443
}
0 commit comments