@@ -36,6 +36,18 @@ struct PomodoroSession {
3636 date : String ,
3737}
3838
39+ #[ derive( Serialize , Deserialize , Clone ) ]
40+ struct ManualSession {
41+ id : String ,
42+ session_type : String , // "focus", "break", "longBreak", "custom"
43+ duration : u32 , // in minutes
44+ start_time : String , // "HH:MM"
45+ end_time : String , // "HH:MM"
46+ notes : Option < String > ,
47+ created_at : String , // ISO string
48+ date : String , // Date string for the session date
49+ }
50+
3951#[ derive( Serialize , Deserialize ) ]
4052struct Task {
4153 id : u64 ,
@@ -697,6 +709,7 @@ async fn reset_all_data(app: AppHandle) -> Result<(), String> {
697709 "tasks.json" ,
698710 "history.json" ,
699711 "settings.json" ,
712+ "manual_sessions.json" ,
700713 ] ;
701714
702715 for file_name in files_to_delete {
@@ -742,6 +755,93 @@ async fn is_autostart_enabled(app: AppHandle) -> Result<bool, String> {
742755 . map_err ( |e| format ! ( "Failed to check autostart status: {}" , e) )
743756}
744757
758+ #[ tauri:: command]
759+ async fn save_manual_sessions ( sessions : Vec < ManualSession > , app : AppHandle ) -> Result < ( ) , String > {
760+ let app_data_dir = app
761+ . path ( )
762+ . app_data_dir ( )
763+ . map_err ( |e| format ! ( "Failed to get app data directory: {}" , e) ) ?;
764+
765+ // Create the directory if it doesn't exist
766+ fs:: create_dir_all ( & app_data_dir) . map_err ( |e| format ! ( "Failed to create directory: {}" , e) ) ?;
767+
768+ let file_path = app_data_dir. join ( "manual_sessions.json" ) ;
769+ let json = serde_json:: to_string_pretty ( & sessions)
770+ . map_err ( |e| format ! ( "Failed to serialize manual sessions: {}" , e) ) ?;
771+
772+ fs:: write ( file_path, json) . map_err ( |e| format ! ( "Failed to write manual sessions file: {}" , e) ) ?;
773+
774+ // Track manual sessions saved analytics (if enabled)
775+ if are_analytics_enabled ( & app) . await {
776+ let properties = Some ( serde_json:: json!( {
777+ "session_count" : sessions. len( )
778+ } ) ) ;
779+ let _ = app. track_event ( "manual_sessions_saved" , properties) ;
780+ }
781+
782+ Ok ( ( ) )
783+ }
784+
785+ #[ tauri:: command]
786+ async fn load_manual_sessions ( app : AppHandle ) -> Result < Vec < ManualSession > , String > {
787+ let app_data_dir = app
788+ . path ( )
789+ . app_data_dir ( )
790+ . map_err ( |e| format ! ( "Failed to get app data directory: {}" , e) ) ?;
791+ let file_path = app_data_dir. join ( "manual_sessions.json" ) ;
792+
793+ if !file_path. exists ( ) {
794+ return Ok ( Vec :: new ( ) ) ;
795+ }
796+
797+ let content = fs:: read_to_string ( file_path)
798+ . map_err ( |e| format ! ( "Failed to read manual sessions file: {}" , e) ) ?;
799+ let sessions: Vec < ManualSession > =
800+ serde_json:: from_str ( & content) . map_err ( |e| format ! ( "Failed to parse manual sessions: {}" , e) ) ?;
801+
802+ Ok ( sessions)
803+ }
804+
805+ #[ tauri:: command]
806+ async fn save_manual_session ( session : ManualSession , app : AppHandle ) -> Result < ( ) , String > {
807+ // Load existing sessions
808+ let mut sessions = load_manual_sessions ( app. clone ( ) ) . await ?;
809+
810+ // Remove existing session with same ID if it exists (for updates)
811+ sessions. retain ( |s| s. id != session. id ) ;
812+
813+ // Add the new/updated session
814+ sessions. push ( session) ;
815+
816+ // Save all sessions back
817+ save_manual_sessions ( sessions, app) . await
818+ }
819+
820+ #[ tauri:: command]
821+ async fn delete_manual_session ( session_id : String , app : AppHandle ) -> Result < ( ) , String > {
822+ // Load existing sessions
823+ let mut sessions = load_manual_sessions ( app. clone ( ) ) . await ?;
824+
825+ // Remove the session with the specified ID
826+ sessions. retain ( |s| s. id != session_id) ;
827+
828+ // Save the updated sessions back
829+ save_manual_sessions ( sessions, app) . await
830+ }
831+
832+ #[ tauri:: command]
833+ async fn get_manual_sessions_for_date ( date : String , app : AppHandle ) -> Result < Vec < ManualSession > , String > {
834+ let sessions = load_manual_sessions ( app) . await ?;
835+
836+ // Filter sessions for the specified date
837+ let filtered_sessions: Vec < ManualSession > = sessions
838+ . into_iter ( )
839+ . filter ( |s| s. date == date)
840+ . collect ( ) ;
841+
842+ Ok ( filtered_sessions)
843+ }
844+
745845#[ cfg_attr( mobile, tauri:: mobile_entry_point) ]
746846pub fn run ( ) {
747847 tauri:: async_runtime:: block_on ( async {
@@ -778,7 +878,12 @@ pub fn run() {
778878 update_activity_timeout,
779879 enable_autostart,
780880 disable_autostart,
781- is_autostart_enabled
881+ is_autostart_enabled,
882+ save_manual_sessions,
883+ load_manual_sessions,
884+ save_manual_session,
885+ delete_manual_session,
886+ get_manual_sessions_for_date
782887 ] )
783888 . setup ( |app| {
784889 // Track app started event (if enabled)
0 commit comments