@@ -24,10 +24,13 @@ use cosmic::{
2424
2525use super :: {
2626 message:: { AppMsg , ConfigMsg } ,
27- tray:: { SystemTray , SystemTrayMsg , SystemTrayStream } ,
2827 view:: { main_window, settings_window} ,
2928 wave:: AudioWave ,
3029} ;
30+
31+ #[ cfg( not( target_os = "linux" ) ) ]
32+ use super :: tray:: { SystemTray , SystemTrayMsg , SystemTrayStream } ;
33+
3134use crate :: {
3235 audio:: { AudioPacketFormat , AudioProcessParams } ,
3336 config:: {
@@ -128,7 +131,9 @@ pub struct AppState {
128131 pub about_window : Option < CustomWindow > ,
129132 pub logs : Vec < markdown:: Item > ,
130133 log_path : String ,
134+ #[ cfg( not( target_os = "linux" ) ) ]
131135 pub system_tray : Option < SystemTray > ,
136+ #[ cfg( not( target_os = "linux" ) ) ]
132137 pub system_tray_stream : Option < SystemTrayStream > ,
133138 has_shown_minimize_notification : bool ,
134139 launched_automatically : bool ,
@@ -240,6 +245,7 @@ impl AppState {
240245 self . audio_stream = None ;
241246 self . audio_wave . clear ( ) ;
242247
248+ #[ cfg( not( target_os = "linux" ) ) ]
243249 if let Some ( system_tray) = self . system_tray . as_mut ( ) {
244250 system_tray. update_menu_state ( true , & fl ! ( "state_disconnected" ) ) ;
245251 }
@@ -349,6 +355,7 @@ impl Application for AppState {
349355 } ;
350356
351357 // initialize system tray
358+ #[ cfg( not( target_os = "linux" ) ) ]
352359 let ( system_tray, system_tray_stream) = match SystemTray :: new ( ) {
353360 Ok ( ( mut tray, stream) ) => {
354361 tray. update_menu_state ( true , & fl ! ( "state_disconnected" ) ) ;
@@ -379,7 +386,9 @@ impl Application for AppState {
379386 about_window : None ,
380387 logs : Vec :: new ( ) ,
381388 log_path : flags. log_path . clone ( ) ,
389+ #[ cfg( not( target_os = "linux" ) ) ]
382390 system_tray,
391+ #[ cfg( not( target_os = "linux" ) ) ]
383392 system_tray_stream,
384393 has_shown_minimize_notification : false ,
385394 launched_automatically : flags. launched_automatically ,
@@ -400,10 +409,14 @@ impl Application for AppState {
400409 info ! ( "config path: {}" , flags. config_path) ;
401410 info ! ( "log path: {}" , flags. log_path) ;
402411
412+ #[ cfg( not( target_os = "linux" ) ) ]
403413 if !flags. launched_automatically || !app. config . data ( ) . start_minimized {
404414 commands. push ( app. open_main_window ( ) ) ;
405415 }
406416
417+ #[ cfg( target_os = "linux" ) ]
418+ commands. push ( app. open_main_window ( ) ) ;
419+
407420 match single_instance:: stream ( ) {
408421 Ok ( stream) => {
409422 commands. push ( cosmic:: iced:: task:: Task :: run ( stream, |event| match event {
@@ -455,6 +468,7 @@ impl Application for AppState {
455468 error ! ( "{e}" ) ;
456469 }
457470
471+ #[ cfg( not( target_os = "linux" ) ) ]
458472 if let Some ( system_tray) = self . system_tray . as_mut ( ) {
459473 system_tray. update_menu_state ( false , & fl ! ( "state_listening" ) ) ;
460474 }
@@ -487,6 +501,7 @@ impl Application for AppState {
487501 error ! ( "{e}" ) ;
488502 }
489503
504+ #[ cfg( not( target_os = "linux" ) ) ]
490505 if let Some ( system_tray) = self . system_tray . as_mut ( ) {
491506 system_tray. update_menu_state ( false , & fl ! ( "state_connected" ) ) ;
492507 }
@@ -756,6 +771,7 @@ impl Application for AppState {
756771 error ! ( "{e}" ) ;
757772 }
758773 }
774+ #[ cfg( not( target_os = "linux" ) ) ]
759775 AppMsg :: SystemTray ( tray_msg) => match tray_msg {
760776 SystemTrayMsg :: Show => {
761777 if let Some ( main_window) = & self . main_window {
@@ -791,6 +807,9 @@ impl Application for AppState {
791807 return Task :: batch ( vec ! [ command, self . update_audio_stream( ) ] ) ;
792808 }
793809 }
810+ AppMsg :: Exit => {
811+ return cosmic:: iced_runtime:: task:: effect ( cosmic:: iced:: runtime:: Action :: Exit ) ;
812+ }
794813 }
795814
796815 Task :: none ( )
@@ -822,8 +841,9 @@ impl Application for AppState {
822841 }
823842
824843 fn subscription ( & self ) -> cosmic:: iced:: Subscription < Self :: Message > {
825- let mut subscriptions = vec ! [ Subscription :: run( || streamer:: sub( ) . map( AppMsg :: Streamer ) ) ] ;
844+ let subscriptions = vec ! [ Subscription :: run( || streamer:: sub( ) . map( AppMsg :: Streamer ) ) ] ;
826845
846+ #[ cfg( not( target_os = "linux" ) ) ]
827847 if let Some ( system_tray_stream) = & self . system_tray_stream {
828848 subscriptions. push ( Subscription :: run_with_id (
829849 "system-tray" ,
@@ -848,8 +868,11 @@ impl Application for AppState {
848868 if let Some ( window) = & self . main_window
849869 && window. window_id == id
850870 {
851- // close the app
871+ # [ cfg ( not ( target_os = "linux" ) ) ]
852872 return Some ( AppMsg :: HideWindow ) ;
873+
874+ #[ cfg( target_os = "linux" ) ]
875+ return Some ( AppMsg :: Exit ) ;
853876 }
854877
855878 None
0 commit comments