@@ -136,6 +136,7 @@ pub struct AppState {
136136 log_path : String ,
137137 pub system_tray : Option < SystemTray > ,
138138 pub system_tray_stream : Option < SystemTrayStream > ,
139+ has_shown_minimize_notification : bool ,
139140}
140141
141142pub struct CustomWindow {
@@ -363,6 +364,7 @@ impl Application for AppState {
363364 log_path : flags. log_path . clone ( ) ,
364365 system_tray,
365366 system_tray_stream,
367+ has_shown_minimize_notification : false ,
366368 } ;
367369
368370 commands. push (
@@ -677,14 +679,17 @@ impl Application for AppState {
677679 self . about_window = None ;
678680 }
679681
680- let _ = Notification :: new ( )
681- . summary ( "AndroidMic" )
682- . body ( & fl ! ( "minimized_to_tray" ) )
683- . auto_icon ( )
684- . show ( )
685- . map_err ( |e| {
686- error ! ( "failed to show notification: {e}" ) ;
687- } ) ;
682+ if !self . has_shown_minimize_notification {
683+ let _ = Notification :: new ( )
684+ . summary ( "AndroidMic" )
685+ . body ( & fl ! ( "minimized_to_tray" ) )
686+ . auto_icon ( )
687+ . show ( )
688+ . map_err ( |e| {
689+ error ! ( "failed to show notification: {e}" ) ;
690+ } ) ;
691+ self . has_shown_minimize_notification = true ;
692+ }
688693
689694 return cosmic:: iced_runtime:: Task :: batch ( effects) ;
690695 }
@@ -708,25 +713,35 @@ impl Application for AppState {
708713 }
709714 AppMsg :: SystemTray ( tray_msg) => match tray_msg {
710715 SystemTrayMsg :: Show => {
711- let settings = window:: Settings {
712- size : Size :: new ( 800.0 , 600.0 ) ,
713- position : window:: Position :: Centered ,
714- icon : window_icon ! ( "icon" ) ,
715- ..Default :: default ( )
716- } ;
717-
718- let ( new_id, command) = cosmic:: iced:: window:: open ( settings) ;
719- self . main_window = Some ( CustomWindow { window_id : new_id } ) ;
720- let set_window_title = self . set_window_title ( fl ! ( "main_window_title" ) , new_id) ;
721-
722- return command
723- . map ( |_| cosmic:: action:: Action :: None )
724- . chain ( set_window_title)
725- . chain ( cosmic:: iced_runtime:: task:: effect (
716+ if let Some ( main_window) = & self . main_window {
717+ // avoid duplicate window
718+ return cosmic:: iced_runtime:: task:: effect (
726719 cosmic:: iced:: runtime:: Action :: Window ( window:: Action :: GainFocus (
727- new_id ,
720+ main_window . window_id ,
728721 ) ) ,
729- ) ) ;
722+ ) ;
723+ } else {
724+ let settings = window:: Settings {
725+ size : Size :: new ( 800.0 , 600.0 ) ,
726+ position : window:: Position :: Centered ,
727+ icon : window_icon ! ( "icon" ) ,
728+ ..Default :: default ( )
729+ } ;
730+
731+ let ( new_id, command) = cosmic:: iced:: window:: open ( settings) ;
732+ self . main_window = Some ( CustomWindow { window_id : new_id } ) ;
733+ let set_window_title =
734+ self . set_window_title ( fl ! ( "main_window_title" ) , new_id) ;
735+
736+ return command
737+ . map ( |_| cosmic:: action:: Action :: None )
738+ . chain ( set_window_title)
739+ . chain ( cosmic:: iced_runtime:: task:: effect (
740+ cosmic:: iced:: runtime:: Action :: Window ( window:: Action :: GainFocus (
741+ new_id,
742+ ) ) ,
743+ ) ) ;
744+ }
730745 }
731746 SystemTrayMsg :: Exit => {
732747 return cosmic:: iced_runtime:: task:: effect ( cosmic:: iced:: runtime:: Action :: Exit ) ;
0 commit comments