diff --git a/app/assets/js/scripts/settings.js b/app/assets/js/scripts/settings.js
index d673cf48..a10c7204 100644
--- a/app/assets/js/scripts/settings.js
+++ b/app/assets/js/scripts/settings.js
@@ -5,6 +5,7 @@ const semver = require('semver')
const { JavaGuard } = require('./assets/js/assetguard')
const DropinModUtil = require('./assets/js/dropinmodutil')
const { MSFT_OPCODE, MSFT_REPLY_TYPE, MSFT_ERROR } = require('./assets/js/ipcconstants')
+const loggerSettings = require('./assets/js/loggerutil')('%c[Settings]', 'color: #353232; font-weight: bold')
const settingsState = {
invalid: new Set()
@@ -137,6 +138,8 @@ function initSettingsValues(){
v.value = gFn()
} else if (cVal === 'DataDirectory'){
v.value = gFn()
+ } else if (cVal === 'ServerCode'){
+ v.value = gFn()
} else if(cVal === 'JVMOptions'){
v.value = gFn().join(' ')
} else {
@@ -423,6 +426,44 @@ ipcRenderer.on(MSFT_OPCODE.REPLY_LOGIN, (_, ...arguments_) => {
}
})
+/**
+ * Binds the functionality within the server codes section of the launcher settings
+ */
+ function bindServerCodeButtons(){
+ // Sets up the onclick listeners for the button to add codes
+ document.getElementById('settingsAddServerCode').onclick = () => {
+ for(let ele of document.getElementsByClassName('settingsInputServerCodeVal')){
+ const code = ele.value
+ ele.value = ''
+ if(!ConfigManager.getServerCodes().includes(code) && code){
+ ConfigManager.getServerCodes().push(code)
+ ConfigManager.save()
+ loggerSettings.log('Added server code to configuration and saved it')
+ prepareLauncherTab()
+ } else {
+ loggerSettings.log('Server code already exists or is empty, not adding.')
+ }
+ }
+ }
+
+ // Sets up the onclick listeners for each remove code buttons
+ const sEls = document.querySelectorAll('[remcode]')
+ Array.from(sEls).map((v, index, arr) => {
+ v.onclick = () => {
+ if(v.hasAttribute('remcode')){
+ const code = v.getAttribute('remcode')
+ if(ConfigManager.getServerCodes().includes(code)){
+ ConfigManager.getServerCodes().splice(ConfigManager.getServerCodes().indexOf(code), 1)
+ ConfigManager.save()
+ loggerSettings.log('Added removed code from configuration and saved it')
+ prepareLauncherTab()
+ }
+ }
+ loggerSettings.log('Server code doesnt exist!, not removing.')
+ }
+ })
+}
+
/**
* Bind functionality for the account selection buttons. If another account
* is selected, the UI of the previously selected account will be updated.
@@ -662,6 +703,14 @@ function prepareAccountsTab() {
bindAuthAccountLogOut()
}
+/**
+ * Prepare the launcher tab for display.
+ */
+ function prepareLauncherTab() {
+ resolveServerCodesForUI()
+ bindServerCodeButtons()
+}
+
/**
* Minecraft Tab
*/
@@ -864,6 +913,60 @@ function resolveDropinModsForUI(){
document.getElementById('settingsDropinModsContent').innerHTML = dropinMods
}
+function resolveServerCodesForUI(){
+ /* Server Codes */
+ let servCodes = ''
+ for(let servCode of ConfigManager.getServerCodes()){
+ const servs = DistroManager.getDistribution().getServersFromCode(servCode)
+ const valid = servs && servs.length
+ servCodes +=
+ `
+
+ `
+ }
+
+ document.getElementById('settingsServerCodesListContent').innerHTML = servCodes
+
+ /* Server Names List */
+ for(let ele of document.getElementsByClassName('settingsServerCodeServerNamesContent')){
+ servNames = ''
+ const code = ele.getAttribute('code')
+ const servs = DistroManager.getDistribution().getServersFromCode(code)
+ const valid = servs && servs.length
+ loggerSettings.log('valid: ' + valid)
+ if(valid){
+ for(let serv of servs){
+ loggerSettings.log('server: ' + serv.getName())
+ servNames +=
+ `
+
${serv.getName()}
+ `
+ }
+ } else {
+ servNames =
+ `
+
Invalid Code
+ `
+ }
+
+ ele.innerHTML = servNames
+ }
+}
+
/**
* Bind the remove button for each loaded drop-in mod.
*/
@@ -1526,6 +1629,7 @@ function prepareSettings(first = false) {
initSettingsValues()
prepareAccountsTab()
prepareJavaTab()
+ prepareLauncherTab()
prepareAboutTab()
}
diff --git a/app/settings.ejs b/app/settings.ejs
index 65a1796d..eb837807 100644
--- a/app/settings.ejs
+++ b/app/settings.ejs
@@ -295,6 +295,19 @@
All game files and local Java installations will be stored in the data directory.
Screenshots and world saves are stored in the instance folder for the corresponding server configuration.
+