From e3845e1849d951b8c6e05776a0f04c8a114da0f8 Mon Sep 17 00:00:00 2001 From: MasterAcnolo <68693319+MasterAcnolo@users.noreply.github.com> Date: Sat, 15 Nov 2025 23:52:43 +0100 Subject: [PATCH] Loading Bar taskbar --- main.js | 5 +++++ preload.js | 1 + public/script/downloadstatus.js | 2 +- public/script/progressBar.js | 8 +++++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 5ad7e8c..b03e633 100644 --- a/main.js +++ b/main.js @@ -76,6 +76,11 @@ ipcMain.handle("select-download-folder", async () => { ipcMain.handle("get-default-download-path", () => defaultDownloadPath); +ipcMain.on("set-progress", (event, percent) => { + mainWindow.setProgressBar(percent / 100); // Electron attend 0 → 1 +}); + + function setupMenu() { const menuTemplate = [ { diff --git a/preload.js b/preload.js index 27bfdac..a1f3787 100644 --- a/preload.js +++ b/preload.js @@ -3,4 +3,5 @@ const { contextBridge, ipcRenderer } = require("electron"); contextBridge.exposeInMainWorld("electronAPI", { getDefaultDownloadPath: () => ipcRenderer.invoke("get-default-download-path"), selectDownloadFolder: () => ipcRenderer.invoke("select-download-folder"), + setProgress: (percent) => ipcRenderer.send("set-progress", percent) }); diff --git a/public/script/downloadstatus.js b/public/script/downloadstatus.js index af9774f..d80888e 100644 --- a/public/script/downloadstatus.js +++ b/public/script/downloadstatus.js @@ -34,4 +34,4 @@ form.addEventListener("submit", async (e) => { statusDiv.textContent = ""; }, 5000); } -}); +}); \ No newline at end of file diff --git a/public/script/progressBar.js b/public/script/progressBar.js index 3cc8c94..246a067 100644 --- a/public/script/progressBar.js +++ b/public/script/progressBar.js @@ -26,17 +26,23 @@ 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); - if (percent >= 100) setTimeout(resetProgress, 500); + window.electronAPI.setProgress(percent); // update barre des tâches + if (percent >= 100) setTimeout(() => { + resetProgress(); + window.electronAPI.setProgress(-1); // retire la barre + }, 500); } };