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

@@ -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());
}