@@ -20,11 +20,11 @@ mod organize_type;
2020
2121use std:: collections:: BTreeMap ;
2222
23+ use :: tray_icon:: TrayIcon ;
2324use config:: Config ;
2425use consts:: { APPNAME , BOLD_FONT_TTF , ICON_FONT_TTF , MEDIUM_FONT , MEDIUM_FONT_TTF } ;
2526use iced:: { Task , daemon, window:: Id } ;
2627use interprocess:: local_socket:: { self , GenericNamespaced , ToNsName , traits:: Stream } ;
27- use tray_icon:: create_tray_icon;
2828use window:: AppWindow ;
2929
3030fn main ( ) -> Result < ( ) , iced:: Error > {
@@ -36,13 +36,10 @@ fn main() -> Result<(), iced::Error> {
3636 return Ok ( ( ) ) ;
3737 } ;
3838
39- #[ cfg( not( target_os = "linux" ) ) ]
40- let _tray_icon = create_tray_icon ( ) ;
41-
4239 #[ cfg( target_os = "linux" ) ]
4340 std:: thread:: spawn ( || {
4441 gtk:: init ( ) . expect ( "GTK must be initialized" ) ;
45- let _tray_icon = create_tray_icon ( ) ;
42+ let _tray_icon = tray_icon :: create_tray_icon ( ) ;
4643 gtk:: main ( ) ;
4744 } ) ;
4845
@@ -65,6 +62,7 @@ pub struct App {
6562
6663 config : Config ,
6764 windows : BTreeMap < Id , AppWindow > ,
65+ tray_icon : Option < TrayIcon > ,
6866}
6967
7068#[ derive( Debug , Clone ) ]
@@ -80,6 +78,7 @@ pub enum Message {
8078 ExitApp ,
8179 Settings ( Id , settings:: Message ) ,
8280 Capture ( Id , capture:: Message ) ,
81+ CreateTrayIcon ,
8382}
8483
8584impl App {
@@ -97,6 +96,11 @@ impl App {
9796 }
9897 Err ( _) => ( Config :: default ( ) , Task :: done ( Message :: OpenSettingsWindow ) ) ,
9998 } ;
99+ let task = Task :: batch ( [
100+ task,
101+ #[ cfg( not( target_os = "linux" ) ) ]
102+ Task :: done ( Message :: CreateTrayIcon ) ,
103+ ] ) ;
100104
101105 (
102106 App {
@@ -106,6 +110,7 @@ impl App {
106110
107111 config,
108112 windows : BTreeMap :: new ( ) ,
113+ tray_icon : None ,
109114 } ,
110115 task,
111116 )
0 commit comments