diff --git a/app/assets/js/dropinmodutil.js b/app/assets/js/dropinmodutil.js index fa742039..c6e62001 100644 --- a/app/assets/js/dropinmodutil.js +++ b/app/assets/js/dropinmodutil.js @@ -1,4 +1,5 @@ const fs = require('fs') +const mkpath = require('mkdirp') const path = require('path') const { shell } = require('electron') @@ -8,6 +9,18 @@ const { shell } = require('electron') const MOD_REGEX = /^(.+(jar|zip|litemod))(?:\.(disabled))?$/ const DISABLED_EXT = '.disabled' +/** + * Validate that the given mods directory exists. If not, + * it is created. + * + * @param {string} modsDir The path to the mods directory. + */ +exports.validateModsDir = function(modsDir) { + if(!fs.existsSync(modsDir)) { + mkpath.sync(modsDir) + } +} + /** * Scan for drop-in mods in both the mods folder and version * safe mods folder. diff --git a/app/assets/js/scripts/landing.js b/app/assets/js/scripts/landing.js index b52e21e1..48d511f9 100644 --- a/app/assets/js/scripts/landing.js +++ b/app/assets/js/scripts/landing.js @@ -136,17 +136,20 @@ function updateSelectedAccount(authUser){ updateSelectedAccount(ConfigManager.getSelectedAccount()) // Bind selected server -function updateSelectedServer(serverName){ - if(serverName == null){ - serverName = 'No Server Selected' +function updateSelectedServer(serv){ + if(getCurrentView() === VIEWS.settings){ + saveAllModConfigurations() } - server_selection_button.innerHTML = '\u2022 ' + serverName + ConfigManager.setSelectedServer(serv != null ? serv.getID() : null) + ConfigManager.save() + server_selection_button.innerHTML = '\u2022 ' + (serv != null ? serv.getName() : 'No Server Selected') if(getCurrentView() === VIEWS.settings){ animateModsTabRefresh() } + setLaunchEnabled(serv != null) } // Real text is set in uibinder.js on distributionIndexDone. -updateSelectedServer('Loading..') +server_selection_button.innerHTML = '\u2022 Loading..' server_selection_button.onclick = (e) => { e.target.blur() toggleServerSelection(true) diff --git a/app/assets/js/scripts/overlay.js b/app/assets/js/scripts/overlay.js index eab9f323..ed704047 100644 --- a/app/assets/js/scripts/overlay.js +++ b/app/assets/js/scripts/overlay.js @@ -176,10 +176,7 @@ document.getElementById('serverSelectConfirm').addEventListener('click', () => { for(let i=0; i { } // None are selected? Not possible right? Meh, handle it. if(listings.length > 0){ - ConfigManager.setSelectedServer(listings[0].getAttribute('servid')) - ConfigManager.save() - updateSelectedServer() + const serv = DistroManager.getDistribution().getServer(listings[i].getAttribute('servid')) + updateSelectedServer(serv) toggleOverlay(false) } }) diff --git a/app/assets/js/scripts/settings.js b/app/assets/js/scripts/settings.js index 3a52d213..f3fd052b 100644 --- a/app/assets/js/scripts/settings.js +++ b/app/assets/js/scripts/settings.js @@ -552,7 +552,7 @@ function saveModConfiguration(){ * @param {Object} modConf Mod config object to save. */ function _saveModConfiguration(modConf){ - for(m of Object.entries(modConf)){ + for(let m of Object.entries(modConf)){ const tSwitch = settingsModsContainer.querySelectorAll(`[formod='${m[0]}']`) if(!tSwitch[0].hasAttribute('dropin')){ if(typeof m[1] === 'boolean'){ @@ -640,6 +640,7 @@ function bindDropinModsRemoveButton(){ function bindDropinModFileSystemButton(){ const fsBtn = document.getElementById('settingsDropinFileSystemButton') fsBtn.onclick = () => { + DropinModUtil.validateModsDir(CACHE_SETTINGS_MODS_DIR) shell.openItem(CACHE_SETTINGS_MODS_DIR) } } @@ -720,15 +721,21 @@ document.getElementById('settingsSwitchServerButton').addEventListener('click', toggleServerSelection(true) }) +/** + * Save mod configuration for the current selected server. + */ +function saveAllModConfigurations(){ + saveModConfiguration() + ConfigManager.save() + saveDropinModConfiguration() +} + /** * Function to refresh the mods tab whenever the selected * server is changed. */ function animateModsTabRefresh(){ $('#settingsTabMods').fadeOut(500, () => { - saveModConfiguration() - ConfigManager.save() - saveDropinModConfiguration() prepareModsTab() $('#settingsTabMods').fadeIn(500) }) diff --git a/app/assets/js/scripts/uibinder.js b/app/assets/js/scripts/uibinder.js index 8ed4b13b..fef0e103 100644 --- a/app/assets/js/scripts/uibinder.js +++ b/app/assets/js/scripts/uibinder.js @@ -61,7 +61,7 @@ function showMainUI(data){ ipcRenderer.send('autoUpdateAction', 'initAutoUpdater', ConfigManager.getAllowPrerelease()) } - updateSelectedServer(data.getServer(ConfigManager.getSelectedServer()).getName()) + updateSelectedServer(data.getServer(ConfigManager.getSelectedServer())) refreshServerStatus() setTimeout(() => { document.getElementById('frameBar').style.backgroundColor = 'rgba(0, 0, 0, 0.5)' @@ -126,7 +126,7 @@ function showFatalStartupError(){ * @param {Object} data The distro index object. */ function onDistroRefresh(data){ - updateSelectedServer(data.getServer(ConfigManager.getSelectedServer()).getName()) + updateSelectedServer(data.getServer(ConfigManager.getSelectedServer())) refreshServerStatus() initNews() syncModConfigurations(data) diff --git a/package-lock.json b/package-lock.json index 66ac093a..0cd827ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,9 +31,9 @@ } }, "@types/node": { - "version": "8.10.37", - "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.37.tgz", - "integrity": "sha512-Jp39foY8Euv/PG4OGPyzxis82mnjcUtXLEMA8oFMCE4ilmuJgZPdV2nZNV1moz+99EJTtcpOSgDCgATUwABKig==", + "version": "8.10.38", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.38.tgz", + "integrity": "sha512-EibsnbJerd0hBFaDjJStFrVbVBAtOy4dgL8zZFw0uOvPqzBAX59Ci8cgjg3+RgJIWhsB5A4c+pi+D4P9tQQh/A==", "dev": true }, "acorn": { @@ -936,9 +936,9 @@ } }, "electron": { - "version": "3.0.9", - "resolved": "https://registry.npmjs.org/electron/-/electron-3.0.9.tgz", - "integrity": "sha512-OoSoeUWo9PzbArgrwS1yTfTRSlpXmIgrFGWUuUZCjKAk4DGR70elHDNeRnnBJ9NTwXXZVifChcfx73Ah3GnlVQ==", + "version": "3.0.10", + "resolved": "https://registry.npmjs.org/electron/-/electron-3.0.10.tgz", + "integrity": "sha512-I39IeQP3NOlbjKzTDK8uK2JdiHDfhV5SruCS2Gttkn2MaKCY+yIzQ6Wr4DyBXLeTEkL1sbZxbqQVhCavAliv5w==", "dev": true, "requires": { "@types/node": "^8.0.24", diff --git a/package.json b/package.json index 43b25600..381e66c4 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ }, "devDependencies": { "cross-env": "^5.2.0", - "electron": "^3.0.9", + "electron": "^3.0.10", "electron-builder": "^20.36.2", "eslint": "^5.9.0" },