Skip to content

Commit

Permalink
1.17+ Support / Java Settings by Instance (#261)
Browse files Browse the repository at this point in the history
* Patches to get 1.17 working, need to revise into real solutions.

* Add version.jar to cp until 1.17.

* Add server selection button to Java settings tab in preparation for by-instance java settings.

* Java settings by instance

* Use classpath flag instead of hardcode.

* Support 1.19.

* Fix refresh of java exec details.

* Add doc.

* Fix auto download of jdk 17.

* Dependency upgrade.
  • Loading branch information
dscalzi authored Nov 27, 2022
1 parent 190bb4c commit e3ee03e
Show file tree
Hide file tree
Showing 13 changed files with 578 additions and 282 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2019,
"ecmaVersion": 2021,
"sourceType": "module"
},
"rules": {
Expand Down
106 changes: 53 additions & 53 deletions app/assets/css/launcher.css
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,59 @@ body, button {
font-size: 12px;
}

/* Selected server content container */
.settingsSelServContainer {
background: rgba(0, 0, 0, 0.25);
width: 75%;
border-radius: 3px;
display: flex;
justify-content: space-between;
margin: 15px 0px;
}

/* Div which will be populated with the selected server's information. */
.settingsSelServContent {
display: flex;
align-items: center;
justify-content: flex-start;
padding: 5px 0px;
}

/* Wrapper container for the switch server button. */
.settingsSwitchServerContainer {
display: flex;
align-items: center;
padding: 15px;
}

/* Button to switch server configurations on the mods tab. */
.settingsSwitchServerButton {
opacity: 0;
border: 1px solid rgb(255, 255, 255);
color: rgb(255, 255, 255);
background: none;
font-size: 12px;
border-radius: 3px;
font-family: 'Avenir Medium';
transition: 0.25s ease;
cursor: pointer;
outline: none;
}
.settingsSwitchServerButton:hover,
.settingsSwitchServerButton:focus {
box-shadow: 0px 0px 20px rgb(255, 255, 255);
background: rgba(255, 255, 255, 0.25);
}
.settingsSwitchServerButton:active {
box-shadow: 0px 0px 20px rgb(187, 187, 187);
background: rgba(187, 187, 187, 0.25);
border: 1px solid rgb(187, 187, 187);
color: rgb(187, 187, 187);
}
.settingsSelServContainer:hover .settingsSwitchServerButton {
opacity: 1;
}

/* Remove spin button from number inputs. */
#settingsContainer input[type=number]::-webkit-inner-spin-button {
-webkit-appearance: none;
Expand Down Expand Up @@ -1638,59 +1691,6 @@ input:checked + .toggleSwitchSlider:before {
* Settings View (Mods Tab)
* * */

/* Selected server content container */
#settingsSelServContainer {
background: rgba(0, 0, 0, 0.25);
width: 75%;
border-radius: 3px;
display: flex;
justify-content: space-between;
margin: 15px 0px;
}

/* Div which will be populated with the selected server's information. */
#settingsSelServContent {
display: flex;
align-items: center;
justify-content: flex-start;
padding: 5px 0px;
}

/* Wrapper container for the switch server button. */
#settingsSwitchServerContainer {
display: flex;
align-items: center;
padding: 15px;
}

/* Button to switch server configurations on the mods tab. */
#settingsSwitchServerButton {
opacity: 0;
border: 1px solid rgb(255, 255, 255);
color: rgb(255, 255, 255);
background: none;
font-size: 12px;
border-radius: 3px;
font-family: 'Avenir Medium';
transition: 0.25s ease;
cursor: pointer;
outline: none;
}
#settingsSwitchServerButton:hover,
#settingsSwitchServerButton:focus {
box-shadow: 0px 0px 20px rgb(255, 255, 255);
background: rgba(255, 255, 255, 0.25);
}
#settingsSwitchServerButton:active {
box-shadow: 0px 0px 20px rgb(187, 187, 187);
background: rgba(187, 187, 187, 0.25);
border: 1px solid rgb(187, 187, 187);
color: rgb(187, 187, 187);
}
#settingsSelServContainer:hover #settingsSwitchServerButton {
opacity: 1;
}

/* Main content container for the mod elements. */
#settingsModsContainer {
width: 75%;
Expand Down
53 changes: 35 additions & 18 deletions app/assets/js/assetguard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const child_process = require('child_process')
const crypto = require('crypto')
const EventEmitter = require('events')
const fs = require('fs-extra')
const nodeDiskInfo = require('node-disk-info')
const StreamZip = require('node-stream-zip')
const path = require('path')
const Registry = require('winreg')
Expand Down Expand Up @@ -342,6 +343,9 @@ class JavaGuard extends EventEmitter {
* @returns {boolean} True if the path points to a Java executable, otherwise false.
*/
static isJavaExecPath(pth){
if(pth == null) {
return false
}
if(process.platform === 'win32'){
return pth.endsWith(path.join('bin', 'javaw.exe'))
} else if(process.platform === 'darwin'){
Expand Down Expand Up @@ -459,24 +463,29 @@ class JavaGuard extends EventEmitter {
let verString = props[i].split('=')[1].trim()
console.log(props[i].trim())
const verOb = JavaGuard.parseJavaRuntimeVersion(verString)
// TODO implement a support matrix eventually. Right now this is good enough
// 1.7-1.16 = Java 8
// 1.17+ = Java 17
// Actual support may vary, but we're going with this rule for simplicity.
if(verOb.major < 9){
// Java 8
if(verOb.major === 8 && verOb.update > 52){
meta.version = verOb
++checksum
if(checksum === goal){
break
if(!Util.mcVersionAtLeast('1.17', this.mcVersion)){
if(verOb.major === 8 && verOb.update > 52){
meta.version = verOb
++checksum
if(checksum === goal){
break
}
}
}
} else {
} else if(verOb.major >= 17) {
// Java 9+
if(Util.mcVersionAtLeast('1.13', this.mcVersion)){
console.log('Java 9+ not yet tested.')
/* meta.version = verOb
if(Util.mcVersionAtLeast('1.17', this.mcVersion)){
meta.version = verOb
++checksum
if(checksum === goal){
break
} */
}
}
}
// Space included so we get only the vendor.
Expand Down Expand Up @@ -804,13 +813,20 @@ class JavaGuard extends EventEmitter {
// Get possible paths from the registry.
let pathSet1 = await JavaGuard._scanRegistry()
if(pathSet1.size === 0){

// Do a manual file system scan of program files.
pathSet1 = new Set([
...pathSet1,
...(await JavaGuard._scanFileSystem('C:\\Program Files\\Java')),
...(await JavaGuard._scanFileSystem('C:\\Program Files\\Eclipse Foundation')),
...(await JavaGuard._scanFileSystem('C:\\Program Files\\AdoptOpenJDK'))
])
// Check all drives
const driveMounts = nodeDiskInfo.getDiskInfoSync().map(({ mounted }) => mounted)
for(const mount of driveMounts) {
pathSet1 = new Set([
...pathSet1,
...(await JavaGuard._scanFileSystem(`${mount}\\Program Files\\Java`)),
...(await JavaGuard._scanFileSystem(`${mount}\\Program Files\\Eclipse Adoptium`)),
...(await JavaGuard._scanFileSystem(`${mount}\\Program Files\\Eclipse Foundation`)),
...(await JavaGuard._scanFileSystem(`${mount}\\Program Files\\AdoptOpenJDK`))
])
}

}

// Get possible paths from the data directory.
Expand Down Expand Up @@ -1542,9 +1558,10 @@ class AssetGuard extends EventEmitter {
// Java (Category=''') Validation (download) Functions
// #region

_enqueueOpenJDK(dataDir){
_enqueueOpenJDK(dataDir, mcVersion){
return new Promise((resolve, reject) => {
JavaGuard._latestOpenJDK('8').then(verData => {
const major = Util.mcVersionAtLeast('1.17', mcVersion) ? '17' : '8'
JavaGuard._latestOpenJDK(major).then(verData => {
if(verData != null){

dataDir = path.join(dataDir, 'runtime', 'x64')
Expand Down
Loading

0 comments on commit e3ee03e

Please sign in to comment.