@@ -5,7 +5,7 @@ import { arch, platform } from "@tauri-apps/plugin-os";
5
5
import { download } from "@tauri-apps/plugin-upload" ;
6
6
import { fetch } from "@tauri-apps/plugin-http" ;
7
7
import { Child , Command } from "@tauri-apps/plugin-shell" ;
8
- import { mkdir , exists } from "@tauri-apps/plugin-fs" ;
8
+ import { mkdir , exists , readDir , BaseDirectory } from "@tauri-apps/plugin-fs" ;
9
9
import "./App.css" ;
10
10
11
11
const urlNetwork = "https://test.net.zknet.io" ;
@@ -28,6 +28,14 @@ const getPlatformArch = (): string => {
28
28
}
29
29
} ;
30
30
31
+ // Get networks with previously downloaded assets
32
+ const getNetworks = async ( ) => {
33
+ const entries = await readDir ( "networks" , {
34
+ baseDir : BaseDirectory . AppLocalData ,
35
+ } ) ;
36
+ return entries . filter ( ( i ) => i . isDirectory ) . map ( ( i ) => i . name ) ;
37
+ } ;
38
+
31
39
function App ( ) {
32
40
const [ msg , setMsg ] = useState ( "" ) ;
33
41
const [ msgType , setMsgType ] = useState ( "" ) ; // error, info, success
@@ -36,12 +44,18 @@ function App() {
36
44
const [ clientPid , setClientPid ] = useState ( 0 ) ;
37
45
const [ platformArch , setPlatformArch ] = useState ( "" ) ;
38
46
const [ platformSupported , setPlatformSupported ] = useState ( false ) ;
47
+ const [ networks , setNetworks ] = useState < string [ ] > ( [ ] ) ;
39
48
49
+ // run once on startup (twice in dev mode)
40
50
useEffect ( ( ) => {
41
51
try {
42
52
log . info ( `Platform: ${ platform ( ) } -${ arch ( ) } ` ) ;
43
53
setPlatformArch ( getPlatformArch ( ) ) ;
44
54
setPlatformSupported ( true ) ;
55
+
56
+ ( async ( ) => {
57
+ setNetworks ( await getNetworks ( ) ) ;
58
+ } ) ( ) ;
45
59
} catch ( error : any ) {
46
60
log . error ( `${ error } ` ) ;
47
61
setMsgType ( "error" ) ;
@@ -55,6 +69,7 @@ function App() {
55
69
setClientPid ( pid ) ;
56
70
setMsgType ( "info" ) ;
57
71
setMsg ( "" ) ;
72
+ setNetworks ( await getNetworks ( ) ) ;
58
73
} catch ( error : any ) {
59
74
log . error ( `${ error } ` ) ;
60
75
setMsgType ( "error" ) ;
@@ -210,7 +225,13 @@ function App() {
210
225
className = "input focus:outline-none join-item"
211
226
onChange = { ( e ) => setNetworkId ( e . currentTarget . value ) }
212
227
placeholder = "Enter a network_id..."
228
+ list = "networks"
213
229
/>
230
+ < datalist id = "networks" >
231
+ { networks . map ( ( n ) => (
232
+ < option key = { n } value = { n } />
233
+ ) ) }
234
+ </ datalist >
214
235
< button className = "btn btn-primary join-item" type = "submit" >
215
236
Connect
216
237
</ button >
0 commit comments