@@ -105,6 +105,8 @@ impl Default for WindowState {
105105}
106106
107107struct 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 < ( ) > ) ;
108110pub trait AppHandleExt {
109111 /// Saves all open windows state to disk
110112 fn save_window_state ( & self , flags : StateFlags ) -> Result < ( ) > ;
@@ -167,6 +169,8 @@ impl<R: Runtime> WindowExt for Window<R> {
167169 . map ( |map| map ( self . label ( ) ) )
168170 . unwrap_or_else ( || self . label ( ) ) ;
169171
172+ let restoring_window_state = self . state :: < RestoringWindowState > ( ) ;
173+ let _restoring_window_lock = restoring_window_state. 0 . lock ( ) . unwrap ( ) ;
170174 let cache = self . state :: < WindowStateCache > ( ) ;
171175 let mut c = cache. 0 . lock ( ) . unwrap ( ) ;
172176
@@ -396,6 +400,7 @@ impl Builder {
396400 Default :: default ( )
397401 } ;
398402 app. manage ( WindowStateCache ( cache) ) ;
403+ app. manage ( RestoringWindowState ( Mutex :: new ( ( ) ) ) ) ;
399404 app. manage ( PluginState {
400405 filename,
401406 map_label,
@@ -443,7 +448,13 @@ impl Builder {
443448 }
444449
445450 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+ {
447458 let mut c = cache. lock ( ) . unwrap ( ) ;
448459 if let Some ( state) = c. get_mut ( & label) {
449460 state. prev_x = state. x ;
@@ -455,7 +466,12 @@ impl Builder {
455466 }
456467 }
457468 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 ( )
459475 && !window_clone. is_maximized ( ) . unwrap_or_default ( )
460476 {
461477 let mut c = cache. lock ( ) . unwrap ( ) ;
0 commit comments