(id: string)
| 135 | } |
| 136 | |
| 137 | async getJavaRuntimeCommand(id: string) { |
| 138 | const java = this.getJava(id); |
| 139 | if (!java) throw new Error($t("TXT_CODE_77ce8542")); |
| 140 | if (java.info.downloading) throw new Error($t("TXT_CODE_45d02bb7")); |
| 141 | |
| 142 | let javaPath = java.info.path ?? java.path; |
| 143 | if (!javaPath) throw new Error($t("TXT_CODE_82c8bca3")); |
| 144 | |
| 145 | // For macOS, if Java is within a .jdk bundle, use the Contents/Home/bin/java path |
| 146 | if (os.platform() === "darwin") { |
| 147 | // Scan first-level subdirectories under javaPath to find Contents directory |
| 148 | try { |
| 149 | const entries = await fs.readdir(javaPath); |
| 150 | for (const entry of entries) { |
| 151 | const entryPath = path.join(javaPath, entry); |
| 152 | const stat = await fs.stat(entryPath); |
| 153 | if (stat.isDirectory()) { |
| 154 | const contentsPath = path.join(entryPath, "Contents"); |
| 155 | if (await fs.pathExists(contentsPath)) { |
| 156 | // Found Contents directory, construct new javaPath |
| 157 | javaPath = path.join(entryPath, "Contents", "Home"); |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | } catch (error) { |
| 163 | // If scan fails, use original javaPath |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | const javaRuntimePath = path.join( |
| 168 | javaPath, |
| 169 | "bin", |
| 170 | os.platform() == "win32" ? "java.exe" : "java" |
| 171 | ); |
| 172 | |
| 173 | return `"${javaRuntimePath}"`; |
| 174 | } |
| 175 | |
| 176 | async removeJava(id: string) { |
| 177 | const java = this.getJava(id); |
no test coverage detected