mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 19:52:14 -08:00
Compare commits
No commits in common. "e3af7669d8e5739bb498eca5f369499d3e21de95" and "12a84c1cced491ae310908c9d0a86e18b0df2800" have entirely different histories.
e3af7669d8
...
12a84c1cce
@ -1,15 +1,17 @@
|
||||
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')
|
||||
|
||||
const launcherDir = require('@electron/remote').app.getPath('userData')
|
||||
// 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')
|
||||
|
||||
/**
|
||||
* Retrieve the absolute path of the launcher directory.
|
||||
@ -43,30 +45,24 @@ 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(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(ram){
|
||||
exports.getAbsoluteMinRAM = function(){
|
||||
const mem = os.totalmem()
|
||||
const gT16 = mem-(16*1073741824)
|
||||
return Math.floor((mem-(gT16 > 0 ? (Number.parseInt(gT16/8) + (16*1073741824)/4) : mem/4))/1073741824)
|
||||
return mem >= 6000000000 ? 3 : 2
|
||||
}
|
||||
|
||||
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')
|
||||
}
|
||||
exports.getAbsoluteMaxRAM = function(){
|
||||
const mem = os.totalmem()
|
||||
const gT16 = mem-16000000000
|
||||
return Math.floor((mem-1000000000-(gT16 > 0 ? (Number.parseInt(gT16/8) + 16000000000/4) : mem/4))/1000000000)
|
||||
}
|
||||
|
||||
function resolveMaxRAM(){
|
||||
const mem = os.totalmem()
|
||||
return mem >= 8000000000 ? '4G' : (mem >= 6000000000 ? '3G' : '2G')
|
||||
}
|
||||
|
||||
function resolveMinRAM(){
|
||||
return resolveMaxRAM()
|
||||
}
|
||||
|
||||
/**
|
||||
@ -507,18 +503,18 @@ exports.setModConfiguration = function(serverid, configuration){
|
||||
|
||||
// Java Settings
|
||||
|
||||
function defaultJavaConfig(effectiveJavaOptions, ram) {
|
||||
if(effectiveJavaOptions.suggestedMajor > 8) {
|
||||
return defaultJavaConfig17(ram)
|
||||
function defaultJavaConfig(mcVersion) {
|
||||
if(mcVersionAtLeast('1.17', mcVersion)) {
|
||||
return defaultJavaConfig117()
|
||||
} else {
|
||||
return defaultJavaConfig8(ram)
|
||||
return defaultJavaConfigBelow117()
|
||||
}
|
||||
}
|
||||
|
||||
function defaultJavaConfig17(ram) {
|
||||
function defaultJavaConfigBelow117() {
|
||||
return {
|
||||
minRAM: resolveSelectedRAM(ram),
|
||||
maxRAM: resolveSelectedRAM(ram),
|
||||
minRAM: resolveMinRAM(),
|
||||
maxRAM: resolveMaxRAM(), // Dynamic
|
||||
executable: null,
|
||||
jvmOptions: [
|
||||
'-XX:+UseConcMarkSweepGC',
|
||||
@ -529,10 +525,10 @@ function defaultJavaConfig17(ram) {
|
||||
}
|
||||
}
|
||||
|
||||
function defaultJavaConfig8(ram) {
|
||||
function defaultJavaConfig117() {
|
||||
return {
|
||||
minRAM: resolveSelectedRAM(ram),
|
||||
maxRAM: resolveSelectedRAM(ram),
|
||||
minRAM: resolveMinRAM(),
|
||||
maxRAM: resolveMaxRAM(), // Dynamic
|
||||
executable: null,
|
||||
jvmOptions: [
|
||||
'-XX:+UnlockExperimentalVMOptions',
|
||||
@ -551,9 +547,9 @@ function defaultJavaConfig8(ram) {
|
||||
* @param {string} serverid The server id.
|
||||
* @param {*} mcVersion The minecraft version of the server.
|
||||
*/
|
||||
exports.ensureJavaConfig = function(serverid, effectiveJavaOptions, ram) {
|
||||
exports.ensureJavaConfig = function(serverid, mcVersion) {
|
||||
if(!Object.prototype.hasOwnProperty.call(config.javaConfig, serverid)) {
|
||||
config.javaConfig[serverid] = defaultJavaConfig(effectiveJavaOptions, ram)
|
||||
config.javaConfig[serverid] = defaultJavaConfig(mcVersion)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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(type === Type.LiteLoader){
|
||||
if(mdl.type === Type.LiteLoader){
|
||||
continue
|
||||
}
|
||||
}
|
||||
if(type === Type.ForgeMod){
|
||||
if(mdl.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.getExtensionlessMavenIdentifier())
|
||||
ids.push(mod.getExtensionlessID())
|
||||
}
|
||||
} else {
|
||||
for(let mod of mods){
|
||||
ids.push(mod.getMavenIdentifier())
|
||||
ids.push(mod.getExtensionlessID() + '@' + mod.getExtension())
|
||||
}
|
||||
}
|
||||
modList.modRef = ids
|
||||
@ -265,7 +265,7 @@ class ProcessBuilder {
|
||||
// */
|
||||
// constructModArguments(mods){
|
||||
// const argStr = mods.map(mod => {
|
||||
// return mod.getExtensionlessMavenIdentifier()
|
||||
// return mod.getExtensionlessID()
|
||||
// }).join(',')
|
||||
|
||||
// if(argStr){
|
||||
@ -288,7 +288,7 @@ class ProcessBuilder {
|
||||
*/
|
||||
constructModList(mods) {
|
||||
const writeBuffer = mods.map(mod => {
|
||||
return mod.getExtensionlessMavenIdentifier()
|
||||
return mod.getExtensionlessID()
|
||||
}).join('\n')
|
||||
|
||||
if(writeBuffer) {
|
||||
|
@ -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,10 +938,6 @@ 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) => {
|
||||
|
||||
|
@ -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))/1024
|
||||
val = Number(val.substring(0, val.length-1))/1000
|
||||
} else {
|
||||
val = Number.parseFloat(val)
|
||||
}
|
||||
@ -1158,6 +1158,16 @@ 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) => {
|
||||
|
||||
@ -1168,7 +1178,7 @@ settingsMinRAMRange.onchange = (e) => {
|
||||
// Get reference to range bar.
|
||||
const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
|
||||
// Calculate effective total memory.
|
||||
const max = os.totalmem()/1073741824
|
||||
const max = (os.totalmem()-1000000000)/1000000000
|
||||
|
||||
// Change range bar color based on the selected value.
|
||||
if(sMinV >= max/2){
|
||||
@ -1200,7 +1210,7 @@ settingsMaxRAMRange.onchange = (e) => {
|
||||
// Get reference to range bar.
|
||||
const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
|
||||
// Calculate effective total memory.
|
||||
const max = os.totalmem()/1073741824
|
||||
const max = (os.totalmem()-1000000000)/1000000000
|
||||
|
||||
// Change range bar color based on the selected value.
|
||||
if(sMaxV >= max/2){
|
||||
@ -1328,8 +1338,8 @@ function updateRangedSlider(element, value, notch){
|
||||
* Display the total and available RAM.
|
||||
*/
|
||||
function populateMemoryStatus(){
|
||||
settingsMemoryTotal.innerHTML = Number((os.totalmem()-1073741824)/1073741824).toFixed(1) + 'G'
|
||||
settingsMemoryAvail.innerHTML = Number(os.freemem()/1073741824).toFixed(1) + 'G'
|
||||
settingsMemoryTotal.innerHTML = Number((os.totalmem()-1000000000)/1000000000).toFixed(1) + 'G'
|
||||
settingsMemoryAvail.innerHTML = Number(os.freemem()/1000000000).toFixed(1) + 'G'
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1350,11 +1360,15 @@ async function populateJavaExecDetails(execPath){
|
||||
}
|
||||
}
|
||||
|
||||
function populateJavaReqDesc(server) {
|
||||
// TODO Update to use semver range
|
||||
async function populateJavaReqDesc() {
|
||||
const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer())
|
||||
settingsJavaReqDesc.innerHTML = `Requires Java ${server.effectiveJavaOptions.suggestedMajor} x64.`
|
||||
}
|
||||
|
||||
function populateJvmOptsLink(server) {
|
||||
// TODO Update to use semver range
|
||||
async function populateJvmOptsLink() {
|
||||
const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer())
|
||||
const major = server.effectiveJavaOptions.suggestedMajor
|
||||
settingsJvmOptsLink.innerHTML = `Available Options for Java ${major} (HotSpot VM)`
|
||||
if(major >= 12) {
|
||||
@ -1371,28 +1385,14 @@ function populateJvmOptsLink(server) {
|
||||
}
|
||||
}
|
||||
|
||||
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(){
|
||||
const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer())
|
||||
bindMinMaxRam(server)
|
||||
bindRangeSlider(server)
|
||||
bindRangeSlider()
|
||||
populateMemoryStatus()
|
||||
populateJavaReqDesc(server)
|
||||
populateJvmOptsLink(server)
|
||||
await populateJavaReqDesc()
|
||||
await populateJvmOptsLink()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -234,7 +234,7 @@ function ensureJavaSettings(data) {
|
||||
|
||||
// Nothing too fancy for now.
|
||||
for(const serv of data.servers){
|
||||
ConfigManager.ensureJavaConfig(serv.rawServer.id, serv.effectiveJavaOptions, serv.rawServer.javaOptions?.ram)
|
||||
ConfigManager.ensureJavaConfig(serv.rawServer.id, serv.rawServer.minecraftVersion)
|
||||
}
|
||||
|
||||
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.refreshDistributionOrFallback()
|
||||
const data = await DistroAPI.getDistributionLocalLoadOnly()
|
||||
ensureJavaSettings(data)
|
||||
updateSelectedServer(data.servers[0])
|
||||
updateSelectedServer(data.getServers()[0])
|
||||
syncModConfigurations(data)
|
||||
}
|
||||
|
8
package-lock.json
generated
8
package-lock.json
generated
@ -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.2",
|
||||
"helios-core": "~0.2.0-pre.1",
|
||||
"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.2",
|
||||
"resolved": "https://registry.npmjs.org/helios-core/-/helios-core-0.2.0-pre.2.tgz",
|
||||
"integrity": "sha512-rS9xa2CfQBa+2uINOhIYFSR/nDZQJp8DJrbHXxKFSRckGvdPWwandEwwFoN+bwm3bPSdVhCe2xiSESbMK86UOA==",
|
||||
"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==",
|
||||
"dependencies": {
|
||||
"fastq": "^1.15.0",
|
||||
"fs-extra": "^10.1.0",
|
||||
|
@ -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.2",
|
||||
"helios-core": "~0.2.0-pre.1",
|
||||
"helios-distribution-types": "^1.2.0-pre.1",
|
||||
"jquery": "^3.6.1",
|
||||
"semver": "^7.3.8"
|
||||
|
Loading…
Reference in New Issue
Block a user