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++) { for (var _i = 1; _i < arguments.length; _i++) {
args[_i - 1] = arguments[_i]; args[_i - 1] = arguments[_i];
} }
switch (command) {
case 'restart':
var callback = args[0]; var callback = args[0];
if (typeof callback !== 'function') if (typeof callback !== 'function')
return; return;
callback(this.requestRestart()); switch (command) {
break; case 'restart':
return callback(this.requestRestart());
case 'stop':
return callback(this.requestStop());
case 'start':
return callback(this.requestStart());
} }
}; };
UnityRunner.prototype.startStatusClock = function () { UnityRunner.prototype.startStatusClock = function () {
@@ -90,6 +93,24 @@ var UnityRunner = /** @class */ (function () {
this.restart(true); this.restart(true);
return { succeed: 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 () { UnityRunner.prototype.broadcastState = function () {
this._Main.WebServer.socket.emit('unityRunnerState', this.getStatus()); 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.processStatus = document.querySelector('.ntsh_dashboard-unity-processstatus');
this.processInfo = document.querySelector('.ntsh_dashboard-unity-processinfo'); this.processInfo = document.querySelector('.ntsh_dashboard-unity-processinfo');
this.restartButton = document.querySelector('.ntsh_dashboard-unity-restart'); 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.uptimeInfo = document.querySelector('.ntsh_dashboard-unity-uptime');
this.webSocketStatus = document.querySelector('.ntsh_dashboard-unity-websocketstatus'); this.webSocketStatus = document.querySelector('.ntsh_dashboard-unity-websocketstatus');
this.webSocketInfo = document.querySelector('.ntsh_dashboard-unity-websocketinfo'); this.webSocketInfo = document.querySelector('.ntsh_dashboard-unity-websocketinfo');
@@ -73,10 +75,14 @@ var DashboardUnity = /** @class */ (function () {
if (state.state != 'RUNNING') { if (state.state != 'RUNNING') {
state.startTime = -1; state.startTime = -1;
this.restartButton.style.display = 'none'; this.restartButton.style.display = 'none';
this.stopButton.style.display = 'none';
} }
else { else {
this.restartButton.style.display = 'flex'; 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, { (0, utils_1.setStatusState)(this.processStatus, {
RUNNING: 'green', RUNNING: 'green',
STOPPED: 'gray', STOPPED: 'gray',
@@ -356,6 +362,18 @@ var DashboardUnity = /** @class */ (function () {
return [2 /*return*/]; 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 () { this.enableOutOfServiceButton.addEventListener('click', function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) { return __generator(this, function (_a) {
this.executeCommand('enableOutOfService', 'Are you sure you want to set the installation to "Out of Service"?', 'unityWebSocket'); 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', // type: 'icon',
text: 'Shutdown', // text: 'Shutdown',
materialIcon: 'power_settings_new', // materialIcon: 'power_settings_new',
uniqueIdentifier: 'shutdown_installation', // uniqueIdentifier: 'shutdown_installation',
click: function () { return __awaiter(_this, void 0, void 0, function () { // click: async () => {
var mobileMenu; // const mobileMenu: HTMLDivElement =
return __generator(this, function (_a) { // document.querySelector('.mux_mobilemenu');
mobileMenu = document.querySelector('.mux_mobilemenu'); // mobileMenu?.click();
mobileMenu === null || mobileMenu === void 0 ? void 0 : mobileMenu.click(); // this.shutdownInstallation();
this.shutdownInstallation(); // },
return [2 /*return*/]; // },
});
}); },
},
], ],
right: [ right: [
{ {
@@ -115,21 +112,18 @@ var MenuBar = /** @class */ (function () {
}); });
}); }, }); },
}, },
{ // {
type: 'normal', // type: 'normal',
text: 'Shutdown', // text: 'Shutdown',
materialIcon: 'power_settings_new', // materialIcon: 'power_settings_new',
uniqueIdentifier: 'shutdown_installation', // uniqueIdentifier: 'shutdown_installation',
click: function () { return __awaiter(_this, void 0, void 0, function () { // click: async () => {
var mobileMenu; // const mobileMenu: HTMLDivElement =
return __generator(this, function (_a) { // document.querySelector('.mux_mobilemenu');
mobileMenu = document.querySelector('.mux_mobilemenu'); // mobileMenu?.click();
mobileMenu === null || mobileMenu === void 0 ? void 0 : mobileMenu.click(); // this.shutdownInstallation();
this.shutdownInstallation(); // },
return [2 /*return*/]; // },
});
}); },
},
{ {
type: 'normal', type: 'normal',
text: 'Dashboard', text: 'Dashboard',

File diff suppressed because one or more lines are too long

View File

@@ -105,8 +105,15 @@
<td> <td>
<div class="ntsh_buttons"> <div class="ntsh_buttons">
<div class="ntsh_button mux_text ntsh_dashboard-unity-restart"> <div class="ntsh_button mux_text ntsh_dashboard-unity-restart">
Restart Process Restart
</div> </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> </div>
</td> </td>
</tr> </tr>

View File

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

View File

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

View File

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

View File

@@ -26,16 +26,19 @@ export class UnityRunner {
} }
handle(command: string, ...args: any[]) { handle(command: string, ...args: any[]) {
switch (command) {
case 'restart':
const callback: (response: { const callback: (response: {
succeed: boolean; succeed: boolean;
message?: string; message?: string;
}) => void = args[0]; }) => void = args[0];
if (typeof callback !== 'function') return; if (typeof callback !== 'function') return;
callback(this.requestRestart()); switch (command) {
break; case 'restart':
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 }; 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() { broadcastState() {
this._Main.WebServer.socket.emit('unityRunnerState', this.getStatus()); this._Main.WebServer.socket.emit('unityRunnerState', this.getStatus());
} }