Merge pull request #817 from Pax1601/813-fix-last-details-of-the-manager

Fixed error in port detection and default radio buttons values
This commit is contained in:
Pax1601 2024-01-31 14:51:59 +01:00 committed by GitHub
commit 11518485de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 61 additions and 33 deletions

View File

@ -166,6 +166,23 @@ class Manager {
this.updateInstances();
}
/* Reset default radio buttons */
this.typePage.options.onShow = () => {
if (this.getActiveInstance())
this.getActiveInstance().installationType = 'singleplayer';
else {
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${this.getLogLocation()} for more info. </div>`);
}
}
this.connectionsTypePage.options.onShow = () => {
if (this.getActiveInstance())
this.getActiveInstance().connectionsType = 'auto';
else {
showErrorPopup(`<div class='main-message'>A critical error occurred! </div><div class='sub-message'> Check ${this.getLogLocation()} for more info. </div>`);
}
}
/* Reload the instances when we get to the folder page */
this.folderPage.options.onShow = async () => {
if (this.getInstances().length > 0)
@ -248,15 +265,19 @@ class Manager {
this.activePage.hide()
this.typePage.show();
} else {
showConfirmPopup("<div class='main-message'> Olympus is already installed in this instance! </div> <div class='sub-message'>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?</div>",
() => {
this.activePage.hide();
this.typePage.show();
},
async () => {
await this.setState('IDLE');
}
)
if (this.getActiveInstance().webserverOnline || this.getActiveInstance().backendOnline) {
showErrorPopup("<div class='main-message'>The selected Olympus instance is currently active </div><div class='sub-message'> Please stop DCS and Olympus Server/Client before editing it! </div>");
} else {
showConfirmPopup("<div class='main-message'> Olympus is already installed in this instance! </div> <div class='sub-message'>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?</div>",
() => {
this.activePage.hide();
this.typePage.show();
},
async () => {
await this.setState('IDLE');
}
)
}
}
} else {
/* Show the folder selection page */
@ -318,12 +339,19 @@ class Manager {
/* Folder selection page */
if (this.activePage == this.folderPage) {
if (this.getActiveInstance().installed) {
showConfirmPopup("<div class='main-message'> Olympus is already installed in this instance! </div> <div class='sub-message'>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?</div>",
() => {
this.activePage.hide()
this.typePage.show();
}
)
if (this.getActiveInstance().webserverOnline || this.getActiveInstance().backendOnline) {
showErrorPopup("<div class='main-message'>The selected Olympus instance is currently active </div><div class='sub-message'> Please stop DCS and Olympus Server/Client before editing it! </div>");
} else {
showConfirmPopup("<div class='main-message'> Olympus is already installed in this instance! </div> <div class='sub-message'>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?</div>",
() => {
this.activePage.hide();
this.typePage.show();
},
async () => {
await this.setState('IDLE');
}
)
}
} else {
this.activePage.hide();
this.typePage.show();

View File

@ -1,26 +1,27 @@
const portfinder = require('portfinder')
const { logger } = require("./filesystem")
const portfinder = require('portfinder');
const { logger } = require('./filesystem');
/** Checks if a port is already in use
*
*/
function checkPortSync(port, callback) {
portfinder.getPort({ port: port, stopPort: port }, (err, res) => {
if (err !== null) {
logger.error(`Port ${port} already in use`);
callback(false);
} else {
callback(true);
}
});
async function checkPort(port) {
try{
await portfinder.getPortPromise({ port: port, stopPort: port });
return true;
} catch (err) {
logger.log(err);
return false;
}
}
function checkPort(port) {
return portfinder.getPortPromise({ port: port, stopPort: port });
}
function getFreePort(startPort) {
return portfinder.getPortPromise({ port: startPort });
async function getFreePort(startPort) {
try{
var port = await portfinder.getPortPromise({ port: startPort });
return port;
} catch (err) {
logger.log(err);
return false;
}
}
/** Performs a fetch request, with a configurable timeout
@ -44,6 +45,5 @@ async function fetchWithTimeout(resource, options = {}) {
module.exports = {
getFreePort: getFreePort,
checkPort: checkPort,
checkPortSync: checkPortSync,
fetchWithTimeout: fetchWithTimeout
}