Added basic control panel
This commit is contained in:
62
dist/Unity/UnityRunner.js
vendored
62
dist/Unity/UnityRunner.js
vendored
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
||||
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
@@ -45,10 +45,11 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.UnityRunner = void 0;
|
||||
exports.StartOrigin = exports.UnityBuildStateColors = exports.UnityRunner = void 0;
|
||||
var fs_extra_1 = require("fs-extra");
|
||||
var child_process_1 = require("child_process");
|
||||
var Utils_1 = require("../Utils");
|
||||
var Status_1 = require("../Status");
|
||||
var PREFIX = '[UnityRunner]';
|
||||
var LOG_OUTPUT = !process.argv.includes('--no-output-log');
|
||||
var UnityRunner = /** @class */ (function () {
|
||||
@@ -70,11 +71,11 @@ var UnityRunner = /** @class */ (function () {
|
||||
return;
|
||||
switch (command) {
|
||||
case 'restart':
|
||||
return callback(this.requestRestart());
|
||||
return callback(this.requestRestart(StartOrigin.Manual));
|
||||
case 'stop':
|
||||
return callback(this.requestStop());
|
||||
case 'start':
|
||||
return callback(this.requestStart());
|
||||
return callback(this.requestStart(StartOrigin.Manual));
|
||||
}
|
||||
};
|
||||
UnityRunner.prototype.startStatusClock = function () {
|
||||
@@ -84,13 +85,13 @@ var UnityRunner = /** @class */ (function () {
|
||||
_this.broadcastState();
|
||||
}, 3000);
|
||||
};
|
||||
UnityRunner.prototype.requestRestart = function () {
|
||||
UnityRunner.prototype.requestRestart = function (startOrigin) {
|
||||
if (this.state !== 'RUNNING')
|
||||
return {
|
||||
succeed: false,
|
||||
message: 'Cannot restart when process is not running. It is probably restarting already.',
|
||||
};
|
||||
this.restart(true);
|
||||
this.restart(startOrigin, true);
|
||||
return { succeed: true };
|
||||
};
|
||||
UnityRunner.prototype.requestStop = function () {
|
||||
@@ -102,23 +103,29 @@ var UnityRunner = /** @class */ (function () {
|
||||
this.stop();
|
||||
return { succeed: true };
|
||||
};
|
||||
UnityRunner.prototype.requestStart = function () {
|
||||
UnityRunner.prototype.requestStart = function (startOrigin) {
|
||||
if (this.state !== 'STOPPED')
|
||||
return {
|
||||
succeed: false,
|
||||
message: 'Cannot start when process is already running.',
|
||||
};
|
||||
this.start();
|
||||
this.start(startOrigin);
|
||||
return { succeed: true };
|
||||
};
|
||||
UnityRunner.prototype.broadcastState = function () {
|
||||
this._Main.WebServer.socket.emit('unityRunnerState', this.getStatus());
|
||||
};
|
||||
UnityRunner.prototype.setInfo = function (message, error, state) {
|
||||
var _a;
|
||||
if (state === void 0) { state = 'PROBLEM'; }
|
||||
this.message = message;
|
||||
this.error = error;
|
||||
this.state = state;
|
||||
this._Main.Status.update(Status_1.StatusType.UnityBuild, exports.UnityBuildStateColors[state], (_a = message !== null && message !== void 0 ? message : error) !== null && _a !== void 0 ? _a : '', {
|
||||
reboot: state === 'PROBLEM' || state === 'RUNNING',
|
||||
start: state === 'STOPPED',
|
||||
stop: state === 'RUNNING',
|
||||
});
|
||||
this.broadcastState();
|
||||
if (error != null)
|
||||
this._Main.Twilio.sendError('UnityRunner', error);
|
||||
@@ -174,9 +181,9 @@ var UnityRunner = /** @class */ (function () {
|
||||
});
|
||||
});
|
||||
};
|
||||
UnityRunner.prototype.restart = function () {
|
||||
return __awaiter(this, arguments, void 0, function (instant) {
|
||||
if (instant === void 0) { instant = false; }
|
||||
UnityRunner.prototype.restart = function (origin, instant) {
|
||||
if (instant === void 0) { instant = false; }
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
@@ -186,6 +193,7 @@ var UnityRunner = /** @class */ (function () {
|
||||
this._Main.WebServer.Calibration.hasCalibrationImage = false;
|
||||
clearInterval(this.statusClock);
|
||||
this.startTime = -1;
|
||||
this.startOrigin = null;
|
||||
this.broadcastState();
|
||||
if (!!instant) return [3 /*break*/, 2];
|
||||
return [4 /*yield*/, (0, Utils_1.delay)(2000)];
|
||||
@@ -216,7 +224,7 @@ var UnityRunner = /** @class */ (function () {
|
||||
case 7:
|
||||
_a.sent();
|
||||
_a.label = 8;
|
||||
case 8: return [4 /*yield*/, this.start()];
|
||||
case 8: return [4 /*yield*/, this.start(this.startOrigin)];
|
||||
case 9:
|
||||
_a.sent();
|
||||
return [2 /*return*/];
|
||||
@@ -224,11 +232,11 @@ var UnityRunner = /** @class */ (function () {
|
||||
});
|
||||
});
|
||||
};
|
||||
UnityRunner.prototype.start = function () {
|
||||
UnityRunner.prototype.start = function (origin) {
|
||||
var _a, _b, _c;
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var path, fileName;
|
||||
var _this = this;
|
||||
var _a, _b, _c;
|
||||
return __generator(this, function (_d) {
|
||||
switch (_d.label) {
|
||||
case 0:
|
||||
@@ -285,11 +293,11 @@ var UnityRunner = /** @class */ (function () {
|
||||
if (_this.restartTriggered)
|
||||
return;
|
||||
_this.setInfo('Process exited', "Process exited with code ".concat(code, " and signal ").concat(signal), 'PROBLEM');
|
||||
_this.restart();
|
||||
_this.restart(_this.startOrigin);
|
||||
});
|
||||
this.process.on('error', function (err) {
|
||||
_this.setInfo('Process error', err.message);
|
||||
_this.restart();
|
||||
_this.restart(_this.startOrigin);
|
||||
});
|
||||
(_b = this.process.stdout) === null || _b === void 0 ? void 0 : _b.on('data', function (data) {
|
||||
var lines = data
|
||||
@@ -317,6 +325,7 @@ var UnityRunner = /** @class */ (function () {
|
||||
_this.output.current.push(formattedLine);
|
||||
});
|
||||
});
|
||||
this.startOrigin = origin;
|
||||
this.startStatusClock();
|
||||
setTimeout(function () {
|
||||
var _a, _b;
|
||||
@@ -346,4 +355,23 @@ var UnityRunner = /** @class */ (function () {
|
||||
return UnityRunner;
|
||||
}());
|
||||
exports.UnityRunner = UnityRunner;
|
||||
var State;
|
||||
(function (State) {
|
||||
State["Green"] = "GREEN";
|
||||
State["Yellow"] = "YELLOW";
|
||||
State["Red"] = "RED";
|
||||
State["Gray"] = "GRAY";
|
||||
})(State || (State = {}));
|
||||
exports.UnityBuildStateColors = {
|
||||
RUNNING: State.Green,
|
||||
STOPPED: State.Gray,
|
||||
STARTING: State.Yellow,
|
||||
PROBLEM: State.Red,
|
||||
};
|
||||
var StartOrigin;
|
||||
(function (StartOrigin) {
|
||||
StartOrigin["Timer"] = "TIMER";
|
||||
StartOrigin["Manual"] = "MANUAL";
|
||||
StartOrigin["Startup"] = "STARTUP";
|
||||
})(StartOrigin || (exports.StartOrigin = StartOrigin = {}));
|
||||
//# sourceMappingURL=UnityRunner.js.map
|
||||
Reference in New Issue
Block a user