mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-23 04:02: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 fs = require('fs-extra')
|
||||||
const { LoggerUtil } = require('helios-core')
|
const { LoggerUtil } = require('helios-core')
|
||||||
|
const { mcVersionAtLeast } = require('helios-core/common')
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const logger = LoggerUtil.getLogger('ConfigManager')
|
const logger = LoggerUtil.getLogger('ConfigManager')
|
||||||
|
|
||||||
const sysRoot = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME)
|
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 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.
|
* 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 configPathLEGACY = path.join(dataPath, 'config.json')
|
||||||
const firstLaunch = !fs.existsSync(configPath) && !fs.existsSync(configPathLEGACY)
|
const firstLaunch = !fs.existsSync(configPath) && !fs.existsSync(configPathLEGACY)
|
||||||
|
|
||||||
exports.getAbsoluteMinRAM = function(ram){
|
exports.getAbsoluteMinRAM = function(){
|
||||||
if(ram?.minimum != null) {
|
|
||||||
return ram.minimum/1024
|
|
||||||
} else {
|
|
||||||
// Legacy behavior
|
|
||||||
const mem = os.totalmem()
|
const mem = os.totalmem()
|
||||||
return mem >= (6*1073741824) ? 3 : 2
|
return mem >= 6000000000 ? 3 : 2
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getAbsoluteMaxRAM = function(ram){
|
exports.getAbsoluteMaxRAM = function(){
|
||||||
const mem = os.totalmem()
|
const mem = os.totalmem()
|
||||||
const gT16 = mem-(16*1073741824)
|
const gT16 = mem-16000000000
|
||||||
return Math.floor((mem-(gT16 > 0 ? (Number.parseInt(gT16/8) + (16*1073741824)/4) : mem/4))/1073741824)
|
return Math.floor((mem-1000000000-(gT16 > 0 ? (Number.parseInt(gT16/8) + 16000000000/4) : mem/4))/1000000000)
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveSelectedRAM(ram) {
|
function resolveMaxRAM(){
|
||||||
if(ram?.recommended != null) {
|
|
||||||
return `${ram.recommended}M`
|
|
||||||
} else {
|
|
||||||
// Legacy behavior
|
|
||||||
const mem = os.totalmem()
|
const mem = os.totalmem()
|
||||||
return mem >= (8*1073741824) ? '4G' : (mem >= (6*1073741824) ? '3G' : '2G')
|
return mem >= 8000000000 ? '4G' : (mem >= 6000000000 ? '3G' : '2G')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveMinRAM(){
|
||||||
|
return resolveMaxRAM()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -507,18 +503,18 @@ exports.setModConfiguration = function(serverid, configuration){
|
|||||||
|
|
||||||
// Java Settings
|
// Java Settings
|
||||||
|
|
||||||
function defaultJavaConfig(effectiveJavaOptions, ram) {
|
function defaultJavaConfig(mcVersion) {
|
||||||
if(effectiveJavaOptions.suggestedMajor > 8) {
|
if(mcVersionAtLeast('1.17', mcVersion)) {
|
||||||
return defaultJavaConfig17(ram)
|
return defaultJavaConfig117()
|
||||||
} else {
|
} else {
|
||||||
return defaultJavaConfig8(ram)
|
return defaultJavaConfigBelow117()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function defaultJavaConfig17(ram) {
|
function defaultJavaConfigBelow117() {
|
||||||
return {
|
return {
|
||||||
minRAM: resolveSelectedRAM(ram),
|
minRAM: resolveMinRAM(),
|
||||||
maxRAM: resolveSelectedRAM(ram),
|
maxRAM: resolveMaxRAM(), // Dynamic
|
||||||
executable: null,
|
executable: null,
|
||||||
jvmOptions: [
|
jvmOptions: [
|
||||||
'-XX:+UseConcMarkSweepGC',
|
'-XX:+UseConcMarkSweepGC',
|
||||||
@ -529,10 +525,10 @@ function defaultJavaConfig17(ram) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function defaultJavaConfig8(ram) {
|
function defaultJavaConfig117() {
|
||||||
return {
|
return {
|
||||||
minRAM: resolveSelectedRAM(ram),
|
minRAM: resolveMinRAM(),
|
||||||
maxRAM: resolveSelectedRAM(ram),
|
maxRAM: resolveMaxRAM(), // Dynamic
|
||||||
executable: null,
|
executable: null,
|
||||||
jvmOptions: [
|
jvmOptions: [
|
||||||
'-XX:+UnlockExperimentalVMOptions',
|
'-XX:+UnlockExperimentalVMOptions',
|
||||||
@ -551,9 +547,9 @@ function defaultJavaConfig8(ram) {
|
|||||||
* @param {string} serverid The server id.
|
* @param {string} serverid The server id.
|
||||||
* @param {*} mcVersion The minecraft version of the server.
|
* @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)) {
|
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)
|
const v = this.resolveModConfiguration(modCfg[mdl.getVersionlessMavenIdentifier()].mods, mdl.subModules)
|
||||||
fMods = fMods.concat(v.fMods)
|
fMods = fMods.concat(v.fMods)
|
||||||
lMods = lMods.concat(v.lMods)
|
lMods = lMods.concat(v.lMods)
|
||||||
if(type === Type.LiteLoader){
|
if(mdl.type === Type.LiteLoader){
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(type === Type.ForgeMod){
|
if(mdl.type === Type.ForgeMod){
|
||||||
fMods.push(mdl)
|
fMods.push(mdl)
|
||||||
} else {
|
} else {
|
||||||
lMods.push(mdl)
|
lMods.push(mdl)
|
||||||
@ -241,11 +241,11 @@ class ProcessBuilder {
|
|||||||
const ids = []
|
const ids = []
|
||||||
if(type === 'forge'){
|
if(type === 'forge'){
|
||||||
for(let mod of mods){
|
for(let mod of mods){
|
||||||
ids.push(mod.getExtensionlessMavenIdentifier())
|
ids.push(mod.getExtensionlessID())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(let mod of mods){
|
for(let mod of mods){
|
||||||
ids.push(mod.getMavenIdentifier())
|
ids.push(mod.getExtensionlessID() + '@' + mod.getExtension())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
modList.modRef = ids
|
modList.modRef = ids
|
||||||
@ -265,7 +265,7 @@ class ProcessBuilder {
|
|||||||
// */
|
// */
|
||||||
// constructModArguments(mods){
|
// constructModArguments(mods){
|
||||||
// const argStr = mods.map(mod => {
|
// const argStr = mods.map(mod => {
|
||||||
// return mod.getExtensionlessMavenIdentifier()
|
// return mod.getExtensionlessID()
|
||||||
// }).join(',')
|
// }).join(',')
|
||||||
|
|
||||||
// if(argStr){
|
// if(argStr){
|
||||||
@ -288,7 +288,7 @@ class ProcessBuilder {
|
|||||||
*/
|
*/
|
||||||
constructModList(mods) {
|
constructModList(mods) {
|
||||||
const writeBuffer = mods.map(mod => {
|
const writeBuffer = mods.map(mod => {
|
||||||
return mod.getExtensionlessMavenIdentifier()
|
return mod.getExtensionlessID()
|
||||||
}).join('\n')
|
}).join('\n')
|
||||||
|
|
||||||
if(writeBuffer) {
|
if(writeBuffer) {
|
||||||
|
@ -540,8 +540,8 @@ async function dlAsync(login = true) {
|
|||||||
toggleLaunchArea(false)
|
toggleLaunchArea(false)
|
||||||
if(hasRPC){
|
if(hasRPC){
|
||||||
DiscordWrapper.updateDetails('Loading game..')
|
DiscordWrapper.updateDetails('Loading game..')
|
||||||
proc.stdout.on('data', gameStateChange)
|
|
||||||
}
|
}
|
||||||
|
proc.stdout.on('data', gameStateChange)
|
||||||
proc.stdout.removeListener('data', tempListener)
|
proc.stdout.removeListener('data', tempListener)
|
||||||
proc.stderr.removeListener('data', gameErrorListener)
|
proc.stderr.removeListener('data', gameErrorListener)
|
||||||
}
|
}
|
||||||
@ -789,7 +789,7 @@ function initNews(){
|
|||||||
let news = {}
|
let news = {}
|
||||||
loadNews().then(news => {
|
loadNews().then(news => {
|
||||||
|
|
||||||
newsArr = news?.articles || null
|
newsArr = news.articles || null
|
||||||
|
|
||||||
if(newsArr == null){
|
if(newsArr == null){
|
||||||
// News Loading Failed
|
// News Loading Failed
|
||||||
@ -938,10 +938,6 @@ function displayArticle(articleObject, index){
|
|||||||
async function loadNews(){
|
async function loadNews(){
|
||||||
|
|
||||||
const distroData = await DistroAPI.getDistribution()
|
const distroData = await DistroAPI.getDistribution()
|
||||||
if(!distroData.rawDistribution.rss) {
|
|
||||||
loggerLanding.debug('No RSS feed provided.')
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const promise = new Promise((resolve, reject) => {
|
const promise = new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ async function initSettingsValues(){
|
|||||||
if(cVal === 'MinRAM' || cVal === 'MaxRAM'){
|
if(cVal === 'MinRAM' || cVal === 'MaxRAM'){
|
||||||
let val = gFn.apply(null, gFnOpts)
|
let val = gFn.apply(null, gFnOpts)
|
||||||
if(val.endsWith('M')){
|
if(val.endsWith('M')){
|
||||||
val = Number(val.substring(0, val.length-1))/1024
|
val = Number(val.substring(0, val.length-1))/1000
|
||||||
} else {
|
} else {
|
||||||
val = Number.parseFloat(val)
|
val = Number.parseFloat(val)
|
||||||
}
|
}
|
||||||
@ -1158,6 +1158,16 @@ const settingsJavaExecDetails = document.getElementById('settingsJavaExecDetails
|
|||||||
const settingsJavaReqDesc = document.getElementById('settingsJavaReqDesc')
|
const settingsJavaReqDesc = document.getElementById('settingsJavaReqDesc')
|
||||||
const settingsJvmOptsLink = document.getElementById('settingsJvmOptsLink')
|
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.
|
// Bind on change event for min memory container.
|
||||||
settingsMinRAMRange.onchange = (e) => {
|
settingsMinRAMRange.onchange = (e) => {
|
||||||
|
|
||||||
@ -1168,7 +1178,7 @@ settingsMinRAMRange.onchange = (e) => {
|
|||||||
// Get reference to range bar.
|
// Get reference to range bar.
|
||||||
const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
|
const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
|
||||||
// Calculate effective total memory.
|
// Calculate effective total memory.
|
||||||
const max = os.totalmem()/1073741824
|
const max = (os.totalmem()-1000000000)/1000000000
|
||||||
|
|
||||||
// Change range bar color based on the selected value.
|
// Change range bar color based on the selected value.
|
||||||
if(sMinV >= max/2){
|
if(sMinV >= max/2){
|
||||||
@ -1200,7 +1210,7 @@ settingsMaxRAMRange.onchange = (e) => {
|
|||||||
// Get reference to range bar.
|
// Get reference to range bar.
|
||||||
const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
|
const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
|
||||||
// Calculate effective total memory.
|
// Calculate effective total memory.
|
||||||
const max = os.totalmem()/1073741824
|
const max = (os.totalmem()-1000000000)/1000000000
|
||||||
|
|
||||||
// Change range bar color based on the selected value.
|
// Change range bar color based on the selected value.
|
||||||
if(sMaxV >= max/2){
|
if(sMaxV >= max/2){
|
||||||
@ -1328,8 +1338,8 @@ function updateRangedSlider(element, value, notch){
|
|||||||
* Display the total and available RAM.
|
* Display the total and available RAM.
|
||||||
*/
|
*/
|
||||||
function populateMemoryStatus(){
|
function populateMemoryStatus(){
|
||||||
settingsMemoryTotal.innerHTML = Number((os.totalmem()-1073741824)/1073741824).toFixed(1) + 'G'
|
settingsMemoryTotal.innerHTML = Number((os.totalmem()-1000000000)/1000000000).toFixed(1) + 'G'
|
||||||
settingsMemoryAvail.innerHTML = Number(os.freemem()/1073741824).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.`
|
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
|
const major = server.effectiveJavaOptions.suggestedMajor
|
||||||
settingsJvmOptsLink.innerHTML = `Available Options for Java ${major} (HotSpot VM)`
|
settingsJvmOptsLink.innerHTML = `Available Options for Java ${major} (HotSpot VM)`
|
||||||
if(major >= 12) {
|
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.
|
* Prepare the Java tab for display.
|
||||||
*/
|
*/
|
||||||
async function prepareJavaTab(){
|
async function prepareJavaTab(){
|
||||||
const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer())
|
bindRangeSlider()
|
||||||
bindMinMaxRam(server)
|
|
||||||
bindRangeSlider(server)
|
|
||||||
populateMemoryStatus()
|
populateMemoryStatus()
|
||||||
populateJavaReqDesc(server)
|
await populateJavaReqDesc()
|
||||||
populateJvmOptsLink(server)
|
await populateJvmOptsLink()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -234,7 +234,7 @@ function ensureJavaSettings(data) {
|
|||||||
|
|
||||||
// Nothing too fancy for now.
|
// Nothing too fancy for now.
|
||||||
for(const serv of data.servers){
|
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()
|
ConfigManager.save()
|
||||||
@ -458,8 +458,8 @@ ipcRenderer.on('distributionIndexDone', async (event, res) => {
|
|||||||
// Util for development
|
// Util for development
|
||||||
async function devModeToggle() {
|
async function devModeToggle() {
|
||||||
DistroAPI.toggleDevMode(true)
|
DistroAPI.toggleDevMode(true)
|
||||||
const data = await DistroAPI.refreshDistributionOrFallback()
|
const data = await DistroAPI.getDistributionLocalLoadOnly()
|
||||||
ensureJavaSettings(data)
|
ensureJavaSettings(data)
|
||||||
updateSelectedServer(data.servers[0])
|
updateSelectedServer(data.getServers()[0])
|
||||||
syncModConfigurations(data)
|
syncModConfigurations(data)
|
||||||
}
|
}
|
||||||
|
8
package-lock.json
generated
8
package-lock.json
generated
@ -19,7 +19,7 @@
|
|||||||
"fs-extra": "^11.1.0",
|
"fs-extra": "^11.1.0",
|
||||||
"github-syntax-dark": "^0.5.0",
|
"github-syntax-dark": "^0.5.0",
|
||||||
"got": "^11.8.5",
|
"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",
|
"helios-distribution-types": "^1.2.0-pre.1",
|
||||||
"jquery": "^3.6.1",
|
"jquery": "^3.6.1",
|
||||||
"semver": "^7.3.8"
|
"semver": "^7.3.8"
|
||||||
@ -2180,9 +2180,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/helios-core": {
|
"node_modules/helios-core": {
|
||||||
"version": "0.2.0-pre.2",
|
"version": "0.2.0-pre.1",
|
||||||
"resolved": "https://registry.npmjs.org/helios-core/-/helios-core-0.2.0-pre.2.tgz",
|
"resolved": "https://registry.npmjs.org/helios-core/-/helios-core-0.2.0-pre.1.tgz",
|
||||||
"integrity": "sha512-rS9xa2CfQBa+2uINOhIYFSR/nDZQJp8DJrbHXxKFSRckGvdPWwandEwwFoN+bwm3bPSdVhCe2xiSESbMK86UOA==",
|
"integrity": "sha512-hH5AtEZMVRR8/Wstq/8xOrL773p8+wrXZoqTbeqTGcLn1bv9+vmh9ifIAuAQUNaWxXgE/t/Nrw0ph0QJQ/NA6g==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fastq": "^1.15.0",
|
"fastq": "^1.15.0",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^10.1.0",
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
"fs-extra": "^11.1.0",
|
"fs-extra": "^11.1.0",
|
||||||
"github-syntax-dark": "^0.5.0",
|
"github-syntax-dark": "^0.5.0",
|
||||||
"got": "^11.8.5",
|
"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",
|
"helios-distribution-types": "^1.2.0-pre.1",
|
||||||
"jquery": "^3.6.1",
|
"jquery": "^3.6.1",
|
||||||
"semver": "^7.3.8"
|
"semver": "^7.3.8"
|
||||||
|
Loading…
Reference in New Issue
Block a user