@@ -105,6 +105,8 @@ impl Default for WindowState {
105
105
}
106
106
107
107
struct WindowStateCache ( Arc < Mutex < HashMap < String , WindowState > > > ) ;
108
+ /// Used to prevent deadlocks from resize and position event listeners setting the cached state on restoring states
109
+ struct RestoringWindowState ( Mutex < ( ) > ) ;
108
110
pub trait AppHandleExt {
109
111
/// Saves all open windows state to disk
110
112
fn save_window_state ( & self , flags : StateFlags ) -> Result < ( ) > ;
@@ -167,6 +169,8 @@ impl<R: Runtime> WindowExt for Window<R> {
167
169
. map ( |map| map ( self . label ( ) ) )
168
170
. unwrap_or_else ( || self . label ( ) ) ;
169
171
172
+ let restoring_window_state = self . state :: < RestoringWindowState > ( ) ;
173
+ let _restoring_window_lock = restoring_window_state. 0 . lock ( ) . unwrap ( ) ;
170
174
let cache = self . state :: < WindowStateCache > ( ) ;
171
175
let mut c = cache. 0 . lock ( ) . unwrap ( ) ;
172
176
@@ -396,6 +400,7 @@ impl Builder {
396
400
Default :: default ( )
397
401
} ;
398
402
app. manage ( WindowStateCache ( cache) ) ;
403
+ app. manage ( RestoringWindowState ( Mutex :: new ( ( ) ) ) ) ;
399
404
app. manage ( PluginState {
400
405
filename,
401
406
map_label,
@@ -443,7 +448,13 @@ impl Builder {
443
448
}
444
449
445
450
WindowEvent :: Moved ( position) if flags. contains ( StateFlags :: POSITION ) => {
446
- if !window_clone. is_minimized ( ) . unwrap_or_default ( ) {
451
+ if window_clone
452
+ . state :: < RestoringWindowState > ( )
453
+ . 0
454
+ . try_lock ( )
455
+ . is_ok ( )
456
+ && !window_clone. is_minimized ( ) . unwrap_or_default ( )
457
+ {
447
458
let mut c = cache. lock ( ) . unwrap ( ) ;
448
459
if let Some ( state) = c. get_mut ( & label) {
449
460
state. prev_x = state. x ;
@@ -455,7 +466,12 @@ impl Builder {
455
466
}
456
467
}
457
468
WindowEvent :: Resized ( size) if flags. contains ( StateFlags :: SIZE ) => {
458
- if !window_clone. is_minimized ( ) . unwrap_or_default ( )
469
+ if window_clone
470
+ . state :: < RestoringWindowState > ( )
471
+ . 0
472
+ . try_lock ( )
473
+ . is_ok ( )
474
+ && !window_clone. is_minimized ( ) . unwrap_or_default ( )
459
475
&& !window_clone. is_maximized ( ) . unwrap_or_default ( )
460
476
{
461
477
let mut c = cache. lock ( ) . unwrap ( ) ;
0 commit comments