2018-06-20 03:15:10 -07:00
// Requirements
const os = require ( 'os' )
const semver = require ( 'semver' )
2018-06-11 19:11:05 -07:00
2018-08-07 01:16:15 -07:00
const DropinModUtil = require ( './assets/js/dropinmodutil' )
2022-02-11 16:51:28 -08:00
const { MSFT _OPCODE , MSFT _REPLY _TYPE , MSFT _ERROR } = require ( './assets/js/ipcconstants' )
2018-07-22 08:40:15 -07:00
2018-06-04 13:28:17 -07:00
const settingsState = {
invalid : new Set ( )
}
2018-12-21 03:51:08 -08:00
function bindSettingsSelect ( ) {
for ( let ele of document . getElementsByClassName ( 'settingsSelectContainer' ) ) {
const selectedDiv = ele . getElementsByClassName ( 'settingsSelectSelected' ) [ 0 ]
selectedDiv . onclick = ( e ) => {
e . stopPropagation ( )
closeSettingsSelect ( e . target )
e . target . nextElementSibling . toggleAttribute ( 'hidden' )
e . target . classList . toggle ( 'select-arrow-active' )
}
}
}
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 ) ) {
selectedDiv . classList . remove ( 'select-arrow-active' )
optionsDiv . setAttribute ( 'hidden' , '' )
}
}
}
/ * I f t h e u s e r c l i c k s a n y w h e r e o u t s i d e t h e s e l e c t b o x ,
then close all select boxes : * /
document . addEventListener ( 'click' , closeSettingsSelect )
bindSettingsSelect ( )
2019-01-04 11:25:27 -08:00
function bindFileSelectors ( ) {
2020-05-21 18:02:58 -07:00
for ( let ele of document . getElementsByClassName ( 'settingsFileSelButton' ) ) {
ele . onclick = async e => {
const isJavaExecSel = ele . id === 'settingsJavaExecSel'
const directoryDialog = ele . hasAttribute ( 'dialogDirectory' ) && ele . getAttribute ( 'dialogDirectory' ) == 'true'
const properties = directoryDialog ? [ 'openDirectory' , 'createDirectory' ] : [ 'openFile' ]
const options = {
properties
2019-01-04 11:25:27 -08:00
}
2020-05-21 18:02:58 -07:00
if ( ele . hasAttribute ( 'dialogTitle' ) ) {
options . title = ele . getAttribute ( 'dialogTitle' )
}
if ( isJavaExecSel && process . platform === 'win32' ) {
options . filters = [
{ name : 'Executables' , extensions : [ 'exe' ] } ,
{ name : 'All Files' , extensions : [ '*' ] }
]
}
const res = await remote . dialog . showOpenDialog ( remote . getCurrentWindow ( ) , options )
if ( ! res . canceled ) {
ele . previousElementSibling . value = res . filePaths [ 0 ]
if ( isJavaExecSel ) {
2023-02-24 18:02:18 -08:00
await populateJavaExecDetails ( ele . previousElementSibling . value )
2020-05-21 18:02:58 -07:00
}
2019-01-04 11:25:27 -08:00
}
}
}
}
bindFileSelectors ( )
2018-05-30 19:22:17 -07:00
/ * *
* General Settings Functions
* /
2018-07-22 10:31:15 -07:00
/ * *
2018-06-04 13:28:17 -07:00
* Bind value validators to the settings UI elements . These will
* validate against the criteria defined in the ConfigManager ( if
2021-10-30 23:20:03 -07:00
* any ) . If the value is invalid , the UI will reflect this and saving
2018-06-04 13:28:17 -07:00
* will be disabled until the value is corrected . This is an automated
* process . More complex UI may need to be bound separately .
* /
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' ) {
v . addEventListener ( 'keyup' , ( e ) => {
const v = e . target
if ( ! vFn ( v . value ) ) {
settingsState . invalid . add ( v . id )
v . setAttribute ( 'error' , '' )
settingsSaveDisabled ( true )
} else {
if ( v . hasAttribute ( 'error' ) ) {
v . removeAttribute ( 'error' )
settingsState . invalid . delete ( v . id )
if ( settingsState . invalid . size === 0 ) {
settingsSaveDisabled ( false )
}
}
}
} )
}
}
}
} )
}
/ * *
* Load configuration values onto the UI . This is an automated process .
* /
2023-02-24 18:02:18 -08:00
async function initSettingsValues ( ) {
2018-06-04 13:28:17 -07:00
const sEls = document . getElementById ( 'settingsContainer' ) . querySelectorAll ( '[cValue]' )
2023-02-24 18:02:18 -08:00
for ( const v of sEls ) {
2018-07-29 05:42:11 -07:00
const cVal = v . getAttribute ( 'cValue' )
2022-11-27 15:13:50 -08:00
const serverDependent = v . hasAttribute ( 'serverDependent' ) // Means the first argument is the server id.
2018-07-29 05:42:11 -07:00
const gFn = ConfigManager [ 'get' + cVal ]
2022-11-27 15:13:50 -08:00
const gFnOpts = [ ]
if ( serverDependent ) {
gFnOpts . push ( ConfigManager . getSelectedServer ( ) )
}
2018-06-04 13:28:17 -07:00
if ( typeof gFn === 'function' ) {
if ( v . tagName === 'INPUT' ) {
if ( v . type === 'number' || v . type === 'text' ) {
2018-07-22 10:31:15 -07:00
// Special Conditions
2018-06-14 00:49:55 -07:00
if ( cVal === 'JavaExecutable' ) {
2022-11-27 15:13:50 -08:00
v . value = gFn . apply ( null , gFnOpts )
2023-02-24 18:02:18 -08:00
await populateJavaExecDetails ( v . value )
2019-01-04 11:25:27 -08:00
} else if ( cVal === 'DataDirectory' ) {
2022-11-27 15:13:50 -08:00
v . value = gFn . apply ( null , gFnOpts )
2018-06-14 03:09:09 -07:00
} else if ( cVal === 'JVMOptions' ) {
2022-11-27 15:13:50 -08:00
v . value = gFn . apply ( null , gFnOpts ) . join ( ' ' )
2018-06-14 03:09:09 -07:00
} else {
2022-11-27 15:13:50 -08:00
v . value = gFn . apply ( null , gFnOpts )
2018-06-14 00:49:55 -07:00
}
2018-06-04 13:28:17 -07:00
} else if ( v . type === 'checkbox' ) {
2022-11-27 15:13:50 -08:00
v . checked = gFn . apply ( null , gFnOpts )
2018-06-04 13:28:17 -07:00
}
2018-06-11 19:11:05 -07:00
} else if ( v . tagName === 'DIV' ) {
if ( v . classList . contains ( 'rangeSlider' ) ) {
2018-06-12 00:25:36 -07:00
// Special Conditions
if ( cVal === 'MinRAM' || cVal === 'MaxRAM' ) {
2022-11-27 15:13:50 -08:00
let val = gFn . apply ( null , gFnOpts )
2018-06-12 00:25:36 -07:00
if ( val . endsWith ( 'M' ) ) {
2023-03-18 18:22:18 -07:00
val = Number ( val . substring ( 0 , val . length - 1 ) ) / 1024
2018-06-12 00:25:36 -07:00
} else {
val = Number . parseFloat ( val )
}
v . setAttribute ( 'value' , val )
} else {
2022-11-27 15:13:50 -08:00
v . setAttribute ( 'value' , Number . parseFloat ( gFn . apply ( null , gFnOpts ) ) )
2018-06-12 00:25:36 -07:00
}
2018-06-11 19:11:05 -07:00
}
2018-06-04 13:28:17 -07:00
}
}
2023-02-24 18:02:18 -08:00
}
2018-06-04 13:28:17 -07:00
}
/ * *
* Save the settings values .
* /
function saveSettingsValues ( ) {
const sEls = document . getElementById ( 'settingsContainer' ) . querySelectorAll ( '[cValue]' )
Array . from ( sEls ) . map ( ( v , index , arr ) => {
2018-07-29 05:42:11 -07:00
const cVal = v . getAttribute ( 'cValue' )
2022-11-27 15:13:50 -08:00
const serverDependent = v . hasAttribute ( 'serverDependent' ) // Means the first argument is the server id.
2018-07-29 05:42:11 -07:00
const sFn = ConfigManager [ 'set' + cVal ]
2022-11-27 15:13:50 -08:00
const sFnOpts = [ ]
if ( serverDependent ) {
sFnOpts . push ( ConfigManager . getSelectedServer ( ) )
}
2018-06-04 13:28:17 -07:00
if ( typeof sFn === 'function' ) {
if ( v . tagName === 'INPUT' ) {
if ( v . type === 'number' || v . type === 'text' ) {
2018-06-14 03:09:09 -07:00
// Special Conditions
if ( cVal === 'JVMOptions' ) {
2022-04-03 14:32:59 -07:00
if ( ! v . value . trim ( ) ) {
2022-11-27 15:13:50 -08:00
sFnOpts . push ( [ ] )
sFn . apply ( null , sFnOpts )
2022-04-03 14:32:59 -07:00
} else {
2022-11-27 15:13:50 -08:00
sFnOpts . push ( v . value . trim ( ) . split ( /\s+/ ) )
sFn . apply ( null , sFnOpts )
2022-04-03 14:32:59 -07:00
}
2018-06-14 03:09:09 -07:00
} else {
2022-11-27 15:13:50 -08:00
sFnOpts . push ( v . value )
sFn . apply ( null , sFnOpts )
2018-06-14 03:09:09 -07:00
}
2018-06-04 13:28:17 -07:00
} else if ( v . type === 'checkbox' ) {
2022-11-27 15:13:50 -08:00
sFnOpts . push ( v . checked )
sFn . apply ( null , sFnOpts )
2018-06-04 16:34:47 -07:00
// Special Conditions
if ( cVal === 'AllowPrerelease' ) {
changeAllowPrerelease ( v . checked )
}
2018-06-04 13:28:17 -07:00
}
2018-06-12 00:25:36 -07:00
} else if ( v . tagName === 'DIV' ) {
if ( v . classList . contains ( 'rangeSlider' ) ) {
// Special Conditions
if ( cVal === 'MinRAM' || cVal === 'MaxRAM' ) {
let val = Number ( v . getAttribute ( 'value' ) )
if ( val % 1 > 0 ) {
val = val * 1000 + 'M'
} else {
val = val + 'G'
}
2022-11-27 15:13:50 -08:00
sFnOpts . push ( val )
sFn . apply ( null , sFnOpts )
2018-06-12 00:25:36 -07:00
} else {
2022-11-27 15:13:50 -08:00
sFnOpts . push ( v . getAttribute ( 'value' ) )
sFn . apply ( null , sFnOpts )
2018-06-12 00:25:36 -07:00
}
}
2018-06-04 13:28:17 -07:00
}
}
} )
}
2018-06-21 09:38:21 -07:00
let selectedSettingsTab = 'settingsTabAccount'
2018-05-30 13:00:07 -07:00
2018-06-20 04:38:53 -07:00
/ * *
* Modify the settings container UI when the scroll threshold reaches
* a certain poin .
*
* @ param { UIEvent } e The scroll event .
* /
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' )
}
}
2018-05-30 19:22:17 -07:00
/ * *
* Bind functionality for the settings navigation items .
* /
2018-05-30 13:00:07 -07:00
function setupSettingsTabs ( ) {
Array . from ( document . getElementsByClassName ( 'settingsNavItem' ) ) . map ( ( val ) => {
2018-06-20 04:38:53 -07:00
if ( val . hasAttribute ( 'rSc' ) ) {
2018-06-21 09:38:21 -07:00
val . onclick = ( ) => {
settingsNavItemListener ( val )
2018-05-30 13:00:07 -07:00
}
}
} )
}
2018-06-21 09:38:21 -07:00
/ * *
* Settings nav item onclick lisener . Function is exposed so that
* other UI elements can quickly toggle to a certain tab from other views .
*
* @ 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' ) ) {
return
}
const navItems = document . getElementsByClassName ( 'settingsNavItem' )
for ( let i = 0 ; i < navItems . length ; i ++ ) {
if ( navItems [ i ] . hasAttribute ( 'selected' ) ) {
navItems [ i ] . removeAttribute ( 'selected' )
}
}
ele . setAttribute ( 'selected' , '' )
let prevTab = selectedSettingsTab
selectedSettingsTab = ele . getAttribute ( 'rSc' )
document . getElementById ( prevTab ) . onscroll = null
document . getElementById ( selectedSettingsTab ) . onscroll = settingsTabScrollListener
if ( fade ) {
$ ( ` # ${ prevTab } ` ) . fadeOut ( 250 , ( ) => {
$ ( ` # ${ selectedSettingsTab } ` ) . fadeIn ( {
duration : 250 ,
start : ( ) => {
settingsTabScrollListener ( {
target : document . getElementById ( selectedSettingsTab )
} )
}
} )
} )
} else {
$ ( ` # ${ prevTab } ` ) . hide ( 0 , ( ) => {
$ ( ` # ${ selectedSettingsTab } ` ) . show ( {
duration : 0 ,
start : ( ) => {
settingsTabScrollListener ( {
target : document . getElementById ( selectedSettingsTab )
} )
}
} )
} )
}
}
2018-06-20 03:15:10 -07:00
const settingsNavDone = document . getElementById ( 'settingsNavDone' )
2018-06-04 13:28:17 -07:00
/ * *
* Set if the settings save ( done ) button is disabled .
*
* @ param { boolean } v True to disable , false to enable .
* /
function settingsSaveDisabled ( v ) {
settingsNavDone . disabled = v
}
2022-11-27 15:13:50 -08:00
function fullSettingsSave ( ) {
2018-06-04 13:28:17 -07:00
saveSettingsValues ( )
2018-07-29 05:42:11 -07:00
saveModConfiguration ( )
2018-06-04 13:28:17 -07:00
ConfigManager . save ( )
2018-08-07 01:16:15 -07:00
saveDropinModConfiguration ( )
2018-12-21 05:02:24 -08:00
saveShaderpackSettings ( )
2022-11-27 15:13:50 -08:00
}
/* Closes the settings view and saves all data. */
settingsNavDone . onclick = ( ) => {
fullSettingsSave ( )
2018-05-30 20:32:51 -07:00
switchView ( getCurrentView ( ) , VIEWS . landing )
}
2018-05-30 19:22:17 -07:00
/ * *
* Account Management Tab
* /
2022-02-11 16:51:28 -08:00
const msftLoginLogger = LoggerUtil . getLogger ( 'Microsoft Login' )
const msftLogoutLogger = LoggerUtil . getLogger ( 'Microsoft Logout' )
// Bind the add mojang account button.
document . getElementById ( 'settingsAddMojangAccount' ) . onclick = ( e ) => {
2018-05-30 19:22:17 -07:00
switchView ( getCurrentView ( ) , VIEWS . login , 500 , 500 , ( ) => {
loginViewOnCancel = VIEWS . settings
loginViewOnSuccess = VIEWS . settings
loginCancelEnabled ( true )
} )
}
2022-02-11 16:51:28 -08:00
// Bind the add microsoft account button.
document . getElementById ( 'settingsAddMicrosoftAccount' ) . onclick = ( e ) => {
switchView ( getCurrentView ( ) , VIEWS . waiting , 500 , 500 , ( ) => {
ipcRenderer . send ( MSFT _OPCODE . OPEN _LOGIN , VIEWS . settings , VIEWS . settings )
} )
}
// Bind reply for Microsoft Login.
ipcRenderer . on ( MSFT _OPCODE . REPLY _LOGIN , ( _ , ... arguments _ ) => {
if ( arguments _ [ 0 ] === MSFT _REPLY _TYPE . ERROR ) {
const viewOnClose = arguments _ [ 2 ]
console . log ( arguments _ )
switchView ( getCurrentView ( ) , viewOnClose , 500 , 500 , ( ) => {
if ( arguments _ [ 1 ] === MSFT _ERROR . NOT _FINISHED ) {
// User cancelled.
msftLoginLogger . info ( 'Login cancelled by user.' )
return
}
// Unexpected error.
setOverlayContent (
'Something Went Wrong' ,
'Microsoft authentication failed. Please try again.' ,
'OK'
)
setOverlayHandler ( ( ) => {
toggleOverlay ( false )
} )
toggleOverlay ( true )
} )
} else if ( arguments _ [ 0 ] === MSFT _REPLY _TYPE . SUCCESS ) {
const queryMap = arguments _ [ 1 ]
const viewOnClose = arguments _ [ 2 ]
// Error from request to Microsoft.
if ( Object . prototype . hasOwnProperty . call ( queryMap , 'error' ) ) {
switchView ( getCurrentView ( ) , viewOnClose , 500 , 500 , ( ) => {
// TODO Dont know what these errors are. Just show them I guess.
2022-12-09 20:49:47 -08:00
// This is probably if you messed up the app registration with Azure.
2022-02-11 16:51:28 -08:00
let error = queryMap . error // Error might be 'access_denied' ?
let errorDesc = queryMap . error _description
2022-12-09 20:49:47 -08:00
console . log ( 'Error getting authCode, is Azure application registered correctly?' )
console . log ( error )
console . log ( errorDesc )
console . log ( 'Full query map: ' , queryMap )
2022-02-11 16:51:28 -08:00
setOverlayContent (
error ,
errorDesc ,
'OK'
)
setOverlayHandler ( ( ) => {
toggleOverlay ( false )
} )
toggleOverlay ( true )
} )
} else {
msftLoginLogger . info ( 'Acquired authCode, proceeding with authentication.' )
const authCode = queryMap . code
AuthManager . addMicrosoftAccount ( authCode ) . then ( value => {
updateSelectedAccount ( value )
2023-02-24 18:02:18 -08:00
switchView ( getCurrentView ( ) , viewOnClose , 500 , 500 , async ( ) => {
await prepareSettings ( )
2022-02-11 16:51:28 -08:00
} )
} )
. catch ( ( displayableError ) => {
let actualDisplayableError
if ( isDisplayableError ( displayableError ) ) {
msftLoginLogger . error ( 'Error while logging in.' , displayableError )
actualDisplayableError = displayableError
} else {
// Uh oh.
msftLoginLogger . error ( 'Unhandled error during login.' , displayableError )
actualDisplayableError = {
title : 'Unknown Error During Login' ,
desc : 'An unknown error has occurred. Please see the console for details.'
}
}
switchView ( getCurrentView ( ) , viewOnClose , 500 , 500 , ( ) => {
setOverlayContent ( actualDisplayableError . title , actualDisplayableError . desc , Lang . queryJS ( 'login.tryAgain' ) )
setOverlayHandler ( ( ) => {
toggleOverlay ( false )
} )
toggleOverlay ( true )
} )
} )
}
}
} )
2018-05-30 19:22:17 -07:00
/ * *
* Bind functionality for the account selection buttons . If another account
* is selected , the UI of the previously selected account will be updated .
* /
function bindAuthAccountSelect ( ) {
Array . from ( document . getElementsByClassName ( 'settingsAuthAccountSelect' ) ) . map ( ( val ) => {
val . onclick = ( e ) => {
if ( val . hasAttribute ( 'selected' ) ) {
return
}
const selectBtns = document . getElementsByClassName ( 'settingsAuthAccountSelect' )
for ( let i = 0 ; i < selectBtns . length ; i ++ ) {
if ( selectBtns [ i ] . hasAttribute ( 'selected' ) ) {
selectBtns [ i ] . removeAttribute ( 'selected' )
selectBtns [ i ] . innerHTML = 'Select Account'
}
}
val . setAttribute ( 'selected' , '' )
val . innerHTML = 'Selected Account ✔'
2018-05-30 20:32:51 -07:00
setSelectedAccount ( val . closest ( '.settingsAuthAccount' ) . getAttribute ( 'uuid' ) )
2018-05-30 19:22:17 -07:00
}
} )
}
/ * *
* Bind functionality for the log out button . If the logged out account was
* the selected account , another account will be selected and the UI will
* be updated accordingly .
* /
function bindAuthAccountLogOut ( ) {
Array . from ( document . getElementsByClassName ( 'settingsAuthAccountLogOut' ) ) . map ( ( val ) => {
val . onclick = ( e ) => {
2018-05-30 20:32:51 -07:00
let isLastAccount = false
if ( Object . keys ( ConfigManager . getAuthAccounts ( ) ) . length === 1 ) {
isLastAccount = true
setOverlayContent (
'Warning<br>This is Your Last Account' ,
'In order to use the launcher you must be logged into at least one account. You will need to login again after.<br><br>Are you sure you want to log out?' ,
'I\'m Sure' ,
'Cancel'
)
setOverlayHandler ( ( ) => {
processLogOut ( val , isLastAccount )
toggleOverlay ( false )
} )
setDismissHandler ( ( ) => {
toggleOverlay ( false )
} )
toggleOverlay ( true , true )
} else {
processLogOut ( val , isLastAccount )
}
}
} )
}
2022-02-11 16:51:28 -08:00
let msAccDomElementCache
2018-05-30 20:32:51 -07:00
/ * *
* 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 ) {
const parent = val . closest ( '.settingsAuthAccount' )
const uuid = parent . getAttribute ( 'uuid' )
const prevSelAcc = ConfigManager . getSelectedAccount ( )
2022-02-11 16:51:28 -08:00
const targetAcc = ConfigManager . getAuthAccount ( uuid )
if ( targetAcc . type === 'microsoft' ) {
msAccDomElementCache = parent
switchView ( getCurrentView ( ) , VIEWS . waiting , 500 , 500 , ( ) => {
ipcRenderer . send ( MSFT _OPCODE . OPEN _LOGOUT , uuid , isLastAccount )
} )
} else {
AuthManager . removeMojangAccount ( uuid ) . then ( ( ) => {
if ( ! isLastAccount && uuid === prevSelAcc . uuid ) {
const selAcc = ConfigManager . getSelectedAccount ( )
refreshAuthAccountSelected ( selAcc . uuid )
updateSelectedAccount ( selAcc )
validateSelectedAccount ( )
}
if ( isLastAccount ) {
loginOptionsCancelEnabled ( false )
loginOptionsViewOnLoginSuccess = VIEWS . settings
loginOptionsViewOnLoginCancel = VIEWS . loginOptions
switchView ( getCurrentView ( ) , VIEWS . loginOptions )
}
} )
$ ( parent ) . fadeOut ( 250 , ( ) => {
parent . remove ( )
} )
}
2018-05-30 19:22:17 -07:00
}
2022-02-11 16:51:28 -08:00
// Bind reply for Microsoft Logout.
ipcRenderer . on ( MSFT _OPCODE . REPLY _LOGOUT , ( _ , ... arguments _ ) => {
if ( arguments _ [ 0 ] === MSFT _REPLY _TYPE . ERROR ) {
switchView ( getCurrentView ( ) , VIEWS . settings , 500 , 500 , ( ) => {
if ( arguments _ . length > 1 && arguments _ [ 1 ] === MSFT _ERROR . NOT _FINISHED ) {
// User cancelled.
msftLogoutLogger . info ( 'Logout cancelled by user.' )
return
}
// Unexpected error.
setOverlayContent (
'Something Went Wrong' ,
'Microsoft logout failed. Please try again.' ,
'OK'
)
setOverlayHandler ( ( ) => {
toggleOverlay ( false )
} )
toggleOverlay ( true )
} )
} else if ( arguments _ [ 0 ] === MSFT _REPLY _TYPE . SUCCESS ) {
const uuid = arguments _ [ 1 ]
const isLastAccount = arguments _ [ 2 ]
const prevSelAcc = ConfigManager . getSelectedAccount ( )
msftLogoutLogger . info ( 'Logout Successful. uuid:' , uuid )
AuthManager . removeMicrosoftAccount ( uuid )
. then ( ( ) => {
if ( ! isLastAccount && uuid === prevSelAcc . uuid ) {
const selAcc = ConfigManager . getSelectedAccount ( )
refreshAuthAccountSelected ( selAcc . uuid )
updateSelectedAccount ( selAcc )
validateSelectedAccount ( )
}
if ( isLastAccount ) {
loginOptionsCancelEnabled ( false )
loginOptionsViewOnLoginSuccess = VIEWS . settings
loginOptionsViewOnLoginCancel = VIEWS . loginOptions
switchView ( getCurrentView ( ) , VIEWS . loginOptions )
}
if ( msAccDomElementCache ) {
msAccDomElementCache . remove ( )
msAccDomElementCache = null
}
} )
. finally ( ( ) => {
if ( ! isLastAccount ) {
switchView ( getCurrentView ( ) , VIEWS . settings , 500 , 500 )
}
} )
}
} )
2018-05-30 19:22:17 -07:00
/ * *
* 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 ) {
Array . from ( document . getElementsByClassName ( 'settingsAuthAccount' ) ) . map ( ( val ) => {
const selBtn = val . getElementsByClassName ( 'settingsAuthAccountSelect' ) [ 0 ]
if ( uuid === val . getAttribute ( 'uuid' ) ) {
selBtn . setAttribute ( 'selected' , '' )
selBtn . innerHTML = 'Selected Account ✔'
} else {
if ( selBtn . hasAttribute ( 'selected' ) ) {
selBtn . removeAttribute ( 'selected' )
}
selBtn . innerHTML = 'Select Account'
}
} )
}
2022-02-11 16:51:28 -08:00
const settingsCurrentMicrosoftAccounts = document . getElementById ( 'settingsCurrentMicrosoftAccounts' )
const settingsCurrentMojangAccounts = document . getElementById ( 'settingsCurrentMojangAccounts' )
2018-06-20 03:15:10 -07:00
2018-05-30 19:22:17 -07:00
/ * *
* Add auth account elements for each one stored in the authentication database .
* /
function populateAuthAccounts ( ) {
const authAccounts = ConfigManager . getAuthAccounts ( )
const authKeys = Object . keys ( authAccounts )
2018-08-13 03:31:46 -07:00
if ( authKeys . length === 0 ) {
return
}
2018-05-30 19:22:17 -07:00
const selectedUUID = ConfigManager . getSelectedAccount ( ) . uuid
2022-02-11 16:51:28 -08:00
let microsoftAuthAccountStr = ''
let mojangAuthAccountStr = ''
2018-05-30 19:22:17 -07:00
2022-02-11 16:51:28 -08:00
authKeys . forEach ( ( val ) => {
2018-05-30 19:22:17 -07:00
const acc = authAccounts [ val ]
2022-02-11 16:51:28 -08:00
const accHtml = ` <div class="settingsAuthAccount" uuid=" ${ acc . uuid } ">
2018-05-30 19:22:17 -07:00
< div class = "settingsAuthAccountLeft" >
2021-07-19 08:08:55 -07:00
< img class = "settingsAuthAccountImage" alt = "${acc.displayName}" src = "https://mc-heads.net/body/${acc.uuid}/60" >
2018-05-30 19:22:17 -07:00
< / d i v >
< div class = "settingsAuthAccountRight" >
< div class = "settingsAuthAccountDetails" >
< div class = "settingsAuthAccountDetailPane" >
< div class = "settingsAuthAccountDetailTitle" > Username < / d i v >
< div class = "settingsAuthAccountDetailValue" > $ { acc . displayName } < / d i v >
< / d i v >
< div class = "settingsAuthAccountDetailPane" >
2018-07-01 23:08:48 -07:00
< div class = "settingsAuthAccountDetailTitle" > UUID < / d i v >
< div class = "settingsAuthAccountDetailValue" > $ { acc . uuid } < / d i v >
2018-05-30 19:22:17 -07:00
< / d i v >
< / d i v >
< div class = "settingsAuthAccountActions" >
< button class = "settingsAuthAccountSelect" $ { selectedUUID === acc . uuid ? 'selected>Selected Account ✔' : '>Select Account' } < / b u t t o n >
< div class = "settingsAuthAccountWrapper" >
< button class = "settingsAuthAccountLogOut" > Log Out < / b u t t o n >
< / d i v >
< / d i v >
< / d i v >
< / d i v > `
2022-02-11 16:51:28 -08:00
if ( acc . type === 'microsoft' ) {
microsoftAuthAccountStr += accHtml
} else {
mojangAuthAccountStr += accHtml
}
2018-05-30 19:22:17 -07:00
} )
2022-02-11 16:51:28 -08:00
settingsCurrentMicrosoftAccounts . innerHTML = microsoftAuthAccountStr
settingsCurrentMojangAccounts . innerHTML = mojangAuthAccountStr
2018-05-30 19:22:17 -07:00
}
2018-06-14 03:09:09 -07:00
/ * *
* Prepare the accounts tab for display .
* /
2018-05-30 19:22:17 -07:00
function prepareAccountsTab ( ) {
populateAuthAccounts ( )
bindAuthAccountSelect ( )
bindAuthAccountLogOut ( )
}
2018-06-04 13:28:17 -07:00
/ * *
* Minecraft Tab
* /
2018-07-22 10:31:15 -07:00
/ * *
2018-06-04 13:28:17 -07:00
* Disable decimals , negative signs , and scientific notation .
* /
2018-07-22 10:31:15 -07:00
document . getElementById ( 'settingsGameWidth' ) . addEventListener ( 'keydown' , ( e ) => {
if ( /^[-.eE]$/ . test ( e . key ) ) {
2018-06-04 13:28:17 -07:00
e . preventDefault ( )
}
} )
2018-06-20 03:15:10 -07:00
document . getElementById ( 'settingsGameHeight' ) . addEventListener ( 'keydown' , ( e ) => {
2018-07-22 10:31:15 -07:00
if ( /^[-.eE]$/ . test ( e . key ) ) {
2018-06-04 13:28:17 -07:00
e . preventDefault ( )
}
} )
2018-07-23 22:14:26 -07:00
/ * *
* Mods Tab
* /
2018-07-29 05:42:11 -07:00
const settingsModsContainer = document . getElementById ( 'settingsModsContainer' )
2018-08-07 01:41:26 -07:00
/ * *
* Resolve and update the mods on the UI .
* /
2023-02-24 18:02:18 -08:00
async function resolveModsForUI ( ) {
2018-07-23 22:14:26 -07:00
const serv = ConfigManager . getSelectedServer ( )
2023-02-24 18:02:18 -08:00
const distro = await DistroAPI . getDistribution ( )
2018-07-23 22:14:26 -07:00
const servConf = ConfigManager . getModConfiguration ( serv )
2023-02-24 18:02:18 -08:00
const modStr = parseModulesForUI ( distro . getServerById ( serv ) . modules , false , servConf . mods )
2018-07-23 22:14:26 -07:00
document . getElementById ( 'settingsReqModsContent' ) . innerHTML = modStr . reqMods
document . getElementById ( 'settingsOptModsContent' ) . innerHTML = modStr . optMods
}
2018-08-07 01:41:26 -07:00
/ * *
* Recursively build the mod UI elements .
*
* @ param { Object [ ] } mdls An array of modules to parse .
* @ param { boolean } submodules Whether or not we are parsing submodules .
* @ param { Object } servConf The server configuration object for this module level .
* /
2018-08-06 21:58:32 -07:00
function parseModulesForUI ( mdls , submodules , servConf ) {
2018-07-23 22:14:26 -07:00
let reqMods = ''
let optMods = ''
for ( const mdl of mdls ) {
2023-02-24 18:02:18 -08:00
if ( mdl . rawModule . type === Type . ForgeMod || mdl . rawModule . type === Type . LiteMod || mdl . rawModule . type === Type . LiteLoader ) {
2018-07-23 22:14:26 -07:00
2023-02-24 18:02:18 -08:00
if ( mdl . getRequired ( ) . value ) {
2018-07-23 22:14:26 -07:00
2023-02-24 18:02:18 -08:00
reqMods += ` <div id=" ${ mdl . getVersionlessMavenIdentifier ( ) } " class="settingsBaseMod settings ${ submodules ? 'Sub' : '' } Mod" enabled>
2018-07-23 22:14:26 -07:00
< div class = "settingsModContent" >
< div class = "settingsModMainWrapper" >
< div class = "settingsModStatus" > < / d i v >
< div class = "settingsModDetails" >
2023-02-24 18:02:18 -08:00
< span class = "settingsModName" > $ { mdl . rawModule . name } < / s p a n >
< span class = "settingsModVersion" > v$ { mdl . mavenComponents . version } < / s p a n >
2018-07-23 22:14:26 -07:00
< / d i v >
< / d i v >
< label class = "toggleSwitch" reqmod >
< input type = "checkbox" checked >
< span class = "toggleSwitchSlider" > < / s p a n >
< / l a b e l >
< / d i v >
2023-02-24 18:02:18 -08:00
$ { mdl . subModules . length > 0 ? ` <div class="settingsSubModContainer">
$ { Object . values ( parseModulesForUI ( mdl . subModules , true , servConf [ mdl . getVersionlessMavenIdentifier ( ) ] ) ) . join ( '' ) }
2018-07-23 22:14:26 -07:00
< / d i v > ` : ' ' }
< / d i v > `
} else {
2023-02-24 18:02:18 -08:00
const conf = servConf [ mdl . getVersionlessMavenIdentifier ( ) ]
2018-07-23 22:14:26 -07:00
const val = typeof conf === 'object' ? conf . value : conf
2023-02-24 18:02:18 -08:00
optMods += ` <div id=" ${ mdl . getVersionlessMavenIdentifier ( ) } " class="settingsBaseMod settings ${ submodules ? 'Sub' : '' } Mod" ${ val ? 'enabled' : '' } >
2018-07-23 22:14:26 -07:00
< div class = "settingsModContent" >
< div class = "settingsModMainWrapper" >
< div class = "settingsModStatus" > < / d i v >
< div class = "settingsModDetails" >
2023-02-24 18:02:18 -08:00
< span class = "settingsModName" > $ { mdl . rawModule . name } < / s p a n >
< span class = "settingsModVersion" > v$ { mdl . mavenComponents . version } < / s p a n >
2018-07-23 22:14:26 -07:00
< / d i v >
< / d i v >
< label class = "toggleSwitch" >
2023-02-24 18:02:18 -08:00
< input type = "checkbox" formod = "${mdl.getVersionlessMavenIdentifier()}" $ { val ? 'checked' : '' } >
2018-07-23 22:14:26 -07:00
< span class = "toggleSwitchSlider" > < / s p a n >
< / l a b e l >
< / d i v >
2023-02-24 18:02:18 -08:00
$ { mdl . subModules . length > 0 ? ` <div class="settingsSubModContainer">
$ { Object . values ( parseModulesForUI ( mdl . subModules , true , conf . mods ) ) . join ( '' ) }
2018-07-23 22:14:26 -07:00
< / d i v > ` : ' ' }
< / d i v > `
}
}
}
return {
reqMods ,
optMods
}
}
2018-07-29 05:42:11 -07:00
/ * *
* 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 ( ) {
const sEls = settingsModsContainer . querySelectorAll ( '[formod]' )
Array . from ( sEls ) . map ( ( v , index , arr ) => {
v . onchange = ( ) => {
if ( v . checked ) {
document . getElementById ( v . getAttribute ( 'formod' ) ) . setAttribute ( 'enabled' , '' )
} else {
document . getElementById ( v . getAttribute ( 'formod' ) ) . removeAttribute ( 'enabled' )
}
}
} )
}
/ * *
* Save the mod configuration based on the UI values .
* /
function saveModConfiguration ( ) {
const serv = ConfigManager . getSelectedServer ( )
const modConf = ConfigManager . getModConfiguration ( serv )
modConf . mods = _saveModConfiguration ( modConf . mods )
ConfigManager . setModConfiguration ( serv , modConf )
}
/ * *
* Recursively save mod config with submods .
*
* @ param { Object } modConf Mod config object to save .
* /
function _saveModConfiguration ( modConf ) {
2018-11-20 02:19:59 -08:00
for ( let m of Object . entries ( modConf ) ) {
2018-07-29 07:32:41 -07:00
const tSwitch = settingsModsContainer . querySelectorAll ( ` [formod=' ${ m [ 0 ] } '] ` )
2018-08-07 01:16:15 -07:00
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 ) {
modConf [ m [ 0 ] ] . value = tSwitch [ 0 ] . checked
}
modConf [ m [ 0 ] ] . mods = _saveModConfiguration ( modConf [ m [ 0 ] ] . mods )
2018-07-29 07:32:41 -07:00
}
2018-07-29 05:42:11 -07:00
}
}
}
return modConf
}
2018-08-07 01:41:26 -07:00
// Drop-in mod elements.
2018-08-06 21:58:32 -07:00
2018-08-07 01:16:15 -07:00
let CACHE _SETTINGS _MODS _DIR
let CACHE _DROPIN _MODS
2018-08-07 01:41:26 -07:00
/ * *
* Resolve any located drop - in mods for this server and
* populate the results onto the UI .
* /
2023-02-24 18:02:18 -08:00
async function resolveDropinModsForUI ( ) {
const serv = ( await DistroAPI . getDistribution ( ) ) . getServerById ( ConfigManager . getSelectedServer ( ) )
CACHE _SETTINGS _MODS _DIR = path . join ( ConfigManager . getInstanceDirectory ( ) , serv . rawServer . id , 'mods' )
CACHE _DROPIN _MODS = DropinModUtil . scanForDropinMods ( CACHE _SETTINGS _MODS _DIR , serv . rawServer . minecraftVersion )
2018-08-07 01:16:15 -07:00
let dropinMods = ''
for ( dropin of CACHE _DROPIN _MODS ) {
dropinMods += ` <div id=" ${ dropin . fullName } " class="settingsBaseMod settingsDropinMod" ${ ! dropin . disabled ? 'enabled' : '' } >
< div class = "settingsModContent" >
< div class = "settingsModMainWrapper" >
< div class = "settingsModStatus" > < / d i v >
< div class = "settingsModDetails" >
< span class = "settingsModName" > $ { dropin . name } < / s p a n >
< div class = "settingsDropinRemoveWrapper" >
< button class = "settingsDropinRemoveButton" remmod = "${dropin.fullName}" > Remove < / b u t t o n >
< / d i v >
< / d i v >
< / d i v >
< label class = "toggleSwitch" >
< input type = "checkbox" formod = "${dropin.fullName}" dropin $ { ! dropin . disabled ? 'checked' : '' } >
< span class = "toggleSwitchSlider" > < / s p a n >
< / l a b e l >
< / d i v >
< / d i v > `
}
document . getElementById ( 'settingsDropinModsContent' ) . innerHTML = dropinMods
}
2018-08-07 01:41:26 -07:00
/ * *
* Bind the remove button for each loaded drop - in mod .
* /
2018-08-07 01:16:15 -07:00
function bindDropinModsRemoveButton ( ) {
const sEls = settingsModsContainer . querySelectorAll ( '[remmod]' )
Array . from ( sEls ) . map ( ( v , index , arr ) => {
2021-06-23 17:27:04 -07:00
v . onclick = async ( ) => {
2018-08-07 01:16:15 -07:00
const fullName = v . getAttribute ( 'remmod' )
2021-06-23 17:27:04 -07:00
const res = await DropinModUtil . deleteDropinMod ( CACHE _SETTINGS _MODS _DIR , fullName )
2018-08-07 01:16:15 -07:00
if ( res ) {
document . getElementById ( fullName ) . remove ( )
} else {
setOverlayContent (
` Failed to Delete<br>Drop-in Mod ${ fullName } ` ,
'Make sure the file is not in use and try again.' ,
'Okay'
)
setOverlayHandler ( null )
toggleOverlay ( true )
}
}
} )
}
2018-08-07 01:41:26 -07:00
/ * *
* Bind functionality to the file system button for the selected
* server configuration .
* /
2018-08-07 01:16:15 -07:00
function bindDropinModFileSystemButton ( ) {
const fsBtn = document . getElementById ( 'settingsDropinFileSystemButton' )
fsBtn . onclick = ( ) => {
2018-12-21 03:51:08 -08:00
DropinModUtil . validateDir ( CACHE _SETTINGS _MODS _DIR )
2020-05-21 18:02:58 -07:00
shell . openPath ( CACHE _SETTINGS _MODS _DIR )
2018-08-07 01:16:15 -07:00
}
2018-12-01 05:20:42 -08:00
fsBtn . ondragenter = e => {
e . dataTransfer . dropEffect = 'move'
fsBtn . setAttribute ( 'drag' , '' )
e . preventDefault ( )
}
fsBtn . ondragover = e => {
e . preventDefault ( )
}
fsBtn . ondragleave = e => {
fsBtn . removeAttribute ( 'drag' )
}
2023-02-24 18:02:18 -08:00
fsBtn . ondrop = async e => {
2018-12-01 05:20:42 -08:00
fsBtn . removeAttribute ( 'drag' )
e . preventDefault ( )
DropinModUtil . addDropinMods ( e . dataTransfer . files , CACHE _SETTINGS _MODS _DIR )
2023-02-24 18:02:18 -08:00
await reloadDropinMods ( )
2018-12-01 05:20:42 -08:00
}
2018-08-07 01:16:15 -07:00
}
2018-08-07 01:41:26 -07:00
/ * *
* Save drop - in mod states . Enabling and disabling is just a matter
* of adding / removing the . disabled extension .
* /
2018-08-07 01:16:15 -07:00
function saveDropinModConfiguration ( ) {
for ( dropin of CACHE _DROPIN _MODS ) {
const dropinUI = document . getElementById ( dropin . fullName )
if ( dropinUI != null ) {
const dropinUIEnabled = dropinUI . hasAttribute ( 'enabled' )
if ( DropinModUtil . isDropinModEnabled ( dropin . fullName ) != dropinUIEnabled ) {
DropinModUtil . toggleDropinMod ( CACHE _SETTINGS _MODS _DIR , dropin . fullName , dropinUIEnabled ) . catch ( err => {
if ( ! isOverlayVisible ( ) ) {
setOverlayContent (
'Failed to Toggle<br>One or More Drop-in Mods' ,
err . message ,
'Okay'
)
setOverlayHandler ( null )
toggleOverlay ( true )
}
} )
}
}
}
}
2018-08-07 01:41:26 -07:00
// Refresh the drop-in mods when F5 is pressed.
// Only active on the mods tab.
2023-02-24 18:02:18 -08:00
document . addEventListener ( 'keydown' , async ( e ) => {
2018-08-07 01:16:15 -07:00
if ( getCurrentView ( ) === VIEWS . settings && selectedSettingsTab === 'settingsTabMods' ) {
if ( e . key === 'F5' ) {
2023-02-24 18:02:18 -08:00
await reloadDropinMods ( )
2018-12-21 05:02:24 -08:00
saveShaderpackSettings ( )
2023-02-24 18:02:18 -08:00
await resolveShaderpacksForUI ( )
2018-08-07 01:16:15 -07:00
}
}
} )
2023-02-24 18:02:18 -08:00
async function reloadDropinMods ( ) {
await resolveDropinModsForUI ( )
2018-12-01 05:20:42 -08:00
bindDropinModsRemoveButton ( )
bindDropinModFileSystemButton ( )
bindModsToggleSwitch ( )
}
2018-12-21 03:51:08 -08:00
// Shaderpack
let CACHE _SETTINGS _INSTANCE _DIR
let CACHE _SHADERPACKS
let CACHE _SELECTED _SHADERPACK
/ * *
* Load shaderpack information .
* /
2023-02-24 18:02:18 -08:00
async function resolveShaderpacksForUI ( ) {
const serv = ( await DistroAPI . getDistribution ( ) ) . getServerById ( ConfigManager . getSelectedServer ( ) )
CACHE _SETTINGS _INSTANCE _DIR = path . join ( ConfigManager . getInstanceDirectory ( ) , serv . rawServer . id )
2018-12-21 03:51:08 -08:00
CACHE _SHADERPACKS = DropinModUtil . scanForShaderpacks ( CACHE _SETTINGS _INSTANCE _DIR )
CACHE _SELECTED _SHADERPACK = DropinModUtil . getEnabledShaderpack ( CACHE _SETTINGS _INSTANCE _DIR )
setShadersOptions ( CACHE _SHADERPACKS , CACHE _SELECTED _SHADERPACK )
}
function setShadersOptions ( arr , selected ) {
const cont = document . getElementById ( 'settingsShadersOptions' )
cont . innerHTML = ''
for ( let opt of arr ) {
const d = document . createElement ( 'DIV' )
d . innerHTML = opt . name
d . setAttribute ( 'value' , opt . fullName )
if ( opt . fullName === selected ) {
d . setAttribute ( 'selected' , '' )
document . getElementById ( 'settingsShadersSelected' ) . innerHTML = opt . name
}
d . addEventListener ( 'click' , function ( e ) {
this . parentNode . previousElementSibling . innerHTML = this . innerHTML
for ( let sib of this . parentNode . children ) {
sib . removeAttribute ( 'selected' )
}
this . setAttribute ( 'selected' , '' )
closeSettingsSelect ( )
} )
cont . appendChild ( d )
}
}
2018-12-21 05:02:24 -08:00
function saveShaderpackSettings ( ) {
let sel = 'OFF'
for ( let opt of document . getElementById ( 'settingsShadersOptions' ) . childNodes ) {
if ( opt . hasAttribute ( 'selected' ) ) {
sel = opt . getAttribute ( 'value' )
}
}
DropinModUtil . setEnabledShaderpack ( CACHE _SETTINGS _INSTANCE _DIR , sel )
}
function bindShaderpackButton ( ) {
const spBtn = document . getElementById ( 'settingsShaderpackButton' )
spBtn . onclick = ( ) => {
const p = path . join ( CACHE _SETTINGS _INSTANCE _DIR , 'shaderpacks' )
DropinModUtil . validateDir ( p )
2020-05-21 18:02:58 -07:00
shell . openPath ( p )
2018-12-21 05:02:24 -08:00
}
spBtn . ondragenter = e => {
e . dataTransfer . dropEffect = 'move'
spBtn . setAttribute ( 'drag' , '' )
e . preventDefault ( )
}
spBtn . ondragover = e => {
e . preventDefault ( )
}
spBtn . ondragleave = e => {
spBtn . removeAttribute ( 'drag' )
}
2023-02-24 18:02:18 -08:00
spBtn . ondrop = async e => {
2018-12-21 05:02:24 -08:00
spBtn . removeAttribute ( 'drag' )
e . preventDefault ( )
DropinModUtil . addShaderpacks ( e . dataTransfer . files , CACHE _SETTINGS _INSTANCE _DIR )
2018-12-21 13:06:34 -08:00
saveShaderpackSettings ( )
2023-02-24 18:02:18 -08:00
await resolveShaderpacksForUI ( )
2018-12-21 05:02:24 -08:00
}
}
2018-08-07 01:41:26 -07:00
// Server status bar functions.
/ * *
* Load the currently selected server information onto the mods tab .
* /
2023-02-24 18:02:18 -08:00
async function loadSelectedServerOnModsTab ( ) {
const serv = ( await DistroAPI . getDistribution ( ) ) . getServerById ( ConfigManager . getSelectedServer ( ) )
2018-08-07 01:41:26 -07:00
2022-11-27 15:13:50 -08:00
for ( const el of document . getElementsByClassName ( 'settingsSelServContent' ) ) {
el . innerHTML = `
2023-02-24 18:02:18 -08:00
< img class = "serverListingImg" src = "${serv.rawServer.icon}" / >
2022-11-27 15:13:50 -08:00
< div class = "serverListingDetails" >
2023-02-24 18:02:18 -08:00
< span class = "serverListingName" > $ { serv . rawServer . name } < / s p a n >
< span class = "serverListingDescription" > $ { serv . rawServer . description } < / s p a n >
2022-11-27 15:13:50 -08:00
< div class = "serverListingInfo" >
2023-02-24 18:02:18 -08:00
< div class = "serverListingVersion" > $ { serv . rawServer . minecraftVersion } < / d i v >
< div class = "serverListingRevision" > $ { serv . rawServer . version } < / d i v >
$ { serv . rawServer . mainServer ? ` <div class="serverListingStarWrapper">
2022-11-27 15:13:50 -08:00
< 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 ; } < / s t y l e >
< / d e f s >
< 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" / >
< / s v g >
< span class = "serverListingStarTooltip" > Main Server < / s p a n >
< / d i v > ` : ' ' }
< / d i v >
2018-08-07 01:41:26 -07:00
< / d i v >
2022-11-27 15:13:50 -08:00
`
}
2018-08-07 01:41:26 -07:00
}
// Bind functionality to the server switch button.
2022-11-27 15:13:50 -08:00
Array . from ( document . getElementsByClassName ( 'settingsSwitchServerButton' ) ) . forEach ( el => {
2023-02-24 18:02:18 -08:00
el . addEventListener ( 'click' , async e => {
2022-11-27 15:13:50 -08:00
e . target . blur ( )
2023-02-24 18:02:18 -08:00
await toggleServerSelection ( true )
2022-11-27 15:13:50 -08:00
} )
2018-08-07 01:41:26 -07:00
} )
2018-11-20 02:19:59 -08:00
/ * *
* Save mod configuration for the current selected server .
* /
function saveAllModConfigurations ( ) {
saveModConfiguration ( )
ConfigManager . save ( )
saveDropinModConfiguration ( )
}
2018-08-07 01:41:26 -07:00
/ * *
2022-11-27 15:13:50 -08:00
* Function to refresh the current tab whenever the selected
2018-08-07 01:41:26 -07:00
* server is changed .
* /
2022-11-27 15:13:50 -08:00
function animateSettingsTabRefresh ( ) {
2023-02-24 18:02:18 -08:00
$ ( ` # ${ selectedSettingsTab } ` ) . fadeOut ( 500 , async ( ) => {
await prepareSettings ( )
2022-11-27 15:13:50 -08:00
$ ( ` # ${ selectedSettingsTab } ` ) . fadeIn ( 500 )
2018-08-06 21:58:32 -07:00
} )
}
2018-07-23 22:14:26 -07:00
/ * *
2018-08-06 21:58:32 -07:00
* Prepare the Mods tab for display .
2018-07-23 22:14:26 -07:00
* /
2023-02-24 18:02:18 -08:00
async function prepareModsTab ( first ) {
await resolveModsForUI ( )
await resolveDropinModsForUI ( )
await resolveShaderpacksForUI ( )
2018-08-07 01:16:15 -07:00
bindDropinModsRemoveButton ( )
bindDropinModFileSystemButton ( )
2018-12-21 05:02:24 -08:00
bindShaderpackButton ( )
2018-07-29 05:42:11 -07:00
bindModsToggleSwitch ( )
2023-02-24 18:02:18 -08:00
await loadSelectedServerOnModsTab ( )
2018-07-23 22:14:26 -07:00
}
2018-06-11 19:11:05 -07:00
/ * *
* Java Tab
* /
2018-06-20 03:15:10 -07:00
// 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 settingsJavaExecDetails = document . getElementById ( 'settingsJavaExecDetails' )
2022-11-27 15:13:50 -08:00
const settingsJavaReqDesc = document . getElementById ( 'settingsJavaReqDesc' )
const settingsJvmOptsLink = document . getElementById ( 'settingsJvmOptsLink' )
2018-06-20 03:15:10 -07:00
2018-06-14 03:09:09 -07:00
// Bind on change event for min memory container.
2018-06-11 19:11:05 -07:00
settingsMinRAMRange . onchange = ( e ) => {
2018-06-14 03:09:09 -07:00
// Current range values
2018-06-11 19:11:05 -07:00
const sMaxV = Number ( settingsMaxRAMRange . getAttribute ( 'value' ) )
const sMinV = Number ( settingsMinRAMRange . getAttribute ( 'value' ) )
2018-06-14 03:09:09 -07:00
// Get reference to range bar.
2018-06-12 00:48:36 -07:00
const bar = e . target . getElementsByClassName ( 'rangeSliderBar' ) [ 0 ]
2018-06-14 03:09:09 -07:00
// Calculate effective total memory.
2023-03-18 18:22:18 -07:00
const max = os . totalmem ( ) / 1073741824
2018-06-14 03:09:09 -07:00
// Change range bar color based on the selected value.
2018-06-12 00:48:36 -07:00
if ( sMinV >= max / 2 ) {
bar . style . background = '#e86060'
} else if ( sMinV >= max / 4 ) {
bar . style . background = '#e8e18b'
} else {
bar . style . background = null
}
2018-06-14 03:09:09 -07:00
// Increase maximum memory if the minimum exceeds its value.
2018-06-11 19:11:05 -07:00
if ( sMaxV < sMinV ) {
const sliderMeta = calculateRangeSliderMeta ( settingsMaxRAMRange )
updateRangedSlider ( settingsMaxRAMRange , sMinV ,
2018-07-22 10:31:15 -07:00
( ( sMinV - sliderMeta . min ) / sliderMeta . step ) * sliderMeta . inc )
2018-06-12 00:25:36 -07:00
settingsMaxRAMLabel . innerHTML = sMinV . toFixed ( 1 ) + 'G'
2018-06-11 19:11:05 -07:00
}
2018-06-14 03:09:09 -07:00
// Update label
2018-06-12 00:25:36 -07:00
settingsMinRAMLabel . innerHTML = sMinV . toFixed ( 1 ) + 'G'
2018-06-11 19:11:05 -07:00
}
2018-06-12 00:25:36 -07:00
2018-06-14 03:09:09 -07:00
// Bind on change event for max memory container.
2018-06-11 19:11:05 -07:00
settingsMaxRAMRange . onchange = ( e ) => {
2018-06-14 03:09:09 -07:00
// Current range values
2018-06-11 19:11:05 -07:00
const sMaxV = Number ( settingsMaxRAMRange . getAttribute ( 'value' ) )
const sMinV = Number ( settingsMinRAMRange . getAttribute ( 'value' ) )
2018-06-14 03:09:09 -07:00
// Get reference to range bar.
2018-06-12 00:48:36 -07:00
const bar = e . target . getElementsByClassName ( 'rangeSliderBar' ) [ 0 ]
2018-06-14 03:09:09 -07:00
// Calculate effective total memory.
2023-03-18 18:22:18 -07:00
const max = os . totalmem ( ) / 1073741824
2018-06-14 03:09:09 -07:00
// Change range bar color based on the selected value.
2018-06-12 00:48:36 -07:00
if ( sMaxV >= max / 2 ) {
bar . style . background = '#e86060'
} else if ( sMaxV >= max / 4 ) {
bar . style . background = '#e8e18b'
} else {
bar . style . background = null
}
2018-06-14 03:09:09 -07:00
// Decrease the minimum memory if the maximum value is less.
2018-06-11 19:11:05 -07:00
if ( sMaxV < sMinV ) {
2018-06-12 00:25:36 -07:00
const sliderMeta = calculateRangeSliderMeta ( settingsMaxRAMRange )
updateRangedSlider ( settingsMinRAMRange , sMaxV ,
2018-07-22 10:31:15 -07:00
( ( sMaxV - sliderMeta . min ) / sliderMeta . step ) * sliderMeta . inc )
2018-06-12 00:25:36 -07:00
settingsMinRAMLabel . innerHTML = sMaxV . toFixed ( 1 ) + 'G'
2018-06-11 19:11:05 -07:00
}
2018-06-12 00:25:36 -07:00
settingsMaxRAMLabel . innerHTML = sMaxV . toFixed ( 1 ) + 'G'
2018-06-11 19:11:05 -07:00
}
2018-06-14 03:09:09 -07:00
/ * *
* Calculate common values for a ranged slider .
*
* @ param { Element } v The range slider to calculate against .
* @ returns { Object } An object with meta values for the provided ranged slider .
* /
2018-06-11 19:11:05 -07:00
function calculateRangeSliderMeta ( v ) {
const val = {
max : Number ( v . getAttribute ( 'max' ) ) ,
min : Number ( v . getAttribute ( 'min' ) ) ,
step : Number ( v . getAttribute ( 'step' ) ) ,
}
2018-06-12 00:48:36 -07:00
val . ticks = ( val . max - val . min ) / val . step
2018-06-11 19:11:05 -07:00
val . inc = 100 / val . ticks
return val
}
2018-06-14 03:09:09 -07:00
/ * *
* Binds functionality to the ranged sliders . They ' re more than
* just divs now : ' ) .
* /
2018-06-11 19:11:05 -07:00
function bindRangeSlider ( ) {
Array . from ( document . getElementsByClassName ( 'rangeSlider' ) ) . map ( ( v ) => {
2018-06-14 03:09:09 -07:00
// Reference the track (thumb).
2018-06-11 19:11:05 -07:00
const track = v . getElementsByClassName ( 'rangeSliderTrack' ) [ 0 ]
2018-06-14 03:09:09 -07:00
// Set the initial slider value.
2018-06-11 19:11:05 -07:00
const value = v . getAttribute ( 'value' )
const sliderMeta = calculateRangeSliderMeta ( v )
2018-06-14 03:09:09 -07:00
updateRangedSlider ( v , value , ( ( value - sliderMeta . min ) / sliderMeta . step ) * sliderMeta . inc )
// The magic happens when we click on the track.
2018-06-11 19:11:05 -07:00
track . onmousedown = ( e ) => {
2018-06-14 03:09:09 -07:00
// Stop moving the track on mouse up.
2018-06-11 19:11:05 -07:00
document . onmouseup = ( e ) => {
document . onmousemove = null
document . onmouseup = null
}
2018-06-14 03:09:09 -07:00
// Move slider according to the mouse position.
2018-06-11 19:11:05 -07:00
document . onmousemove = ( e ) => {
2018-06-14 03:09:09 -07:00
// Distance from the beginning of the bar in pixels.
2018-06-11 19:11:05 -07:00
const diff = e . pageX - v . offsetLeft - track . offsetWidth / 2
2018-06-14 03:09:09 -07:00
// Don't move the track off the bar.
2018-06-11 19:11:05 -07:00
if ( diff >= 0 && diff <= v . offsetWidth - track . offsetWidth / 2 ) {
2018-06-14 03:09:09 -07:00
// Convert the difference to a percentage.
2018-06-11 19:11:05 -07:00
const perc = ( diff / v . offsetWidth ) * 100
2018-06-14 03:09:09 -07:00
// Calculate the percentage of the closest notch.
2018-06-11 19:11:05 -07:00
const notch = Number ( perc / sliderMeta . inc ) . toFixed ( 0 ) * sliderMeta . inc
2018-06-12 00:48:36 -07:00
2018-06-14 03:09:09 -07:00
// If we're close to that notch, stick to it.
2018-06-11 19:11:05 -07:00
if ( Math . abs ( perc - notch ) < sliderMeta . inc / 2 ) {
2018-06-12 00:48:36 -07:00
updateRangedSlider ( v , sliderMeta . min + ( sliderMeta . step * ( notch / sliderMeta . inc ) ) , notch )
2018-06-11 19:11:05 -07:00
}
}
}
}
} )
}
2018-06-14 03:09:09 -07:00
/ * *
* Update a ranged slider ' s value and position .
*
* @ param { Element } element The ranged slider to update .
* @ param { string | number } value The new value for the ranged slider .
* @ param { number } notch The notch that the slider should now be at .
* /
2018-06-11 19:11:05 -07:00
function updateRangedSlider ( element , value , notch ) {
const oldVal = element . getAttribute ( 'value' )
const bar = element . getElementsByClassName ( 'rangeSliderBar' ) [ 0 ]
const track = element . getElementsByClassName ( 'rangeSliderTrack' ) [ 0 ]
2018-06-14 03:09:09 -07:00
2018-06-11 19:11:05 -07:00
element . setAttribute ( 'value' , value )
2018-06-14 03:09:09 -07:00
2018-06-21 18:04:10 -07:00
if ( notch < 0 ) {
notch = 0
} else if ( notch > 100 ) {
notch = 100
}
2018-06-11 19:11:05 -07:00
const event = new MouseEvent ( 'change' , {
target : element ,
type : 'change' ,
bubbles : false ,
cancelable : true
} )
2018-06-14 03:09:09 -07:00
2018-06-11 19:11:05 -07:00
let cancelled = ! element . dispatchEvent ( event )
2018-06-14 03:09:09 -07:00
2018-06-11 19:11:05 -07:00
if ( ! cancelled ) {
track . style . left = notch + '%'
bar . style . width = notch + '%'
} else {
element . setAttribute ( 'value' , oldVal )
}
}
2018-06-14 03:09:09 -07:00
/ * *
* Display the total and available RAM .
* /
function populateMemoryStatus ( ) {
2023-03-18 18:22:18 -07:00
settingsMemoryTotal . innerHTML = Number ( ( os . totalmem ( ) - 1073741824 ) / 1073741824 ) . toFixed ( 1 ) + 'G'
settingsMemoryAvail . innerHTML = Number ( os . freemem ( ) / 1073741824 ) . toFixed ( 1 ) + 'G'
2018-06-12 00:25:36 -07:00
}
2018-06-14 03:09:09 -07:00
/ * *
* Validate the provided executable path and display the data on
* the UI .
*
* @ param { string } execPath The executable path to populate against .
* /
2023-02-24 18:02:18 -08:00
async function populateJavaExecDetails ( execPath ) {
2023-03-17 23:49:10 -07:00
const server = ( await DistroAPI . getDistribution ( ) ) . getServerById ( ConfigManager . getSelectedServer ( ) )
2023-03-12 23:06:58 -07:00
2023-03-17 23:49:10 -07:00
const details = await validateSelectedJvm ( ensureJavaDirIsRoot ( execPath ) , server . effectiveJavaOptions . supported )
2023-03-12 23:06:58 -07:00
if ( details != null ) {
2023-03-17 23:49:10 -07:00
settingsJavaExecDetails . innerHTML = ` Selected: Java ${ details . semverStr } ( ${ details . vendor } ) `
2023-03-12 23:06:58 -07:00
} else {
settingsJavaExecDetails . innerHTML = 'Invalid Selection'
}
2018-06-14 03:09:09 -07:00
}
2023-03-18 18:22:18 -07:00
function populateJavaReqDesc ( server ) {
2023-03-17 23:49:10 -07:00
settingsJavaReqDesc . innerHTML = ` Requires Java ${ server . effectiveJavaOptions . suggestedMajor } x64. `
2022-11-27 15:13:50 -08:00
}
2023-03-18 18:22:18 -07:00
function populateJvmOptsLink ( server ) {
2023-03-17 23:49:10 -07:00
const major = server . effectiveJavaOptions . suggestedMajor
settingsJvmOptsLink . innerHTML = ` Available Options for Java ${ major } (HotSpot VM) `
if ( major >= 12 ) {
settingsJvmOptsLink . href = ` https://docs.oracle.com/en/java/javase/ ${ major } /docs/specs/man/java.html#extra-options-for-java `
}
else if ( major >= 11 ) {
settingsJvmOptsLink . href = 'https://docs.oracle.com/en/java/javase/11/tools/java.html#GUID-3B1CE181-CD30-4178-9602-230B800D4FAE'
}
else if ( major >= 9 ) {
settingsJvmOptsLink . href = ` https://docs.oracle.com/javase/ ${ major } /tools/java.htm `
}
else {
settingsJvmOptsLink . href = ` https://docs.oracle.com/javase/ ${ major } /docs/technotes/tools/ ${ process . platform === 'win32' ? 'windows' : 'unix' } /java.html `
2022-11-27 15:13:50 -08:00
}
}
2023-03-18 18:22:18 -07:00
function bindMinMaxRam ( server ) {
// Store maximum memory values.
const SETTINGS _MAX _MEMORY = ConfigManager . getAbsoluteMaxRAM ( server . rawServer . javaOptions ? . ram )
const SETTINGS _MIN _MEMORY = ConfigManager . getAbsoluteMinRAM ( server . rawServer . javaOptions ? . ram )
// Set the max and min values for the ranged sliders.
settingsMaxRAMRange . setAttribute ( 'max' , SETTINGS _MAX _MEMORY )
settingsMaxRAMRange . setAttribute ( 'min' , SETTINGS _MIN _MEMORY )
settingsMinRAMRange . setAttribute ( 'max' , SETTINGS _MAX _MEMORY )
settingsMinRAMRange . setAttribute ( 'min' , SETTINGS _MIN _MEMORY )
}
2018-06-14 03:09:09 -07:00
/ * *
* Prepare the Java tab for display .
* /
2023-02-24 18:02:18 -08:00
async function prepareJavaTab ( ) {
2023-03-18 18:22:18 -07:00
const server = ( await DistroAPI . getDistribution ( ) ) . getServerById ( ConfigManager . getSelectedServer ( ) )
bindMinMaxRam ( server )
bindRangeSlider ( server )
2018-06-14 03:09:09 -07:00
populateMemoryStatus ( )
2023-03-18 18:22:18 -07:00
populateJavaReqDesc ( server )
populateJvmOptsLink ( server )
2018-06-11 19:11:05 -07:00
}
2018-06-20 03:15:10 -07:00
/ * *
* About Tab
* /
2018-08-13 03:13:13 -07:00
const settingsTabAbout = document . getElementById ( 'settingsTabAbout' )
const settingsAboutChangelogTitle = settingsTabAbout . getElementsByClassName ( 'settingsChangelogTitle' ) [ 0 ]
const settingsAboutChangelogText = settingsTabAbout . getElementsByClassName ( 'settingsChangelogText' ) [ 0 ]
const settingsAboutChangelogButton = settingsTabAbout . getElementsByClassName ( 'settingsChangelogButton' ) [ 0 ]
2018-06-20 03:15:10 -07:00
// Bind the devtools toggle button.
document . getElementById ( 'settingsAboutDevToolsButton' ) . onclick = ( e ) => {
let window = remote . getCurrentWindow ( )
window . toggleDevTools ( )
}
/ * *
2018-08-13 03:13:13 -07:00
* Return whether or not the provided version is a prerelease .
*
* @ param { string } version The semver version to test .
* @ returns { boolean } True if the version is a prerelease , otherwise false .
2018-06-20 03:15:10 -07:00
* /
2018-08-13 03:13:13 -07:00
function isPrerelease ( version ) {
2018-06-20 03:15:10 -07:00
const preRelComp = semver . prerelease ( version )
2018-08-13 03:13:13 -07:00
return preRelComp != null && preRelComp . length > 0
}
/ * *
* Utility method to display version information on the
* About and Update settings tabs .
*
* @ param { string } version The semver version to display .
* @ param { Element } valueElement The value element .
* @ param { Element } titleElement The title element .
* @ param { Element } checkElement The check mark element .
* /
function populateVersionInformation ( version , valueElement , titleElement , checkElement ) {
valueElement . innerHTML = version
if ( isPrerelease ( version ) ) {
titleElement . innerHTML = 'Pre-release'
titleElement . style . color = '#ff886d'
checkElement . style . background = '#ff886d'
2018-06-20 03:15:10 -07:00
} else {
2018-08-13 03:13:13 -07:00
titleElement . innerHTML = 'Stable Release'
titleElement . style . color = null
checkElement . style . background = null
2018-06-20 03:15:10 -07:00
}
}
2018-08-13 03:13:13 -07:00
/ * *
* Retrieve the version information and display it on the UI .
* /
function populateAboutVersionInformation ( ) {
populateVersionInformation ( remote . app . getVersion ( ) , document . getElementById ( 'settingsAboutCurrentVersionValue' ) , document . getElementById ( 'settingsAboutCurrentVersionTitle' ) , document . getElementById ( 'settingsAboutCurrentVersionCheck' ) )
}
2018-06-20 03:15:10 -07:00
/ * *
* 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 ( ) {
$ . ajax ( {
2019-09-05 13:08:47 -07:00
url : 'https://github.com/dscalzi/HeliosLauncher/releases.atom' ,
2018-06-20 03:15:10 -07:00
success : ( data ) => {
const version = 'v' + remote . app . getVersion ( )
const entries = $ ( data ) . find ( 'entry' )
for ( let i = 0 ; i < entries . length ; i ++ ) {
const entry = $ ( entries [ i ] )
let id = entry . find ( 'id' ) . text ( )
id = id . substring ( id . lastIndexOf ( '/' ) + 1 )
if ( id === version ) {
2018-08-13 03:13:13 -07:00
settingsAboutChangelogTitle . innerHTML = entry . find ( 'title' ) . text ( )
settingsAboutChangelogText . innerHTML = entry . find ( 'content' ) . text ( )
settingsAboutChangelogButton . href = entry . find ( 'link' ) . attr ( 'href' )
2018-06-20 03:15:10 -07:00
}
}
} ,
timeout : 2500
} ) . catch ( err => {
2018-08-13 03:13:13 -07:00
settingsAboutChangelogText . innerHTML = 'Failed to load release notes.'
2018-06-20 03:15:10 -07:00
} )
}
/ * *
* Prepare account tab for display .
* /
function prepareAboutTab ( ) {
2018-08-13 03:13:13 -07:00
populateAboutVersionInformation ( )
2018-06-20 03:15:10 -07:00
populateReleaseNotes ( )
}
2018-08-13 03:13:13 -07:00
/ * *
* 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 settingsUpdateChangelogTitle = settingsTabUpdate . getElementsByClassName ( 'settingsChangelogTitle' ) [ 0 ]
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 .
*
* @ param { string } text The new button text .
* @ param { boolean } disabled Optional . Disable or enable the button
* @ param { function } handler Optional . New button event handler .
* /
function settingsUpdateButtonStatus ( text , disabled = false , handler = null ) {
settingsUpdateActionButton . innerHTML = text
settingsUpdateActionButton . disabled = disabled
if ( handler != null ) {
settingsUpdateActionButton . onclick = handler
}
}
/ * *
* Populate the update tab with relevant information .
*
* @ param { Object } data The update data .
* /
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 )
2018-11-18 18:51:48 -08:00
if ( process . platform === 'darwin' ) {
2018-11-18 19:03:17 -08:00
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 , ( ) => {
2018-11-18 18:51:48 -08:00
shell . openExternal ( data . darwindownload )
} )
} else {
settingsUpdateButtonStatus ( 'Downloading..' , true )
}
2018-08-13 03:13:13 -07:00
} 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 , ( ) => {
2018-08-13 03:31:46 -07:00
if ( ! isDev ) {
ipcRenderer . send ( 'autoUpdateAction' , 'checkForUpdate' )
settingsUpdateButtonStatus ( 'Checking for Updates..' , true )
}
2018-08-13 03:13:13 -07:00
} )
}
}
/ * *
* Prepare update tab for display .
*
* @ param { Object } data The update data .
* /
function prepareUpdateTab ( data = null ) {
populateSettingsUpdateInformation ( data )
}
2018-06-11 19:11:05 -07:00
2018-05-30 19:22:17 -07:00
/ * *
* Settings preparation functions .
* /
2018-07-22 10:31:15 -07:00
/ * *
2018-05-30 19:22:17 -07:00
* Prepare the entire settings UI .
2018-06-04 13:28:17 -07:00
*
* @ param { boolean } first Whether or not it is the first load .
2018-05-30 19:22:17 -07:00
* /
2023-02-24 18:02:18 -08:00
async function prepareSettings ( first = false ) {
2018-06-04 13:28:17 -07:00
if ( first ) {
setupSettingsTabs ( )
initSettingsValidators ( )
2018-08-13 03:13:13 -07:00
prepareUpdateTab ( )
2018-07-23 22:14:26 -07:00
} else {
2023-02-24 18:02:18 -08:00
await prepareModsTab ( )
2018-06-04 13:28:17 -07:00
}
2023-02-24 18:02:18 -08:00
await initSettingsValues ( )
2018-05-30 19:22:17 -07:00
prepareAccountsTab ( )
2023-02-24 18:02:18 -08:00
await prepareJavaTab ( )
2018-06-20 03:15:10 -07:00
prepareAboutTab ( )
2018-05-30 19:22:17 -07:00
}
// Prepare the settings UI on startup.
2022-12-09 20:49:47 -08:00
//prepareSettings(true)