Change a bit on startup #7

Took 33 minutes
This commit is contained in:
Tobias Hopp 2022-12-02 11:06:55 +01:00
parent 3e522ceb0a
commit 852dd01152
2 changed files with 30 additions and 14 deletions

View File

@ -2,6 +2,7 @@ import * as dns from "dns";
import * as fs from "fs";
import * as https from 'https';
import path from "path";
import {Settings} from "./Settings";
export class Utils {
public static checkInternet(): Promise<boolean> {
@ -61,4 +62,26 @@ export class Utils {
return fs.existsSync("./public/images/" + id + ".png");
}
static waitForReady(timeout: number = 0): Promise<void> {
let millis = 0;
return new Promise((resolve, reject) => {
function wait() {
millis += 100;
if (Settings.setupDone) {
resolve()
return;
}
if (timeout != 0 && timeout <= millis) {
reject();
return;
}
setTimeout(() => wait(), 100);
}
setTimeout(wait, 100);
});
}
}

View File

@ -33,22 +33,15 @@ const wsApp = new WebsocketApp();
}
function checkStart() {
setTimeout(async () => {
if (!Settings.setupDone) {
checkStart();
return;
}
Settings.saveSettings();
log("Waiting for ready status...");
await Utils.waitForReady();
log("Check OK, starting...");
await init();
setInterval(refresh, 1000 * 60);
iTender.setStatus(iTenderStatus.READY);
}, 1000);
}
Settings.saveSettings();
checkStart();
log("Check OK, starting...");
await init();
setInterval(refresh, 1000 * 60);
iTender.setStatus(iTenderStatus.READY);
} catch (e) {
console.error("---- ERROR ----");