1- import {
2- exists ,
3- BaseDirectory ,
4- readTextFile ,
5- } from "@tauri-apps/plugin-fs" ;
6- import { useEffect } from "react" ;
1+ import * as stylex from "@stylexjs/stylex" ;
2+ import { exists , BaseDirectory , readTextFile } from "@tauri-apps/plugin-fs" ;
3+ import { useEffect , useState } from "react" ;
74import useRequestStore from "./stores/request_store/index.ts" ;
85import { useNavigate } from "react-router" ;
9-
10- // TODO: have different file for local and prod version of app
11- const session_file = "last_session.json" ;
12-
13- // import { listen } from "@tauri-apps/api/event";
6+ import { LoadingSize , LoadingSpinner } from "@controlkit/ui" ;
7+ import { appDataDir } from "@tauri-apps/api/path" ;
8+
9+ const session_file = import . meta. env . DEV ? "last_session_dev_mode.json" : "last_session.json" ;
10+ const roaming_dir = await appDataDir ( ) ; // "com.construct.app";
11+
12+ const styles = stylex . create ( {
13+ wrapper : {
14+ backgroundColor : "var(--color-bg)" ,
15+ position : "absolute" ,
16+ width : "100%" ,
17+ height : "calc(100% - var(--navbar-height))" ,
18+ zIndex : 1000 ,
19+ display : "flex" ,
20+ flexDirection : "column" ,
21+ gap : "1rem" ,
22+ justifyContent : "center" ,
23+ alignItems : "center" ,
24+ } ,
25+ } ) ;
1426
1527export default function SessionSaveAndLoadManager ( ) {
1628 const navigate = useNavigate ( ) ;
1729
30+ const [ loading , setLoading ] = useState < boolean > ( true ) ;
31+
1832 const setAllDataFromSessionSave = useRequestStore (
1933 ( state ) => state . setAllDataFromSessionSave ,
2034 ) ;
@@ -44,10 +58,8 @@ export default function SessionSaveAndLoadManager() {
4458 // }
4559 // };
4660
47- // // TODO: need to figure this out in case of alt f4 or other types of window close events
48- // // listen("tauri://close-requested", async (event) => {
49- // // await AttemptToSaveLocalSession();
50- // // });
61+ // TODO: need to figure this out in case of alt f4 or other types of window close events
62+
5163
5264 // window.addEventListener("keydown", handleKeyDown);
5365
@@ -56,20 +68,19 @@ export default function SessionSaveAndLoadManager() {
5668 // };
5769 } , [ ] ) ;
5870
59-
6071 async function SetLocalSessionIfExists ( ) {
6172 // TODO: https://tauri.app/plugin/file-system/#read
6273 // probably should use readTextFileLines or Binary data format for session file instead of raw json
6374 // but its fine for now
6475
6576 // TODO: create a separate file within appConfig for settings store in the future
6677
67- const previous_session_exists = await exists ( session_file , {
78+ const previous_session_exists = await exists ( ` ${ roaming_dir } / ${ session_file } ` , {
6879 baseDir : BaseDirectory . AppData ,
6980 } ) ;
7081
7182 if ( previous_session_exists ) {
72- const session_json = await readTextFile ( session_file , {
83+ const session_json = await readTextFile ( ` ${ roaming_dir } / ${ session_file } ` , {
7384 baseDir : BaseDirectory . AppData ,
7485 } ) ;
7586
@@ -95,8 +106,18 @@ export default function SessionSaveAndLoadManager() {
95106 } else {
96107 console . log ( "doesnt exists" ) ;
97108 }
109+
110+ setLoading ( false ) ;
98111 }
99112
100- return < > </ > ;
113+ return (
114+ < >
115+ { loading && (
116+ < div { ...stylex . props ( styles . wrapper ) } >
117+ < LoadingSpinner size = { LoadingSize . LARGE } />
118+ < p > Checking for local session...</ p >
119+ </ div >
120+ ) }
121+ </ >
122+ ) ;
101123}
102-
0 commit comments