Skip to content

Commit

Permalink
Mod config bug fixes, electron upgrade.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dscalzi committed Nov 20, 2018
1 parent 79d1d59 commit 684e884
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 25 deletions.
13 changes: 13 additions & 0 deletions app/assets/js/dropinmodutil.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs')
const mkpath = require('mkdirp')
const path = require('path')
const { shell } = require('electron')

Expand All @@ -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.
Expand Down
13 changes: 8 additions & 5 deletions app/assets/js/scripts/landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 3 additions & 7 deletions app/assets/js/scripts/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,16 @@ document.getElementById('serverSelectConfirm').addEventListener('click', () => {
for(let i=0; i<listings.length; i++){
if(listings[i].hasAttribute('selected')){
const serv = DistroManager.getDistribution().getServer(listings[i].getAttribute('servid'))
ConfigManager.setSelectedServer(serv != null ? serv.getID() : null)
ConfigManager.save()
updateSelectedServer(serv != null ? serv.getName() : null)
setLaunchEnabled(serv != null)
updateSelectedServer(serv)
refreshServerStatus(true)
toggleOverlay(false)
return
}
}
// 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)
}
})
Expand Down
15 changes: 11 additions & 4 deletions app/assets/js/scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'){
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
})
Expand Down
4 changes: 2 additions & 2 deletions app/assets/js/scripts/uibinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 684e884

Please sign in to comment.