From 29118e1ea19c47c88e0b0eef6aa82d7f916069a8 Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Wed, 31 Jan 2024 14:51:42 +0100 Subject: [PATCH] Fixed error in port detection and default radio buttons values --- manager/javascripts/manager.js | 58 +++++++++++++++++++++++++--------- manager/javascripts/net.js | 36 ++++++++++----------- 2 files changed, 61 insertions(+), 33 deletions(-) diff --git a/manager/javascripts/manager.js b/manager/javascripts/manager.js index 589930b6..e3f85ffb 100644 --- a/manager/javascripts/manager.js +++ b/manager/javascripts/manager.js @@ -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(`
A critical error occurred!
Check ${this.getLogLocation()} for more info.
`); + } + } + + this.connectionsTypePage.options.onShow = () => { + if (this.getActiveInstance()) + this.getActiveInstance().connectionsType = 'auto'; + else { + showErrorPopup(`
A critical error occurred!
Check ${this.getLogLocation()} for more info.
`); + } + } + /* 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("
Olympus is already installed in this instance!
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.activePage.hide(); - this.typePage.show(); - }, - async () => { - await this.setState('IDLE'); - } - ) + if (this.getActiveInstance().webserverOnline || this.getActiveInstance().backendOnline) { + showErrorPopup("
The selected Olympus instance is currently active
Please stop DCS and Olympus Server/Client before editing it!
"); + } else { + showConfirmPopup("
Olympus is already installed in this instance!
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.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("
Olympus is already installed in this instance!
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.activePage.hide() - this.typePage.show(); - } - ) + if (this.getActiveInstance().webserverOnline || this.getActiveInstance().backendOnline) { + showErrorPopup("
The selected Olympus instance is currently active
Please stop DCS and Olympus Server/Client before editing it!
"); + } else { + showConfirmPopup("
Olympus is already installed in this instance!
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.activePage.hide(); + this.typePage.show(); + }, + async () => { + await this.setState('IDLE'); + } + ) + } } else { this.activePage.hide(); this.typePage.show(); diff --git a/manager/javascripts/net.js b/manager/javascripts/net.js index b1e5dc04..2c014b16 100644 --- a/manager/javascripts/net.js +++ b/manager/javascripts/net.js @@ -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 }