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

@ -1,5 +1,7 @@
@echo OFF
SET PATH=%PATH%;%WINDIR%\System32;%WINDIR%\System32\WindowsPowerShell\v1.0;
WHERE /q powershell
if %ERRORLEVEL% NEQ 0 (
.\scripts\install.bat

32
manager/DCS.openbeta.log Normal file
View File

@ -0,0 +1,32 @@
^CTerminare il processo batch (S/N)?
Microsoft (R) Windows Script Host Versione 5.812
Copyright (C) Microsoft Corporation. Tutti i diritti riservati.
C:\Users\Davide Passoni\Documents\DCSOlympus\client\client.vbs(1, 1) Errore di run-time di Microsoft VBScript: Indice non incluso nell'intervallo
Microsoft (R) Windows Script Host Versione 5.812
Copyright (C) Microsoft Corporation. Tutti i diritti riservati.
C:\Users\Davide Passoni\Documents\DCSOlympus\client\client.vbs(1, 1) Errore di run-time di Microsoft VBScript: Indice non incluso nell'intervallo
Microsoft (R) Windows Script Host Versione 5.812
Copyright (C) Microsoft Corporation. Tutti i diritti riservati.
Microsoft (R) Windows Script Host Versione 5.812
Copyright (C) Microsoft Corporation. Tutti i diritti riservati.
Microsoft (R) Windows Script Host Versione 5.812
Copyright (C) Microsoft Corporation. Tutti i diritti riservati.
Microsoft (R) Windows Script Host Versione 5.812
Copyright (C) Microsoft Corporation. Tutti i diritti riservati.
Microsoft (R) Windows Script Host Versione 5.812
Copyright (C) Microsoft Corporation. Tutti i diritti riservati.
Microsoft (R) Windows Script Host Versione 5.812
Copyright (C) Microsoft Corporation. Tutti i diritti riservati.
Microsoft (R) Windows Script Host Versione 5.812
Copyright (C) Microsoft Corporation. Tutti i diritti riservati.

View File

@ -104,6 +104,10 @@
font-weight: normal;
}
#manager-instances .start-stop-client {
margin-right: auto;
}
</style>
<div id="manager-instances">
<div class="content">
@ -163,7 +167,7 @@
<div class="button uninstall">Uninstall</div>
<% } else { %>
<div class="button start-stop-server">Start server</div>
<!--<div class="button start-client">Start client</div>-->
<div class="button start-stop-client">Start client</div>
<% } %>
</div>
</div>

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(

View File

@ -5,6 +5,8 @@ const path = require('path');
let window;
process.env['PATH'] = process.env['PATH'] + "%WINDIR%\\System32;"
function createWindow() {
const window = new electronBrowserWindow({
width: 1500,

View File

@ -221,7 +221,7 @@ body {
border: 1px solid var(--offwhite);
}
.edit, .start-stop-server, .start-client {
.edit, .start-stop-server, .start-stop-client {
color: var(--offwhite);
background-color: var(--blue);
}
@ -485,6 +485,7 @@ input {
flex-direction: row;
width: 100%;
justify-content: space-between;
column-gap: 10px;
}
.instance-info .info {