mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Implement more wizard page, result page still wip
This commit is contained in:
@@ -1,102 +0,0 @@
|
||||
const ManagerPage = require("./managerpage");
|
||||
const ejs = require('ejs')
|
||||
const { logger } = require("./filesystem")
|
||||
|
||||
/** Connections page, allows the user to set the ports and address for each Olympus instance
|
||||
*
|
||||
*/
|
||||
class ConnectionsPage extends ManagerPage {
|
||||
constructor(manager, options) {
|
||||
super(manager, options);
|
||||
}
|
||||
|
||||
render(str) {
|
||||
const element = this.getElement();
|
||||
element.innerHTML = str;
|
||||
|
||||
if (this.element.querySelector(".button.auto"))
|
||||
this.element.querySelector(".button.auto").addEventListener("click", (e) => this.onOptionSelected(true));
|
||||
|
||||
if (this.element.querySelector(".button.manual"))
|
||||
this.element.querySelector(".button.manual").addEventListener("click", (e) => this.onOptionSelected(false));
|
||||
|
||||
if (this.element.querySelector(".client-port"))
|
||||
this.element.querySelector(".client-port").querySelector("input").addEventListener("change", async (e) => { this.setClientPort(Number(e.target.value)); })
|
||||
|
||||
if (this.element.querySelector(".backend-port"))
|
||||
this.element.querySelector(".backend-port").querySelector("input").addEventListener("change", async (e) => { this.setBackendPort(Number(e.target.value)); })
|
||||
|
||||
if (this.element.querySelector(".backend-address"))
|
||||
this.element.querySelector(".backend-address").querySelector("input").addEventListener("change", async (e) => { this.manager.getActiveInstance().setBackendAddress(e.target.value); })
|
||||
|
||||
super.render();
|
||||
}
|
||||
|
||||
show(previousPage) {
|
||||
ejs.renderFile("./ejs/connections.ejs", {...this.options, ...this.manager.options}, {}, (err, str) => {
|
||||
if (!err) {
|
||||
this.render(str);
|
||||
|
||||
/* Call the port setters to check if the ports are free */
|
||||
this.setClientPort(this.manager.getActiveInstance().clientPort);
|
||||
this.setBackendPort(this.manager.getActiveInstance().backendPort);
|
||||
} else {
|
||||
logger.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
super.show(previousPage);
|
||||
}
|
||||
|
||||
onNextClicked() {
|
||||
this.hide();
|
||||
this.manager.passwordsPage.show(this);
|
||||
}
|
||||
|
||||
onCancelClicked() {
|
||||
this.hide();
|
||||
this.manager.menuPage.show()
|
||||
}
|
||||
|
||||
onOptionSelected(auto) {
|
||||
this.options.selectAutoOrManual = false;
|
||||
this.options.auto = auto;
|
||||
if (auto) {
|
||||
|
||||
} else {
|
||||
this.show();
|
||||
}
|
||||
}
|
||||
|
||||
/** Asynchronously check if the client port is free and if it is, set the new value
|
||||
*
|
||||
*/
|
||||
async setClientPort(newPort) {
|
||||
const success = await this.manager.getActiveInstance().setClientPort(newPort);
|
||||
var successEls = this.element.querySelector(".client-port").querySelectorAll(".success");
|
||||
for (let i = 0; i < successEls.length; i++) {
|
||||
successEls[i].classList.toggle("hide", !success);
|
||||
}
|
||||
var errorEls = this.element.querySelector(".client-port").querySelectorAll(".error");
|
||||
for (let i = 0; i < errorEls.length; i++) {
|
||||
errorEls[i].classList.toggle("hide", success);
|
||||
}
|
||||
}
|
||||
|
||||
/** Asynchronously check if the backend port is free and if it is, set the new value
|
||||
*
|
||||
*/
|
||||
async setBackendPort(newPort) {
|
||||
const success = await this.manager.getActiveInstance().setBackendPort(newPort);
|
||||
var successEls = this.element.querySelector(".backend-port").querySelectorAll(".success");
|
||||
for (let i = 0; i < successEls.length; i++) {
|
||||
successEls[i].classList.toggle("hide", !success);
|
||||
}
|
||||
var errorEls = this.element.querySelector(".backend-port").querySelectorAll(".error");
|
||||
for (let i = 0; i < errorEls.length; i++) {
|
||||
errorEls[i].classList.toggle("hide", success);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ConnectionsPage;
|
||||
@@ -8,7 +8,7 @@ const { checkPort, fetchWithTimeout } = require('./net')
|
||||
const dircompare = require('dir-compare');
|
||||
const { spawn } = require('child_process');
|
||||
const find = require('find-process');
|
||||
const { uninstallInstance } = require('./filesystem')
|
||||
const { uninstallInstance, installHooks, installMod, installJSON, applyConfiguration, installShortCuts } = require('./filesystem')
|
||||
const { showErrorPopup, showConfirmPopup } = require('./popup')
|
||||
const { logger } = require("./filesystem")
|
||||
|
||||
@@ -79,6 +79,8 @@ class DCSInstance {
|
||||
missionTime = "";
|
||||
load = 0;
|
||||
fps = 0;
|
||||
installationType = 'singleplayer';
|
||||
connectionsType = 'auto';
|
||||
|
||||
constructor(folder) {
|
||||
this.folder = folder;
|
||||
@@ -146,7 +148,7 @@ class DCSInstance {
|
||||
*/
|
||||
async setBackendPort(newPort) {
|
||||
if (await this.checkBackendPort(newPort)) {
|
||||
logger.log(`Instance ${this.folder} client port set to ${newPort}`)
|
||||
logger.log(`Instance ${this.folder} backend port set to ${newPort}`)
|
||||
this.backendPort = newPort;
|
||||
return true;
|
||||
}
|
||||
@@ -236,6 +238,7 @@ class DCSInstance {
|
||||
} else {
|
||||
logger.log(`Port ${port} currently in use`);
|
||||
}
|
||||
logger.log(`Port ${port} is free`);
|
||||
res(portFree);
|
||||
})
|
||||
})
|
||||
@@ -340,6 +343,48 @@ class DCSInstance {
|
||||
})
|
||||
}
|
||||
|
||||
/* Install this instance */
|
||||
install() {
|
||||
installHooks(getManager().getActiveInstance().folder).then(
|
||||
() => {
|
||||
},
|
||||
(err) => {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
).then(() => installMod(getManager().getActiveInstance().folder, getManager().getActiveInstance().name)).then(
|
||||
() => {
|
||||
},
|
||||
(err) => {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
).then(() => installJSON(getManager().getActiveInstance().folder)).then(
|
||||
() => {
|
||||
},
|
||||
(err) => {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
).then(() => applyConfiguration(getManager().getActiveInstance().folder, getManager().getActiveInstance())).then(
|
||||
() => {
|
||||
},
|
||||
(err) => {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
).then(() => installShortCuts(getManager().getActiveInstance().folder, getManager().getActiveInstance().name)).then(
|
||||
() => {
|
||||
},
|
||||
(err) => {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
).then(
|
||||
() => {
|
||||
//getManager().resultPage.getElement()
|
||||
},
|
||||
() => {
|
||||
//getManager().resultPage.getElement()
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/* Uninstall this instance */
|
||||
uninstall() {
|
||||
showConfirmPopup("<div style='font-size: 18px; max-width: 100%'> Are you sure you want to remove Olympus? </div> If you click Accept, the Olympus mod will be removed from your DCS installation.", () =>
|
||||
@@ -353,7 +398,8 @@ class DCSInstance {
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
));
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
const DCSInstance = require("./dcsinstance");
|
||||
const ManagerPage = require("./managerpage");
|
||||
const ejs = require('ejs')
|
||||
const { logger } = require("./filesystem");
|
||||
const { showConfirmPopup } = require("./popup");
|
||||
|
||||
class installationPage extends ManagerPage {
|
||||
constructor(manager, options) {
|
||||
super(manager, options);
|
||||
}
|
||||
|
||||
render(str) {
|
||||
this.element.innerHTML = str;
|
||||
|
||||
var options = this.element.querySelectorAll(".option");
|
||||
for (let i = 0; i < options.length; i++) {
|
||||
options[i].onclick = (e) => {this.onOptionClicked(e);}
|
||||
}
|
||||
|
||||
if (this.element.querySelector(".cancel"))
|
||||
this.element.querySelector(".cancel").addEventListener("click", (e) => this.onCancelClicked(e));
|
||||
|
||||
super.render();
|
||||
}
|
||||
|
||||
async onOptionClicked(e) {
|
||||
this.onInstanceSelection((await DCSInstance.getInstances()).find((instance) => {return instance.folder === e.target.dataset.folder}));
|
||||
}
|
||||
|
||||
show(previousPage) {
|
||||
ejs.renderFile("./ejs/installations.ejs", {...this.options, ...this.manager.options}, {}, (err, str) => {
|
||||
if (!err) {
|
||||
this.render(str);
|
||||
} else {
|
||||
logger.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
super.show(previousPage);
|
||||
}
|
||||
|
||||
onInstanceSelection(activeInstance) {
|
||||
this.manager.options.activeInstance = activeInstance;
|
||||
this.manager.options.install = !activeInstance.installed;
|
||||
|
||||
/* Show the connections page */
|
||||
if (!activeInstance.installed || !this.managers.options.install) {
|
||||
this.hide();
|
||||
this.manager.typePage.show(this);
|
||||
} else {
|
||||
showConfirmPopup("<div style='font-size: 18px; max-width: 100%'> Olympus is already installed in this instance! </div> If you click Accept, it will be installed again and all changes, e.g. custom databases or mods support, will be lost. Are you sure you want to continue?",
|
||||
() => {
|
||||
this.hide();
|
||||
this.manager.typePage.show(this);
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
onCancelClicked(e) {
|
||||
/* Go back to the main menu */
|
||||
this.hide();
|
||||
this.manager.menuPage.show();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = installationPage;
|
||||
@@ -1,169 +0,0 @@
|
||||
const DCSInstance = require("./dcsinstance");
|
||||
const ManagerPage = require("./managerpage");
|
||||
const ejs = require('ejs');
|
||||
const { showErrorPopup } = require("./popup");
|
||||
const { exec } = require("child_process");
|
||||
const { logger } = require("./filesystem")
|
||||
|
||||
class InstancesPage extends ManagerPage {
|
||||
startInstance;
|
||||
|
||||
constructor(manager, options) {
|
||||
super(manager, options);
|
||||
}
|
||||
|
||||
render(str) {
|
||||
this.element.innerHTML = str;
|
||||
|
||||
var editButtons = this.element.querySelectorAll(".button.edit");
|
||||
for (let i = 0; i < editButtons.length; i++) {
|
||||
editButtons[i].onclick = (e) => {this.onEditClicked(e);}
|
||||
}
|
||||
|
||||
var installButtons = this.element.querySelectorAll(".button.install");
|
||||
for (let i = 0; i < installButtons.length; i++) {
|
||||
installButtons[i].onclick = (e) => {this.onInstallClicked(e);}
|
||||
}
|
||||
|
||||
var uninstallButtons = this.element.querySelectorAll(".button.uninstall");
|
||||
for (let i = 0; i < uninstallButtons.length; i++) {
|
||||
uninstallButtons[i].onclick = (e) => {this.onUninstallClicked(e);}
|
||||
}
|
||||
|
||||
var startServerButtons = this.element.querySelectorAll(".button.start-server");
|
||||
for (let i = 0; i < startServerButtons.length; i++) {
|
||||
startServerButtons[i].onclick = (e) => {this.onStartServerClicked(e);}
|
||||
}
|
||||
|
||||
var startClientButtons = this.element.querySelectorAll(".button.start-client");
|
||||
for (let i = 0; i < startClientButtons.length; i++) {
|
||||
startClientButtons[i].onclick = (e) => {this.onStartClientClicked(e);}
|
||||
}
|
||||
|
||||
var openBrowserButtons = this.element.querySelectorAll(".button.open-browser");
|
||||
for (let i = 0; i < openBrowserButtons.length; i++) {
|
||||
openBrowserButtons[i].onclick = (e) => {this.onOpenBrowserClicked(e);}
|
||||
}
|
||||
|
||||
var stopButtons = this.element.querySelectorAll(".button.stop");
|
||||
for (let i = 0; i < stopButtons.length; i++) {
|
||||
stopButtons[i].onclick = (e) => {this.onStopClicked(e);}
|
||||
}
|
||||
|
||||
super.render();
|
||||
}
|
||||
|
||||
async onStartServerClicked(e) {
|
||||
e.target.closest(".collapse").classList.add("loading");
|
||||
this.getClickedInstance(e).then((instance) => instance.startServer());
|
||||
}
|
||||
|
||||
async onStartClientClicked(e) {
|
||||
e.target.closest(".collapse").classList.add("loading");
|
||||
this.getClickedInstance(e).then(instance => instance.startClient());
|
||||
}
|
||||
|
||||
async onOpenBrowserClicked(e) {
|
||||
this.getClickedInstance(e).then((instance) => exec(`start http://localhost:${instance.clientPort}`));
|
||||
}
|
||||
|
||||
async onStopClicked(e) {
|
||||
this.getClickedInstance(e).then((instance) => instance.stop());
|
||||
}
|
||||
|
||||
async onEditClicked(e) {
|
||||
this.getClickedInstance(e).then((instance) => {
|
||||
if (instance.webserverOnline || instance.backendOnline) {
|
||||
showErrorPopup("Error, the selected Olympus instance is currently active, please stop Olympus before editing it!")
|
||||
} else {
|
||||
this.manager.options.activeInstance = instance;
|
||||
this.manager.options.install = false;
|
||||
this.manager.options.singleInstance = false;
|
||||
this.hide();
|
||||
this.manager.typePage.show(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async onInstallClicked(e) {
|
||||
this.getClickedInstance(e).then((instance) => {
|
||||
this.manager.options.activeInstance = instance;
|
||||
this.manager.options.install = true;
|
||||
this.manager.options.singleInstance = false;
|
||||
this.hide();
|
||||
this.manager.typePage.show(this);
|
||||
});
|
||||
}
|
||||
|
||||
async onUninstallClicked(e) {
|
||||
this.getClickedInstance(e).then((instance) => {
|
||||
instance.webserverOnline || instance.backendOnline? showErrorPopup("Error, the selected Olympus instance is currently active, please stop Olympus before uninstalling it!") : instance.uninstall();
|
||||
});
|
||||
}
|
||||
|
||||
async getClickedInstance(e) {
|
||||
return DCSInstance.getInstances().then((instances) => {
|
||||
return instances.find((instance) => {
|
||||
return instance.folder === e.target.closest('.option').dataset.folder
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
show(previousPage) {
|
||||
ejs.renderFile("./ejs/instances.ejs", {...this.options, ...this.manager.options}, {}, (err, str) => {
|
||||
if (!err) {
|
||||
this.render(str);
|
||||
} else {
|
||||
logger.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
var instanceDivs = this.element.querySelectorAll(`.option`);
|
||||
for (let i = 0; i < instanceDivs.length; i++) {
|
||||
var instanceDiv = instanceDivs[i];
|
||||
var instance = this.manager.options.instances.find((instance) => { return instance.folder === instanceDivs[i].dataset.folder;})
|
||||
if (instance) {
|
||||
instanceDiv.querySelector(".button.install").classList.toggle("hide", instance.installed);
|
||||
instanceDiv.querySelector(".button.start").classList.toggle("hide", !instance.installed)
|
||||
instanceDiv.querySelector(".button.uninstall").classList.toggle("hide", !instance.installed)
|
||||
instanceDiv.querySelector(".button.edit").classList.toggle("hide", !instance.installed)
|
||||
}
|
||||
}
|
||||
|
||||
super.show(previousPage);
|
||||
}
|
||||
|
||||
update() {
|
||||
|
||||
var instanceDivs = this.element.querySelectorAll(`.option`);
|
||||
for (let i = 0; i < instanceDivs.length; i++) {
|
||||
var instance = this.manager.options.instances.find((instance) => { return instance.folder === instanceDivs[i].dataset.folder;})
|
||||
if (instance && instance.installed) {
|
||||
var instanceDiv = instanceDivs[i];
|
||||
if (instanceDiv.querySelector(".webserver.online") !== null) {
|
||||
instanceDiv.querySelector(".webserver.online").classList.toggle("hide", !instance.webserverOnline)
|
||||
instanceDiv.querySelector(".webserver.offline").classList.toggle("hide", instance.webserverOnline)
|
||||
instanceDiv.querySelector(".backend.online").classList.toggle("hide", !instance.backendOnline)
|
||||
instanceDiv.querySelector(".backend.offline").classList.toggle("hide", instance.backendOnline)
|
||||
|
||||
if (this.backendOnline) {
|
||||
instanceDiv.querySelector(".fps .data").innerText = instance.fps;
|
||||
instanceDiv.querySelector(".load .data").innerText = instance.load;
|
||||
}
|
||||
|
||||
instanceDiv.querySelector(".button.start").classList.toggle("hide", instance.webserverOnline)
|
||||
instanceDiv.querySelector(".button.uninstall").classList.toggle("hide", instance.webserverOnline)
|
||||
instanceDiv.querySelector(".button.edit").classList.toggle("hide", instance.webserverOnline)
|
||||
instanceDiv.querySelector(".button.open-browser").classList.toggle("hide", !instance.webserverOnline)
|
||||
instanceDiv.querySelector(".button.stop").classList.toggle("hide", !instance.webserverOnline)
|
||||
|
||||
if (this.webserverOnline)
|
||||
instanceDiv.querySelector(".button.start").classList.remove("loading")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InstancesPage;
|
||||
@@ -15,37 +15,40 @@ class Manager {
|
||||
configLoaded: false
|
||||
};
|
||||
|
||||
activePage = null;
|
||||
welcomePage = null;
|
||||
folderPage = null;
|
||||
typePage = null;
|
||||
connectionsTypePage = null;
|
||||
connectionsPage = null;
|
||||
passwordsPage = null;
|
||||
resultPage = null;
|
||||
instancesPage = null;
|
||||
|
||||
constructor() {
|
||||
console.log("constructor")
|
||||
document.addEventListener("signal", (ev) => {
|
||||
const callback = ev.detail.callback;
|
||||
const params = ev.detail.params;
|
||||
const params = JSON.stringify(ev.detail.params);
|
||||
try {
|
||||
eval(`this.${callback}(${params})`)
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async start() {
|
||||
/* Check if the options file exists */
|
||||
if (fs.existsSync("options.json")) {
|
||||
/* Load the options from the json file */
|
||||
try {
|
||||
this.options = {...this.options, ...JSON.parse(fs.readFileSync("options.json"))};
|
||||
this.options = { ...this.options, ...JSON.parse(fs.readFileSync("options.json")) };
|
||||
this.options.configLoaded = true;
|
||||
} catch (e) {
|
||||
logger.error(`An error occurred while reading the options.json file: ${e}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.options.configLoaded) {
|
||||
/* Hide the loading page */
|
||||
@@ -82,9 +85,9 @@ class Manager {
|
||||
return instance.installed && instance.error;
|
||||
})).then(
|
||||
() => { location.reload() },
|
||||
(err) => {
|
||||
(err) => {
|
||||
logger.error(err);
|
||||
showErrorPopup(`An error occurred while trying to fix your installations. Please reinstall Olympus manually. <br><br> You can find more info in ${path.join(__dirname, "..", "manager.log")}`);
|
||||
showErrorPopup(`An error occurred while trying to fix your installations. Please reinstall Olympus manually. <br><br> You can find more info in ${path.join(__dirname, "..", "manager.log")}`);
|
||||
}
|
||||
)
|
||||
})
|
||||
@@ -101,13 +104,14 @@ class Manager {
|
||||
|
||||
/* Create all the HTML pages */
|
||||
this.menuPage = new ManagerPage(this, "./ejs/menu.ejs");
|
||||
this.folderPage = new WizardPage(this, "./ejs/installation.ejs");
|
||||
this.typePage = new WizardPage(this, "./ejs/type.ejs");
|
||||
//this.connectionsPage = new ConnectionsPage(this);
|
||||
//this.passwordsPage = new PasswordsPage(this);
|
||||
//this.resultPage = new ResultPage(this);
|
||||
this.folderPage = new WizardPage(this, "./ejs/installation.ejs");
|
||||
this.typePage = new WizardPage(this, "./ejs/type.ejs");
|
||||
this.connectionsTypePage = new WizardPage(this, "./ejs/connectionsType.ejs");
|
||||
this.connectionsPage = new WizardPage(this, "./ejs/connections.ejs");
|
||||
this.passwordsPage = new WizardPage(this, "./ejs/passwords.ejs");
|
||||
this.resultPage = new ManagerPage(this, "./ejs/result.ejs");
|
||||
//this.instancesPage = new InstancesPage(this);
|
||||
|
||||
|
||||
if (this.options.mode === "basic") {
|
||||
/* In basic mode no dashboard is shown */
|
||||
this.menuPage.show();
|
||||
@@ -124,7 +128,7 @@ class Manager {
|
||||
|
||||
createOptionsFile(mode) {
|
||||
try {
|
||||
fs.writeFileSync("options.json", JSON.stringify({mode: mode}));
|
||||
fs.writeFileSync("options.json", JSON.stringify({ mode: mode }));
|
||||
location.reload();
|
||||
} catch (e) {
|
||||
showErrorPopup(`A critical error occurred, check ${this.options.logLocation} for more info.`)
|
||||
@@ -155,26 +159,26 @@ class Manager {
|
||||
/* When the install button is clicked go the installation page */
|
||||
onInstallClicked() {
|
||||
this.options.install = true;
|
||||
|
||||
|
||||
if (this.options.singleInstance) {
|
||||
this.options.activeInstance = this.options.instances[0];
|
||||
|
||||
/* Show the type selection page */
|
||||
if (!this.options.activeInstance.installed) {
|
||||
this.menuPage.hide();
|
||||
this.typePage.show(this.menuPage);
|
||||
this.typePage.show();
|
||||
} else {
|
||||
showConfirmPopup("<div style='font-size: 18px; max-width: 100%'> Olympus is already installed in this instance! </div> If you click Accept, it will be installed again and all changes, e.g. custom databases or mods support, will be lost. Are you sure you want to continue?",
|
||||
() => {
|
||||
this.menuPage.hide();
|
||||
this.typePage.show(this.menuPage);
|
||||
this.typePage.show();
|
||||
}
|
||||
)
|
||||
}
|
||||
} else {
|
||||
/* Show the folder selection page */
|
||||
this.menuPage.hide();
|
||||
this.folderPage.show(this.menuPage);
|
||||
this.folderPage.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,16 +186,115 @@ class Manager {
|
||||
onEditClicked() {
|
||||
this.hide();
|
||||
this.options.install = false;
|
||||
|
||||
|
||||
if (this.options.singleInstance) {
|
||||
this.options.activeInstance = this.options.instances[0];
|
||||
this.typePage.show(this);
|
||||
this.typePage.show();
|
||||
} else {
|
||||
this.folderPage.show(this);
|
||||
this.folderPage.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* When the installation type is selected */
|
||||
onInstallTypeClicked(type) {
|
||||
this.typePage.getElement().querySelector(`.singleplayer`).classList.toggle("selected", type === 'singleplayer');
|
||||
this.typePage.getElement().querySelector(`.multiplayer`).classList.toggle("selected", type === 'multiplayer');
|
||||
if (this.options.activeInstance)
|
||||
this.options.activeInstance.installationType = type;
|
||||
else
|
||||
showErrorPopup("A critical error has occurred. Please restart the Manager.")
|
||||
}
|
||||
|
||||
/* When the connections type is selected */
|
||||
onConnectionsTypeClicked(type) {
|
||||
this.connectionsTypePage.getElement().querySelector(`.auto`).classList.toggle("selected", type === 'auto');
|
||||
this.connectionsTypePage.getElement().querySelector(`.manual`).classList.toggle("selected", type === 'manual');
|
||||
if (this.options.activeInstance)
|
||||
this.options.activeInstance.connectionsType = type;
|
||||
else
|
||||
showErrorPopup("A critical error has occurred. Please restart the Manager.")
|
||||
}
|
||||
|
||||
/* When the back button of a wizard page is clicked */
|
||||
onBackClicked() {
|
||||
this.activePage.hide();
|
||||
this.activePage.previousPage.show();
|
||||
}
|
||||
|
||||
/* When the next button of a wizard page is clicked */
|
||||
onNextClicked() {
|
||||
this.activePage.hide();
|
||||
|
||||
/* Choose which page to show depending on the active page */
|
||||
if (this.activePage == this.typePage) {
|
||||
this.connectionsTypePage.show();
|
||||
} else if (this.activePage == this.connectionsTypePage) {
|
||||
if (this.options.activeInstance) {
|
||||
if (this.options.activeInstance.connectionsType === 'auto') {
|
||||
this.passwordsPage.show();
|
||||
}
|
||||
else {
|
||||
this.connectionsPage.show();
|
||||
this.setPort('client', this.options.activeInstance.clientPort);
|
||||
this.setPort('backend', this.options.activeInstance.backendPort);
|
||||
this.connectionsPage.getElement().querySelector(".backend-address .checkbox").classList.toggle("checked", this.options.activeInstance.backendAddress === '*')
|
||||
}
|
||||
} else {
|
||||
showErrorPopup("A critical error has occurred. Please restart the Manager.")
|
||||
}
|
||||
} else if (this.activePage == this.connectionsPage) {
|
||||
this.passwordsPage.show();
|
||||
} else if (this.activePage == this.passwordsPage) {
|
||||
if (this.options.activeInstance) {
|
||||
this.options.activeInstance.install();
|
||||
this.resultPage.show();
|
||||
} else {
|
||||
showErrorPopup("A critical error has occurred. Please restart the Manager.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* When the client port input value is changed */
|
||||
onClientPortChanged(value) {
|
||||
this.setPort('client', Number(value));
|
||||
}
|
||||
|
||||
/* When the backend port input value is changed */
|
||||
onBackendPortChanged(value) {
|
||||
this.setPort('backend', Number(value));
|
||||
}
|
||||
|
||||
/* When the "Enable API connection" checkbox is clicked */
|
||||
onEnableAPIClicked() {
|
||||
if (this.options.activeInstance) {
|
||||
if (this.options.activeInstance.backendAddress === 'localhost') {
|
||||
this.options.activeInstance.backendAddress = '*';
|
||||
} else {
|
||||
this.options.activeInstance.backendAddress = 'localhost';
|
||||
}
|
||||
this.connectionsPage.getElement().querySelector(".backend-address .checkbox").classList.toggle("checked", this.options.activeInstance.backendAddress === '*')
|
||||
} else {
|
||||
showErrorPopup("A critical error has occurred. Please restart the Manager.")
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the selected port to the dcs instance */
|
||||
async setPort(port, value) {
|
||||
var success;
|
||||
if (port === 'client')
|
||||
success = await this.options.activeInstance.setClientPort(value);
|
||||
else
|
||||
success = await this.options.activeInstance.setBackendPort(value);
|
||||
|
||||
var successEls = this.connectionsPage.getElement().querySelector(`.${port}-port`).querySelectorAll(".success");
|
||||
for (let i = 0; i < successEls.length; i++) {
|
||||
successEls[i].classList.toggle("hide", !success);
|
||||
}
|
||||
var errorEls = this.connectionsPage.getElement().querySelector(`.${port}-port`).querySelectorAll(".error");
|
||||
for (let i = 0; i < errorEls.length; i++) {
|
||||
errorEls[i].classList.toggle("hide", success);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Manager;
|
||||
@@ -1,12 +1,12 @@
|
||||
var manager = null;
|
||||
/* TODO: find a better solution without using the window object to persist the manager singleton */
|
||||
|
||||
function getManager() {
|
||||
if (manager) {
|
||||
return manager;
|
||||
if (window.manager) {
|
||||
return window.manager;
|
||||
} else {
|
||||
const Manager = require("./manager");
|
||||
manager = new Manager();
|
||||
return manager;
|
||||
window.manager = new Manager();
|
||||
return window.manager;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ class ManagerPage {
|
||||
|
||||
this.element.classList.remove("hide");
|
||||
|
||||
if (previousPage !== undefined)
|
||||
this.previousPage = previousPage;
|
||||
this.previousPage = this.manager.activePage;
|
||||
this.manager.activePage = this;
|
||||
}
|
||||
|
||||
hide() {
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
const ManagerPage = require("./managerpage");
|
||||
const ejs = require('ejs')
|
||||
const { logger } = require("./filesystem")
|
||||
|
||||
class PasswordsPage extends ManagerPage {
|
||||
constructor(manager, options) {
|
||||
super(manager, options);
|
||||
}
|
||||
|
||||
render(str) {
|
||||
const element = this.getElement();
|
||||
element.innerHTML = str;
|
||||
|
||||
this.element.querySelector(".game-master").querySelector("input").addEventListener("change", async (e) => { this.manager.getActiveInstance().setGameMasterPassword(e.target.value); })
|
||||
this.element.querySelector(".blue-commander").querySelector("input").addEventListener("change", async (e) => { this.manager.getActiveInstance().setBlueCommanderPassword(e.target.value); })
|
||||
this.element.querySelector(".red-commander").querySelector("input").addEventListener("change", async (e) => { this.manager.getActiveInstance().setRedCommanderPassword(e.target.value); })
|
||||
|
||||
super.render();
|
||||
}
|
||||
|
||||
show(previousPage) {
|
||||
ejs.renderFile("./ejs/passwords.ejs", {...this.options, ...this.manager.options}, {}, (err, str) => {
|
||||
if (!err) {
|
||||
this.render(str);
|
||||
} else {
|
||||
logger.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
super.show(previousPage);
|
||||
}
|
||||
|
||||
onNextClicked() {
|
||||
this.hide();
|
||||
this.manager.resultPage.show();
|
||||
this.manager.resultPage.startInstallation();
|
||||
}
|
||||
|
||||
onCancelClicked() {
|
||||
this.hide();
|
||||
this.manager.menuPage.show()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PasswordsPage;
|
||||
@@ -1,113 +0,0 @@
|
||||
const { installMod, installHooks, installJSON, applyConfiguration, installShortCuts } = require("./filesystem");
|
||||
const ManagerPage = require("./managerpage");
|
||||
const ejs = require('ejs')
|
||||
const { logger } = require("./filesystem")
|
||||
|
||||
class ResultPage extends ManagerPage {
|
||||
constructor(manager, options) {
|
||||
super(manager, options);
|
||||
}
|
||||
|
||||
render(str) {
|
||||
const element = this.getElement();
|
||||
element.innerHTML = str;
|
||||
|
||||
super.render();
|
||||
}
|
||||
|
||||
show(previousPage) {
|
||||
ejs.renderFile("./ejs/result.ejs", {...this.options, ...this.manager.options}, {}, (err, str) => {
|
||||
if (!err) {
|
||||
this.render(str);
|
||||
} else {
|
||||
logger.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
super.show(previousPage);
|
||||
}
|
||||
|
||||
onBackClicked() {
|
||||
location.reload();
|
||||
}
|
||||
|
||||
/** Installation is performed by using an then chain of async functions. Installation is aborted on any error along the chain
|
||||
*
|
||||
*/
|
||||
startInstallation() {
|
||||
installHooks(this.manager.getActiveInstance().folder).then(
|
||||
() => {
|
||||
this.applyStepSuccess(".hook");
|
||||
},
|
||||
(err) => {
|
||||
this.applyStepFailure(".hook");
|
||||
return Promise.reject(err);
|
||||
}
|
||||
).then(() => installMod(this.manager.getActiveInstance().folder, this.manager.getActiveInstance().name)).then(
|
||||
() => {
|
||||
this.applyStepSuccess(".mod");
|
||||
},
|
||||
(err) => {
|
||||
this.applyStepFailure(".mod");
|
||||
return Promise.reject(err);
|
||||
}
|
||||
).then(() => installJSON(this.manager.getActiveInstance().folder)).then(
|
||||
() => {
|
||||
this.applyStepSuccess(".json");
|
||||
},
|
||||
(err) => {
|
||||
this.applyStepFailure(".json");
|
||||
return Promise.reject(err);
|
||||
}
|
||||
).then(() => applyConfiguration(this.manager.getActiveInstance().folder, this.manager.getActiveInstance())).then(
|
||||
() => {
|
||||
this.applyStepSuccess(".config");
|
||||
},
|
||||
(err) => {
|
||||
this.applyStepFailure(".config");
|
||||
return Promise.reject(err);
|
||||
}
|
||||
).then(() => installShortCuts(this.manager.getActiveInstance().folder, this.manager.getActiveInstance().name)).then(
|
||||
() => {
|
||||
this.applyStepSuccess(".shortcuts");
|
||||
},
|
||||
(err) => {
|
||||
this.applyStepFailure(".shortcuts");
|
||||
return Promise.reject(err);
|
||||
}
|
||||
).then(
|
||||
() => {
|
||||
this.element.querySelector(".summary.success").classList.remove("hide");
|
||||
this.element.querySelector(".summary.error").classList.add("hide");
|
||||
this.element.querySelector(".info.success").classList.remove("hide");
|
||||
this.element.querySelector(".info.error").classList.add("hide");
|
||||
this.element.querySelector(".result .success").classList.remove("hide");
|
||||
this.element.querySelector(".result .error").classList.add("hide");
|
||||
this.element.querySelector(".result .wait").classList.add("hide");
|
||||
},
|
||||
() => {
|
||||
this.element.querySelector(".summary.success").classList.add("hide");
|
||||
this.element.querySelector(".summary.error").classList.remove("hide");
|
||||
this.element.querySelector(".info.success").classList.add("hide");
|
||||
this.element.querySelector(".info.error").classList.remove("hide");
|
||||
this.element.querySelector(".result .success").classList.add("hide");
|
||||
this.element.querySelector(".result .error").classList.remove("hide");
|
||||
this.element.querySelector(".result .wait").classList.add("hide");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
applyStepSuccess(step) {
|
||||
this.element.querySelector(step).querySelector(".success").classList.remove("hide");
|
||||
this.element.querySelector(step).querySelector(".error").classList.add("hide");
|
||||
this.element.querySelector(step).querySelector(".wait").classList.add("hide");
|
||||
}
|
||||
|
||||
applyStepFailure(step) {
|
||||
this.element.querySelector(step).querySelector(".success").classList.add("hide");
|
||||
this.element.querySelector(step).querySelector(".error").classList.remove("hide");
|
||||
this.element.querySelector(step).querySelector(".wait").classList.add("hide");
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ResultPage;
|
||||
@@ -1,49 +0,0 @@
|
||||
const ManagerPage = require("./managerpage");
|
||||
const ejs = require('ejs')
|
||||
const { logger } = require("./filesystem")
|
||||
|
||||
/** Type of install page, allows the user to select single player or multi player installation
|
||||
*
|
||||
*/
|
||||
class TypePage extends ManagerPage {
|
||||
constructor(manager, options) {
|
||||
super(manager, options);
|
||||
}
|
||||
|
||||
render(str) {
|
||||
const element = this.getElement();
|
||||
element.innerHTML = str;
|
||||
|
||||
this.element.querySelector(".singleplayer").addEventListener("click", (e) => this.onOptionSelected(false));
|
||||
this.element.querySelector(".multiplayer").addEventListener("click", (e) => this.onOptionSelected(true));
|
||||
|
||||
super.render();
|
||||
}
|
||||
|
||||
show(previousPage) {
|
||||
ejs.renderFile("./ejs/type.ejs", {...this.options, ...this.manager.options}, {}, (err, str) => {
|
||||
if (!err) {
|
||||
this.render(str);
|
||||
|
||||
} else {
|
||||
logger.error(err);
|
||||
}
|
||||
});
|
||||
|
||||
super.show(previousPage);
|
||||
}
|
||||
|
||||
onCancelClicked() {
|
||||
this.hide();
|
||||
this.manager.menuPage.show()
|
||||
}
|
||||
|
||||
onOptionSelected(multiplayer) {
|
||||
this.manager.options.multiplayer = multiplayer;
|
||||
this.hide();
|
||||
this.manager.connectionsPage.options.selectAutoOrManual = true;
|
||||
this.manager.connectionsPage.show(this);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TypePage;
|
||||
Reference in New Issue
Block a user