mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-07-29 18:25:47 +02:00
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
const progressWrapper = document.getElementById("downloadProgressWrapper");
|
|
const progressBar = document.getElementById("downloadProgress");
|
|
const progressBarText = document.getElementById("downloadProgressText")
|
|
|
|
function startProgress() {
|
|
progressWrapper.style.display = "block";
|
|
progressBar.style.width = "0%";
|
|
progressBarText.style.display = "block";
|
|
progressBarText.innerHTML = "0%";
|
|
}
|
|
|
|
function updateProgress(percent) {
|
|
progressBar.style.width = `${percent}%`;
|
|
progressBarText.innerHTML = `${percent}%`;
|
|
}
|
|
|
|
function resetProgress() {
|
|
progressBar.style.width = "0%";
|
|
progressBarText.innerHTML = "";
|
|
progressBarText.style.display = "none";
|
|
progressWrapper.style.display = "none";
|
|
}
|
|
|
|
// Connexion SSE
|
|
const evtSource = new EventSource("/download/progress");
|
|
evtSource.onmessage = e => {
|
|
if (e.data === "reset") {
|
|
startProgress();
|
|
window.electronAPI.setProgress(0);
|
|
return;
|
|
}
|
|
|
|
if (e.data === "done") {
|
|
resetProgress();
|
|
window.electronAPI.setProgress(-1);
|
|
return;
|
|
}
|
|
|
|
const percent = parseFloat(e.data);
|
|
if (!isNaN(percent)) {
|
|
updateProgress(percent);
|
|
window.electronAPI.setProgress(percent); // update barre des tâches
|
|
if (percent >= 100) setTimeout(() => {
|
|
resetProgress();
|
|
window.electronAPI.setProgress(-1); // retire la barre
|
|
}, 500);
|
|
}
|
|
};
|