@@ -14,8 +14,8 @@ function App() {
14
14
const [ executing , setExecuting ] = useState < string | undefined > ( ) ;
15
15
const [ executed , setExecuted ] = useState < string | undefined > ( ) ;
16
16
17
- useEffect ( ( ) => {
18
- greet ( ) ;
17
+ async function startLogging ( ) {
18
+ await greet ( ) ;
19
19
//get the url of the hello node
20
20
setExecutableurl ( GetHelloNodeUrl ( ) ) ;
21
21
// detect if autostart is enabled
@@ -24,7 +24,10 @@ function App() {
24
24
setEnabledAutostart ( true ) ;
25
25
}
26
26
} ) ;
27
+ }
27
28
29
+ useEffect ( ( ) => {
30
+ startLogging ( ) ;
28
31
//listen the event "command_executed"
29
32
listen ( "command_executed" , ( event ) => {
30
33
setExecuted ( event . payload as string ) ;
@@ -37,36 +40,47 @@ function App() {
37
40
} ;
38
41
} , [ logs ] ) ;
39
42
40
- useEffect ( ( ) => {
43
+ async function verifyHelloNodeInstallation ( ) {
41
44
if ( ! executableurl ) return ;
42
45
// check if hello node is installed (from localstorage)
43
46
let helloNodeInstalled = localStorage . getItem ( "hello-node-installed" ) ;
44
47
if ( ! helloNodeInstalled ) {
45
- setExecuting ( "curl" ) ;
46
48
// install hello node
47
- ExecuteCommand (
48
- "curl" ,
49
- [ "-O" , "-L" , executableurl ] ,
50
- true
51
- ) . then ( ( ) => {
52
- // update localstorage
53
- // localStorage.setItem("hello-node-installed", "true");
54
- addLog ( "Hello Node installed" ) ;
55
- } ) ;
49
+ setExecuting ( "curl" ) ;
56
50
addLog ( "Installing Hello Node" ) ;
51
+ await ExecuteCommand ( "curl" , [ "-O" , "-L" , executableurl ] , true ) ;
57
52
} else {
58
53
addLog ( "Hello Node already installed" ) ;
54
+
55
+ // start hello node
56
+ addLog ( "Starting Hello Node" ) ;
57
+ const executableName = executableurl ?. split ( "/" ) . pop ( ) ;
58
+ await ExecuteCommand ( "./" + executableName , [ ] ) ;
59
59
}
60
+ }
61
+
62
+ useEffect ( ( ) => {
63
+ verifyHelloNodeInstallation ( ) ;
60
64
} , [ executableurl ] ) ;
61
65
62
66
// detect if command (executing) is finished
63
67
useEffect ( ( ) => {
64
68
if ( ! executed ) return ;
65
- if ( ! executing ) return ;
66
- if ( ! executed . includes ( executing ) ) return ;
69
+ if ( ! executing ) return ;
70
+ if ( ! executed . includes ( executing ) ) return ;
67
71
setExecuting ( undefined ) ;
68
72
setExecuted ( undefined ) ;
69
73
addLog ( "Command waited: " + executed ) ;
74
+ if ( executed === "curl" ) {
75
+ // update localstorage
76
+ localStorage . setItem ( "hello-node-installed" , "true" ) ;
77
+ addLog ( "Hello Node installed" ) ;
78
+
79
+ // start hello node
80
+ addLog ( "Starting Hello Node" ) ;
81
+ const executableName = executableurl ?. split ( "/" ) . pop ( ) ;
82
+ ExecuteCommand ( "./" + executableName , [ ] ) ;
83
+ }
70
84
} , [ executed ] ) ;
71
85
72
86
async function switchAutostart ( ) {
0 commit comments