@@ -770,6 +770,7 @@ pub fn run() {
770770 get_stats_history,
771771 save_daily_stats,
772772 update_tray_icon,
773+ update_tray_menu,
773774 show_window,
774775 save_settings,
775776 load_settings,
@@ -794,23 +795,58 @@ pub fn run() {
794795
795796 let show_item =
796797 MenuItem :: with_id ( app, "show" , "Mostra Presto" , true , None :: < & str > ) ?;
798+ let start_session_item =
799+ MenuItem :: with_id ( app, "start_session" , "Inizia sessione" , false , None :: < & str > ) ?;
800+ let pause_item =
801+ MenuItem :: with_id ( app, "pause" , "Pausa" , false , None :: < & str > ) ?;
802+ let skip_item =
803+ MenuItem :: with_id ( app, "skip" , "Salta sessione" , false , None :: < & str > ) ?;
804+ let cancel_item =
805+ MenuItem :: with_id ( app, "cancel" , "Annulla" , false , None :: < & str > ) ?;
797806 let quit_item = MenuItem :: with_id ( app, "quit" , "Esci" , true , None :: < & str > ) ?;
798- let menu = Menu :: with_items ( app, & [ & show_item, & quit_item] ) ?;
807+ let menu = Menu :: with_items ( app, & [ & show_item, & start_session_item , & pause_item , & skip_item , & cancel_item , & quit_item] ) ?;
799808
800809 let app_handle = app. handle ( ) . clone ( ) ;
801810 let app_handle_for_click = app_handle. clone ( ) ;
802811
803812 let _tray = TrayIconBuilder :: with_id ( "main" )
804- . icon ( app. default_window_icon ( ) . unwrap ( ) . clone ( ) )
805813 . menu ( & menu)
806- . show_menu_on_left_click ( false )
814+ . show_menu_on_left_click ( true )
807815 . on_menu_event ( move |_tray, event| match event. id . as_ref ( ) {
808816 "show" => {
809817 if let Some ( window) = app_handle. get_webview_window ( "main" ) {
810818 let _ = window. show ( ) ;
811819 let _ = window. set_focus ( ) ;
812820 }
813821 }
822+ "start_session" => {
823+ if let Some ( window) = app_handle. get_webview_window ( "main" ) {
824+ let _ = window. emit ( "tray-start-session" , ( ) ) ;
825+ let _ = window. show ( ) ;
826+ let _ = window. set_focus ( ) ;
827+ }
828+ }
829+ "pause" => {
830+ if let Some ( window) = app_handle. get_webview_window ( "main" ) {
831+ let _ = window. emit ( "tray-pause" , ( ) ) ;
832+ let _ = window. show ( ) ;
833+ let _ = window. set_focus ( ) ;
834+ }
835+ }
836+ "skip" => {
837+ if let Some ( window) = app_handle. get_webview_window ( "main" ) {
838+ let _ = window. emit ( "tray-skip" , ( ) ) ;
839+ let _ = window. show ( ) ;
840+ let _ = window. set_focus ( ) ;
841+ }
842+ }
843+ "cancel" => {
844+ if let Some ( window) = app_handle. get_webview_window ( "main" ) {
845+ let _ = window. emit ( "tray-cancel" , ( ) ) ;
846+ let _ = window. show ( ) ;
847+ let _ = window. set_focus ( ) ;
848+ }
849+ }
814850 "quit" => {
815851 app_handle. exit ( 0 ) ;
816852 }
@@ -879,3 +915,72 @@ pub fn run() {
879915 } ) ;
880916 } )
881917}
918+
919+ #[ tauri:: command]
920+ async fn update_tray_menu (
921+ app : AppHandle ,
922+ is_running : bool ,
923+ is_paused : bool ,
924+ current_mode : String ,
925+ ) -> Result < ( ) , String > {
926+ let tray = app. tray_by_id ( "main" ) ;
927+
928+ if let Some ( tray) = tray {
929+ let show_item = MenuItem :: with_id ( & app, "show" , "Mostra Presto" , true , None :: < & str > )
930+ . map_err ( |e| format ! ( "Failed to create show item: {}" , e) ) ?;
931+
932+ // Inizia sessione: abilitato solo se non è in esecuzione
933+ let start_session_item = MenuItem :: with_id (
934+ & app,
935+ "start_session" ,
936+ "Inizia sessione" ,
937+ !is_running,
938+ None :: < & str > ,
939+ ) . map_err ( |e| format ! ( "Failed to create start session item: {}" , e) ) ?;
940+
941+ // Pausa: abilitata solo se è in esecuzione e non in pausa
942+ let pause_item = MenuItem :: with_id (
943+ & app,
944+ "pause" ,
945+ "Pausa" ,
946+ is_running && !is_paused,
947+ None :: < & str > ,
948+ ) . map_err ( |e| format ! ( "Failed to create pause item: {}" , e) ) ?;
949+
950+ // Skip: abilitato solo se è in esecuzione
951+ let skip_item = MenuItem :: with_id (
952+ & app,
953+ "skip" ,
954+ "Salta sessione" ,
955+ is_running,
956+ None :: < & str > ,
957+ ) . map_err ( |e| format ! ( "Failed to create skip item: {}" , e) ) ?;
958+
959+ // Annulla: abilitato se è in modalità focus, disabilitato in break/longBreak (undo)
960+ let cancel_text = if current_mode == "focus" {
961+ "Annulla"
962+ } else {
963+ "Annulla ultima"
964+ } ;
965+ let cancel_item = MenuItem :: with_id (
966+ & app,
967+ "cancel" ,
968+ cancel_text,
969+ true ,
970+ None :: < & str > ,
971+ ) . map_err ( |e| format ! ( "Failed to create cancel item: {}" , e) ) ?;
972+
973+ let quit_item = MenuItem :: with_id ( & app, "quit" , "Esci" , true , None :: < & str > )
974+ . map_err ( |e| format ! ( "Failed to create quit item: {}" , e) ) ?;
975+
976+ let new_menu = Menu :: with_items (
977+ & app,
978+ & [ & show_item, & start_session_item, & pause_item, & skip_item, & cancel_item, & quit_item] ,
979+ ) . map_err ( |e| format ! ( "Failed to create menu: {}" , e) ) ?;
980+
981+ tray. set_menu ( Some ( new_menu) )
982+ . map_err ( |e| format ! ( "Failed to set tray menu: {}" , e) ) ?;
983+ }
984+
985+ Ok ( ( ) )
986+ }
0 commit comments