Compare commits

..

3 Commits

Author SHA1 Message Date
Daniel Scalzi
e3af7669d8
cleanup. 2023-03-18 22:07:22 -04:00
Daniel Scalzi
a731fa90ea
Server specific ram. 2023-03-18 21:22:18 -04:00
Daniel Scalzi
3ef5fabb35
bugfixes. 2023-03-18 19:01:22 -04:00
7 changed files with 77 additions and 69 deletions

View File

@ -1,17 +1,15 @@
const fs = require('fs-extra')
const { LoggerUtil } = require('helios-core')
const { mcVersionAtLeast } = require('helios-core/common')
const os = require('os')
const path = require('path')
const logger = LoggerUtil.getLogger('ConfigManager')
const sysRoot = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME)
// TODO change
const dataPath = path.join(sysRoot, '.helioslauncher')
// Forked processes do not have access to electron, so we have this workaround.
const launcherDir = process.env.CONFIG_DIRECT_PATH || require('@electron/remote').app.getPath('userData')
const launcherDir = require('@electron/remote').app.getPath('userData')
/**
* Retrieve the absolute path of the launcher directory.
@ -45,24 +43,30 @@ const configPath = path.join(exports.getLauncherDirectory(), 'config.json')
const configPathLEGACY = path.join(dataPath, 'config.json')
const firstLaunch = !fs.existsSync(configPath) && !fs.existsSync(configPathLEGACY)
exports.getAbsoluteMinRAM = function(){
const mem = os.totalmem()
return mem >= 6000000000 ? 3 : 2
exports.getAbsoluteMinRAM = function(ram){
if(ram?.minimum != null) {
return ram.minimum/1024
} else {
// Legacy behavior
const mem = os.totalmem()
return mem >= (6*1073741824) ? 3 : 2
}
}
exports.getAbsoluteMaxRAM = function(){
exports.getAbsoluteMaxRAM = function(ram){
const mem = os.totalmem()
const gT16 = mem-16000000000
return Math.floor((mem-1000000000-(gT16 > 0 ? (Number.parseInt(gT16/8) + 16000000000/4) : mem/4))/1000000000)
const gT16 = mem-(16*1073741824)
return Math.floor((mem-(gT16 > 0 ? (Number.parseInt(gT16/8) + (16*1073741824)/4) : mem/4))/1073741824)
}
function resolveMaxRAM(){
const mem = os.totalmem()
return mem >= 8000000000 ? '4G' : (mem >= 6000000000 ? '3G' : '2G')
}
function resolveMinRAM(){
return resolveMaxRAM()
function resolveSelectedRAM(ram) {
if(ram?.recommended != null) {
return `${ram.recommended}M`
} else {
// Legacy behavior
const mem = os.totalmem()
return mem >= (8*1073741824) ? '4G' : (mem >= (6*1073741824) ? '3G' : '2G')
}
}
/**
@ -503,18 +507,18 @@ exports.setModConfiguration = function(serverid, configuration){
// Java Settings
function defaultJavaConfig(mcVersion) {
if(mcVersionAtLeast('1.17', mcVersion)) {
return defaultJavaConfig117()
function defaultJavaConfig(effectiveJavaOptions, ram) {
if(effectiveJavaOptions.suggestedMajor > 8) {
return defaultJavaConfig17(ram)
} else {
return defaultJavaConfigBelow117()
return defaultJavaConfig8(ram)
}
}
function defaultJavaConfigBelow117() {
function defaultJavaConfig17(ram) {
return {
minRAM: resolveMinRAM(),
maxRAM: resolveMaxRAM(), // Dynamic
minRAM: resolveSelectedRAM(ram),
maxRAM: resolveSelectedRAM(ram),
executable: null,
jvmOptions: [
'-XX:+UseConcMarkSweepGC',
@ -525,10 +529,10 @@ function defaultJavaConfigBelow117() {
}
}
function defaultJavaConfig117() {
function defaultJavaConfig8(ram) {
return {
minRAM: resolveMinRAM(),
maxRAM: resolveMaxRAM(), // Dynamic
minRAM: resolveSelectedRAM(ram),
maxRAM: resolveSelectedRAM(ram),
executable: null,
jvmOptions: [
'-XX:+UnlockExperimentalVMOptions',
@ -547,9 +551,9 @@ function defaultJavaConfig117() {
* @param {string} serverid The server id.
* @param {*} mcVersion The minecraft version of the server.
*/
exports.ensureJavaConfig = function(serverid, mcVersion) {
exports.ensureJavaConfig = function(serverid, effectiveJavaOptions, ram) {
if(!Object.prototype.hasOwnProperty.call(config.javaConfig, serverid)) {
config.javaConfig[serverid] = defaultJavaConfig(mcVersion)
config.javaConfig[serverid] = defaultJavaConfig(effectiveJavaOptions, ram)
}
}

View File

@ -174,11 +174,11 @@ class ProcessBuilder {
const v = this.resolveModConfiguration(modCfg[mdl.getVersionlessMavenIdentifier()].mods, mdl.subModules)
fMods = fMods.concat(v.fMods)
lMods = lMods.concat(v.lMods)
if(mdl.type === Type.LiteLoader){
if(type === Type.LiteLoader){
continue
}
}
if(mdl.type === Type.ForgeMod){
if(type === Type.ForgeMod){
fMods.push(mdl)
} else {
lMods.push(mdl)
@ -241,11 +241,11 @@ class ProcessBuilder {
const ids = []
if(type === 'forge'){
for(let mod of mods){
ids.push(mod.getExtensionlessID())
ids.push(mod.getExtensionlessMavenIdentifier())
}
} else {
for(let mod of mods){
ids.push(mod.getExtensionlessID() + '@' + mod.getExtension())
ids.push(mod.getMavenIdentifier())
}
}
modList.modRef = ids
@ -265,7 +265,7 @@ class ProcessBuilder {
// */
// constructModArguments(mods){
// const argStr = mods.map(mod => {
// return mod.getExtensionlessID()
// return mod.getExtensionlessMavenIdentifier()
// }).join(',')
// if(argStr){
@ -288,7 +288,7 @@ class ProcessBuilder {
*/
constructModList(mods) {
const writeBuffer = mods.map(mod => {
return mod.getExtensionlessID()
return mod.getExtensionlessMavenIdentifier()
}).join('\n')
if(writeBuffer) {

View File

@ -540,8 +540,8 @@ async function dlAsync(login = true) {
toggleLaunchArea(false)
if(hasRPC){
DiscordWrapper.updateDetails('Loading game..')
proc.stdout.on('data', gameStateChange)
}
proc.stdout.on('data', gameStateChange)
proc.stdout.removeListener('data', tempListener)
proc.stderr.removeListener('data', gameErrorListener)
}
@ -789,7 +789,7 @@ function initNews(){
let news = {}
loadNews().then(news => {
newsArr = news.articles || null
newsArr = news?.articles || null
if(newsArr == null){
// News Loading Failed
@ -938,6 +938,10 @@ function displayArticle(articleObject, index){
async function loadNews(){
const distroData = await DistroAPI.getDistribution()
if(!distroData.rawDistribution.rss) {
loggerLanding.debug('No RSS feed provided.')
return null
}
const promise = new Promise((resolve, reject) => {

View File

@ -156,7 +156,7 @@ async function initSettingsValues(){
if(cVal === 'MinRAM' || cVal === 'MaxRAM'){
let val = gFn.apply(null, gFnOpts)
if(val.endsWith('M')){
val = Number(val.substring(0, val.length-1))/1000
val = Number(val.substring(0, val.length-1))/1024
} else {
val = Number.parseFloat(val)
}
@ -1158,16 +1158,6 @@ const settingsJavaExecDetails = document.getElementById('settingsJavaExecDetails
const settingsJavaReqDesc = document.getElementById('settingsJavaReqDesc')
const settingsJvmOptsLink = document.getElementById('settingsJvmOptsLink')
// 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) => {
@ -1178,7 +1168,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()/1073741824
// Change range bar color based on the selected value.
if(sMinV >= max/2){
@ -1210,7 +1200,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()/1073741824
// Change range bar color based on the selected value.
if(sMaxV >= max/2){
@ -1338,8 +1328,8 @@ 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'
settingsMemoryTotal.innerHTML = Number((os.totalmem()-1073741824)/1073741824).toFixed(1) + 'G'
settingsMemoryAvail.innerHTML = Number(os.freemem()/1073741824).toFixed(1) + 'G'
}
/**
@ -1360,15 +1350,11 @@ async function populateJavaExecDetails(execPath){
}
}
// TODO Update to use semver range
async function populateJavaReqDesc() {
const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer())
function populateJavaReqDesc(server) {
settingsJavaReqDesc.innerHTML = `Requires Java ${server.effectiveJavaOptions.suggestedMajor} x64.`
}
// TODO Update to use semver range
async function populateJvmOptsLink() {
const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer())
function populateJvmOptsLink(server) {
const major = server.effectiveJavaOptions.suggestedMajor
settingsJvmOptsLink.innerHTML = `Available Options for Java ${major} (HotSpot VM)`
if(major >= 12) {
@ -1385,14 +1371,28 @@ async function populateJvmOptsLink() {
}
}
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)
}
/**
* Prepare the Java tab for display.
*/
async function prepareJavaTab(){
bindRangeSlider()
const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer())
bindMinMaxRam(server)
bindRangeSlider(server)
populateMemoryStatus()
await populateJavaReqDesc()
await populateJvmOptsLink()
populateJavaReqDesc(server)
populateJvmOptsLink(server)
}
/**

View File

@ -234,7 +234,7 @@ function ensureJavaSettings(data) {
// Nothing too fancy for now.
for(const serv of data.servers){
ConfigManager.ensureJavaConfig(serv.rawServer.id, serv.rawServer.minecraftVersion)
ConfigManager.ensureJavaConfig(serv.rawServer.id, serv.effectiveJavaOptions, serv.rawServer.javaOptions?.ram)
}
ConfigManager.save()
@ -458,8 +458,8 @@ ipcRenderer.on('distributionIndexDone', async (event, res) => {
// Util for development
async function devModeToggle() {
DistroAPI.toggleDevMode(true)
const data = await DistroAPI.getDistributionLocalLoadOnly()
const data = await DistroAPI.refreshDistributionOrFallback()
ensureJavaSettings(data)
updateSelectedServer(data.getServers()[0])
updateSelectedServer(data.servers[0])
syncModConfigurations(data)
}

8
package-lock.json generated
View File

@ -19,7 +19,7 @@
"fs-extra": "^11.1.0",
"github-syntax-dark": "^0.5.0",
"got": "^11.8.5",
"helios-core": "~0.2.0-pre.1",
"helios-core": "~0.2.0-pre.2",
"helios-distribution-types": "^1.2.0-pre.1",
"jquery": "^3.6.1",
"semver": "^7.3.8"
@ -2180,9 +2180,9 @@
}
},
"node_modules/helios-core": {
"version": "0.2.0-pre.1",
"resolved": "https://registry.npmjs.org/helios-core/-/helios-core-0.2.0-pre.1.tgz",
"integrity": "sha512-hH5AtEZMVRR8/Wstq/8xOrL773p8+wrXZoqTbeqTGcLn1bv9+vmh9ifIAuAQUNaWxXgE/t/Nrw0ph0QJQ/NA6g==",
"version": "0.2.0-pre.2",
"resolved": "https://registry.npmjs.org/helios-core/-/helios-core-0.2.0-pre.2.tgz",
"integrity": "sha512-rS9xa2CfQBa+2uINOhIYFSR/nDZQJp8DJrbHXxKFSRckGvdPWwandEwwFoN+bwm3bPSdVhCe2xiSESbMK86UOA==",
"dependencies": {
"fastq": "^1.15.0",
"fs-extra": "^10.1.0",

View File

@ -33,7 +33,7 @@
"fs-extra": "^11.1.0",
"github-syntax-dark": "^0.5.0",
"got": "^11.8.5",
"helios-core": "~0.2.0-pre.1",
"helios-core": "~0.2.0-pre.2",
"helios-distribution-types": "^1.2.0-pre.1",
"jquery": "^3.6.1",
"semver": "^7.3.8"