From fb586cca699b854d50945eba3b56b020bd6be9cd Mon Sep 17 00:00:00 2001 From: Ritsu Date: Tue, 7 Mar 2023 16:11:44 +0200 Subject: [PATCH] (Apple Silicon) aarch64 OpenJDK detect and install (#273) * (Apple Silicon) aarch64 OpenJDK detect and install * Fix undefined reference on amd64 macOS * Revise logic a bit. * variable isARM64, remove includes * const isARM64 * forgot replace in _latestCorretto * Update assetguard.js * Update assetguard.js --------- Co-authored-by: Daniel Scalzi --- app/assets/js/assetguard.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/assets/js/assetguard.js b/app/assets/js/assetguard.js index 1c206c5..ced889a 100644 --- a/app/assets/js/assetguard.js +++ b/app/assets/js/assetguard.js @@ -18,6 +18,8 @@ const ConfigManager = require('./configmanager') const DistroManager = require('./distromanager') const isDev = require('./isdev') +const isARM64 = process.arch === 'arm64'; + // Classes /** Class representing a base asset. */ @@ -302,7 +304,8 @@ class JavaGuard extends EventEmitter { break } - const url = `https://corretto.aws/downloads/latest/amazon-corretto-${major}-x64-${sanitizedOS}-jdk.${ext}` + const arch = isARM64 ? 'aarch64' : 'x64' + const url = `https://corretto.aws/downloads/latest/amazon-corretto-${major}-${arch}-${sanitizedOS}-jdk.${ext}` return new Promise((resolve, reject) => { request.head({url, json: true}, (err, resp) => { @@ -495,6 +498,8 @@ class JavaGuard extends EventEmitter { let vendorName = props[i].split('=')[1].trim() this.logger.debug(props[i].trim()) meta.vendor = vendorName + } else if (props[i].indexOf('os.arch') > -1) { + meta.isARM = props[i].split('=')[1].trim() === 'aarch64' } } @@ -866,6 +871,9 @@ class JavaGuard extends EventEmitter { * @param {string} dataDir The base launcher directory. * @returns {Promise.} A Promise which resolves to the executable path of a valid * x64 Java installation. If none are found, null is returned. + * + * Added: On the system with ARM architecture attempts to find aarch64 Java. + * */ async _darwinJavaValidate(dataDir){ @@ -894,7 +902,16 @@ class JavaGuard extends EventEmitter { pathArr = JavaGuard._sortValidJavaArray(pathArr) if(pathArr.length > 0){ - return pathArr[0].execPath + + // TODO Revise this a bit, seems to work for now. Discovery logic should + // probably just filter out the invalid architectures before it even + // gets to this point. + if (isARM64) { + return pathArr.find(({ isARM }) => isARM)?.execPath ?? null + } else { + return pathArr.find(({ isARM }) => !isARM)?.execPath ?? null + } + } else { return null } @@ -1891,4 +1908,4 @@ module.exports = { JavaGuard, Asset, Library -} \ No newline at end of file +}