diff --git a/app/assets/js/assetguard.js b/app/assets/js/assetguard.js index 0db05e56..0e8320cf 100644 --- a/app/assets/js/assetguard.js +++ b/app/assets/js/assetguard.js @@ -266,7 +266,11 @@ class JavaGuard extends EventEmitter { */ /** - * Fetch the last open JDK binary. Uses https://api.adoptopenjdk.net/ + * Fetch the last open JDK binary. + * + * HOTFIX: Uses Corretto 8 for macOS. + * See: https://github.com/dscalzi/HeliosLauncher/issues/70 + * See: https://github.com/AdoptOpenJDK/openjdk-support/issues/101 * * @param {string} major The major version of Java to fetch. * @@ -274,6 +278,15 @@ class JavaGuard extends EventEmitter { */ static _latestOpenJDK(major = '8'){ + if(process.platform === 'darwin') { + return this._latestCorretto(major) + } else { + return this._latestAdoptOpenJDK(major) + } + } + + static _latestAdoptOpenJDK(major) { + const sanitizedOS = process.platform === 'win32' ? 'windows' : (process.platform === 'darwin' ? 'mac' : process.platform) const url = `https://api.adoptopenjdk.net/v2/latestAssets/nightly/openjdk${major}?os=${sanitizedOS}&arch=x64&heap_size=normal&openjdk_impl=hotspot&type=jre` @@ -291,6 +304,48 @@ class JavaGuard extends EventEmitter { } }) }) + + } + + static _latestCorretto(major) { + + let sanitizedOS, ext + + switch(process.platform) { + case 'win32': + sanitizedOS = 'windows' + ext = 'zip' + break + case 'darwin': + sanitizedOS = 'macos' + ext = 'tar.gz' + break + case 'linux': + sanitizedOS = 'linux' + ext = 'tar.gz' + break + default: + sanitizedOS = process.platform + ext = 'tar.gz' + break + } + + const url = `https://corretto.aws/downloads/latest/amazon-corretto-${major}-x64-${sanitizedOS}-jdk.${ext}` + + return new Promise((resolve, reject) => { + request.head({url, json: true}, (err, resp) => { + if(!err && resp.statusCode === 200){ + resolve({ + uri: url, + size: parseInt(resp.headers['content-length']), + name: url.substr(url.lastIndexOf('/')+1) + }) + } else { + resolve(null) + } + }) + }) + } /** @@ -455,6 +510,11 @@ class JavaGuard extends EventEmitter { } */ } } + // Space included so we get only the vendor. + } else if(props[i].lastIndexOf('java.vendor ') > -1) { + let vendorName = props[i].split('=')[1].trim() + console.log(props[i].trim()) + meta.vendor = vendorName } } diff --git a/app/assets/js/scripts/settings.js b/app/assets/js/scripts/settings.js index 23ef79c0..4412a7aa 100644 --- a/app/assets/js/scripts/settings.js +++ b/app/assets/js/scripts/settings.js @@ -1139,10 +1139,11 @@ function populateJavaExecDetails(execPath){ const jg = new JavaGuard(DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()).getMinecraftVersion()) jg._validateJavaBinary(execPath).then(v => { if(v.valid){ + const vendor = v.vendor != null ? ` (${v.vendor})` : '' if(v.version.major < 9) { - settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major} Update ${v.version.update} (x${v.arch})` + settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major} Update ${v.version.update} (x${v.arch})${vendor}` } else { - settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major}.${v.version.minor}.${v.version.revision} (x${v.arch})` + settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major}.${v.version.minor}.${v.version.revision} (x${v.arch})${vendor}` } } else { settingsJavaExecDetails.innerHTML = 'Invalid Selection'