Skip to content

Commit a94b1c3

Browse files
committed
feat: executing hello node
1 parent 810d592 commit a94b1c3

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed
-37.8 MB
Binary file not shown.

src/App.tsx

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ function App() {
1414
const [executing, setExecuting] = useState<string | undefined>();
1515
const [executed, setExecuted] = useState<string | undefined>();
1616

17-
useEffect(() => {
18-
greet();
17+
async function startLogging() {
18+
await greet();
1919
//get the url of the hello node
2020
setExecutableurl(GetHelloNodeUrl());
2121
// detect if autostart is enabled
@@ -24,7 +24,10 @@ function App() {
2424
setEnabledAutostart(true);
2525
}
2626
});
27+
}
2728

29+
useEffect(() => {
30+
startLogging();
2831
//listen the event "command_executed"
2932
listen("command_executed", (event) => {
3033
setExecuted(event.payload as string);
@@ -37,36 +40,47 @@ function App() {
3740
};
3841
}, [logs]);
3942

40-
useEffect(() => {
43+
async function verifyHelloNodeInstallation() {
4144
if (!executableurl) return;
4245
// check if hello node is installed (from localstorage)
4346
let helloNodeInstalled = localStorage.getItem("hello-node-installed");
4447
if (!helloNodeInstalled) {
45-
setExecuting("curl");
4648
// 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");
5650
addLog("Installing Hello Node");
51+
await ExecuteCommand("curl", ["-O", "-L", executableurl], true);
5752
} else {
5853
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, []);
5959
}
60+
}
61+
62+
useEffect(() => {
63+
verifyHelloNodeInstallation();
6064
}, [executableurl]);
6165

6266
// detect if command (executing) is finished
6367
useEffect(() => {
6468
if (!executed) return;
65-
if(!executing) return;
66-
if(!executed.includes(executing)) return;
69+
if (!executing) return;
70+
if (!executed.includes(executing)) return;
6771
setExecuting(undefined);
6872
setExecuted(undefined);
6973
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+
}
7084
}, [executed]);
7185

7286
async function switchAutostart() {

0 commit comments

Comments
 (0)