From 6c9189da23ed5712df87b990fc438c0d9f169238 Mon Sep 17 00:00:00 2001 From: r1tsuu Date: Thu, 2 Mar 2023 23:07:55 +0200 Subject: [PATCH] (macOS) Added ARM arch JRE detect and install. --- app/assets/js/assetguard.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/assets/js/assetguard.js b/app/assets/js/assetguard.js index 1c206c50..f6b0328b 100644 --- a/app/assets/js/assetguard.js +++ b/app/assets/js/assetguard.js @@ -302,7 +302,7 @@ class JavaGuard extends EventEmitter { break } - const url = `https://corretto.aws/downloads/latest/amazon-corretto-${major}-x64-${sanitizedOS}-jdk.${ext}` + const url = `https://corretto.aws/downloads/latest/amazon-corretto-${major}-${process.arch.includes("arm") ? "aarch64" : "x64"}-${sanitizedOS}-jdk.${ext}` return new Promise((resolve, reject) => { request.head({url, json: true}, (err, resp) => { @@ -495,6 +495,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' } } @@ -856,6 +858,7 @@ class JavaGuard extends EventEmitter { /** * Attempts to find a valid x64 installation of Java on MacOS. + * If using Apple Silicon * The system JVM directory is scanned for possible installations. * The JAVA_HOME enviroment variable and internet plugins directory * are also scanned and validated. @@ -894,7 +897,14 @@ class JavaGuard extends EventEmitter { pathArr = JavaGuard._sortValidJavaArray(pathArr) if(pathArr.length > 0){ - return pathArr[0].execPath + let amd64Path = pathArr.find(({ isARM }) => !isARM).execPath + let armPath = pathArr.find(({ isARM }) => isARM).execPath + if (process.arch.includes("arm")) { + if (armPath) return armPath + // If ARM JRE is not installed, AMD64 JRE still will run through Rosseta2 + return amd64Path + } + return pathArr.find(({ isARM }) => !isARM).execPath } else { return null }