Mod config bug fixes, electron upgrade.

If the instance mods directory does not exist when the 'Add Drop-In Mod' button is clicked, it will be created.
The update selected server code has been modified. Previously, the server would be updated before the mod config was saved. This has been fixed so that the mod config is saved before the server is switched.
Updated electron to v3.0.10.
This commit is contained in:
Daniel Scalzi 2018-11-20 05:19:59 -05:00
parent 79d1d59451
commit 684e884d9c
No known key found for this signature in database
GPG Key ID: 5CA2F145B63535F9
7 changed files with 44 additions and 25 deletions

View File

@ -1,4 +1,5 @@
const fs = require('fs') const fs = require('fs')
const mkpath = require('mkdirp')
const path = require('path') const path = require('path')
const { shell } = require('electron') const { shell } = require('electron')
@ -8,6 +9,18 @@ const { shell } = require('electron')
const MOD_REGEX = /^(.+(jar|zip|litemod))(?:\.(disabled))?$/ const MOD_REGEX = /^(.+(jar|zip|litemod))(?:\.(disabled))?$/
const DISABLED_EXT = '.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 * Scan for drop-in mods in both the mods folder and version
* safe mods folder. * safe mods folder.

View File

@ -136,17 +136,20 @@ function updateSelectedAccount(authUser){
updateSelectedAccount(ConfigManager.getSelectedAccount()) updateSelectedAccount(ConfigManager.getSelectedAccount())
// Bind selected server // Bind selected server
function updateSelectedServer(serverName){ function updateSelectedServer(serv){
if(serverName == null){ if(getCurrentView() === VIEWS.settings){
serverName = 'No Server Selected' 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){ if(getCurrentView() === VIEWS.settings){
animateModsTabRefresh() animateModsTabRefresh()
} }
setLaunchEnabled(serv != null)
} }
// Real text is set in uibinder.js on distributionIndexDone. // Real text is set in uibinder.js on distributionIndexDone.
updateSelectedServer('Loading..') server_selection_button.innerHTML = '\u2022 Loading..'
server_selection_button.onclick = (e) => { server_selection_button.onclick = (e) => {
e.target.blur() e.target.blur()
toggleServerSelection(true) toggleServerSelection(true)

View File

@ -176,10 +176,7 @@ document.getElementById('serverSelectConfirm').addEventListener('click', () => {
for(let i=0; i<listings.length; i++){ for(let i=0; i<listings.length; i++){
if(listings[i].hasAttribute('selected')){ if(listings[i].hasAttribute('selected')){
const serv = DistroManager.getDistribution().getServer(listings[i].getAttribute('servid')) const serv = DistroManager.getDistribution().getServer(listings[i].getAttribute('servid'))
ConfigManager.setSelectedServer(serv != null ? serv.getID() : null) updateSelectedServer(serv)
ConfigManager.save()
updateSelectedServer(serv != null ? serv.getName() : null)
setLaunchEnabled(serv != null)
refreshServerStatus(true) refreshServerStatus(true)
toggleOverlay(false) toggleOverlay(false)
return return
@ -187,9 +184,8 @@ document.getElementById('serverSelectConfirm').addEventListener('click', () => {
} }
// None are selected? Not possible right? Meh, handle it. // None are selected? Not possible right? Meh, handle it.
if(listings.length > 0){ if(listings.length > 0){
ConfigManager.setSelectedServer(listings[0].getAttribute('servid')) const serv = DistroManager.getDistribution().getServer(listings[i].getAttribute('servid'))
ConfigManager.save() updateSelectedServer(serv)
updateSelectedServer()
toggleOverlay(false) toggleOverlay(false)
} }
}) })

View File

@ -552,7 +552,7 @@ function saveModConfiguration(){
* @param {Object} modConf Mod config object to save. * @param {Object} modConf Mod config object to save.
*/ */
function _saveModConfiguration(modConf){ function _saveModConfiguration(modConf){
for(m of Object.entries(modConf)){ for(let m of Object.entries(modConf)){
const tSwitch = settingsModsContainer.querySelectorAll(`[formod='${m[0]}']`) const tSwitch = settingsModsContainer.querySelectorAll(`[formod='${m[0]}']`)
if(!tSwitch[0].hasAttribute('dropin')){ if(!tSwitch[0].hasAttribute('dropin')){
if(typeof m[1] === 'boolean'){ if(typeof m[1] === 'boolean'){
@ -640,6 +640,7 @@ function bindDropinModsRemoveButton(){
function bindDropinModFileSystemButton(){ function bindDropinModFileSystemButton(){
const fsBtn = document.getElementById('settingsDropinFileSystemButton') const fsBtn = document.getElementById('settingsDropinFileSystemButton')
fsBtn.onclick = () => { fsBtn.onclick = () => {
DropinModUtil.validateModsDir(CACHE_SETTINGS_MODS_DIR)
shell.openItem(CACHE_SETTINGS_MODS_DIR) shell.openItem(CACHE_SETTINGS_MODS_DIR)
} }
} }
@ -720,15 +721,21 @@ document.getElementById('settingsSwitchServerButton').addEventListener('click',
toggleServerSelection(true) 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 * Function to refresh the mods tab whenever the selected
* server is changed. * server is changed.
*/ */
function animateModsTabRefresh(){ function animateModsTabRefresh(){
$('#settingsTabMods').fadeOut(500, () => { $('#settingsTabMods').fadeOut(500, () => {
saveModConfiguration()
ConfigManager.save()
saveDropinModConfiguration()
prepareModsTab() prepareModsTab()
$('#settingsTabMods').fadeIn(500) $('#settingsTabMods').fadeIn(500)
}) })

View File

@ -61,7 +61,7 @@ function showMainUI(data){
ipcRenderer.send('autoUpdateAction', 'initAutoUpdater', ConfigManager.getAllowPrerelease()) ipcRenderer.send('autoUpdateAction', 'initAutoUpdater', ConfigManager.getAllowPrerelease())
} }
updateSelectedServer(data.getServer(ConfigManager.getSelectedServer()).getName()) updateSelectedServer(data.getServer(ConfigManager.getSelectedServer()))
refreshServerStatus() refreshServerStatus()
setTimeout(() => { setTimeout(() => {
document.getElementById('frameBar').style.backgroundColor = 'rgba(0, 0, 0, 0.5)' document.getElementById('frameBar').style.backgroundColor = 'rgba(0, 0, 0, 0.5)'
@ -126,7 +126,7 @@ function showFatalStartupError(){
* @param {Object} data The distro index object. * @param {Object} data The distro index object.
*/ */
function onDistroRefresh(data){ function onDistroRefresh(data){
updateSelectedServer(data.getServer(ConfigManager.getSelectedServer()).getName()) updateSelectedServer(data.getServer(ConfigManager.getSelectedServer()))
refreshServerStatus() refreshServerStatus()
initNews() initNews()
syncModConfigurations(data) syncModConfigurations(data)

12
package-lock.json generated
View File

@ -31,9 +31,9 @@
} }
}, },
"@types/node": { "@types/node": {
"version": "8.10.37", "version": "8.10.38",
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.37.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.38.tgz",
"integrity": "sha512-Jp39foY8Euv/PG4OGPyzxis82mnjcUtXLEMA8oFMCE4ilmuJgZPdV2nZNV1moz+99EJTtcpOSgDCgATUwABKig==", "integrity": "sha512-EibsnbJerd0hBFaDjJStFrVbVBAtOy4dgL8zZFw0uOvPqzBAX59Ci8cgjg3+RgJIWhsB5A4c+pi+D4P9tQQh/A==",
"dev": true "dev": true
}, },
"acorn": { "acorn": {
@ -936,9 +936,9 @@
} }
}, },
"electron": { "electron": {
"version": "3.0.9", "version": "3.0.10",
"resolved": "https://registry.npmjs.org/electron/-/electron-3.0.9.tgz", "resolved": "https://registry.npmjs.org/electron/-/electron-3.0.10.tgz",
"integrity": "sha512-OoSoeUWo9PzbArgrwS1yTfTRSlpXmIgrFGWUuUZCjKAk4DGR70elHDNeRnnBJ9NTwXXZVifChcfx73Ah3GnlVQ==", "integrity": "sha512-I39IeQP3NOlbjKzTDK8uK2JdiHDfhV5SruCS2Gttkn2MaKCY+yIzQ6Wr4DyBXLeTEkL1sbZxbqQVhCavAliv5w==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/node": "^8.0.24", "@types/node": "^8.0.24",

View File

@ -42,7 +42,7 @@
}, },
"devDependencies": { "devDependencies": {
"cross-env": "^5.2.0", "cross-env": "^5.2.0",
"electron": "^3.0.9", "electron": "^3.0.10",
"electron-builder": "^20.36.2", "electron-builder": "^20.36.2",
"eslint": "^5.9.0" "eslint": "^5.9.0"
}, },