URGENT FIX

Fixed an issue that caused the login token to become invalid on using another launcher
Fixed an issue that prevented you from logging out
Removed Logo Seal from the login screen (Un necessary placement)
Made the status colours easy to understand. (Brighter and more vibrant colours.
This commit is contained in:
Peter 2021-07-17 16:13:18 +01:00
parent 71123b55a9
commit 14e266c556
4 changed files with 219 additions and 224 deletions

View File

@ -67,14 +67,14 @@ const statuses = [
exports.statusToHex = function(status){ exports.statusToHex = function(status){
switch(status.toLowerCase()){ switch(status.toLowerCase()){
case 'green': case 'green':
return '#a5c325' return '#4DDD19'
case 'yellow': case 'yellow':
return '#eac918' return '#FFE300'
case 'red': case 'red':
return '#c32625' return '#c32625'
case 'grey': case 'grey':
default: default:
return '#848484' return '#3B3B3B'
} }
} }

View File

@ -396,20 +396,6 @@ ipcRenderer.on('MSALoginWindowReply', (event, ...args) => {
// Temporary workaround // Temporary workaround
if (loginViewOnSuccess === VIEWS.settings) { if (loginViewOnSuccess === VIEWS.settings) {
prepareSettings() prepareSettings()
if(hasRPC){
DiscordWrapper.updateDetails('In the Settings...')
DiscordWrapper.clearState()
}
} else {
if(hasRPC){
if(ConfigManager.getSelectedServer()){
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
DiscordWrapper.updateDetails('Ready to Play!')
DiscordWrapper.updateState('Modpack: ' + serv.getName())
} else {
DiscordWrapper.updateDetails('Landing Screen...')
}
}
} }
loginViewOnSuccess = VIEWS.landing // Reset this for good measure. loginViewOnSuccess = VIEWS.landing // Reset this for good measure.
loginCancelEnabled(false) // Reset this for good measure. loginCancelEnabled(false) // Reset this for good measure.

View File

@ -11,8 +11,8 @@ const settingsState = {
invalid: new Set() invalid: new Set()
} }
function bindSettingsSelect(){ function bindSettingsSelect() {
for(let ele of document.getElementsByClassName('settingsSelectContainer')) { for (let ele of document.getElementsByClassName('settingsSelectContainer')) {
const selectedDiv = ele.getElementsByClassName('settingsSelectSelected')[0] const selectedDiv = ele.getElementsByClassName('settingsSelectSelected')[0]
selectedDiv.onclick = (e) => { selectedDiv.onclick = (e) => {
@ -24,12 +24,12 @@ function bindSettingsSelect(){
} }
} }
function closeSettingsSelect(el){ function closeSettingsSelect(el) {
for(let ele of document.getElementsByClassName('settingsSelectContainer')) { for (let ele of document.getElementsByClassName('settingsSelectContainer')) {
const selectedDiv = ele.getElementsByClassName('settingsSelectSelected')[0] const selectedDiv = ele.getElementsByClassName('settingsSelectSelected')[0]
const optionsDiv = ele.getElementsByClassName('settingsSelectOptions')[0] const optionsDiv = ele.getElementsByClassName('settingsSelectOptions')[0]
if(!(selectedDiv === el)) { if (!(selectedDiv === el)) {
selectedDiv.classList.remove('select-arrow-active') selectedDiv.classList.remove('select-arrow-active')
optionsDiv.setAttribute('hidden', '') optionsDiv.setAttribute('hidden', '')
} }
@ -42,6 +42,21 @@ document.addEventListener('click', closeSettingsSelect)
bindSettingsSelect() bindSettingsSelect()
function bindFolderOpeners(){
for(let ele of document.getElementsByClassName('settingsFolderOpenButton')){
ele.onclick = async e => {
const pathId = ele.getAttribute('pathId')
if(pathId){
if(pathId === 'DataDirectory'){
shell.openPath(ConfigManager.getDataDirectory())
}
}
}
}
}
bindFolderOpeners()
function bindFileSelectors(){ function bindFileSelectors(){
for(let ele of document.getElementsByClassName('settingsFileSelButton')){ for(let ele of document.getElementsByClassName('settingsFileSelButton')){
@ -55,11 +70,11 @@ function bindFileSelectors(){
properties properties
} }
if(ele.hasAttribute('dialogTitle')) { if (ele.hasAttribute('dialogTitle')) {
options.title = ele.getAttribute('dialogTitle') options.title = ele.getAttribute('dialogTitle')
} }
if(isJavaExecSel && process.platform === 'win32') { if (isJavaExecSel && process.platform === 'win32') {
options.filters = [ options.filters = [
{ name: 'Executables', extensions: ['exe'] }, { name: 'Executables', extensions: ['exe'] },
{ name: 'All Files', extensions: ['*'] } { name: 'All Files', extensions: ['*'] }
@ -67,9 +82,9 @@ function bindFileSelectors(){
} }
const res = await remote.dialog.showOpenDialog(remote.getCurrentWindow(), options) const res = await remote.dialog.showOpenDialog(remote.getCurrentWindow(), options)
if(!res.canceled) { if (!res.canceled) {
ele.previousElementSibling.value = res.filePaths[0] ele.previousElementSibling.value = res.filePaths[0]
if(isJavaExecSel) { if (isJavaExecSel) {
populateJavaExecDetails(ele.previousElementSibling.value) populateJavaExecDetails(ele.previousElementSibling.value)
} }
} }
@ -91,24 +106,24 @@ bindFileSelectors()
* will be disabled until the value is corrected. This is an automated * will be disabled until the value is corrected. This is an automated
* process. More complex UI may need to be bound separately. * process. More complex UI may need to be bound separately.
*/ */
function initSettingsValidators(){ function initSettingsValidators() {
const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]') const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]')
Array.from(sEls).map((v, index, arr) => { Array.from(sEls).map((v, index, arr) => {
const vFn = ConfigManager['validate' + v.getAttribute('cValue')] const vFn = ConfigManager['validate' + v.getAttribute('cValue')]
if(typeof vFn === 'function'){ if (typeof vFn === 'function') {
if(v.tagName === 'INPUT'){ if (v.tagName === 'INPUT') {
if(v.type === 'number' || v.type === 'text'){ if (v.type === 'number' || v.type === 'text') {
v.addEventListener('keyup', (e) => { v.addEventListener('keyup', (e) => {
const v = e.target const v = e.target
if(!vFn(v.value)){ if (!vFn(v.value)) {
settingsState.invalid.add(v.id) settingsState.invalid.add(v.id)
v.setAttribute('error', '') v.setAttribute('error', '')
settingsSaveDisabled(true) settingsSaveDisabled(true)
} else { } else {
if(v.hasAttribute('error')){ if (v.hasAttribute('error')) {
v.removeAttribute('error') v.removeAttribute('error')
settingsState.invalid.delete(v.id) settingsState.invalid.delete(v.id)
if(settingsState.invalid.size === 0){ if (settingsState.invalid.size === 0) {
settingsSaveDisabled(false) settingsSaveDisabled(false)
} }
} }
@ -124,19 +139,19 @@ function initSettingsValidators(){
/** /**
* Load configuration values onto the UI. This is an automated process. * Load configuration values onto the UI. This is an automated process.
*/ */
function initSettingsValues(){ function initSettingsValues() {
const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]') const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]')
Array.from(sEls).map((v, index, arr) => { Array.from(sEls).map((v, index, arr) => {
const cVal = v.getAttribute('cValue') const cVal = v.getAttribute('cValue')
const gFn = ConfigManager['get' + cVal] const gFn = ConfigManager['get' + cVal]
if(typeof gFn === 'function'){ if (typeof gFn === 'function') {
if(v.tagName === 'INPUT'){ if (v.tagName === 'INPUT') {
if(v.type === 'number' || v.type === 'text'){ if (v.type === 'number' || v.type === 'text') {
// Special Conditions // Special Conditions
if(cVal === 'JavaExecutable'){ if (cVal === 'JavaExecutable') {
populateJavaExecDetails(v.value) populateJavaExecDetails(v.value)
v.value = gFn() v.value = gFn()
} else if (cVal === 'DataDirectory'){ } else if (cVal === 'DataDirectory') {
v.value = gFn() v.value = gFn()
} else if (cVal === 'ServerCode'){ } else if (cVal === 'ServerCode'){
v.value = gFn() v.value = gFn()
@ -145,16 +160,16 @@ function initSettingsValues(){
} else { } else {
v.value = gFn() v.value = gFn()
} }
} else if(v.type === 'checkbox'){ } else if (v.type === 'checkbox') {
v.checked = gFn() v.checked = gFn()
} }
} else if(v.tagName === 'DIV'){ } else if (v.tagName === 'DIV') {
if(v.classList.contains('rangeSlider')){ if (v.classList.contains('rangeSlider')) {
// Special Conditions // Special Conditions
if(cVal === 'MinRAM' || cVal === 'MaxRAM'){ if (cVal === 'MinRAM' || cVal === 'MaxRAM') {
let val = gFn() let val = gFn()
if(val.endsWith('M')){ if (val.endsWith('M')) {
val = Number(val.substring(0, val.length-1))/1000 val = Number(val.substring(0, val.length - 1)) / 1000
} else { } else {
val = Number.parseFloat(val) val = Number.parseFloat(val)
} }
@ -173,34 +188,34 @@ function initSettingsValues(){
/** /**
* Save the settings values. * Save the settings values.
*/ */
function saveSettingsValues(){ function saveSettingsValues() {
const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]') const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]')
Array.from(sEls).map((v, index, arr) => { Array.from(sEls).map((v, index, arr) => {
const cVal = v.getAttribute('cValue') const cVal = v.getAttribute('cValue')
const sFn = ConfigManager['set' + cVal] const sFn = ConfigManager['set' + cVal]
if(typeof sFn === 'function'){ if (typeof sFn === 'function') {
if(v.tagName === 'INPUT'){ if (v.tagName === 'INPUT') {
if(v.type === 'number' || v.type === 'text'){ if (v.type === 'number' || v.type === 'text') {
// Special Conditions // Special Conditions
if(cVal === 'JVMOptions'){ if (cVal === 'JVMOptions') {
sFn(v.value.split(' ')) sFn(v.value.split(' '))
} else { } else {
sFn(v.value) sFn(v.value)
} }
} else if(v.type === 'checkbox'){ } else if (v.type === 'checkbox') {
sFn(v.checked) sFn(v.checked)
// Special Conditions // Special Conditions
if(cVal === 'AllowPrerelease'){ if (cVal === 'AllowPrerelease') {
changeAllowPrerelease(v.checked) changeAllowPrerelease(v.checked)
} }
} }
} else if(v.tagName === 'DIV'){ } else if (v.tagName === 'DIV') {
if(v.classList.contains('rangeSlider')){ if (v.classList.contains('rangeSlider')) {
// Special Conditions // Special Conditions
if(cVal === 'MinRAM' || cVal === 'MaxRAM'){ if (cVal === 'MinRAM' || cVal === 'MaxRAM') {
let val = Number(v.getAttribute('value')) let val = Number(v.getAttribute('value'))
if(val%1 > 0){ if (val % 1 > 0) {
val = val*1000 + 'M' val = val * 1000 + 'M'
} else { } else {
val = val + 'G' val = val + 'G'
} }
@ -223,8 +238,8 @@ let selectedSettingsTab = 'settingsTabAccount'
* *
* @param {UIEvent} e The scroll event. * @param {UIEvent} e The scroll event.
*/ */
function settingsTabScrollListener(e){ function settingsTabScrollListener(e) {
if(e.target.scrollTop > Number.parseFloat(getComputedStyle(e.target.firstElementChild).marginTop)){ if (e.target.scrollTop > Number.parseFloat(getComputedStyle(e.target.firstElementChild).marginTop)) {
document.getElementById('settingsContainer').setAttribute('scrolled', '') document.getElementById('settingsContainer').setAttribute('scrolled', '')
} else { } else {
document.getElementById('settingsContainer').removeAttribute('scrolled') document.getElementById('settingsContainer').removeAttribute('scrolled')
@ -234,9 +249,9 @@ function settingsTabScrollListener(e){
/** /**
* Bind functionality for the settings navigation items. * Bind functionality for the settings navigation items.
*/ */
function setupSettingsTabs(){ function setupSettingsTabs() {
Array.from(document.getElementsByClassName('settingsNavItem')).map((val) => { Array.from(document.getElementsByClassName('settingsNavItem')).map((val) => {
if(val.hasAttribute('rSc')){ if (val.hasAttribute('rSc')) {
val.onclick = () => { val.onclick = () => {
settingsNavItemListener(val) settingsNavItemListener(val)
} }
@ -251,13 +266,13 @@ function setupSettingsTabs(){
* @param {Element} ele The nav item which has been clicked. * @param {Element} ele The nav item which has been clicked.
* @param {boolean} fade Optional. True to fade transition. * @param {boolean} fade Optional. True to fade transition.
*/ */
function settingsNavItemListener(ele, fade = true){ function settingsNavItemListener(ele, fade = true) {
if(ele.hasAttribute('selected')){ if (ele.hasAttribute('selected')) {
return return
} }
const navItems = document.getElementsByClassName('settingsNavItem') const navItems = document.getElementsByClassName('settingsNavItem')
for(let i=0; i<navItems.length; i++){ for (let i = 0; i < navItems.length; i++) {
if(navItems[i].hasAttribute('selected')){ if (navItems[i].hasAttribute('selected')) {
navItems[i].removeAttribute('selected') navItems[i].removeAttribute('selected')
} }
} }
@ -269,9 +284,9 @@ function settingsNavItemListener(ele, fade = true){
document.getElementById(selectedSettingsTab).onscroll = settingsTabScrollListener document.getElementById(selectedSettingsTab).onscroll = settingsTabScrollListener
if(fade){ if(fade){
$(`#${prevTab}`).fadeOut(250, () => { $(`#${prevTab}`).fadeOut(150, () => {
$(`#${selectedSettingsTab}`).fadeIn({ $(`#${selectedSettingsTab}`).fadeIn({
duration: 250, duration: 150,
start: () => { start: () => {
settingsTabScrollListener({ settingsTabScrollListener({
target: document.getElementById(selectedSettingsTab) target: document.getElementById(selectedSettingsTab)
@ -300,7 +315,7 @@ const settingsNavDone = document.getElementById('settingsNavDone')
* *
* @param {boolean} v True to disable, false to enable. * @param {boolean} v True to disable, false to enable.
*/ */
function settingsSaveDisabled(v){ function settingsSaveDisabled(v) {
settingsNavDone.disabled = v settingsNavDone.disabled = v
} }
@ -316,7 +331,7 @@ settingsNavDone.onclick = () => {
if(ConfigManager.getSelectedServer()){ if(ConfigManager.getSelectedServer()){
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()) const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
DiscordWrapper.updateDetails('Ready to Play!') DiscordWrapper.updateDetails('Ready to Play!')
DiscordWrapper.updateState('Modpack: ' + serv.getName()) DiscordWrapper.updateState('Server: ' + serv.getName())
} else { } else {
DiscordWrapper.updateDetails('Landing Screen...') DiscordWrapper.updateDetails('Landing Screen...')
} }
@ -329,7 +344,7 @@ settingsNavDone.onclick = () => {
// Bind the add account button. // Bind the add account button.
document.getElementById('settingsAddAccount').onclick = (e) => { document.getElementById('settingsAddAccount').onclick = (e) => {
switchView(getCurrentView(), VIEWS.login, 500, 500, () => { switchView(getCurrentView(), VIEWS.login, 250, 250, () => {
loginViewOnCancel = VIEWS.settings loginViewOnCancel = VIEWS.settings
loginViewOnSuccess = VIEWS.settings loginViewOnSuccess = VIEWS.settings
loginCancelEnabled(true) loginCancelEnabled(true)
@ -352,10 +367,10 @@ function bindServerCodeButtons(){
if(!ConfigManager.getServerCodes().includes(code) && code){ if(!ConfigManager.getServerCodes().includes(code) && code){
ConfigManager.getServerCodes().push(code) ConfigManager.getServerCodes().push(code)
ConfigManager.save() ConfigManager.save()
loggerSettings.log('Added modpack code to configuration and saved it') loggerSettings.log('Added server code to configuration and saved it')
prepareLauncherTab() prepareLauncherTab()
} else { } else {
loggerSettings.log('Modpack code already exists or is empty, not adding.') loggerSettings.log('Server code already exists or is empty, not adding.')
} }
} }
} }
@ -373,7 +388,7 @@ function bindServerCodeButtons(){
prepareLauncherTab() prepareLauncherTab()
} }
} }
loggerSettings.log('Modpack code doesnt exist!, not removing.') loggerSettings.log('Server code doesnt exist!, not removing.')
} }
}) })
} }
@ -382,15 +397,15 @@ function bindServerCodeButtons(){
* Bind functionality for the account selection buttons. If another account * Bind functionality for the account selection buttons. If another account
* is selected, the UI of the previously selected account will be updated. * is selected, the UI of the previously selected account will be updated.
*/ */
function bindAuthAccountSelect(){ function bindAuthAccountSelect() {
Array.from(document.getElementsByClassName('settingsAuthAccountSelect')).map((val) => { Array.from(document.getElementsByClassName('settingsAuthAccountSelect')).map((val) => {
val.onclick = (e) => { val.onclick = (e) => {
if(val.hasAttribute('selected')){ if (val.hasAttribute('selected')) {
return return
} }
const selectBtns = document.getElementsByClassName('settingsAuthAccountSelect') const selectBtns = document.getElementsByClassName('settingsAuthAccountSelect')
for(let i=0; i<selectBtns.length; i++){ for (let i = 0; i < selectBtns.length; i++) {
if(selectBtns[i].hasAttribute('selected')){ if (selectBtns[i].hasAttribute('selected')) {
selectBtns[i].removeAttribute('selected') selectBtns[i].removeAttribute('selected')
selectBtns[i].innerHTML = 'Select Account' selectBtns[i].innerHTML = 'Select Account'
} }
@ -407,11 +422,11 @@ function bindAuthAccountSelect(){
* the selected account, another account will be selected and the UI will * the selected account, another account will be selected and the UI will
* be updated accordingly. * be updated accordingly.
*/ */
function bindAuthAccountLogOut(){ function bindAuthAccountLogOut() {
Array.from(document.getElementsByClassName('settingsAuthAccountLogOut')).map((val) => { Array.from(document.getElementsByClassName('settingsAuthAccountLogOut')).map((val) => {
val.onclick = (e) => { val.onclick = (e) => {
let isLastAccount = false let isLastAccount = false
if(Object.keys(ConfigManager.getAuthAccounts()).length === 1){ if (Object.keys(ConfigManager.getAuthAccounts()).length === 1) {
isLastAccount = true isLastAccount = true
setOverlayContent( setOverlayContent(
'Warning<br>This is Your Last Account', 'Warning<br>This is Your Last Account',
@ -440,20 +455,24 @@ function bindAuthAccountLogOut(){
}) })
} }
let data = null
/** /**
* Process a log out. * Process a log out.
* *
* @param {Element} val The log out button element. * @param {Element} val The log out button element.
* @param {boolean} isLastAccount If this logout is on the last added account. * @param {boolean} isLastAccount If this logout is on the last added account.
*/ */
function processLogOut(val, isLastAccount, skip = false) { function processLogOut(val, isLastAccount, skip = false) {
data = { data = {
val, val,
isLastAccount isLastAccount
} }
if (!skip) {
const parent = val.closest('.settingsAuthAccount') const parent = val.closest('.settingsAuthAccount')
const uuid = parent.getAttribute('uuid') const uuid = parent.getAttribute('uuid')
if (!skip) {
const account = ConfigManager.getAuthAccount(uuid) const account = ConfigManager.getAuthAccount(uuid)
if (account.type === 'microsoft') { if (account.type === 'microsoft') {
toggleOverlay(true, false, 'msOverlay') toggleOverlay(true, false, 'msOverlay')
@ -462,14 +481,14 @@ function bindAuthAccountLogOut(){
} }
const prevSelAcc = ConfigManager.getSelectedAccount() const prevSelAcc = ConfigManager.getSelectedAccount()
AuthManager.removeAccount(uuid).then(() => { AuthManager.removeAccount(uuid).then(() => {
if(!isLastAccount && uuid === prevSelAcc.uuid){ if (!isLastAccount && uuid === prevSelAcc.uuid) {
const selAcc = ConfigManager.getSelectedAccount() const selAcc = ConfigManager.getSelectedAccount()
refreshAuthAccountSelected(selAcc.uuid) refreshAuthAccountSelected(selAcc.uuid)
updateSelectedAccount(selAcc) updateSelectedAccount(selAcc)
validateSelectedAccount() validateSelectedAccount()
} }
}) })
$(parent).fadeOut(250, () => { $(parent).fadeOut(150, () => {
parent.remove() parent.remove()
}) })
} }
@ -479,21 +498,20 @@ ipcRenderer.on('MSALogoutWindowReply', (event, ...args) => {
processLogOut(data.val, data.isLastAccount, true) processLogOut(data.val, data.isLastAccount, true)
}) })
/** /**
* Refreshes the status of the selected account on the auth account * Refreshes the status of the selected account on the auth account
* elements. * elements.
* *
* @param {string} uuid The UUID of the new selected account. * @param {string} uuid The UUID of the new selected account.
*/ */
function refreshAuthAccountSelected(uuid){ function refreshAuthAccountSelected(uuid) {
Array.from(document.getElementsByClassName('settingsAuthAccount')).map((val) => { Array.from(document.getElementsByClassName('settingsAuthAccount')).map((val) => {
const selBtn = val.getElementsByClassName('settingsAuthAccountSelect')[0] const selBtn = val.getElementsByClassName('settingsAuthAccountSelect')[0]
if(uuid === val.getAttribute('uuid')){ if (uuid === val.getAttribute('uuid')) {
selBtn.setAttribute('selected', '') selBtn.setAttribute('selected', '')
selBtn.innerHTML = 'Selected Account &#10004;' selBtn.innerHTML = 'Selected Account &#10004;'
} else { } else {
if(selBtn.hasAttribute('selected')){ if (selBtn.hasAttribute('selected')) {
selBtn.removeAttribute('selected') selBtn.removeAttribute('selected')
} }
selBtn.innerHTML = 'Select Account' selBtn.innerHTML = 'Select Account'
@ -506,10 +524,10 @@ const settingsCurrentAccounts = document.getElementById('settingsCurrentAccounts
/** /**
* Add auth account elements for each one stored in the authentication database. * Add auth account elements for each one stored in the authentication database.
*/ */
function populateAuthAccounts(){ function populateAuthAccounts() {
const authAccounts = ConfigManager.getAuthAccounts() const authAccounts = ConfigManager.getAuthAccounts()
const authKeys = Object.keys(authAccounts) const authKeys = Object.keys(authAccounts)
if(authKeys.length === 0){ if (authKeys.length === 0) {
return return
} }
const selectedUUID = ConfigManager.getSelectedAccount().uuid const selectedUUID = ConfigManager.getSelectedAccount().uuid
@ -571,12 +589,12 @@ function prepareLauncherTab() {
* Disable decimals, negative signs, and scientific notation. * Disable decimals, negative signs, and scientific notation.
*/ */
document.getElementById('settingsGameWidth').addEventListener('keydown', (e) => { document.getElementById('settingsGameWidth').addEventListener('keydown', (e) => {
if(/^[-.eE]$/.test(e.key)){ if (/^[-.eE]$/.test(e.key)) {
e.preventDefault() e.preventDefault()
} }
}) })
document.getElementById('settingsGameHeight').addEventListener('keydown', (e) => { document.getElementById('settingsGameHeight').addEventListener('keydown', (e) => {
if(/^[-.eE]$/.test(e.key)){ if (/^[-.eE]$/.test(e.key)) {
e.preventDefault() e.preventDefault()
} }
}) })
@ -590,7 +608,7 @@ const settingsModsContainer = document.getElementById('settingsModsContainer')
/** /**
* Resolve and update the mods on the UI. * Resolve and update the mods on the UI.
*/ */
function resolveModsForUI(){ function resolveModsForUI() {
const serv = ConfigManager.getSelectedServer() const serv = ConfigManager.getSelectedServer()
const distro = DistroManager.getDistribution() const distro = DistroManager.getDistribution()
@ -609,16 +627,16 @@ function resolveModsForUI(){
* @param {boolean} submodules Whether or not we are parsing submodules. * @param {boolean} submodules Whether or not we are parsing submodules.
* @param {Object} servConf The server configuration object for this module level. * @param {Object} servConf The server configuration object for this module level.
*/ */
function parseModulesForUI(mdls, submodules, servConf){ function parseModulesForUI(mdls, submodules, servConf) {
let reqMods = '' let reqMods = ''
let optMods = '' let optMods = ''
for(const mdl of mdls){ for (const mdl of mdls) {
if(mdl.getType() === DistroManager.Types.ForgeMod || mdl.getType() === DistroManager.Types.LiteMod || mdl.getType() === DistroManager.Types.LiteLoader){ if (mdl.getType() === DistroManager.Types.ForgeMod || mdl.getType() === DistroManager.Types.LiteMod || mdl.getType() === DistroManager.Types.LiteLoader) {
if(mdl.getRequired().isRequired()){ if (mdl.getRequired().isRequired()) {
reqMods += `<div id="${mdl.getVersionlessID()}" class="settingsBaseMod settings${submodules ? 'Sub' : ''}Mod" enabled> reqMods += `<div id="${mdl.getVersionlessID()}" class="settingsBaseMod settings${submodules ? 'Sub' : ''}Mod" enabled>
<div class="settingsModContent"> <div class="settingsModContent">
@ -678,11 +696,11 @@ function parseModulesForUI(mdls, submodules, servConf){
* Bind functionality to mod config toggle switches. Switching the value * Bind functionality to mod config toggle switches. Switching the value
* will also switch the status color on the left of the mod UI. * will also switch the status color on the left of the mod UI.
*/ */
function bindModsToggleSwitch(){ function bindModsToggleSwitch() {
const sEls = settingsModsContainer.querySelectorAll('[formod]') const sEls = settingsModsContainer.querySelectorAll('[formod]')
Array.from(sEls).map((v, index, arr) => { Array.from(sEls).map((v, index, arr) => {
v.onchange = () => { v.onchange = () => {
if(v.checked) { if (v.checked) {
document.getElementById(v.getAttribute('formod')).setAttribute('enabled', '') document.getElementById(v.getAttribute('formod')).setAttribute('enabled', '')
} else { } else {
document.getElementById(v.getAttribute('formod')).removeAttribute('enabled') document.getElementById(v.getAttribute('formod')).removeAttribute('enabled')
@ -695,7 +713,7 @@ function bindModsToggleSwitch(){
/** /**
* Save the mod configuration based on the UI values. * Save the mod configuration based on the UI values.
*/ */
function saveModConfiguration(){ function saveModConfiguration() {
const serv = ConfigManager.getSelectedServer() const serv = ConfigManager.getSelectedServer()
const modConf = ConfigManager.getModConfiguration(serv) const modConf = ConfigManager.getModConfiguration(serv)
modConf.mods = _saveModConfiguration(modConf.mods) modConf.mods = _saveModConfiguration(modConf.mods)
@ -707,15 +725,15 @@ 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(let 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') {
modConf[m[0]] = tSwitch[0].checked modConf[m[0]] = tSwitch[0].checked
} else { } else {
if(m[1] != null){ if (m[1] != null) {
if(tSwitch.length > 0){ if (tSwitch.length > 0) {
modConf[m[0]].value = tSwitch[0].checked modConf[m[0]].value = tSwitch[0].checked
} }
modConf[m[0]].mods = _saveModConfiguration(modConf[m[0]].mods) modConf[m[0]].mods = _saveModConfiguration(modConf[m[0]].mods)
@ -735,7 +753,7 @@ let CACHE_DROPIN_MODS
* Resolve any located drop-in mods for this server and * Resolve any located drop-in mods for this server and
* populate the results onto the UI. * populate the results onto the UI.
*/ */
function resolveDropinModsForUI(){ function resolveDropinModsForUI() {
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()) const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
CACHE_SETTINGS_MODS_DIR = path.join(ConfigManager.getInstanceDirectory(), serv.getID(), 'mods') CACHE_SETTINGS_MODS_DIR = path.join(ConfigManager.getInstanceDirectory(), serv.getID(), 'mods')
CACHE_DROPIN_MODS = DropinModUtil.scanForDropinMods(CACHE_SETTINGS_MODS_DIR, serv.getMinecraftVersion()) CACHE_DROPIN_MODS = DropinModUtil.scanForDropinMods(CACHE_SETTINGS_MODS_DIR, serv.getMinecraftVersion())
@ -743,6 +761,7 @@ function resolveDropinModsForUI(){
let dropinMods = '' let dropinMods = ''
for(dropin of CACHE_DROPIN_MODS){ for(dropin of CACHE_DROPIN_MODS){
dropinMods += `<div id="${dropin.fullName}" class="settingsBaseMod settingsDropinMod" ${!dropin.disabled ? 'enabled' : ''}> dropinMods += `<div id="${dropin.fullName}" class="settingsBaseMod settingsDropinMod" ${!dropin.disabled ? 'enabled' : ''}>
<div class="settingsModContent"> <div class="settingsModContent">
<div class="settingsModMainWrapper"> <div class="settingsModMainWrapper">
@ -799,7 +818,6 @@ function resolveServerCodesForUI(){
const code = ele.getAttribute('code') const code = ele.getAttribute('code')
const servs = DistroManager.getDistribution().getServersFromCode(code) const servs = DistroManager.getDistribution().getServersFromCode(code)
const valid = servs && servs.length const valid = servs && servs.length
loggerSettings.log('valid: ' + valid)
if(valid){ if(valid){
for(let serv of servs){ for(let serv of servs){
loggerSettings.log('server: ' + serv.getName()) loggerSettings.log('server: ' + serv.getName())
@ -821,13 +839,13 @@ function resolveServerCodesForUI(){
/** /**
* Bind the remove button for each loaded drop-in mod. * Bind the remove button for each loaded drop-in mod.
*/ */
function bindDropinModsRemoveButton(){ function bindDropinModsRemoveButton() {
const sEls = settingsModsContainer.querySelectorAll('[remmod]') const sEls = settingsModsContainer.querySelectorAll('[remmod]')
Array.from(sEls).map((v, index, arr) => { Array.from(sEls).map((v, index, arr) => {
v.onclick = async () => { v.onclick = () => {
const fullName = v.getAttribute('remmod') const fullName = v.getAttribute('remmod')
const res = await DropinModUtil.deleteDropinMod(CACHE_SETTINGS_MODS_DIR, fullName) const res = DropinModUtil.deleteDropinMod(CACHE_SETTINGS_MODS_DIR, fullName)
if(res){ if (res) {
document.getElementById(fullName).remove() document.getElementById(fullName).remove()
} else { } else {
setOverlayContent( setOverlayContent(
@ -846,7 +864,7 @@ function bindDropinModsRemoveButton(){
* Bind functionality to the file system button for the selected * Bind functionality to the file system button for the selected
* server configuration. * server configuration.
*/ */
function bindDropinModFileSystemButton(){ function bindDropinModFileSystemButton() {
const fsBtn = document.getElementById('settingsDropinFileSystemButton') const fsBtn = document.getElementById('settingsDropinFileSystemButton')
fsBtn.onclick = () => { fsBtn.onclick = () => {
DropinModUtil.validateDir(CACHE_SETTINGS_MODS_DIR) DropinModUtil.validateDir(CACHE_SETTINGS_MODS_DIR)
@ -877,14 +895,14 @@ function bindDropinModFileSystemButton(){
* Save drop-in mod states. Enabling and disabling is just a matter * Save drop-in mod states. Enabling and disabling is just a matter
* of adding/removing the .disabled extension. * of adding/removing the .disabled extension.
*/ */
function saveDropinModConfiguration(){ function saveDropinModConfiguration() {
for(dropin of CACHE_DROPIN_MODS){ for (dropin of CACHE_DROPIN_MODS) {
const dropinUI = document.getElementById(dropin.fullName) const dropinUI = document.getElementById(dropin.fullName)
if(dropinUI != null){ if (dropinUI != null) {
const dropinUIEnabled = dropinUI.hasAttribute('enabled') const dropinUIEnabled = dropinUI.hasAttribute('enabled')
if(DropinModUtil.isDropinModEnabled(dropin.fullName) != dropinUIEnabled){ if (DropinModUtil.isDropinModEnabled(dropin.fullName) != dropinUIEnabled) {
DropinModUtil.toggleDropinMod(CACHE_SETTINGS_MODS_DIR, dropin.fullName, dropinUIEnabled).catch(err => { DropinModUtil.toggleDropinMod(CACHE_SETTINGS_MODS_DIR, dropin.fullName, dropinUIEnabled).catch(err => {
if(!isOverlayVisible()){ if (!isOverlayVisible()) {
setOverlayContent( setOverlayContent(
'Failed to Toggle<br>One or More Drop-in Mods', 'Failed to Toggle<br>One or More Drop-in Mods',
err.message, err.message,
@ -902,16 +920,15 @@ function saveDropinModConfiguration(){
// Refresh the drop-in mods when F5 is pressed. // Refresh the drop-in mods when F5 is pressed.
// Only active on the mods tab. // Only active on the mods tab.
document.addEventListener('keydown', (e) => { document.addEventListener('keydown', (e) => {
if(getCurrentView() === VIEWS.settings && selectedSettingsTab === 'settingsTabMods'){ if (getCurrentView() === VIEWS.settings && selectedSettingsTab === 'settingsTabMods') {
if(e.key === 'F5'){ if (e.key === 'F5') {
reloadDropinMods() reloadDropinMods()
saveShaderpackSettings()
resolveShaderpacksForUI() resolveShaderpacksForUI()
} }
} }
}) })
function reloadDropinMods(){ function reloadDropinMods() {
resolveDropinModsForUI() resolveDropinModsForUI()
bindDropinModsRemoveButton() bindDropinModsRemoveButton()
bindDropinModFileSystemButton() bindDropinModFileSystemButton()
@ -927,7 +944,7 @@ let CACHE_SELECTED_SHADERPACK
/** /**
* Load shaderpack information. * Load shaderpack information.
*/ */
function resolveShaderpacksForUI(){ function resolveShaderpacksForUI() {
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()) const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
CACHE_SETTINGS_INSTANCE_DIR = path.join(ConfigManager.getInstanceDirectory(), serv.getID()) CACHE_SETTINGS_INSTANCE_DIR = path.join(ConfigManager.getInstanceDirectory(), serv.getID())
CACHE_SHADERPACKS = DropinModUtil.scanForShaderpacks(CACHE_SETTINGS_INSTANCE_DIR) CACHE_SHADERPACKS = DropinModUtil.scanForShaderpacks(CACHE_SETTINGS_INSTANCE_DIR)
@ -936,20 +953,20 @@ function resolveShaderpacksForUI(){
setShadersOptions(CACHE_SHADERPACKS, CACHE_SELECTED_SHADERPACK) setShadersOptions(CACHE_SHADERPACKS, CACHE_SELECTED_SHADERPACK)
} }
function setShadersOptions(arr, selected){ function setShadersOptions(arr, selected) {
const cont = document.getElementById('settingsShadersOptions') const cont = document.getElementById('settingsShadersOptions')
cont.innerHTML = '' cont.innerHTML = ''
for(let opt of arr) { for (let opt of arr) {
const d = document.createElement('DIV') const d = document.createElement('DIV')
d.innerHTML = opt.name d.innerHTML = opt.name
d.setAttribute('value', opt.fullName) d.setAttribute('value', opt.fullName)
if(opt.fullName === selected) { if (opt.fullName === selected) {
d.setAttribute('selected', '') d.setAttribute('selected', '')
document.getElementById('settingsShadersSelected').innerHTML = opt.name document.getElementById('settingsShadersSelected').innerHTML = opt.name
} }
d.addEventListener('click', function(e) { d.addEventListener('click', function (e) {
this.parentNode.previousElementSibling.innerHTML = this.innerHTML this.parentNode.previousElementSibling.innerHTML = this.innerHTML
for(let sib of this.parentNode.children){ for (let sib of this.parentNode.children) {
sib.removeAttribute('selected') sib.removeAttribute('selected')
} }
this.setAttribute('selected', '') this.setAttribute('selected', '')
@ -959,10 +976,10 @@ function setShadersOptions(arr, selected){
} }
} }
function saveShaderpackSettings(){ function saveShaderpackSettings() {
let sel = 'OFF' let sel = 'OFF'
for(let opt of document.getElementById('settingsShadersOptions').childNodes){ for (let opt of document.getElementById('settingsShadersOptions').childNodes) {
if(opt.hasAttribute('selected')){ if (opt.hasAttribute('selected')) {
sel = opt.getAttribute('value') sel = opt.getAttribute('value')
} }
} }
@ -998,32 +1015,22 @@ function bindShaderpackButton() {
} }
} }
// Server status bar functions. // Server status bar functions.
/** /**
* Load the currently selected server information onto the mods tab. * Load the currently selected server information onto the mods tab.
*/ */
function loadSelectedServerOnModsTab(){ function loadSelectedServerOnModsTab() {
const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()) const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
document.getElementById('settingsSelServContent').innerHTML = ` document.getElementById('settingsSelServContent').innerHTML = `
<img class="serverListingImg" src="${serv.getIcon()}"/>
<div class="serverListingDetails"> <div class="serverListingDetails">
<img class="serverListingImg" src="${serv.getIcon()}"/>
<span class="serverListingName">${serv.getName()}</span> <span class="serverListingName">${serv.getName()}</span>
<span class="serverListingDescription">${serv.getDescription()}</span> <span class="serverListingDescription">${serv.getDescription()}</span>
<div class="serverListingInfo"> <div class="serverListingInfo">
<div class="serverListingVersion">${serv.getMinecraftVersion()}</div>
<div class="serverListingRevision">${serv.getVersion()}</div> <div class="serverListingRevision">${serv.getVersion()}</div>
${serv.isMainServer() ? `<div class="serverListingStarWrapper">
<svg id="Layer_1" viewBox="0 0 107.45 104.74" width="20px" height="20px">
<defs>
<style>.cls-1{fill:#fff;}.cls-2{fill:none;stroke:#fff;stroke-miterlimit:10;}</style>
</defs>
<path class="cls-1" d="M100.93,65.54C89,62,68.18,55.65,63.54,52.13c2.7-5.23,18.8-19.2,28-27.55C81.36,31.74,63.74,43.87,58.09,45.3c-2.41-5.37-3.61-26.52-4.37-39-.77,12.46-2,33.64-4.36,39-5.7-1.46-23.3-13.57-33.49-20.72,9.26,8.37,25.39,22.36,28,27.55C39.21,55.68,18.47,62,6.52,65.55c12.32-2,33.63-6.06,39.34-4.9-.16,5.87-8.41,26.16-13.11,37.69,6.1-10.89,16.52-30.16,21-33.9,4.5,3.79,14.93,23.09,21,34C70,86.84,61.73,66.48,61.59,60.65,67.36,59.49,88.64,63.52,100.93,65.54Z"/>
<circle class="cls-2" cx="53.73" cy="53.9" r="38"/>
</svg>
<span class="serverListingStarTooltip">Main Server</span>
</div>` : ''}
</div> </div>
</div> </div>
` `
@ -1038,7 +1045,7 @@ document.getElementById('settingsSwitchServerButton').addEventListener('click',
/** /**
* Save mod configuration for the current selected server. * Save mod configuration for the current selected server.
*/ */
function saveAllModConfigurations(){ function saveAllModConfigurations() {
saveModConfiguration() saveModConfiguration()
ConfigManager.save() ConfigManager.save()
saveDropinModConfiguration() saveDropinModConfiguration()
@ -1049,16 +1056,16 @@ function saveAllModConfigurations(){
* server is changed. * server is changed.
*/ */
function animateModsTabRefresh(){ function animateModsTabRefresh(){
$('#settingsTabMods').fadeOut(500, () => { $('#settingsTabMods').fadeOut(150, () => {
prepareModsTab() prepareModsTab()
$('#settingsTabMods').fadeIn(500) $('#settingsTabMods').fadeIn(150)
}) })
} }
/** /**
* Prepare the Mods tab for display. * Prepare the Mods tab for display.
*/ */
function prepareModsTab(first){ function prepareModsTab(first) {
resolveModsForUI() resolveModsForUI()
resolveDropinModsForUI() resolveDropinModsForUI()
resolveShaderpacksForUI() resolveShaderpacksForUI()
@ -1090,7 +1097,7 @@ const SETTINGS_MIN_MEMORY = ConfigManager.getAbsoluteMinRAM()
settingsMaxRAMRange.setAttribute('max', SETTINGS_MAX_MEMORY) settingsMaxRAMRange.setAttribute('max', SETTINGS_MAX_MEMORY)
settingsMaxRAMRange.setAttribute('min', SETTINGS_MIN_MEMORY) settingsMaxRAMRange.setAttribute('min', SETTINGS_MIN_MEMORY)
settingsMinRAMRange.setAttribute('max', SETTINGS_MAX_MEMORY) settingsMinRAMRange.setAttribute('max', SETTINGS_MAX_MEMORY)
settingsMinRAMRange.setAttribute('min', SETTINGS_MIN_MEMORY ) settingsMinRAMRange.setAttribute('min', SETTINGS_MIN_MEMORY)
// Bind on change event for min memory container. // Bind on change event for min memory container.
settingsMinRAMRange.onchange = (e) => { settingsMinRAMRange.onchange = (e) => {
@ -1102,7 +1109,7 @@ settingsMinRAMRange.onchange = (e) => {
// Get reference to range bar. // Get reference to range bar.
const bar = e.target.getElementsByClassName('rangeSliderBar')[0] const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
// Calculate effective total memory. // Calculate effective total memory.
const max = (os.totalmem()-1000000000)/1000000000 const max = (os.totalmem() - 1000000000) / 1000000000
// Change range bar color based on the selected value. // Change range bar color based on the selected value.
if(sMinV >= max/1.25){ if(sMinV >= max/1.25){
@ -1114,10 +1121,10 @@ settingsMinRAMRange.onchange = (e) => {
} }
// Increase maximum memory if the minimum exceeds its value. // Increase maximum memory if the minimum exceeds its value.
if(sMaxV < sMinV){ if (sMaxV < sMinV) {
const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange) const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange)
updateRangedSlider(settingsMaxRAMRange, sMinV, updateRangedSlider(settingsMaxRAMRange, sMinV,
((sMinV-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc) ((sMinV - sliderMeta.min) / sliderMeta.step) * sliderMeta.inc)
settingsMaxRAMLabel.innerHTML = sMinV.toFixed(1) + 'G' settingsMaxRAMLabel.innerHTML = sMinV.toFixed(1) + 'G'
} }
@ -1134,7 +1141,7 @@ settingsMaxRAMRange.onchange = (e) => {
// Get reference to range bar. // Get reference to range bar.
const bar = e.target.getElementsByClassName('rangeSliderBar')[0] const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
// Calculate effective total memory. // Calculate effective total memory.
const max = (os.totalmem()-1000000000)/1000000000 const max = (os.totalmem() - 1000000000) / 1000000000
// Change range bar color based on the selected value. // Change range bar color based on the selected value.
if(sMaxV >= max/1.25){ if(sMaxV >= max/1.25){
@ -1146,10 +1153,10 @@ settingsMaxRAMRange.onchange = (e) => {
} }
// Decrease the minimum memory if the maximum value is less. // Decrease the minimum memory if the maximum value is less.
if(sMaxV < sMinV){ if (sMaxV < sMinV) {
const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange) const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange)
updateRangedSlider(settingsMinRAMRange, sMaxV, updateRangedSlider(settingsMinRAMRange, sMaxV,
((sMaxV-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc) ((sMaxV - sliderMeta.min) / sliderMeta.step) * sliderMeta.inc)
settingsMinRAMLabel.innerHTML = sMaxV.toFixed(1) + 'G' settingsMinRAMLabel.innerHTML = sMaxV.toFixed(1) + 'G'
} }
settingsMaxRAMLabel.innerHTML = sMaxV.toFixed(1) + 'G' settingsMaxRAMLabel.innerHTML = sMaxV.toFixed(1) + 'G'
@ -1161,14 +1168,14 @@ settingsMaxRAMRange.onchange = (e) => {
* @param {Element} v The range slider to calculate against. * @param {Element} v The range slider to calculate against.
* @returns {Object} An object with meta values for the provided ranged slider. * @returns {Object} An object with meta values for the provided ranged slider.
*/ */
function calculateRangeSliderMeta(v){ function calculateRangeSliderMeta(v) {
const val = { const val = {
max: Number(v.getAttribute('max')), max: Number(v.getAttribute('max')),
min: Number(v.getAttribute('min')), min: Number(v.getAttribute('min')),
step: Number(v.getAttribute('step')), step: Number(v.getAttribute('step')),
} }
val.ticks = (val.max-val.min)/val.step val.ticks = (val.max - val.min) / val.step
val.inc = 100/val.ticks val.inc = 100 / val.ticks
return val return val
} }
@ -1176,7 +1183,7 @@ function calculateRangeSliderMeta(v){
* Binds functionality to the ranged sliders. They're more than * Binds functionality to the ranged sliders. They're more than
* just divs now :'). * just divs now :').
*/ */
function bindRangeSlider(){ function bindRangeSlider() {
Array.from(document.getElementsByClassName('rangeSlider')).map((v) => { Array.from(document.getElementsByClassName('rangeSlider')).map((v) => {
// Reference the track (thumb). // Reference the track (thumb).
@ -1186,7 +1193,7 @@ function bindRangeSlider(){
const value = v.getAttribute('value') const value = v.getAttribute('value')
const sliderMeta = calculateRangeSliderMeta(v) const sliderMeta = calculateRangeSliderMeta(v)
updateRangedSlider(v, value, ((value-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc) updateRangedSlider(v, value, ((value - sliderMeta.min) / sliderMeta.step) * sliderMeta.inc)
// The magic happens when we click on the track. // The magic happens when we click on the track.
track.onmousedown = (e) => { track.onmousedown = (e) => {
@ -1201,19 +1208,19 @@ function bindRangeSlider(){
document.onmousemove = (e) => { document.onmousemove = (e) => {
// Distance from the beginning of the bar in pixels. // Distance from the beginning of the bar in pixels.
const diff = e.pageX - v.offsetLeft - track.offsetWidth/2 const diff = e.pageX - v.offsetLeft - track.offsetWidth / 2
// Don't move the track off the bar. // Don't move the track off the bar.
if(diff >= 0 && diff <= v.offsetWidth-track.offsetWidth/2){ if (diff >= 0 && diff <= v.offsetWidth - track.offsetWidth / 2) {
// Convert the difference to a percentage. // Convert the difference to a percentage.
const perc = (diff/v.offsetWidth)*100 const perc = (diff / v.offsetWidth) * 100
// Calculate the percentage of the closest notch. // Calculate the percentage of the closest notch.
const notch = Number(perc/sliderMeta.inc).toFixed(0)*sliderMeta.inc const notch = Number(perc / sliderMeta.inc).toFixed(0) * sliderMeta.inc
// If we're close to that notch, stick to it. // If we're close to that notch, stick to it.
if(Math.abs(perc-notch) < sliderMeta.inc/2){ if (Math.abs(perc - notch) < sliderMeta.inc / 2) {
updateRangedSlider(v, sliderMeta.min+(sliderMeta.step*(notch/sliderMeta.inc)), notch) updateRangedSlider(v, sliderMeta.min + (sliderMeta.step * (notch / sliderMeta.inc)), notch)
} }
} }
} }
@ -1228,16 +1235,16 @@ function bindRangeSlider(){
* @param {string | number} value The new value for the ranged slider. * @param {string | number} value The new value for the ranged slider.
* @param {number} notch The notch that the slider should now be at. * @param {number} notch The notch that the slider should now be at.
*/ */
function updateRangedSlider(element, value, notch){ function updateRangedSlider(element, value, notch) {
const oldVal = element.getAttribute('value') const oldVal = element.getAttribute('value')
const bar = element.getElementsByClassName('rangeSliderBar')[0] const bar = element.getElementsByClassName('rangeSliderBar')[0]
const track = element.getElementsByClassName('rangeSliderTrack')[0] const track = element.getElementsByClassName('rangeSliderTrack')[0]
element.setAttribute('value', value) element.setAttribute('value', value)
if(notch < 0){ if (notch < 0) {
notch = 0 notch = 0
} else if(notch > 100) { } else if (notch > 100) {
notch = 100 notch = 100
} }
@ -1250,7 +1257,7 @@ function updateRangedSlider(element, value, notch){
let cancelled = !element.dispatchEvent(event) let cancelled = !element.dispatchEvent(event)
if(!cancelled){ if (!cancelled) {
track.style.left = notch + '%' track.style.left = notch + '%'
bar.style.width = notch + '%' bar.style.width = notch + '%'
} else { } else {
@ -1261,9 +1268,9 @@ function updateRangedSlider(element, value, notch){
/** /**
* Display the total and available RAM. * Display the total and available RAM.
*/ */
function populateMemoryStatus(){ function populateMemoryStatus() {
settingsMemoryTotal.innerHTML = Number((os.totalmem()-1000000000)/1000000000).toFixed(1) + 'G' settingsMemoryTotal.innerHTML = Number((os.totalmem() - 1000000000) / 1000000000).toFixed(1) + 'G'
settingsMemoryAvail.innerHTML = Number(os.freemem()/1000000000).toFixed(1) + 'G' settingsMemoryAvail.innerHTML = Number(os.freemem() / 1000000000).toFixed(1) + 'G'
} }
/** /**
@ -1272,12 +1279,12 @@ function populateMemoryStatus(){
* *
* @param {string} execPath The executable path to populate against. * @param {string} execPath The executable path to populate against.
*/ */
function populateJavaExecDetails(execPath){ function populateJavaExecDetails(execPath) {
const jg = new JavaGuard(DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()).getMinecraftVersion()) const jg = new JavaGuard(DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()).getMinecraftVersion())
jg._validateJavaBinary(execPath).then(v => { jg._validateJavaBinary(execPath).then(v => {
if(v.valid){ if (v.valid) {
const vendor = v.vendor != null ? ` (${v.vendor})` : '' const vendor = v.vendor != null ? ` (${v.vendor})` : ''
if(v.version.major < 9) { if (v.version.major < 9) {
settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major} Update ${v.version.update} (x${v.arch})${vendor}` settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major} Update ${v.version.update} (x${v.arch})${vendor}`
} else { } else {
settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major}.${v.version.minor}.${v.version.revision} (x${v.arch})${vendor}` settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major}.${v.version.minor}.${v.version.revision} (x${v.arch})${vendor}`
@ -1291,7 +1298,7 @@ function populateJavaExecDetails(execPath){
/** /**
* Prepare the Java tab for display. * Prepare the Java tab for display.
*/ */
function prepareJavaTab(){ function prepareJavaTab() {
bindRangeSlider() bindRangeSlider()
populateMemoryStatus() populateMemoryStatus()
} }
@ -1317,8 +1324,11 @@ document.getElementById('settingsAboutDevToolsButton').onclick = (e) => {
* @param {string} version The semver version to test. * @param {string} version The semver version to test.
* @returns {boolean} True if the version is a prerelease, otherwise false. * @returns {boolean} True if the version is a prerelease, otherwise false.
*/ */
function isPrerelease(version){ function isPrerelease(version) {
const preRelComp = semver.prerelease(version) const preRelComp = semver.prerelease(version)
if(preRelComp != null && preRelComp.includes('release')) {
return false
}
return preRelComp != null && preRelComp.length > 0 return preRelComp != null && preRelComp.length > 0
} }
@ -1331,9 +1341,9 @@ function isPrerelease(version){
* @param {Element} titleElement The title element. * @param {Element} titleElement The title element.
* @param {Element} checkElement The check mark element. * @param {Element} checkElement The check mark element.
*/ */
function populateVersionInformation(version, valueElement, titleElement, checkElement){ function populateVersionInformation(version, valueElement, titleElement, checkElement) {
valueElement.innerHTML = version valueElement.innerHTML = version
if(isPrerelease(version)){ if (isPrerelease(version)) {
titleElement.innerHTML = 'Pre-release' titleElement.innerHTML = 'Pre-release'
titleElement.style.color = '#ff886d' titleElement.style.color = '#ff886d'
checkElement.style.background = '#ff886d' checkElement.style.background = '#ff886d'
@ -1347,7 +1357,7 @@ function populateVersionInformation(version, valueElement, titleElement, checkEl
/** /**
* Retrieve the version information and display it on the UI. * Retrieve the version information and display it on the UI.
*/ */
function populateAboutVersionInformation(){ function populateAboutVersionInformation() {
populateVersionInformation(remote.app.getVersion(), document.getElementById('settingsAboutCurrentVersionValue'), document.getElementById('settingsAboutCurrentVersionTitle'), document.getElementById('settingsAboutCurrentVersionCheck')) populateVersionInformation(remote.app.getVersion(), document.getElementById('settingsAboutCurrentVersionValue'), document.getElementById('settingsAboutCurrentVersionTitle'), document.getElementById('settingsAboutCurrentVersionCheck'))
} }
@ -1355,19 +1365,19 @@ function populateAboutVersionInformation(){
* Fetches the GitHub atom release feed and parses it for the release notes * Fetches the GitHub atom release feed and parses it for the release notes
* of the current version. This value is displayed on the UI. * of the current version. This value is displayed on the UI.
*/ */
function populateReleaseNotes(){ function populateReleaseNotes() {
$.ajax({ $.ajax({
url: 'https://github.com/VicariousNetwork/HeliosLauncher/releases.atom', url: 'https://github.com/ModRealms-Network/HeliosLauncher/releases.atom',
success: (data) => { success: (data) => {
const version = 'v' + remote.app.getVersion() const version = 'v' + remote.app.getVersion()
const entries = $(data).find('entry') const entries = $(data).find('entry')
for(let i=0; i<entries.length; i++){ for (let i = 0; i < entries.length; i++) {
const entry = $(entries[i]) const entry = $(entries[i])
let id = entry.find('id').text() let id = entry.find('id').text()
id = id.substring(id.lastIndexOf('/')+1) id = id.substring(id.lastIndexOf('/') + 1)
if(id === version){ if (id === version) {
settingsAboutChangelogTitle.innerHTML = entry.find('title').text() settingsAboutChangelogTitle.innerHTML = entry.find('title').text()
settingsAboutChangelogText.innerHTML = entry.find('content').text() settingsAboutChangelogText.innerHTML = entry.find('content').text()
settingsAboutChangelogButton.href = entry.find('link').attr('href') settingsAboutChangelogButton.href = entry.find('link').attr('href')
@ -1375,7 +1385,7 @@ function populateReleaseNotes(){
} }
}, },
timeout: 2500 timeout: 10000
}).catch(err => { }).catch(err => {
settingsAboutChangelogText.innerHTML = 'Failed to load release notes.' settingsAboutChangelogText.innerHTML = 'Failed to load release notes.'
}) })
@ -1384,7 +1394,7 @@ function populateReleaseNotes(){
/** /**
* Prepare account tab for display. * Prepare account tab for display.
*/ */
function prepareAboutTab(){ function prepareAboutTab() {
populateAboutVersionInformation() populateAboutVersionInformation()
populateReleaseNotes() populateReleaseNotes()
} }
@ -1410,10 +1420,10 @@ const settingsUpdateActionButton = document.getElementById('settingsUpdateActi
* @param {boolean} disabled Optional. Disable or enable the button * @param {boolean} disabled Optional. Disable or enable the button
* @param {function} handler Optional. New button event handler. * @param {function} handler Optional. New button event handler.
*/ */
function settingsUpdateButtonStatus(text, disabled = false, handler = null){ function settingsUpdateButtonStatus(text, disabled = false, handler = null) {
settingsUpdateActionButton.innerHTML = text settingsUpdateActionButton.innerHTML = text
settingsUpdateActionButton.disabled = disabled settingsUpdateActionButton.disabled = disabled
if(handler != null){ if (handler != null) {
settingsUpdateActionButton.onclick = handler settingsUpdateActionButton.onclick = handler
} }
} }
@ -1423,27 +1433,27 @@ function settingsUpdateButtonStatus(text, disabled = false, handler = null){
* *
* @param {Object} data The update data. * @param {Object} data The update data.
*/ */
function populateSettingsUpdateInformation(data){ function populateSettingsUpdateInformation(data) {
if(data != null){ if (data != null) {
settingsUpdateTitle.innerHTML = `New ${isPrerelease(data.version) ? 'Pre-release' : 'Release'} Available` settingsUpdateTitle.innerHTML = `New ${isPrerelease(data.version) ? 'Pre-release' : 'Release'} Available`
settingsUpdateChangelogCont.style.display = null settingsUpdateChangelogCont.style.display = null
settingsUpdateChangelogTitle.innerHTML = data.releaseName settingsUpdateChangelogTitle.innerHTML = data.releaseName
settingsUpdateChangelogText.innerHTML = data.releaseNotes settingsUpdateChangelogText.innerHTML = data.releaseNotes
populateVersionInformation(data.version, settingsUpdateVersionValue, settingsUpdateVersionTitle, settingsUpdateVersionCheck) populateVersionInformation(data.version, settingsUpdateVersionValue, settingsUpdateVersionTitle, settingsUpdateVersionCheck)
if(process.platform === 'darwin'){ if (process.platform === 'darwin') {
settingsUpdateButtonStatus('Download from GitHub<span style="font-size: 10px;color: gray;text-shadow: none !important;">Close the launcher and run the dmg to update.</span>', false, () => { settingsUpdateButtonStatus('Download from GitHub<span style="font-size: 10px;color: gray;text-shadow: none !important;">Close the launcher and run the dmg to update.</span>', false, () => {
shell.openExternal(data.darwindownload) shell.openExternal(data.darwindownload)
}) })
} else { } else {
settingsUpdateButtonStatus('Downloading..', true) settingsUpdateButtonStatus('Downloading...', true)
} }
} else { } else {
settingsUpdateTitle.innerHTML = 'You Are Running the Latest Version' settingsUpdateTitle.innerHTML = 'You Are Running the Latest Version'
settingsUpdateChangelogCont.style.display = 'none' settingsUpdateChangelogCont.style.display = 'none'
populateVersionInformation(remote.app.getVersion(), settingsUpdateVersionValue, settingsUpdateVersionTitle, settingsUpdateVersionCheck) populateVersionInformation(remote.app.getVersion(), settingsUpdateVersionValue, settingsUpdateVersionTitle, settingsUpdateVersionCheck)
settingsUpdateButtonStatus('Check for Updates', false, () => { settingsUpdateButtonStatus('Check for Updates', false, () => {
if(!isDev){ if (!isDev) {
ipcRenderer.send('autoUpdateAction', 'checkForUpdate') ipcRenderer.send('autoUpdateAction', 'checkForUpdate')
settingsUpdateButtonStatus('Checking for Updates..', true) settingsUpdateButtonStatus('Checking for Updates..', true)
} }
@ -1456,7 +1466,7 @@ function populateSettingsUpdateInformation(data){
* *
* @param {Object} data The update data. * @param {Object} data The update data.
*/ */
function prepareUpdateTab(data = null){ function prepareUpdateTab(data = null) {
populateSettingsUpdateInformation(data) populateSettingsUpdateInformation(data)
} }
@ -1470,7 +1480,7 @@ function prepareUpdateTab(data = null){
* @param {boolean} first Whether or not it is the first load. * @param {boolean} first Whether or not it is the first load.
*/ */
function prepareSettings(first = false) { function prepareSettings(first = false) {
if(first){ if (first) {
setupSettingsTabs() setupSettingsTabs()
initSettingsValidators() initSettingsValidators()
prepareUpdateTab() prepareUpdateTab()

View File

@ -7,8 +7,7 @@
</div> </div>
<div id="loginContent"> <div id="loginContent">
<form id="loginForm"> <form id="loginForm">
<img id="loginImageSeal" src="assets/images/SealCircle.png" /> <span id="loginSubheader">MOJANG LOGIN</span>
<span id="loginSubheader">MINECRAFT LOGIN</span>
<div class="loginFieldContainer"> <div class="loginFieldContainer">
<svg id="profileSVG" class="loginSVG" viewBox="40 37 65.36 61.43"> <svg id="profileSVG" class="loginSVG" viewBox="40 37 65.36 61.43">
<g> <g>