Added ability to start/stop client

This commit is contained in:
Pax1601
2023-12-31 12:02:24 +01:00
parent 7391006a2f
commit c9dc5eb2f5
8 changed files with 84 additions and 14 deletions

View File

@@ -124,12 +124,12 @@ class DCSInstance {
instanceDiv.querySelector(".load .data").innerTexr = this.load;
}
instanceDiv.querySelector(".start-stop-server").innerText = this.webserverOnline ? "Stop server" : "Start server";
instanceDiv.querySelector(".start-stop-server").innerText = this.webserverOnline ? "Stop" : "Start server";
instanceDiv.querySelector(".start-stop-client").innerText = this.webserverOnline ? "Open in browser" : "Start client";
}
}
}
}
}, 1000);
}
@@ -262,7 +262,7 @@ class DCSInstance {
console.log(`Starting server for instance at ${this.folder}`)
const out = fs.openSync(`./${this.name}.log`, 'a');
const err = fs.openSync(`./${this.name}.log`, 'a');
const sub = spawn('npm.cmd', ['run', 'start', '--', '--config', path.join(this.folder, "Config", "olympus.json")], {
const sub = spawn('cscript.exe', ['server.vbs', path.join(this.folder, "Config", "olympus.json")], {
detached: true,
cwd: "../client",
stdio: ['ignore', out, err]
@@ -271,7 +271,20 @@ class DCSInstance {
sub.unref();
}
stopServer() {
startClient() {
console.log(`Starting client for instance at ${this.folder}`)
const out = fs.openSync(`./${this.name}.log`, 'a');
const err = fs.openSync(`./${this.name}.log`, 'a');
const sub = spawn('cscript.exe', ['client.vbs', path.join(this.folder, "Config", "olympus.json")], {
detached: true,
cwd: "../client",
stdio: ['ignore', out, err]
});
sub.unref();
}
stop() {
find('port', this.clientPort)
.then((list) => {
if (list.length !== 1) {
@@ -279,13 +292,17 @@ class DCSInstance {
} else {
if (list[0].name.includes("node.exe")) {
console.log(`Killing process ${list[0].name}`)
process.kill(list[0].pid);
try {
process.kill(list[0].pid);
process.kill(list[0].ppid);
} catch (e) {
process.kill(list[0].pid);
}
}
else {
console.log(list[0])
console.error(`The process listening on the specified port has an incorrect name: ${list[0].name}`)
}
}
}, () => {
console.error("Error retrieving list of processes")

View File

@@ -2,6 +2,7 @@ const DCSInstance = require("./dcsinstance");
const ManagerPage = require("./managerpage");
const ejs = require('ejs');
const { showErrorPopup } = require("./popup");
const { exec } = require("child_process");
class InstancesPage extends ManagerPage {
onCancelClicked;
@@ -25,9 +26,14 @@ class InstancesPage extends ManagerPage {
uninstallButtons[i].onclick = (e) => {this.onUninstallClicked(e);}
}
var startButtons = this.element.querySelectorAll(".start-stop-server");
for (let i = 0; i < startButtons.length; i++) {
startButtons[i].onclick = (e) => {this.onStartStopClicked(e);}
var startStopServerButtons = this.element.querySelectorAll(".start-stop-server");
for (let i = 0; i < startStopServerButtons.length; i++) {
startStopServerButtons[i].onclick = (e) => {this.onStartStopServerClicked(e);}
}
var startStopClientButtons = this.element.querySelectorAll(".start-stop-client");
for (let i = 0; i < startStopClientButtons.length; i++) {
startStopClientButtons[i].onclick = (e) => {this.onStartStopClientClicked(e);}
}
this.element.querySelector(".cancel").addEventListener("click", (e) => this.onCancelClicked(e));
@@ -38,9 +44,14 @@ class InstancesPage extends ManagerPage {
this.setSelectedInstance((await DCSInstance.getInstances()).find((instance) => {return instance.folder === e.target.closest('.option').dataset.folder}));
}
async onStartStopClicked(e) {
async onStartStopServerClicked(e) {
var instance = (await DCSInstance.getInstances()).find((instance) => {return instance.folder === e.target.closest('.option').dataset.folder});
instance.webserverOnline? instance.stopServer(): instance.startServer();
instance.webserverOnline? instance.stop(): instance.startServer();
}
async onStartStopClientClicked(e) {
var instance = (await DCSInstance.getInstances()).find((instance) => {return instance.folder === e.target.closest('.option').dataset.folder});
instance.webserverOnline? exec(`start http://localhost:${instance.clientPort}`): instance.startClient();
}
async onUninstallClicked(e) {

View File

@@ -6,7 +6,7 @@ const ResultPage = require('./result');
const InstancesPage = require('./instances');
const DCSInstance = require('./dcsinstance');
const { showErrorPopup } = require('./popup');
const { showErrorPopup, showWaitPopup } = require('./popup');
const { fixInstances } = require('./filesystem');
class Manager {
@@ -23,6 +23,7 @@ class Manager {
return instance.installed && instance.error;
})) {
showErrorPopup("One or more Olympus instances are corrupted or need updating. Press Close to fix this.", async () => {
showWaitPopup("Please wait while your instances are being fixed.")
fixInstances(instances.filter((instance) => {
return instance.installed && instance.error;
})).then(