@@ -15,8 +15,8 @@ use iced::{
1515 widget:: { button, center, container, image, row, text, Column , Text } ,
1616 window, Background , Border , Color , Element , Length , Shadow , Size , Task , Theme ,
1717} ;
18- use platform_tools:: { ensure_default_browser, get_mouse_position} ;
1918use platform_tools:: open_url;
19+ use platform_tools:: { ensure_default_browser, get_mouse_position} ;
2020use std:: mem;
2121use std:: time:: { Duration , Instant } ;
2222use storage:: { BrowserInfo , BrowserProfile , MatchItem , Storage } ;
@@ -75,6 +75,8 @@ enum Message {
7575 WindowOpened ( window:: Id ) ,
7676 CloseWindow ,
7777 MoveWindow ( window:: Id ) ,
78+ WindowClosed ,
79+ WindowUnfocused ,
7880}
7981
8082impl Gomi {
@@ -110,6 +112,7 @@ impl Gomi {
110112 }
111113
112114 fn update ( & mut self , message : Message ) -> Task < Message > {
115+ info ! ( "message: {:?}" , message) ;
113116 match message {
114117 Message :: GoHome ( browsers) => {
115118 self . browser_list = Some ( browsers) ;
@@ -296,19 +299,30 @@ impl Gomi {
296299 }
297300 Message :: WindowOpened ( window_id) => {
298301 self . current_window = Some ( window_id) ;
302+ self . launch_time = Instant :: now ( ) ;
299303 Task :: none ( )
300304 }
301305 Message :: CloseWindow => {
302306 if let Some ( window_id) = self . current_window {
303- let rs = window:: close ( window_id) ;
304- self . current_page = Page :: Home ;
305- self . stacks . clear ( ) ;
306- self . current_url = None ;
307- self . current_window = None ;
308- return rs;
307+ Task :: batch ( [ window:: close ( window_id) , Task :: done ( Message :: WindowClosed ) ] )
308+ } else {
309+ Task :: none ( )
309310 }
311+ }
312+ Message :: WindowClosed => {
313+ self . current_page = Page :: Home ;
314+ self . stacks . clear ( ) ;
315+ self . current_url = None ;
316+ self . current_window = None ;
310317 Task :: none ( )
311318 }
319+ Message :: WindowUnfocused => {
320+ if self . launch_time . elapsed ( ) . as_secs ( ) > 2 {
321+ Task :: done ( Message :: CloseWindow )
322+ } else {
323+ Task :: none ( )
324+ }
325+ }
312326 }
313327 }
314328
@@ -405,7 +419,6 @@ impl Gomi {
405419
406420 let footer = if let Some ( url) = current_url {
407421 let url_cloned = url. clone ( ) ;
408- info ! ( "url_cloned: {}" , url_cloned) ;
409422 let url = Url :: parse ( & url) . unwrap ( ) ;
410423 let host = url. host_str ( ) . unwrap_or_default ( ) . to_string ( ) ;
411424
@@ -572,6 +585,8 @@ impl Gomi {
572585 Event :: Keyboard ( keyboard:: Event :: ModifiersChanged ( modifiers) ) => {
573586 Some ( Message :: KeyboardModifiersChanged ( modifiers) )
574587 }
588+ Event :: Window ( window:: Event :: Unfocused ) => Some ( Message :: WindowUnfocused ) ,
589+ Event :: Window ( window:: Event :: Closed ) => Some ( Message :: WindowClosed ) ,
575590 _ => None ,
576591 }
577592 } ) ,
0 commit comments