Added start/stop control to Unity process
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user