diff --git a/app/assets/js/mojang.js b/app/assets/js/mojang.js index 85e0e7f3..13b4c875 100644 --- a/app/assets/js/mojang.js +++ b/app/assets/js/mojang.js @@ -67,14 +67,14 @@ const statuses = [ exports.statusToHex = function(status){ switch(status.toLowerCase()){ case 'green': - return '#a5c325' + return '#4DDD19' case 'yellow': - return '#eac918' + return '#FFE300' case 'red': return '#c32625' case 'grey': default: - return '#848484' + return '#3B3B3B' } } diff --git a/app/assets/js/scripts/login.js b/app/assets/js/scripts/login.js index cd77d635..0a534ebd 100644 --- a/app/assets/js/scripts/login.js +++ b/app/assets/js/scripts/login.js @@ -396,20 +396,6 @@ ipcRenderer.on('MSALoginWindowReply', (event, ...args) => { // Temporary workaround if (loginViewOnSuccess === VIEWS.settings) { 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. loginCancelEnabled(false) // Reset this for good measure. diff --git a/app/assets/js/scripts/settings.js b/app/assets/js/scripts/settings.js index 93a71f68..d065a7fa 100644 --- a/app/assets/js/scripts/settings.js +++ b/app/assets/js/scripts/settings.js @@ -1,9 +1,9 @@ // Requirements -const os = require('os') +const os = require('os') const semver = require('semver') const { JavaGuard } = require('./assets/js/assetguard') -const DropinModUtil = require('./assets/js/dropinmodutil') +const DropinModUtil = require('./assets/js/dropinmodutil') const loggerSettings = LoggerUtil('%c[Settings]', 'color: #353232; font-weight: bold') @@ -11,8 +11,8 @@ const settingsState = { invalid: new Set() } -function bindSettingsSelect(){ - for(let ele of document.getElementsByClassName('settingsSelectContainer')) { +function bindSettingsSelect() { + for (let ele of document.getElementsByClassName('settingsSelectContainer')) { const selectedDiv = ele.getElementsByClassName('settingsSelectSelected')[0] selectedDiv.onclick = (e) => { @@ -24,12 +24,12 @@ function bindSettingsSelect(){ } } -function closeSettingsSelect(el){ - for(let ele of document.getElementsByClassName('settingsSelectContainer')) { +function closeSettingsSelect(el) { + for (let ele of document.getElementsByClassName('settingsSelectContainer')) { const selectedDiv = ele.getElementsByClassName('settingsSelectSelected')[0] const optionsDiv = ele.getElementsByClassName('settingsSelectOptions')[0] - if(!(selectedDiv === el)) { + if (!(selectedDiv === el)) { selectedDiv.classList.remove('select-arrow-active') optionsDiv.setAttribute('hidden', '') } @@ -42,6 +42,21 @@ document.addEventListener('click', closeSettingsSelect) 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(){ for(let ele of document.getElementsByClassName('settingsFileSelButton')){ @@ -55,11 +70,11 @@ function bindFileSelectors(){ properties } - if(ele.hasAttribute('dialogTitle')) { + if (ele.hasAttribute('dialogTitle')) { options.title = ele.getAttribute('dialogTitle') } - if(isJavaExecSel && process.platform === 'win32') { + if (isJavaExecSel && process.platform === 'win32') { options.filters = [ { name: 'Executables', extensions: ['exe'] }, { name: 'All Files', extensions: ['*'] } @@ -67,9 +82,9 @@ function bindFileSelectors(){ } const res = await remote.dialog.showOpenDialog(remote.getCurrentWindow(), options) - if(!res.canceled) { + if (!res.canceled) { ele.previousElementSibling.value = res.filePaths[0] - if(isJavaExecSel) { + if (isJavaExecSel) { populateJavaExecDetails(ele.previousElementSibling.value) } } @@ -91,24 +106,24 @@ bindFileSelectors() * will be disabled until the value is corrected. This is an automated * process. More complex UI may need to be bound separately. */ -function initSettingsValidators(){ +function initSettingsValidators() { const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]') Array.from(sEls).map((v, index, arr) => { const vFn = ConfigManager['validate' + v.getAttribute('cValue')] - if(typeof vFn === 'function'){ - if(v.tagName === 'INPUT'){ - if(v.type === 'number' || v.type === 'text'){ + if (typeof vFn === 'function') { + if (v.tagName === 'INPUT') { + if (v.type === 'number' || v.type === 'text') { v.addEventListener('keyup', (e) => { const v = e.target - if(!vFn(v.value)){ + if (!vFn(v.value)) { settingsState.invalid.add(v.id) v.setAttribute('error', '') settingsSaveDisabled(true) } else { - if(v.hasAttribute('error')){ + if (v.hasAttribute('error')) { v.removeAttribute('error') settingsState.invalid.delete(v.id) - if(settingsState.invalid.size === 0){ + if (settingsState.invalid.size === 0) { settingsSaveDisabled(false) } } @@ -124,19 +139,19 @@ function initSettingsValidators(){ /** * Load configuration values onto the UI. This is an automated process. */ -function initSettingsValues(){ +function initSettingsValues() { const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]') Array.from(sEls).map((v, index, arr) => { const cVal = v.getAttribute('cValue') const gFn = ConfigManager['get' + cVal] - if(typeof gFn === 'function'){ - if(v.tagName === 'INPUT'){ - if(v.type === 'number' || v.type === 'text'){ + if (typeof gFn === 'function') { + if (v.tagName === 'INPUT') { + if (v.type === 'number' || v.type === 'text') { // Special Conditions - if(cVal === 'JavaExecutable'){ + if (cVal === 'JavaExecutable') { populateJavaExecDetails(v.value) v.value = gFn() - } else if (cVal === 'DataDirectory'){ + } else if (cVal === 'DataDirectory') { v.value = gFn() } else if (cVal === 'ServerCode'){ v.value = gFn() @@ -145,16 +160,16 @@ function initSettingsValues(){ } else { v.value = gFn() } - } else if(v.type === 'checkbox'){ + } else if (v.type === 'checkbox') { v.checked = gFn() } - } else if(v.tagName === 'DIV'){ - if(v.classList.contains('rangeSlider')){ + } else if (v.tagName === 'DIV') { + if (v.classList.contains('rangeSlider')) { // Special Conditions - if(cVal === 'MinRAM' || cVal === 'MaxRAM'){ + if (cVal === 'MinRAM' || cVal === 'MaxRAM') { let val = gFn() - if(val.endsWith('M')){ - val = Number(val.substring(0, val.length-1))/1000 + if (val.endsWith('M')) { + val = Number(val.substring(0, val.length - 1)) / 1000 } else { val = Number.parseFloat(val) } @@ -173,34 +188,34 @@ function initSettingsValues(){ /** * Save the settings values. */ -function saveSettingsValues(){ +function saveSettingsValues() { const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]') Array.from(sEls).map((v, index, arr) => { const cVal = v.getAttribute('cValue') const sFn = ConfigManager['set' + cVal] - if(typeof sFn === 'function'){ - if(v.tagName === 'INPUT'){ - if(v.type === 'number' || v.type === 'text'){ + if (typeof sFn === 'function') { + if (v.tagName === 'INPUT') { + if (v.type === 'number' || v.type === 'text') { // Special Conditions - if(cVal === 'JVMOptions'){ + if (cVal === 'JVMOptions') { sFn(v.value.split(' ')) } else { sFn(v.value) } - } else if(v.type === 'checkbox'){ + } else if (v.type === 'checkbox') { sFn(v.checked) // Special Conditions - if(cVal === 'AllowPrerelease'){ + if (cVal === 'AllowPrerelease') { changeAllowPrerelease(v.checked) } } - } else if(v.tagName === 'DIV'){ - if(v.classList.contains('rangeSlider')){ + } else if (v.tagName === 'DIV') { + if (v.classList.contains('rangeSlider')) { // Special Conditions - if(cVal === 'MinRAM' || cVal === 'MaxRAM'){ + if (cVal === 'MinRAM' || cVal === 'MaxRAM') { let val = Number(v.getAttribute('value')) - if(val%1 > 0){ - val = val*1000 + 'M' + if (val % 1 > 0) { + val = val * 1000 + 'M' } else { val = val + 'G' } @@ -223,8 +238,8 @@ let selectedSettingsTab = 'settingsTabAccount' * * @param {UIEvent} e The scroll event. */ -function settingsTabScrollListener(e){ - if(e.target.scrollTop > Number.parseFloat(getComputedStyle(e.target.firstElementChild).marginTop)){ +function settingsTabScrollListener(e) { + if (e.target.scrollTop > Number.parseFloat(getComputedStyle(e.target.firstElementChild).marginTop)) { document.getElementById('settingsContainer').setAttribute('scrolled', '') } else { document.getElementById('settingsContainer').removeAttribute('scrolled') @@ -234,9 +249,9 @@ function settingsTabScrollListener(e){ /** * Bind functionality for the settings navigation items. */ -function setupSettingsTabs(){ +function setupSettingsTabs() { Array.from(document.getElementsByClassName('settingsNavItem')).map((val) => { - if(val.hasAttribute('rSc')){ + if (val.hasAttribute('rSc')) { val.onclick = () => { settingsNavItemListener(val) } @@ -251,13 +266,13 @@ function setupSettingsTabs(){ * @param {Element} ele The nav item which has been clicked. * @param {boolean} fade Optional. True to fade transition. */ -function settingsNavItemListener(ele, fade = true){ - if(ele.hasAttribute('selected')){ +function settingsNavItemListener(ele, fade = true) { + if (ele.hasAttribute('selected')) { return } const navItems = document.getElementsByClassName('settingsNavItem') - for(let i=0; i { + $(`#${prevTab}`).fadeOut(150, () => { $(`#${selectedSettingsTab}`).fadeIn({ - duration: 250, + duration: 150, start: () => { settingsTabScrollListener({ target: document.getElementById(selectedSettingsTab) @@ -300,7 +315,7 @@ const settingsNavDone = document.getElementById('settingsNavDone') * * @param {boolean} v True to disable, false to enable. */ -function settingsSaveDisabled(v){ +function settingsSaveDisabled(v) { settingsNavDone.disabled = v } @@ -316,7 +331,7 @@ settingsNavDone.onclick = () => { if(ConfigManager.getSelectedServer()){ const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()) DiscordWrapper.updateDetails('Ready to Play!') - DiscordWrapper.updateState('Modpack: ' + serv.getName()) + DiscordWrapper.updateState('Server: ' + serv.getName()) } else { DiscordWrapper.updateDetails('Landing Screen...') } @@ -329,7 +344,7 @@ settingsNavDone.onclick = () => { // Bind the add account button. document.getElementById('settingsAddAccount').onclick = (e) => { - switchView(getCurrentView(), VIEWS.login, 500, 500, () => { + switchView(getCurrentView(), VIEWS.login, 250, 250, () => { loginViewOnCancel = VIEWS.settings loginViewOnSuccess = VIEWS.settings loginCancelEnabled(true) @@ -352,10 +367,10 @@ function bindServerCodeButtons(){ if(!ConfigManager.getServerCodes().includes(code) && code){ ConfigManager.getServerCodes().push(code) ConfigManager.save() - loggerSettings.log('Added modpack code to configuration and saved it') + loggerSettings.log('Added server code to configuration and saved it') prepareLauncherTab() } 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() } } - 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 * is selected, the UI of the previously selected account will be updated. */ -function bindAuthAccountSelect(){ +function bindAuthAccountSelect() { Array.from(document.getElementsByClassName('settingsAuthAccountSelect')).map((val) => { val.onclick = (e) => { - if(val.hasAttribute('selected')){ + if (val.hasAttribute('selected')) { return } const selectBtns = document.getElementsByClassName('settingsAuthAccountSelect') - for(let i=0; i { val.onclick = (e) => { let isLastAccount = false - if(Object.keys(ConfigManager.getAuthAccounts()).length === 1){ + if (Object.keys(ConfigManager.getAuthAccounts()).length === 1) { isLastAccount = true setOverlayContent( 'Warning
This is Your Last Account', @@ -435,25 +450,29 @@ function bindAuthAccountLogOut(){ } else { processLogOut(val, isLastAccount) } - + } }) } +let data = null + /** * Process a log out. * * @param {Element} val The log out button element. * @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 = { val, isLastAccount } + + const parent = val.closest('.settingsAuthAccount') + const uuid = parent.getAttribute('uuid') + if (!skip) { - const parent = val.closest('.settingsAuthAccount') - const uuid = parent.getAttribute('uuid') const account = ConfigManager.getAuthAccount(uuid) if (account.type === 'microsoft') { toggleOverlay(true, false, 'msOverlay') @@ -462,14 +481,14 @@ function bindAuthAccountLogOut(){ } const prevSelAcc = ConfigManager.getSelectedAccount() AuthManager.removeAccount(uuid).then(() => { - if(!isLastAccount && uuid === prevSelAcc.uuid){ + if (!isLastAccount && uuid === prevSelAcc.uuid) { const selAcc = ConfigManager.getSelectedAccount() refreshAuthAccountSelected(selAcc.uuid) updateSelectedAccount(selAcc) validateSelectedAccount() } }) - $(parent).fadeOut(250, () => { + $(parent).fadeOut(150, () => { parent.remove() }) } @@ -479,21 +498,20 @@ ipcRenderer.on('MSALogoutWindowReply', (event, ...args) => { processLogOut(data.val, data.isLastAccount, true) }) - /** * Refreshes the status of the selected account on the auth account * elements. * * @param {string} uuid The UUID of the new selected account. */ -function refreshAuthAccountSelected(uuid){ +function refreshAuthAccountSelected(uuid) { Array.from(document.getElementsByClassName('settingsAuthAccount')).map((val) => { const selBtn = val.getElementsByClassName('settingsAuthAccountSelect')[0] - if(uuid === val.getAttribute('uuid')){ + if (uuid === val.getAttribute('uuid')) { selBtn.setAttribute('selected', '') selBtn.innerHTML = 'Selected Account ✔' } else { - if(selBtn.hasAttribute('selected')){ + if (selBtn.hasAttribute('selected')) { selBtn.removeAttribute('selected') } 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. */ -function populateAuthAccounts(){ +function populateAuthAccounts() { const authAccounts = ConfigManager.getAuthAccounts() const authKeys = Object.keys(authAccounts) - if(authKeys.length === 0){ + if (authKeys.length === 0) { return } const selectedUUID = ConfigManager.getSelectedAccount().uuid @@ -571,12 +589,12 @@ function prepareLauncherTab() { * Disable decimals, negative signs, and scientific notation. */ document.getElementById('settingsGameWidth').addEventListener('keydown', (e) => { - if(/^[-.eE]$/.test(e.key)){ + if (/^[-.eE]$/.test(e.key)) { e.preventDefault() } }) document.getElementById('settingsGameHeight').addEventListener('keydown', (e) => { - if(/^[-.eE]$/.test(e.key)){ + if (/^[-.eE]$/.test(e.key)) { e.preventDefault() } }) @@ -590,7 +608,7 @@ const settingsModsContainer = document.getElementById('settingsModsContainer') /** * Resolve and update the mods on the UI. */ -function resolveModsForUI(){ +function resolveModsForUI() { const serv = ConfigManager.getSelectedServer() const distro = DistroManager.getDistribution() @@ -609,16 +627,16 @@ function resolveModsForUI(){ * @param {boolean} submodules Whether or not we are parsing submodules. * @param {Object} servConf The server configuration object for this module level. */ -function parseModulesForUI(mdls, submodules, servConf){ +function parseModulesForUI(mdls, submodules, servConf) { let reqMods = '' 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 += `
@@ -678,11 +696,11 @@ function parseModulesForUI(mdls, submodules, servConf){ * Bind functionality to mod config toggle switches. Switching the value * will also switch the status color on the left of the mod UI. */ -function bindModsToggleSwitch(){ +function bindModsToggleSwitch() { const sEls = settingsModsContainer.querySelectorAll('[formod]') Array.from(sEls).map((v, index, arr) => { v.onchange = () => { - if(v.checked) { + if (v.checked) { document.getElementById(v.getAttribute('formod')).setAttribute('enabled', '') } else { document.getElementById(v.getAttribute('formod')).removeAttribute('enabled') @@ -695,7 +713,7 @@ function bindModsToggleSwitch(){ /** * Save the mod configuration based on the UI values. */ -function saveModConfiguration(){ +function saveModConfiguration() { const serv = ConfigManager.getSelectedServer() const modConf = ConfigManager.getModConfiguration(serv) modConf.mods = _saveModConfiguration(modConf.mods) @@ -707,15 +725,15 @@ function saveModConfiguration(){ * * @param {Object} modConf Mod config object to save. */ -function _saveModConfiguration(modConf){ - for(let m of Object.entries(modConf)){ +function _saveModConfiguration(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'){ + if (!tSwitch[0].hasAttribute('dropin')) { + if (typeof m[1] === 'boolean') { modConf[m[0]] = tSwitch[0].checked } else { - if(m[1] != null){ - if(tSwitch.length > 0){ + if (m[1] != null) { + if (tSwitch.length > 0) { modConf[m[0]].value = tSwitch[0].checked } 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 * populate the results onto the UI. */ -function resolveDropinModsForUI(){ +function resolveDropinModsForUI() { const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()) CACHE_SETTINGS_MODS_DIR = path.join(ConfigManager.getInstanceDirectory(), serv.getID(), 'mods') CACHE_DROPIN_MODS = DropinModUtil.scanForDropinMods(CACHE_SETTINGS_MODS_DIR, serv.getMinecraftVersion()) @@ -743,6 +761,7 @@ function resolveDropinModsForUI(){ let dropinMods = '' for(dropin of CACHE_DROPIN_MODS){ + dropinMods += `
@@ -799,7 +818,6 @@ function resolveServerCodesForUI(){ 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()) @@ -821,13 +839,13 @@ function resolveServerCodesForUI(){ /** * Bind the remove button for each loaded drop-in mod. */ -function bindDropinModsRemoveButton(){ +function bindDropinModsRemoveButton() { const sEls = settingsModsContainer.querySelectorAll('[remmod]') Array.from(sEls).map((v, index, arr) => { - v.onclick = async () => { + v.onclick = () => { const fullName = v.getAttribute('remmod') - const res = await DropinModUtil.deleteDropinMod(CACHE_SETTINGS_MODS_DIR, fullName) - if(res){ + const res = DropinModUtil.deleteDropinMod(CACHE_SETTINGS_MODS_DIR, fullName) + if (res) { document.getElementById(fullName).remove() } else { setOverlayContent( @@ -846,7 +864,7 @@ function bindDropinModsRemoveButton(){ * Bind functionality to the file system button for the selected * server configuration. */ -function bindDropinModFileSystemButton(){ +function bindDropinModFileSystemButton() { const fsBtn = document.getElementById('settingsDropinFileSystemButton') fsBtn.onclick = () => { DropinModUtil.validateDir(CACHE_SETTINGS_MODS_DIR) @@ -877,14 +895,14 @@ function bindDropinModFileSystemButton(){ * Save drop-in mod states. Enabling and disabling is just a matter * of adding/removing the .disabled extension. */ -function saveDropinModConfiguration(){ - for(dropin of CACHE_DROPIN_MODS){ +function saveDropinModConfiguration() { + for (dropin of CACHE_DROPIN_MODS) { const dropinUI = document.getElementById(dropin.fullName) - if(dropinUI != null){ + if (dropinUI != null) { 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 => { - if(!isOverlayVisible()){ + if (!isOverlayVisible()) { setOverlayContent( 'Failed to Toggle
One or More Drop-in Mods', err.message, @@ -902,16 +920,15 @@ function saveDropinModConfiguration(){ // Refresh the drop-in mods when F5 is pressed. // Only active on the mods tab. document.addEventListener('keydown', (e) => { - if(getCurrentView() === VIEWS.settings && selectedSettingsTab === 'settingsTabMods'){ - if(e.key === 'F5'){ + if (getCurrentView() === VIEWS.settings && selectedSettingsTab === 'settingsTabMods') { + if (e.key === 'F5') { reloadDropinMods() - saveShaderpackSettings() resolveShaderpacksForUI() } } }) -function reloadDropinMods(){ +function reloadDropinMods() { resolveDropinModsForUI() bindDropinModsRemoveButton() bindDropinModFileSystemButton() @@ -927,7 +944,7 @@ let CACHE_SELECTED_SHADERPACK /** * Load shaderpack information. */ -function resolveShaderpacksForUI(){ +function resolveShaderpacksForUI() { const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()) CACHE_SETTINGS_INSTANCE_DIR = path.join(ConfigManager.getInstanceDirectory(), serv.getID()) CACHE_SHADERPACKS = DropinModUtil.scanForShaderpacks(CACHE_SETTINGS_INSTANCE_DIR) @@ -936,20 +953,20 @@ function resolveShaderpacksForUI(){ setShadersOptions(CACHE_SHADERPACKS, CACHE_SELECTED_SHADERPACK) } -function setShadersOptions(arr, selected){ +function setShadersOptions(arr, selected) { const cont = document.getElementById('settingsShadersOptions') cont.innerHTML = '' - for(let opt of arr) { + for (let opt of arr) { const d = document.createElement('DIV') d.innerHTML = opt.name d.setAttribute('value', opt.fullName) - if(opt.fullName === selected) { + if (opt.fullName === selected) { d.setAttribute('selected', '') document.getElementById('settingsShadersSelected').innerHTML = opt.name } - d.addEventListener('click', function(e) { + d.addEventListener('click', function (e) { this.parentNode.previousElementSibling.innerHTML = this.innerHTML - for(let sib of this.parentNode.children){ + for (let sib of this.parentNode.children) { sib.removeAttribute('selected') } this.setAttribute('selected', '') @@ -959,10 +976,10 @@ function setShadersOptions(arr, selected){ } } -function saveShaderpackSettings(){ +function saveShaderpackSettings() { let sel = 'OFF' - for(let opt of document.getElementById('settingsShadersOptions').childNodes){ - if(opt.hasAttribute('selected')){ + for (let opt of document.getElementById('settingsShadersOptions').childNodes) { + if (opt.hasAttribute('selected')) { sel = opt.getAttribute('value') } } @@ -998,32 +1015,22 @@ function bindShaderpackButton() { } } + // Server status bar functions. /** * Load the currently selected server information onto the mods tab. */ -function loadSelectedServerOnModsTab(){ +function loadSelectedServerOnModsTab() { const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()) document.getElementById('settingsSelServContent').innerHTML = ` -
+ ${serv.getName()} ${serv.getDescription()}
-
${serv.getMinecraftVersion()}
${serv.getVersion()}
- ${serv.isMainServer() ? `
- - - - - - - - Main Server -
` : ''}
` @@ -1038,7 +1045,7 @@ document.getElementById('settingsSwitchServerButton').addEventListener('click', /** * Save mod configuration for the current selected server. */ -function saveAllModConfigurations(){ +function saveAllModConfigurations() { saveModConfiguration() ConfigManager.save() saveDropinModConfiguration() @@ -1049,16 +1056,16 @@ function saveAllModConfigurations(){ * server is changed. */ function animateModsTabRefresh(){ - $('#settingsTabMods').fadeOut(500, () => { + $('#settingsTabMods').fadeOut(150, () => { prepareModsTab() - $('#settingsTabMods').fadeIn(500) + $('#settingsTabMods').fadeIn(150) }) } /** * Prepare the Mods tab for display. */ -function prepareModsTab(first){ +function prepareModsTab(first) { resolveModsForUI() resolveDropinModsForUI() resolveShaderpacksForUI() @@ -1074,12 +1081,12 @@ function prepareModsTab(first){ */ // DOM Cache -const settingsMaxRAMRange = document.getElementById('settingsMaxRAMRange') -const settingsMinRAMRange = document.getElementById('settingsMinRAMRange') -const settingsMaxRAMLabel = document.getElementById('settingsMaxRAMLabel') -const settingsMinRAMLabel = document.getElementById('settingsMinRAMLabel') -const settingsMemoryTotal = document.getElementById('settingsMemoryTotal') -const settingsMemoryAvail = document.getElementById('settingsMemoryAvail') +const settingsMaxRAMRange = document.getElementById('settingsMaxRAMRange') +const settingsMinRAMRange = document.getElementById('settingsMinRAMRange') +const settingsMaxRAMLabel = document.getElementById('settingsMaxRAMLabel') +const settingsMinRAMLabel = document.getElementById('settingsMinRAMLabel') +const settingsMemoryTotal = document.getElementById('settingsMemoryTotal') +const settingsMemoryAvail = document.getElementById('settingsMemoryAvail') const settingsJavaExecDetails = document.getElementById('settingsJavaExecDetails') // Store maximum memory values. @@ -1090,7 +1097,7 @@ const SETTINGS_MIN_MEMORY = ConfigManager.getAbsoluteMinRAM() settingsMaxRAMRange.setAttribute('max', SETTINGS_MAX_MEMORY) settingsMaxRAMRange.setAttribute('min', SETTINGS_MIN_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. settingsMinRAMRange.onchange = (e) => { @@ -1102,7 +1109,7 @@ settingsMinRAMRange.onchange = (e) => { // Get reference to range bar. const bar = e.target.getElementsByClassName('rangeSliderBar')[0] // 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. if(sMinV >= max/1.25){ @@ -1114,10 +1121,10 @@ settingsMinRAMRange.onchange = (e) => { } // Increase maximum memory if the minimum exceeds its value. - if(sMaxV < sMinV){ + if (sMaxV < sMinV) { const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange) updateRangedSlider(settingsMaxRAMRange, sMinV, - ((sMinV-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc) + ((sMinV - sliderMeta.min) / sliderMeta.step) * sliderMeta.inc) settingsMaxRAMLabel.innerHTML = sMinV.toFixed(1) + 'G' } @@ -1134,7 +1141,7 @@ settingsMaxRAMRange.onchange = (e) => { // Get reference to range bar. const bar = e.target.getElementsByClassName('rangeSliderBar')[0] // 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. if(sMaxV >= max/1.25){ @@ -1146,10 +1153,10 @@ settingsMaxRAMRange.onchange = (e) => { } // Decrease the minimum memory if the maximum value is less. - if(sMaxV < sMinV){ + if (sMaxV < sMinV) { const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange) updateRangedSlider(settingsMinRAMRange, sMaxV, - ((sMaxV-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc) + ((sMaxV - sliderMeta.min) / sliderMeta.step) * sliderMeta.inc) settingsMinRAMLabel.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. * @returns {Object} An object with meta values for the provided ranged slider. */ -function calculateRangeSliderMeta(v){ +function calculateRangeSliderMeta(v) { const val = { max: Number(v.getAttribute('max')), min: Number(v.getAttribute('min')), step: Number(v.getAttribute('step')), } - val.ticks = (val.max-val.min)/val.step - val.inc = 100/val.ticks + val.ticks = (val.max - val.min) / val.step + val.inc = 100 / val.ticks return val } @@ -1176,7 +1183,7 @@ function calculateRangeSliderMeta(v){ * Binds functionality to the ranged sliders. They're more than * just divs now :'). */ -function bindRangeSlider(){ +function bindRangeSlider() { Array.from(document.getElementsByClassName('rangeSlider')).map((v) => { // Reference the track (thumb). @@ -1186,7 +1193,7 @@ function bindRangeSlider(){ const value = v.getAttribute('value') 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. track.onmousedown = (e) => { @@ -1201,24 +1208,24 @@ function bindRangeSlider(){ document.onmousemove = (e) => { // 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. - if(diff >= 0 && diff <= v.offsetWidth-track.offsetWidth/2){ + if (diff >= 0 && diff <= v.offsetWidth - track.offsetWidth / 2) { // 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. - 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(Math.abs(perc-notch) < sliderMeta.inc/2){ - updateRangedSlider(v, sliderMeta.min+(sliderMeta.step*(notch/sliderMeta.inc)), notch) + if (Math.abs(perc - notch) < sliderMeta.inc / 2) { + 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 {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 bar = element.getElementsByClassName('rangeSliderBar')[0] const track = element.getElementsByClassName('rangeSliderTrack')[0] - + element.setAttribute('value', value) - if(notch < 0){ + if (notch < 0) { notch = 0 - } else if(notch > 100) { + } else if (notch > 100) { notch = 100 } @@ -1250,7 +1257,7 @@ function updateRangedSlider(element, value, notch){ let cancelled = !element.dispatchEvent(event) - if(!cancelled){ + if (!cancelled) { track.style.left = notch + '%' bar.style.width = notch + '%' } else { @@ -1261,9 +1268,9 @@ function updateRangedSlider(element, value, notch){ /** * Display the total and available RAM. */ -function populateMemoryStatus(){ - settingsMemoryTotal.innerHTML = Number((os.totalmem()-1000000000)/1000000000).toFixed(1) + 'G' - settingsMemoryAvail.innerHTML = Number(os.freemem()/1000000000).toFixed(1) + 'G' +function populateMemoryStatus() { + settingsMemoryTotal.innerHTML = Number((os.totalmem() - 1000000000) / 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. */ -function populateJavaExecDetails(execPath){ +function populateJavaExecDetails(execPath) { const jg = new JavaGuard(DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()).getMinecraftVersion()) jg._validateJavaBinary(execPath).then(v => { - if(v.valid){ + if (v.valid) { 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}` } else { 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. */ -function prepareJavaTab(){ +function prepareJavaTab() { bindRangeSlider() populateMemoryStatus() } @@ -1300,9 +1307,9 @@ function prepareJavaTab(){ * About Tab */ -const settingsTabAbout = document.getElementById('settingsTabAbout') -const settingsAboutChangelogTitle = settingsTabAbout.getElementsByClassName('settingsChangelogTitle')[0] -const settingsAboutChangelogText = settingsTabAbout.getElementsByClassName('settingsChangelogText')[0] +const settingsTabAbout = document.getElementById('settingsTabAbout') +const settingsAboutChangelogTitle = settingsTabAbout.getElementsByClassName('settingsChangelogTitle')[0] +const settingsAboutChangelogText = settingsTabAbout.getElementsByClassName('settingsChangelogText')[0] const settingsAboutChangelogButton = settingsTabAbout.getElementsByClassName('settingsChangelogButton')[0] // Bind the devtools toggle button. @@ -1317,8 +1324,11 @@ document.getElementById('settingsAboutDevToolsButton').onclick = (e) => { * @param {string} version The semver version to test. * @returns {boolean} True if the version is a prerelease, otherwise false. */ -function isPrerelease(version){ +function isPrerelease(version) { const preRelComp = semver.prerelease(version) + if(preRelComp != null && preRelComp.includes('release')) { + return false + } return preRelComp != null && preRelComp.length > 0 } @@ -1331,9 +1341,9 @@ function isPrerelease(version){ * @param {Element} titleElement The title element. * @param {Element} checkElement The check mark element. */ -function populateVersionInformation(version, valueElement, titleElement, checkElement){ +function populateVersionInformation(version, valueElement, titleElement, checkElement) { valueElement.innerHTML = version - if(isPrerelease(version)){ + if (isPrerelease(version)) { titleElement.innerHTML = 'Pre-release' titleElement.style.color = '#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. */ -function populateAboutVersionInformation(){ +function populateAboutVersionInformation() { 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 * of the current version. This value is displayed on the UI. */ -function populateReleaseNotes(){ +function populateReleaseNotes() { $.ajax({ - url: 'https://github.com/VicariousNetwork/HeliosLauncher/releases.atom', + url: 'https://github.com/ModRealms-Network/HeliosLauncher/releases.atom', success: (data) => { const version = 'v' + remote.app.getVersion() const entries = $(data).find('entry') - - for(let i=0; i { settingsAboutChangelogText.innerHTML = 'Failed to load release notes.' }) @@ -1384,7 +1394,7 @@ function populateReleaseNotes(){ /** * Prepare account tab for display. */ -function prepareAboutTab(){ +function prepareAboutTab() { populateAboutVersionInformation() populateReleaseNotes() } @@ -1393,15 +1403,15 @@ function prepareAboutTab(){ * Update Tab */ -const settingsTabUpdate = document.getElementById('settingsTabUpdate') -const settingsUpdateTitle = document.getElementById('settingsUpdateTitle') -const settingsUpdateVersionCheck = document.getElementById('settingsUpdateVersionCheck') -const settingsUpdateVersionTitle = document.getElementById('settingsUpdateVersionTitle') -const settingsUpdateVersionValue = document.getElementById('settingsUpdateVersionValue') +const settingsTabUpdate = document.getElementById('settingsTabUpdate') +const settingsUpdateTitle = document.getElementById('settingsUpdateTitle') +const settingsUpdateVersionCheck = document.getElementById('settingsUpdateVersionCheck') +const settingsUpdateVersionTitle = document.getElementById('settingsUpdateVersionTitle') +const settingsUpdateVersionValue = document.getElementById('settingsUpdateVersionValue') const settingsUpdateChangelogTitle = settingsTabUpdate.getElementsByClassName('settingsChangelogTitle')[0] -const settingsUpdateChangelogText = settingsTabUpdate.getElementsByClassName('settingsChangelogText')[0] -const settingsUpdateChangelogCont = settingsTabUpdate.getElementsByClassName('settingsChangelogContainer')[0] -const settingsUpdateActionButton = document.getElementById('settingsUpdateActionButton') +const settingsUpdateChangelogText = settingsTabUpdate.getElementsByClassName('settingsChangelogText')[0] +const settingsUpdateChangelogCont = settingsTabUpdate.getElementsByClassName('settingsChangelogContainer')[0] +const settingsUpdateActionButton = document.getElementById('settingsUpdateActionButton') /** * Update the properties of the update action button. @@ -1410,10 +1420,10 @@ const settingsUpdateActionButton = document.getElementById('settingsUpdateActi * @param {boolean} disabled Optional. Disable or enable the button * @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.disabled = disabled - if(handler != null){ + if (handler != null) { settingsUpdateActionButton.onclick = handler } } @@ -1423,27 +1433,27 @@ function settingsUpdateButtonStatus(text, disabled = false, handler = null){ * * @param {Object} data The update data. */ -function populateSettingsUpdateInformation(data){ - if(data != null){ +function populateSettingsUpdateInformation(data) { + if (data != null) { settingsUpdateTitle.innerHTML = `New ${isPrerelease(data.version) ? 'Pre-release' : 'Release'} Available` settingsUpdateChangelogCont.style.display = null settingsUpdateChangelogTitle.innerHTML = data.releaseName settingsUpdateChangelogText.innerHTML = data.releaseNotes populateVersionInformation(data.version, settingsUpdateVersionValue, settingsUpdateVersionTitle, settingsUpdateVersionCheck) - - if(process.platform === 'darwin'){ + + if (process.platform === 'darwin') { settingsUpdateButtonStatus('Download from GitHubClose the launcher and run the dmg to update.', false, () => { shell.openExternal(data.darwindownload) }) } else { - settingsUpdateButtonStatus('Downloading..', true) + settingsUpdateButtonStatus('Downloading...', true) } } else { settingsUpdateTitle.innerHTML = 'You Are Running the Latest Version' settingsUpdateChangelogCont.style.display = 'none' populateVersionInformation(remote.app.getVersion(), settingsUpdateVersionValue, settingsUpdateVersionTitle, settingsUpdateVersionCheck) settingsUpdateButtonStatus('Check for Updates', false, () => { - if(!isDev){ + if (!isDev) { ipcRenderer.send('autoUpdateAction', 'checkForUpdate') settingsUpdateButtonStatus('Checking for Updates..', true) } @@ -1456,7 +1466,7 @@ function populateSettingsUpdateInformation(data){ * * @param {Object} data The update data. */ -function prepareUpdateTab(data = null){ +function prepareUpdateTab(data = null) { populateSettingsUpdateInformation(data) } @@ -1470,7 +1480,7 @@ function prepareUpdateTab(data = null){ * @param {boolean} first Whether or not it is the first load. */ function prepareSettings(first = false) { - if(first){ + if (first) { setupSettingsTabs() initSettingsValidators() prepareUpdateTab() diff --git a/app/login.ejs b/app/login.ejs index 53b4f413..0f30d3b3 100644 --- a/app/login.ejs +++ b/app/login.ejs @@ -7,8 +7,7 @@
- - MINECRAFT LOGIN + MOJANG LOGIN