Added start/stop control to Unity process

This commit is contained in:
2025-12-01 09:42:20 +01:00
parent b2c5d08ff4
commit 7df210aaf2
13 changed files with 203 additions and 103 deletions

View File

@@ -65,13 +65,16 @@ var UnityRunner = /** @class */ (function () {
for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i];
}
var callback = args[0];
if (typeof callback !== 'function')
return;
switch (command) {
case 'restart':
var callback = args[0];
if (typeof callback !== 'function')
return;
callback(this.requestRestart());
break;
return callback(this.requestRestart());
case 'stop':
return callback(this.requestStop());
case 'start':
return callback(this.requestStart());
}
};
UnityRunner.prototype.startStatusClock = function () {
@@ -90,6 +93,24 @@ var UnityRunner = /** @class */ (function () {
this.restart(true);
return { succeed: true };
};
UnityRunner.prototype.requestStop = function () {
if (this.state !== 'RUNNING')
return {
succeed: false,
message: 'Cannot stop when process is not running. It is probably restarting already.',
};
this.stop();
return { succeed: true };
};
UnityRunner.prototype.requestStart = function () {
if (this.state !== 'STOPPED')
return {
succeed: false,
message: 'Cannot start when process is already running.',
};
this.start();
return { succeed: true };
};
UnityRunner.prototype.broadcastState = function () {
this._Main.WebServer.socket.emit('unityRunnerState', this.getStatus());
};

File diff suppressed because one or more lines are too long

View File

@@ -45,6 +45,8 @@ var DashboardUnity = /** @class */ (function () {
this.processStatus = document.querySelector('.ntsh_dashboard-unity-processstatus');
this.processInfo = document.querySelector('.ntsh_dashboard-unity-processinfo');
this.restartButton = document.querySelector('.ntsh_dashboard-unity-restart');
this.startButton = document.querySelector('.ntsh_dashboard-unity-start');
this.stopButton = document.querySelector('.ntsh_dashboard-unity-stop');
this.uptimeInfo = document.querySelector('.ntsh_dashboard-unity-uptime');
this.webSocketStatus = document.querySelector('.ntsh_dashboard-unity-websocketstatus');
this.webSocketInfo = document.querySelector('.ntsh_dashboard-unity-websocketinfo');
@@ -73,10 +75,14 @@ var DashboardUnity = /** @class */ (function () {
if (state.state != 'RUNNING') {
state.startTime = -1;
this.restartButton.style.display = 'none';
this.stopButton.style.display = 'none';
}
else {
this.restartButton.style.display = 'flex';
this.stopButton.style.display = 'flex';
}
this.startButton.style.display =
state.state == 'STOPPED' ? 'flex' : 'none';
(0, utils_1.setStatusState)(this.processStatus, {
RUNNING: 'green',
STOPPED: 'gray',
@@ -356,6 +362,18 @@ var DashboardUnity = /** @class */ (function () {
return [2 /*return*/];
});
}); });
this.startButton.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.executeCommand('start', 'Are you sure you want to start the Unity Runner process?');
return [2 /*return*/];
});
}); });
this.stopButton.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.executeCommand('stop', 'Are you sure you want to stop the Unity Runner process?');
return [2 /*return*/];
});
}); });
this.enableOutOfServiceButton.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.executeCommand('enableOutOfService', 'Are you sure you want to set the installation to "Out of Service"?', 'unityWebSocket');

File diff suppressed because one or more lines are too long

View File

@@ -73,21 +73,18 @@ var MenuBar = /** @class */ (function () {
});
}); },
},
{
type: 'icon',
text: 'Shutdown',
materialIcon: 'power_settings_new',
uniqueIdentifier: 'shutdown_installation',
click: function () { return __awaiter(_this, void 0, void 0, function () {
var mobileMenu;
return __generator(this, function (_a) {
mobileMenu = document.querySelector('.mux_mobilemenu');
mobileMenu === null || mobileMenu === void 0 ? void 0 : mobileMenu.click();
this.shutdownInstallation();
return [2 /*return*/];
});
}); },
},
// {
// type: 'icon',
// text: 'Shutdown',
// materialIcon: 'power_settings_new',
// uniqueIdentifier: 'shutdown_installation',
// click: async () => {
// const mobileMenu: HTMLDivElement =
// document.querySelector('.mux_mobilemenu');
// mobileMenu?.click();
// this.shutdownInstallation();
// },
// },
],
right: [
{
@@ -115,21 +112,18 @@ var MenuBar = /** @class */ (function () {
});
}); },
},
{
type: 'normal',
text: 'Shutdown',
materialIcon: 'power_settings_new',
uniqueIdentifier: 'shutdown_installation',
click: function () { return __awaiter(_this, void 0, void 0, function () {
var mobileMenu;
return __generator(this, function (_a) {
mobileMenu = document.querySelector('.mux_mobilemenu');
mobileMenu === null || mobileMenu === void 0 ? void 0 : mobileMenu.click();
this.shutdownInstallation();
return [2 /*return*/];
});
}); },
},
// {
// type: 'normal',
// text: 'Shutdown',
// materialIcon: 'power_settings_new',
// uniqueIdentifier: 'shutdown_installation',
// click: async () => {
// const mobileMenu: HTMLDivElement =
// document.querySelector('.mux_mobilemenu');
// mobileMenu?.click();
// this.shutdownInstallation();
// },
// },
{
type: 'normal',
text: 'Dashboard',

File diff suppressed because one or more lines are too long

View File

@@ -105,8 +105,15 @@
<td>
<div class="ntsh_buttons">
<div class="ntsh_button mux_text ntsh_dashboard-unity-restart">
Restart Process
Restart
</div>
<div class="ntsh_button mux_text ntsh_dashboard-unity-stop">
Stop
</div>
<div class="ntsh_button mux_text ntsh_dashboard-unity-start">
Start
</div>
</div>
</td>
</tr>

View File

@@ -14479,21 +14479,18 @@
});
}); },
},
{
type: 'icon',
text: 'Shutdown',
materialIcon: 'power_settings_new',
uniqueIdentifier: 'shutdown_installation',
click: function () { return __awaiter$4(_this, void 0, void 0, function () {
var mobileMenu;
return __generator$4(this, function (_a) {
mobileMenu = document.querySelector('.mux_mobilemenu');
mobileMenu === null || mobileMenu === void 0 ? void 0 : mobileMenu.click();
this.shutdownInstallation();
return [2 /*return*/];
});
}); },
},
// {
// type: 'icon',
// text: 'Shutdown',
// materialIcon: 'power_settings_new',
// uniqueIdentifier: 'shutdown_installation',
// click: async () => {
// const mobileMenu: HTMLDivElement =
// document.querySelector('.mux_mobilemenu');
// mobileMenu?.click();
// this.shutdownInstallation();
// },
// },
],
right: [
{
@@ -14521,21 +14518,18 @@
});
}); },
},
{
type: 'normal',
text: 'Shutdown',
materialIcon: 'power_settings_new',
uniqueIdentifier: 'shutdown_installation',
click: function () { return __awaiter$4(_this, void 0, void 0, function () {
var mobileMenu;
return __generator$4(this, function (_a) {
mobileMenu = document.querySelector('.mux_mobilemenu');
mobileMenu === null || mobileMenu === void 0 ? void 0 : mobileMenu.click();
this.shutdownInstallation();
return [2 /*return*/];
});
}); },
},
// {
// type: 'normal',
// text: 'Shutdown',
// materialIcon: 'power_settings_new',
// uniqueIdentifier: 'shutdown_installation',
// click: async () => {
// const mobileMenu: HTMLDivElement =
// document.querySelector('.mux_mobilemenu');
// mobileMenu?.click();
// this.shutdownInstallation();
// },
// },
{
type: 'normal',
text: 'Dashboard',
@@ -15732,6 +15726,8 @@
this.processStatus = document.querySelector('.ntsh_dashboard-unity-processstatus');
this.processInfo = document.querySelector('.ntsh_dashboard-unity-processinfo');
this.restartButton = document.querySelector('.ntsh_dashboard-unity-restart');
this.startButton = document.querySelector('.ntsh_dashboard-unity-start');
this.stopButton = document.querySelector('.ntsh_dashboard-unity-stop');
this.uptimeInfo = document.querySelector('.ntsh_dashboard-unity-uptime');
this.webSocketStatus = document.querySelector('.ntsh_dashboard-unity-websocketstatus');
this.webSocketInfo = document.querySelector('.ntsh_dashboard-unity-websocketinfo');
@@ -15760,10 +15756,14 @@
if (state.state != 'RUNNING') {
state.startTime = -1;
this.restartButton.style.display = 'none';
this.stopButton.style.display = 'none';
}
else {
this.restartButton.style.display = 'flex';
this.stopButton.style.display = 'flex';
}
this.startButton.style.display =
state.state == 'STOPPED' ? 'flex' : 'none';
(0, utils_1.setStatusState)(this.processStatus, {
RUNNING: 'green',
STOPPED: 'gray',
@@ -16043,6 +16043,18 @@
return [2 /*return*/];
});
}); });
this.startButton.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.executeCommand('start', 'Are you sure you want to start the Unity Runner process?');
return [2 /*return*/];
});
}); });
this.stopButton.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.executeCommand('stop', 'Are you sure you want to stop the Unity Runner process?');
return [2 /*return*/];
});
}); });
this.enableOutOfServiceButton.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
this.executeCommand('enableOutOfService', 'Are you sure you want to set the installation to "Out of Service"?', 'unityWebSocket');

File diff suppressed because one or more lines are too long

View File

@@ -23,6 +23,12 @@ export class DashboardUnity {
restartButton: HTMLDivElement = document.querySelector(
'.ntsh_dashboard-unity-restart'
);
startButton: HTMLDivElement = document.querySelector(
'.ntsh_dashboard-unity-start'
);
stopButton: HTMLDivElement = document.querySelector(
'.ntsh_dashboard-unity-stop'
);
uptimeInfo: HTMLDivElement = document.querySelector(
'.ntsh_dashboard-unity-uptime'
@@ -103,9 +109,13 @@ export class DashboardUnity {
state.startTime = -1;
this.restartButton.style.display = 'none';
this.stopButton.style.display = 'none';
} else {
this.restartButton.style.display = 'flex';
this.stopButton.style.display = 'flex';
}
this.startButton.style.display =
state.state == 'STOPPED' ? 'flex' : 'none';
setStatusState(
this.processStatus,
@@ -603,6 +613,18 @@ export class DashboardUnity {
'Are you sure you want to restart the Unity Runner process?'
);
});
this.startButton.addEventListener('click', async () => {
this.executeCommand(
'start',
'Are you sure you want to start the Unity Runner process?'
);
});
this.stopButton.addEventListener('click', async () => {
this.executeCommand(
'stop',
'Are you sure you want to stop the Unity Runner process?'
);
});
this.enableOutOfServiceButton.addEventListener('click', async () => {
this.executeCommand(

View File

@@ -44,20 +44,20 @@ export class MenuBar {
this.restartInstallation();
},
},
{
type: 'icon',
text: 'Shutdown',
materialIcon: 'power_settings_new',
uniqueIdentifier: 'shutdown_installation',
// {
// type: 'icon',
// text: 'Shutdown',
// materialIcon: 'power_settings_new',
// uniqueIdentifier: 'shutdown_installation',
click: async () => {
const mobileMenu: HTMLDivElement =
document.querySelector('.mux_mobilemenu');
mobileMenu?.click();
// click: async () => {
// const mobileMenu: HTMLDivElement =
// document.querySelector('.mux_mobilemenu');
// mobileMenu?.click();
this.shutdownInstallation();
},
},
// this.shutdownInstallation();
// },
// },
],
right: [
{
@@ -84,20 +84,20 @@ export class MenuBar {
this.restartInstallation();
},
},
{
type: 'normal',
text: 'Shutdown',
materialIcon: 'power_settings_new',
uniqueIdentifier: 'shutdown_installation',
// {
// type: 'normal',
// text: 'Shutdown',
// materialIcon: 'power_settings_new',
// uniqueIdentifier: 'shutdown_installation',
click: async () => {
const mobileMenu: HTMLDivElement =
document.querySelector('.mux_mobilemenu');
mobileMenu?.click();
// click: async () => {
// const mobileMenu: HTMLDivElement =
// document.querySelector('.mux_mobilemenu');
// mobileMenu?.click();
this.shutdownInstallation();
},
},
// this.shutdownInstallation();
// },
// },
{
type: 'normal',
text: 'Dashboard',

View File

@@ -1,6 +1,6 @@
{
"name": "ntshcontrol",
"version": "2025.11.1",
"version": "2025.11.2",
"main": "dist/Entry.js",
"scripts": {
"start": "node ."

View File

@@ -26,16 +26,19 @@ export class UnityRunner {
}
handle(command: string, ...args: any[]) {
const callback: (response: {
succeed: boolean;
message?: string;
}) => void = args[0];
if (typeof callback !== 'function') return;
switch (command) {
case 'restart':
const callback: (response: {
succeed: boolean;
message?: string;
}) => void = args[0];
if (typeof callback !== 'function') return;
callback(this.requestRestart());
break;
return callback(this.requestRestart());
case 'stop':
return callback(this.requestStop());
case 'start':
return callback(this.requestStart());
}
}
@@ -59,6 +62,29 @@ export class UnityRunner {
return { succeed: true };
}
requestStop(): { succeed: boolean; message?: string } {
if (this.state !== 'RUNNING')
return {
succeed: false,
message:
'Cannot stop when process is not running. It is probably restarting already.',
};
this.stop();
return { succeed: true };
}
requestStart(): { succeed: boolean; message?: string } {
if (this.state !== 'STOPPED')
return {
succeed: false,
message: 'Cannot start when process is already running.',
};
this.start();
return { succeed: true };
}
broadcastState() {
this._Main.WebServer.socket.emit('unityRunnerState', this.getStatus());
}