Quellcode durchsuchen

Use corretto on macOS since they use an older version of Xcode. (#70)

Vendor name is now displayed above the selected Java version on the settings page. This is to allow for easier differentiation between versions (ex. Amazon Corretto vs AdoptOpenJDK).
Daniel Scalzi vor 5 Jahren
Ursprung
Commit
9a2c1fd9b9
2 geänderte Dateien mit 64 neuen und 3 gelöschten Zeilen
  1. 61 1
      app/assets/js/assetguard.js
  2. 3 2
      app/assets/js/scripts/settings.js

+ 61 - 1
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
             }
         }
 

+ 3 - 2
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'