@@ -2449,11 +2449,24 @@ fn handle_event_loop<T: UserEvent>(
24492449 callback,
24502450 window_id,
24512451 windows. clone ( ) ,
2452- control_flow,
24532452 window_event_listeners,
24542453 menu_event_listeners. clone ( ) ,
24552454 ) ;
24562455 }
2456+ WryWindowEvent :: Destroyed => {
2457+ let is_empty = windows. lock ( ) . unwrap ( ) . is_empty ( ) ;
2458+ if is_empty {
2459+ let ( tx, rx) = channel ( ) ;
2460+ callback ( RunEvent :: ExitRequested { tx } ) ;
2461+
2462+ let recv = rx. try_recv ( ) ;
2463+ let should_prevent = matches ! ( recv, Ok ( ExitRequestedEventAction :: Prevent ) ) ;
2464+
2465+ if !should_prevent {
2466+ * control_flow = ControlFlow :: Exit ;
2467+ }
2468+ }
2469+ }
24572470 WryWindowEvent :: Resized ( _) => {
24582471 if let Some ( WindowHandle :: Webview ( webview) ) = windows
24592472 . lock ( )
@@ -2476,9 +2489,6 @@ fn handle_event_loop<T: UserEvent>(
24762489 callback,
24772490 id,
24782491 windows. lock ( ) . expect ( "poisoned webview collection" ) ,
2479- control_flow,
2480- #[ cfg( target_os = "linux" ) ]
2481- window_event_listeners,
24822492 menu_event_listeners. clone ( ) ,
24832493 ) ;
24842494 }
@@ -2513,7 +2523,6 @@ fn on_close_requested<'a, T: UserEvent>(
25132523 callback : & ' a mut ( dyn FnMut ( RunEvent < T > ) + ' static ) ,
25142524 window_id : WebviewId ,
25152525 windows : Arc < Mutex < HashMap < WebviewId , WindowWrapper > > > ,
2516- control_flow : & mut ControlFlow ,
25172526 window_event_listeners : & WindowEventListeners ,
25182527 menu_event_listeners : MenuEventListeners ,
25192528) -> Option < WindowWrapper > {
@@ -2547,9 +2556,6 @@ fn on_close_requested<'a, T: UserEvent>(
25472556 callback,
25482557 window_id,
25492558 windows. lock ( ) . expect ( "poisoned webview collection" ) ,
2550- control_flow,
2551- #[ cfg( target_os = "linux" ) ]
2552- window_event_listeners,
25532559 menu_event_listeners,
25542560 )
25552561 }
@@ -2562,50 +2568,17 @@ fn on_window_close<'a, T: UserEvent>(
25622568 callback : & ' a mut ( dyn FnMut ( RunEvent < T > ) + ' static ) ,
25632569 window_id : WebviewId ,
25642570 mut windows : MutexGuard < ' a , HashMap < WebviewId , WindowWrapper > > ,
2565- control_flow : & mut ControlFlow ,
2566- #[ cfg( target_os = "linux" ) ] window_event_listeners : & WindowEventListeners ,
25672571 menu_event_listeners : MenuEventListeners ,
25682572) -> Option < WindowWrapper > {
25692573 #[ allow( unused_mut) ]
25702574 let w = if let Some ( mut webview) = windows. remove ( & window_id) {
2571- let is_empty = windows. is_empty ( ) ;
25722575 drop ( windows) ;
25732576 menu_event_listeners. lock ( ) . unwrap ( ) . remove ( & window_id) ;
25742577 callback ( RunEvent :: WindowClose ( webview. label . clone ( ) ) ) ;
2575-
2576- if is_empty {
2577- let ( tx, rx) = channel ( ) ;
2578- callback ( RunEvent :: ExitRequested {
2579- window_label : webview. label . clone ( ) ,
2580- tx,
2581- } ) ;
2582-
2583- let recv = rx. try_recv ( ) ;
2584- let should_prevent = matches ! ( recv, Ok ( ExitRequestedEventAction :: Prevent ) ) ;
2585-
2586- if !should_prevent {
2587- * control_flow = ControlFlow :: Exit ;
2588- }
2589- }
25902578 Some ( webview)
25912579 } else {
25922580 None
25932581 } ;
2594- // TODO: tao does not fire the destroyed event properly
2595- #[ cfg( target_os = "linux" ) ]
2596- {
2597- for handler in window_event_listeners
2598- . lock ( )
2599- . unwrap ( )
2600- . get ( & window_id)
2601- . unwrap ( )
2602- . lock ( )
2603- . unwrap ( )
2604- . values ( )
2605- {
2606- handler ( & WindowEvent :: Destroyed ) ;
2607- }
2608- }
26092582 w
26102583}
26112584
0 commit comments