|
@@ -17,9 +17,10 @@ const settingsMaxRAMLabel = document.getElementById('settingsMaxRAMLabel')
|
|
|
const settingsMinRAMLabel = document.getElementById('settingsMinRAMLabel')
|
|
const settingsMinRAMLabel = document.getElementById('settingsMinRAMLabel')
|
|
|
const settingsMemoryTotal = document.getElementById('settingsMemoryTotal')
|
|
const settingsMemoryTotal = document.getElementById('settingsMemoryTotal')
|
|
|
const settingsMemoryAvail = document.getElementById('settingsMemoryAvail')
|
|
const settingsMemoryAvail = document.getElementById('settingsMemoryAvail')
|
|
|
-const settingsJavaExecDetails = document.getElementById('settingsJavaExecDetails')
|
|
|
|
|
-const settingsJavaExecVal = document.getElementById('settingsJavaExecVal')
|
|
|
|
|
-const settingsJavaExecSel = document.getElementById('settingsJavaExecSel')
|
|
|
|
|
|
|
+const settingsJavaExecDetails = document.getElementById('settingsJavaExecDetails')
|
|
|
|
|
+const settingsJavaExecVal = document.getElementById('settingsJavaExecVal')
|
|
|
|
|
+const settingsJavaExecSel = document.getElementById('settingsJavaExecSel')
|
|
|
|
|
+const settingsJVMOptsVal = document.getElementById('settingsJVMOptsVal')
|
|
|
|
|
|
|
|
const settingsState = {
|
|
const settingsState = {
|
|
|
invalid: new Set()
|
|
invalid: new Set()
|
|
@@ -76,12 +77,15 @@ function initSettingsValues(){
|
|
|
if(typeof gFn === 'function'){
|
|
if(typeof gFn === 'function'){
|
|
|
if(v.tagName === 'INPUT'){
|
|
if(v.tagName === 'INPUT'){
|
|
|
if(v.type === 'number' || v.type === 'text'){
|
|
if(v.type === 'number' || v.type === 'text'){
|
|
|
- v.value = gFn()
|
|
|
|
|
-
|
|
|
|
|
// Special Conditions
|
|
// Special Conditions
|
|
|
const cVal = v.getAttribute('cValue')
|
|
const cVal = v.getAttribute('cValue')
|
|
|
if(cVal === 'JavaExecutable'){
|
|
if(cVal === 'JavaExecutable'){
|
|
|
populateJavaExecDetails(v.value)
|
|
populateJavaExecDetails(v.value)
|
|
|
|
|
+ v.value = gFn()
|
|
|
|
|
+ } else if(cVal === 'JVMOptions'){
|
|
|
|
|
+ v.value = gFn().join(' ')
|
|
|
|
|
+ } else {
|
|
|
|
|
+ v.value = gFn()
|
|
|
}
|
|
}
|
|
|
} else if(v.type === 'checkbox'){
|
|
} else if(v.type === 'checkbox'){
|
|
|
v.checked = gFn()
|
|
v.checked = gFn()
|
|
@@ -119,7 +123,13 @@ function saveSettingsValues(){
|
|
|
if(typeof sFn === 'function'){
|
|
if(typeof sFn === 'function'){
|
|
|
if(v.tagName === 'INPUT'){
|
|
if(v.tagName === 'INPUT'){
|
|
|
if(v.type === 'number' || v.type === 'text'){
|
|
if(v.type === 'number' || v.type === 'text'){
|
|
|
- sFn(v.value)
|
|
|
|
|
|
|
+ // Special Conditions
|
|
|
|
|
+ const cVal = v.getAttribute('cValue')
|
|
|
|
|
+ if(cVal === 'JVMOptions'){
|
|
|
|
|
+ sFn(v.value.split(' '))
|
|
|
|
|
+ } else {
|
|
|
|
|
+ sFn(v.value)
|
|
|
|
|
+ }
|
|
|
} else if(v.type === 'checkbox'){
|
|
} else if(v.type === 'checkbox'){
|
|
|
sFn(v.checked)
|
|
sFn(v.checked)
|
|
|
// Special Conditions
|
|
// Special Conditions
|
|
@@ -348,6 +358,9 @@ function populateAuthAccounts(){
|
|
|
settingsCurrentAccounts.innerHTML = authAccountStr
|
|
settingsCurrentAccounts.innerHTML = authAccountStr
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Prepare the accounts tab for display.
|
|
|
|
|
+ */
|
|
|
function prepareAccountsTab() {
|
|
function prepareAccountsTab() {
|
|
|
populateAuthAccounts()
|
|
populateAuthAccounts()
|
|
|
bindAuthAccountSelect()
|
|
bindAuthAccountSelect()
|
|
@@ -376,16 +389,29 @@ settingsGameHeight.addEventListener('keydown', (e) => {
|
|
|
* Java Tab
|
|
* Java Tab
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-settingsMaxRAMRange.setAttribute('max', ConfigManager.getAbsoluteMaxRAM())
|
|
|
|
|
-settingsMaxRAMRange.setAttribute('min', ConfigManager.getAbsoluteMinRAM())
|
|
|
|
|
-settingsMinRAMRange.setAttribute('max', ConfigManager.getAbsoluteMaxRAM())
|
|
|
|
|
-settingsMinRAMRange.setAttribute('min', ConfigManager.getAbsoluteMinRAM())
|
|
|
|
|
|
|
+// Store maximum memory values.
|
|
|
|
|
+const SETTINGS_MAX_MEMORY = ConfigManager.getAbsoluteMaxRAM()
|
|
|
|
|
+const SETTINGS_MIN_MEMORY = ConfigManager.getAbsoluteMinRAM()
|
|
|
|
|
+
|
|
|
|
|
+// 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 )
|
|
|
|
|
|
|
|
|
|
+// Bind on change event for min memory container.
|
|
|
settingsMinRAMRange.onchange = (e) => {
|
|
settingsMinRAMRange.onchange = (e) => {
|
|
|
|
|
+
|
|
|
|
|
+ // Current range values
|
|
|
const sMaxV = Number(settingsMaxRAMRange.getAttribute('value'))
|
|
const sMaxV = Number(settingsMaxRAMRange.getAttribute('value'))
|
|
|
const sMinV = Number(settingsMinRAMRange.getAttribute('value'))
|
|
const sMinV = Number(settingsMinRAMRange.getAttribute('value'))
|
|
|
|
|
+
|
|
|
|
|
+ // Get reference to range bar.
|
|
|
const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
|
|
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/2){
|
|
if(sMinV >= max/2){
|
|
|
bar.style.background = '#e86060'
|
|
bar.style.background = '#e86060'
|
|
|
} else if(sMinV >= max/4) {
|
|
} else if(sMinV >= max/4) {
|
|
@@ -393,20 +419,31 @@ settingsMinRAMRange.onchange = (e) => {
|
|
|
} else {
|
|
} else {
|
|
|
bar.style.background = null
|
|
bar.style.background = null
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // Increase maximum memory if the minimum exceeds its value.
|
|
|
if(sMaxV < sMinV){
|
|
if(sMaxV < sMinV){
|
|
|
const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange)
|
|
const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange)
|
|
|
updateRangedSlider(settingsMaxRAMRange, sMinV,
|
|
updateRangedSlider(settingsMaxRAMRange, sMinV,
|
|
|
((sMinV-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc)
|
|
((sMinV-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc)
|
|
|
settingsMaxRAMLabel.innerHTML = sMinV.toFixed(1) + 'G'
|
|
settingsMaxRAMLabel.innerHTML = sMinV.toFixed(1) + 'G'
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // Update label
|
|
|
settingsMinRAMLabel.innerHTML = sMinV.toFixed(1) + 'G'
|
|
settingsMinRAMLabel.innerHTML = sMinV.toFixed(1) + 'G'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// Bind on change event for max memory container.
|
|
|
settingsMaxRAMRange.onchange = (e) => {
|
|
settingsMaxRAMRange.onchange = (e) => {
|
|
|
|
|
+ // Current range values
|
|
|
const sMaxV = Number(settingsMaxRAMRange.getAttribute('value'))
|
|
const sMaxV = Number(settingsMaxRAMRange.getAttribute('value'))
|
|
|
const sMinV = Number(settingsMinRAMRange.getAttribute('value'))
|
|
const sMinV = Number(settingsMinRAMRange.getAttribute('value'))
|
|
|
|
|
+
|
|
|
|
|
+ // Get reference to range bar.
|
|
|
const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
|
|
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/2){
|
|
if(sMaxV >= max/2){
|
|
|
bar.style.background = '#e86060'
|
|
bar.style.background = '#e86060'
|
|
|
} else if(sMaxV >= max/4) {
|
|
} else if(sMaxV >= max/4) {
|
|
@@ -414,6 +451,8 @@ settingsMaxRAMRange.onchange = (e) => {
|
|
|
} else {
|
|
} else {
|
|
|
bar.style.background = null
|
|
bar.style.background = null
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // Decrease the minimum memory if the maximum value is less.
|
|
|
if(sMaxV < sMinV){
|
|
if(sMaxV < sMinV){
|
|
|
const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange)
|
|
const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange)
|
|
|
updateRangedSlider(settingsMinRAMRange, sMaxV,
|
|
updateRangedSlider(settingsMinRAMRange, sMaxV,
|
|
@@ -423,21 +462,12 @@ settingsMaxRAMRange.onchange = (e) => {
|
|
|
settingsMaxRAMLabel.innerHTML = sMaxV.toFixed(1) + 'G'
|
|
settingsMaxRAMLabel.innerHTML = sMaxV.toFixed(1) + 'G'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-settingsJavaExecSel.onchange = (e) => {
|
|
|
|
|
- settingsJavaExecVal.value = settingsJavaExecSel.files[0].path
|
|
|
|
|
- populateJavaExecDetails(settingsJavaExecVal.value)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-function populateJavaExecDetails(execPath){
|
|
|
|
|
- AssetGuard._validateJavaBinary(execPath).then(v => {
|
|
|
|
|
- if(v.valid){
|
|
|
|
|
- settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major} Update ${v.version.update} (x${v.arch})`
|
|
|
|
|
- } else {
|
|
|
|
|
- settingsJavaExecDetails.innerHTML = 'Invalid Selection'
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 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.
|
|
|
|
|
+ */
|
|
|
function calculateRangeSliderMeta(v){
|
|
function calculateRangeSliderMeta(v){
|
|
|
const val = {
|
|
const val = {
|
|
|
max: Number(v.getAttribute('max')),
|
|
max: Number(v.getAttribute('max')),
|
|
@@ -449,30 +479,46 @@ function calculateRangeSliderMeta(v){
|
|
|
return val
|
|
return val
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Binds functionality to the ranged sliders. They're more than
|
|
|
|
|
+ * just divs now :').
|
|
|
|
|
+ */
|
|
|
function bindRangeSlider(){
|
|
function bindRangeSlider(){
|
|
|
Array.from(document.getElementsByClassName('rangeSlider')).map((v) => {
|
|
Array.from(document.getElementsByClassName('rangeSlider')).map((v) => {
|
|
|
|
|
+
|
|
|
|
|
+ // Reference the track (thumb).
|
|
|
const track = v.getElementsByClassName('rangeSliderTrack')[0]
|
|
const track = v.getElementsByClassName('rangeSliderTrack')[0]
|
|
|
|
|
|
|
|
|
|
+ // Set the initial slider value.
|
|
|
const value = v.getAttribute('value')
|
|
const value = v.getAttribute('value')
|
|
|
const sliderMeta = calculateRangeSliderMeta(v)
|
|
const sliderMeta = calculateRangeSliderMeta(v)
|
|
|
- updateRangedSlider(v, value,
|
|
|
|
|
- ((value-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc)
|
|
|
|
|
|
|
|
|
|
|
|
+ updateRangedSlider(v, value, ((value-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc)
|
|
|
|
|
+
|
|
|
|
|
+ // The magic happens when we click on the track.
|
|
|
track.onmousedown = (e) => {
|
|
track.onmousedown = (e) => {
|
|
|
|
|
|
|
|
|
|
+ // Stop moving the track on mouse up.
|
|
|
document.onmouseup = (e) => {
|
|
document.onmouseup = (e) => {
|
|
|
document.onmousemove = null
|
|
document.onmousemove = null
|
|
|
document.onmouseup = null
|
|
document.onmouseup = null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Move slider according to the mouse position.
|
|
|
document.onmousemove = (e) => {
|
|
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){
|
|
if(Math.abs(perc-notch) < sliderMeta.inc/2){
|
|
|
updateRangedSlider(v, sliderMeta.min+(sliderMeta.step*(notch/sliderMeta.inc)), notch)
|
|
updateRangedSlider(v, sliderMeta.min+(sliderMeta.step*(notch/sliderMeta.inc)), notch)
|
|
|
}
|
|
}
|
|
@@ -482,18 +528,29 @@ function bindRangeSlider(){
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 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.
|
|
|
|
|
+ */
|
|
|
function updateRangedSlider(element, value, notch){
|
|
function updateRangedSlider(element, value, notch){
|
|
|
const oldVal = element.getAttribute('value')
|
|
const oldVal = element.getAttribute('value')
|
|
|
const bar = element.getElementsByClassName('rangeSliderBar')[0]
|
|
const bar = element.getElementsByClassName('rangeSliderBar')[0]
|
|
|
const track = element.getElementsByClassName('rangeSliderTrack')[0]
|
|
const track = element.getElementsByClassName('rangeSliderTrack')[0]
|
|
|
|
|
+
|
|
|
element.setAttribute('value', value)
|
|
element.setAttribute('value', value)
|
|
|
|
|
+
|
|
|
const event = new MouseEvent('change', {
|
|
const event = new MouseEvent('change', {
|
|
|
target: element,
|
|
target: element,
|
|
|
type: 'change',
|
|
type: 'change',
|
|
|
bubbles: false,
|
|
bubbles: false,
|
|
|
cancelable: true
|
|
cancelable: true
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
let cancelled = !element.dispatchEvent(event)
|
|
let cancelled = !element.dispatchEvent(event)
|
|
|
|
|
+
|
|
|
if(!cancelled){
|
|
if(!cancelled){
|
|
|
track.style.left = notch + '%'
|
|
track.style.left = notch + '%'
|
|
|
bar.style.width = notch + '%'
|
|
bar.style.width = notch + '%'
|
|
@@ -502,14 +559,42 @@ function updateRangedSlider(element, value, notch){
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function bindMemoryStatus(){
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Display the total and available RAM.
|
|
|
|
|
+ */
|
|
|
|
|
+function populateMemoryStatus(){
|
|
|
settingsMemoryTotal.innerHTML = Number((os.totalmem()-1000000000)/1000000000).toFixed(1) + 'G'
|
|
settingsMemoryTotal.innerHTML = Number((os.totalmem()-1000000000)/1000000000).toFixed(1) + 'G'
|
|
|
settingsMemoryAvail.innerHTML = Number(os.freemem()/1000000000).toFixed(1) + 'G'
|
|
settingsMemoryAvail.innerHTML = Number(os.freemem()/1000000000).toFixed(1) + 'G'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// Bind the executable file input to the display text input.
|
|
|
|
|
+settingsJavaExecSel.onchange = (e) => {
|
|
|
|
|
+ settingsJavaExecVal.value = settingsJavaExecSel.files[0].path
|
|
|
|
|
+ populateJavaExecDetails(settingsJavaExecVal.value)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Validate the provided executable path and display the data on
|
|
|
|
|
+ * the UI.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {string} execPath The executable path to populate against.
|
|
|
|
|
+ */
|
|
|
|
|
+function populateJavaExecDetails(execPath){
|
|
|
|
|
+ AssetGuard._validateJavaBinary(execPath).then(v => {
|
|
|
|
|
+ if(v.valid){
|
|
|
|
|
+ settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major} Update ${v.version.update} (x${v.arch})`
|
|
|
|
|
+ } else {
|
|
|
|
|
+ settingsJavaExecDetails.innerHTML = 'Invalid Selection'
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Prepare the Java tab for display.
|
|
|
|
|
+ */
|
|
|
function prepareJavaTab(){
|
|
function prepareJavaTab(){
|
|
|
bindRangeSlider()
|
|
bindRangeSlider()
|
|
|
- bindMemoryStatus()
|
|
|
|
|
|
|
+ populateMemoryStatus()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|