From 1d38bd6fea89730d87e6fbeee14281baafb5d2ff Mon Sep 17 00:00:00 2001 From: Pax1601 Date: Wed, 24 Jan 2024 19:08:42 +0100 Subject: [PATCH] Added folder selection page and port availability checks --- manager/ejs/connections.ejs | 3 +- manager/ejs/folder.ejs | 24 +++++ manager/ejs/installation.ejs | 143 ----------------------------- manager/ejs/result.ejs | 24 +++-- manager/index.html | 1 + manager/javascripts/dcsinstance.js | 21 ++--- manager/javascripts/manager.js | 58 ++++++++++-- manager/javascripts/preload.js | 10 +- 8 files changed, 105 insertions(+), 179 deletions(-) create mode 100644 manager/ejs/folder.ejs delete mode 100644 manager/ejs/installation.ejs diff --git a/manager/ejs/connections.ejs b/manager/ejs/connections.ejs index e30c71c8..a37ff581 100644 --- a/manager/ejs/connections.ejs +++ b/manager/ejs/connections.ejs @@ -48,7 +48,8 @@ title="This port is used to allow access to Olympus. Be sure to allow this port through your firewall if you want people to connect remotely">
- "> + " + onchange="signal('onClientPortChanged', this.value)">
Port already in use diff --git a/manager/ejs/folder.ejs b/manager/ejs/folder.ejs new file mode 100644 index 00000000..63bc05b2 --- /dev/null +++ b/manager/ejs/folder.ejs @@ -0,0 +1,24 @@ + +
+
+
+ Step 1 of 4 +
+
+ Which DCS instance you want to add Olympus to? +
+
+ Olympus is added to DCS instances individually, and will only work for that specific instance.
+ You can have Olympus installed across multiple DCS instances. Re-run in the install wizard to add Olympus to another DCS install. +
+
+
+ <% for (var i = 0; i < instances.length; i++) { %> +
+ <%= instances[i].name %> +
+ <% } %> +
+
diff --git a/manager/ejs/installation.ejs b/manager/ejs/installation.ejs deleted file mode 100644 index 17c7709d..00000000 --- a/manager/ejs/installation.ejs +++ /dev/null @@ -1,143 +0,0 @@ - -
-
-
<%= install? 'User path': 'Instance selection' %>
-
Type of install
-
Ports and address
-
Passwords
-
<%= install? 'Install': 'Update' %>
-
-
-
- - <% if (install) { %> - Select a DCS path to install Olympus to. - <% } else { %> - Select an Olympus instance to edit. - <% } %> - - - <% if (install) { %> - We have automatically detected the following DCS installations under your Saved Games / DCS folder. - <% } else { %> - These are the DCS instances in which Olympus has already been installed. - <% } %> - - - <% if (install) { %> - Please select which DCS installations you want to add Olympus to. - <% } else { %> - Please select which Olympus installations you want to edit. - <% } %> - - -
-
-
- <% for (let i = 0; i < instances.length; i++) {%> -
- <%= instances[i].name %> - <%= instances[i].folder %> - - <%= instances[i].installed? (instances[i].error? 'Corrupted/outdated Olympus installation': 'Olympus installed'): 'Olympus not installed' %> - -
- <% } %> -
-
-
- <% if (install) { %> - Cancel installation - <% } else { %> - Cancel editing - <% } %> -
-
-
\ No newline at end of file diff --git a/manager/ejs/result.ejs b/manager/ejs/result.ejs index 27dccdb7..6001a329 100644 --- a/manager/ejs/result.ejs +++ b/manager/ejs/result.ejs @@ -74,10 +74,16 @@ height: 30px; width: 30px; } + + #result-page .link { + display: inline; + color: #5CA7FF; + font-weight: bold; + }
-
Olympus successfully added to <%= activeInstance["name"] %>
+
Olympus successfully added to <%= activeInstance["name"] %>!
See the DCS Olympus Wiki for more information on how to use Olympus and for troubleshooting issues. You may now close the installer.
@@ -89,52 +95,52 @@ How to launch Olympus
- To launch Olympus, there are shortcuts available in the DCS Olympus folder under Saved Games. + To launch Olympus, there are shortcuts available in the <%= activeInstance["name"] %> folder under Saved Games.
<% if (activeInstance["installationType"] === "singleplayer") { %>
- Launch the Olympus Client via the shortcut in DCS Olympus / Saved Games. + Launch the Olympus Client via the shortcut on your desktop or in <%= activeInstance["name"] %>.
- Launch DCS, load a mission and unpause the game. Enjoy! + Launch DCS, load a mission and unpause the game. Enjoy!
- Alternatively, you can run the Olympus Server instead and visit http://localhost:<%= activeInstance["clientPort"] %> in a web browser (Google Chrome recommended) to replace the first step above. + Alternatively, you can run the Olympus Server instead and visit in a web browser (Google Chrome recommended) to replace the first step above.
<% } else { %>
- Launch the Olympus Server via the shortcut in DCS Olympus / Saved Games. + Launch the Olympus Server via the shortcut on your desktop or in <%= activeInstance["name"] %>.
- Visit http://<%= ip %>:<%= activeInstance["clientPort"] %> in a web browser (Google Chrome recommended). + To access Olympus remotely visit in a web browser (Google Chrome recommended).
- Launch DCS, load a mission and unpause the game. Enjoy! + Launch DCS, load a mission and unpause the game. Enjoy!
- Note, to access Olympus from this PC, you need to visit http://localhost:<%= activeInstance["clientPort"] %> in a web browser (Google Chrome recommended) instead. + To access Olympus from this PC, you need to visit in a web browser (Google Chrome recommended) instead.
<% } %>
diff --git a/manager/index.html b/manager/index.html index 154763c5..1c068bd6 100644 --- a/manager/index.html +++ b/manager/index.html @@ -34,6 +34,7 @@ +
Loading, please wait... diff --git a/manager/javascripts/dcsinstance.js b/manager/javascripts/dcsinstance.js index 3a688d23..bba617d1 100644 --- a/manager/javascripts/dcsinstance.js +++ b/manager/javascripts/dcsinstance.js @@ -135,28 +135,20 @@ class DCSInstance { }, 1000); } - /** Asynchronously check if the client port is free and if it is, set the new value + /** Asynchronously set the client port * */ async setClientPort(newPort) { - if (await this.checkClientPort(newPort)) { - logger.log(`Instance ${this.folder} client port set to ${newPort}`) - this.clientPort = newPort; - return true; - } - return false; + logger.log(`Instance ${this.folder} client port set to ${newPort}`) + this.clientPort = newPort; } - /** Asynchronously check if the client port is free and if it is, set the new value + /** Asynchronously set the backend port * */ async setBackendPort(newPort) { - if (await this.checkBackendPort(newPort)) { - logger.log(`Instance ${this.folder} backend port set to ${newPort}`) - this.backendPort = newPort; - return true; - } - return false; + logger.log(`Instance ${this.folder} backend port set to ${newPort}`) + this.backendPort = newPort; } /** Set backend address @@ -227,6 +219,7 @@ class DCSInstance { else { logger.log(`Port ${port} currently in use`); } + logger.log(`Port ${port} is free`); res(portFree); }) }) diff --git a/manager/javascripts/manager.js b/manager/javascripts/manager.js index 9406bcb6..3e9062f1 100644 --- a/manager/javascripts/manager.js +++ b/manager/javascripts/manager.js @@ -115,7 +115,7 @@ class Manager { /* Create all the HTML pages */ this.menuPage = new ManagerPage(this, "./ejs/menu.ejs"); - this.folderPage = new WizardPage(this, "./ejs/installation.ejs"); + this.folderPage = new WizardPage(this, "./ejs/folder.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"); @@ -207,6 +207,18 @@ class Manager { } } + onFolderClicked(name) { + this.getClickedInstance(name).then((instance) => { + var instanceDivs = this.folderPage.getElement().querySelectorAll(".button.radio"); + console.log(instanceDivs); + for (let i = 0; i < instanceDivs.length; i++) { + instanceDivs[i].classList.toggle('selected', instanceDivs[i].dataset.folder === instance.folder); + if (instanceDivs[i].dataset.folder === instance.folder) + this.options.activeInstance = instance; + } + }); + } + /* When the installation type is selected */ onInstallTypeClicked(type) { this.typePage.getElement().querySelector(`.singleplayer`).classList.toggle("selected", type === 'singleplayer'); @@ -230,7 +242,10 @@ class Manager { /* When the next button of a wizard page is clicked */ onNextClicked() { /* Choose which page to show depending on the active page */ - if (this.activePage == this.typePage) { + if (this.activePage == this.folderPage) { + this.activePage.hide(); + this.typePage.show(); + } else if (this.activePage == this.typePage) { this.activePage.hide(); this.connectionsTypePage.show(); } else if (this.activePage == this.connectionsTypePage) { @@ -250,8 +265,26 @@ class Manager { showErrorPopup("A critical error has occurred. Please restart the Manager.") } } else if (this.activePage == this.connectionsPage) { - this.activePage.hide(); - this.passwordsPage.show(); + this.options.activeInstance.checkClientPort(this.options.activeInstance.clientPort).then( + (portFree) => { + console.log(this.options.activeInstance.clientPort) + console.log(portFree) + if (portFree) { + return this.options.activeInstance.checkBackendPort(this.options.activeInstance.backendPort); + } else { + return Promise.reject('Port not free'); + } + }).then((portFree) => { + if (portFree) { + this.activePage.hide(); + this.passwordsPage.show(); + } else { + return Promise.reject('Port not free'); + } + }).catch(() => { + showErrorPopup('Please, make sure both the client and backend ports are free!'); + } + ); } else if (this.activePage == this.passwordsPage) { if (this.options.activeInstance) { if (this.options.activeInstance.installed && !this.options.activeInstance.arePasswordsEdited()) { @@ -429,10 +462,14 @@ class 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); + if (port === 'client'){ + success = await this.options.activeInstance.checkClientPort(value); + this.options.activeInstance.setClientPort(value); + } + else { + success = await this.options.activeInstance.checkBackendPort(value); + this.options.activeInstance.setBackendPort(value); + } var successEls = this.connectionsPage.getElement().querySelector(`.${port}-port`).querySelectorAll(".success"); for (let i = 0; i < successEls.length; i++) { @@ -486,6 +523,11 @@ class Manager { } } } + + reload() { + console.log("reload") + this.activePage.show(); + } } module.exports = Manager; \ No newline at end of file diff --git a/manager/javascripts/preload.js b/manager/javascripts/preload.js index aab20ca8..fba22611 100644 --- a/manager/javascripts/preload.js +++ b/manager/javascripts/preload.js @@ -268,10 +268,12 @@ window.addEventListener('DOMContentLoaded', async () => { /* Create event listeners for the hyperlinks */ var links = document.querySelectorAll(".link"); for (let i = 0; i < links.length; i++) { - links[i].addEventListener("click", (e) => { - if (e.target.dataset.link) - exec("start " + e.target.dataset.link); - }) + if (links[i].dataset.link) { + links[i].addEventListener("click", (e) => { + if (e.target.dataset.link) + exec("start " + e.target.dataset.link); + }) + } } })