Implemented shutdown through UI and implemented router check

This commit is contained in:
2025-11-28 10:23:57 +01:00
parent 368f60d7b6
commit b2c5d08ff4
29 changed files with 639 additions and 71 deletions

69
dist/Main.js vendored
View File

@@ -46,6 +46,9 @@ var UnityRunner_1 = require("./Unity/UnityRunner");
var UnityWebSocket_1 = require("./Unity/UnityWebSocket");
var Twilio_1 = require("./Twilio");
var Utils_1 = require("./Utils");
var ping = require("ping");
var Shutdown_1 = require("./Shutdown");
var PREFIX = '[Main]';
var Main = /** @class */ (function () {
function Main() {
this.dataPath = (0, path_1.join)((0, os_1.homedir)(), 'MorphixProductions', 'NTSHControl');
@@ -65,14 +68,17 @@ var Main = /** @class */ (function () {
case 0: return [4 /*yield*/, this.ConfigurationManager.load()];
case 1:
_b.sent();
return [4 /*yield*/, this.WebServer.listen()];
return [4 /*yield*/, this.waitForRouter()];
case 2:
_b.sent();
return [4 /*yield*/, this.Twilio.load()];
return [4 /*yield*/, this.WebServer.listen()];
case 3:
_b.sent();
return [4 /*yield*/, this.CameraRunner.connect()];
return [4 /*yield*/, this.Twilio.load()];
case 4:
_b.sent();
return [4 /*yield*/, this.CameraRunner.connect()];
case 5:
_b.sent();
setTimeout(function () {
_this.UnityRunner.start();
@@ -126,6 +132,63 @@ var Main = /** @class */ (function () {
});
});
};
Main.prototype.shutdown = function () {
return __awaiter(this, void 0, void 0, function () {
var doShutdown;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
console.log('Stopping UnityRunner...');
return [4 /*yield*/, this.UnityRunner.stop()];
case 1:
_a.sent();
doShutdown = process.argv.includes('--no-shutdown')
? false
: true;
if (doShutdown) {
console.log('Shutting down system...');
(0, Shutdown_1.shutdown)();
}
else {
console.log('Shutdown skipped due to --no-shutdown flag.');
}
process.exit(0);
return [2 /*return*/];
}
});
});
};
Main.prototype.waitForRouter = function () {
var _this = this;
var _a;
if (((_a = this.Config.router) === null || _a === void 0 ? void 0 : _a.waitForStartup) !== true)
return;
return new Promise(function (resolve) {
var check = function () {
console.log(PREFIX, 'Waiting for router...');
ping.sys.probe(_this.Config.router.ip, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
var alive = _b.alive;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
if (!alive) return [3 /*break*/, 2];
console.log(PREFIX, 'Router is online');
return [4 /*yield*/, (0, Utils_1.delay)(3000)];
case 1:
_c.sent();
return [2 /*return*/, resolve()];
case 2: return [4 /*yield*/, (0, Utils_1.delay)(1000)];
case 3:
_c.sent();
check();
return [2 /*return*/];
}
});
}); });
};
check();
});
};
return Main;
}());
exports.Main = Main;