Minor fixes

This commit is contained in:
2026-09-06 04:58:10 +02:00
parent 0f2c6677f1
commit 62ee550af7
5 changed files with 94 additions and 90 deletions
+2 -1
View File
@@ -18,7 +18,8 @@ async function installJava(mcVersion, customExec = null) {
const installationPath = await sysinfo.determineInstallationPath(component, majorVersion, customExec) const installationPath = await sysinfo.determineInstallationPath(component, majorVersion, customExec)
const requiredComponentDetails = await web.getJREComponentDetails(component, sysinfo.getPlatformKey()) const requiredComponentDetails = await web.getJREComponentDetails(component, sysinfo.getPlatformKey())
const requiredComponentManifest = await web.getJREComponentManifest(requiredComponentDetails[0].manifest.url) const requiredComponentManifest = await web.getJREComponentManifest(requiredComponentDetails[0].manifest.url)
return await installer.downloadJavaComponent(requiredComponentManifest, installationPath)
return installer.downloadJavaComponent(requiredComponentManifest, installationPath)
} }
module.exports = { module.exports = {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@azures04/minecraft-java-manager", "name": "@azures04/minecraft-java-manager",
"version": "0.0.2", "version": "0.0.3",
"description": "Node module to check if java is installed and install it", "description": "Node module to check if java is installed and install it",
"keywords": [ "keywords": [
"java", "java",
+17 -14
View File
@@ -140,26 +140,28 @@ async function downloadSingleFile(fileEntry, outputRoot, onProgress) {
} }
} }
async function downloadJavaComponent(manifest, outputRoot, options) { function downloadJavaComponent(manifest, outputRoot, options) {
const emitter = new EventEmitter() const emitter = new EventEmitter()
const concurrency = (options && options.concurrency) || 5 const concurrency = (options && options.concurrency) || 5
// On lance le traitement de manière asynchrone SANS l'attendre ici
// setImmediate garantit que l'appelant a le temps d'attacher ses listeners
setImmediate(async () => {
try { try {
const files = extractDownloadableFiles(manifest) const files = extractDownloadableFiles(manifest)
const totalFiles = files.length const totalFiles = files.length
const totalBytesExpected = files.reduce((sum, f) => { return sum + (f.size || 0) }, 0) const totalBytesExpected = files.reduce((sum, f) => sum + (f.size || 0), 0)
emitter.emit("start", { emitter.emit("start", {
totalFiles: totalFiles, totalFiles,
totalBytes: totalBytesExpected, totalBytes: totalBytesExpected,
outputRoot: outputRoot outputRoot
}) })
let completedFiles = 0 let completedFiles = 0
let failedFiles = 0 let failedFiles = 0
let totalBytesDownloaded = 0 let totalBytesDownloaded = 0
const errors = [] const errors = []
const perFileProgress = {} const perFileProgress = {}
function reportGlobalProgress() { function reportGlobalProgress() {
@@ -168,13 +170,13 @@ async function downloadJavaComponent(manifest, outputRoot, options) {
}, 0) }, 0)
emitter.emit("progress", { emitter.emit("progress", {
completedFiles: completedFiles, completedFiles,
totalFiles: totalFiles, totalFiles,
bytesDownloaded: currentTotal, bytesDownloaded: currentTotal,
totalBytes: totalBytesExpected, totalBytes: totalBytesExpected,
percent: totalBytesExpected > 0 ? percent: totalBytesExpected > 0
Math.round((currentTotal / totalBytesExpected) * 100) : ? Math.round((currentTotal / totalBytesExpected) * 100)
null : null
}) })
} }
@@ -225,11 +227,11 @@ async function downloadJavaComponent(manifest, outputRoot, options) {
await Promise.all(workers) await Promise.all(workers)
emitter.emit("complete", { emitter.emit("complete", {
totalFiles: totalFiles, totalFiles,
completedFiles: completedFiles, completedFiles,
failedFiles: failedFiles, failedFiles,
totalBytes: totalBytesDownloaded, totalBytes: totalBytesDownloaded,
errors: errors errors
}) })
} catch (err) { } catch (err) {
@@ -238,6 +240,7 @@ async function downloadJavaComponent(manifest, outputRoot, options) {
error: err error: err
}) })
} }
})
return { events: emitter, path: outputRoot } return { events: emitter, path: outputRoot }
} }
+4 -4
View File
@@ -34,7 +34,7 @@ function getPlatformKey() {
return candidate return candidate
} }
return targets["linux"] ?? null return null
} }
async function determineInstallationPath(component, majorVersion, customInstallPath = null) { async function determineInstallationPath(component, majorVersion, customInstallPath = null) {
@@ -51,9 +51,9 @@ async function determineInstallationPath(component, majorVersion, customInstallP
case "win32": case "win32":
return path.join("C:", "Program files", "Java", component, majorVersion.toString()) return path.join("C:", "Program files", "Java", component, majorVersion.toString())
case "linux": case "linux":
return path.join("opt", "java", component, majorVersion) return path.join("/", "opt", "java", component, majorVersion)
case "macos": case "darwin":
return path.join("Library", "Java", "JavaVirtualMachines", `${component}-${majorVersion}`) return path.join(process.env.HOME || "/", "Library", "Java", "JavaVirtualMachines", `${component}-${majorVersion}`)
default: default:
throw new Error("Unsupported OS") throw new Error("Unsupported OS")
} }
+1 -1
View File
@@ -20,7 +20,7 @@ async function getJREComponentDetails(componentRequested, os) {
const mainifestRequest = await fetch(config.allRuntimes.get()) const mainifestRequest = await fetch(config.allRuntimes.get())
const manifest = await mainifestRequest.json() const manifest = await mainifestRequest.json()
const component = manifest[os][componentRequested] const component = manifest[os][componentRequested]
if (typeof component != "object") { if (!typeof component == "object") {
throw new Error("No JRE Component found") throw new Error("No JRE Component found")
} }
return component return component