diff --git a/src/utils/stats.js b/src/utils/stats.js index fca6b402b1f7241c7a7865cc242bc77727cf87a8..09a93070e514d6210d5d7136d12559d9be47bfa7 100644 --- a/src/utils/stats.js +++ b/src/utils/stats.js @@ -21,19 +21,38 @@ } if (message.command === "threshold-exceeded") { log("[Stats] Mots dépassant le seuil :", message.wordsAboveThreshold); - let alertMessage = "Nouveaux mots dépassant le seuil :\n"; + if (typeof message.wordsAboveThreshold !== "object" || message.wordsAboveThreshold === null) { return; } - for (const [lang, words] of Object.entries(message.wordsAboveThreshold)) { - if (!Array.isArray(words)) { - continue; + let notificationText = "Mots ajoutés :\n"; + let wordsList = []; + for (const [lang, words] of Object.entries(message.wordsAboveThreshold)) { + if (!Array.isArray(words) || words.length === 0) continue; + + words.forEach(word => { + wordsList.push(`${lang.toUpperCase()} : ${word}`); + }); + } + if (wordsList.length === 0) { + log("[Stats] Aucun mot à afficher dans la notification."); + return; + } + notificationText += wordsList.join("\n"); + + // Afficher une notification + if (Notification.permission === "granted") { + new Notification("Ajout automatique", { + body: notificationText, + icon: browser.runtime.getURL("icons/border-48.png") + }); + } else if (Notification.permission !== "denied") { + Notification.requestPermission().then(permission => { + if (permission === "granted") { + new Notification("Ajout automatique", { body: notificationText }); } - - alertMessage += `\n${lang.toUpperCase()} : ${words.join(", ")}`; + }); } - - alert(alertMessage); } }); workerPort.onDisconnect.addListener(() => { diff --git a/src/workers/pyodide_worker.js b/src/workers/pyodide_worker.js index f099a8622c2285814e6630e2a0bbebfd3bc40a4c..99c90ab5a824c66a8430554795078b37291b812e 100644 --- a/src/workers/pyodide_worker.js +++ b/src/workers/pyodide_worker.js @@ -231,7 +231,7 @@ async function checkThreshold(lang) { finalWords.forEach(word => notifiedSet.add(word)); log("Mots dépassant le seuil :", finalWords); - self.postMessage({ type: "threshold-exceeded", wordsAboveThreshold: finalWords }); + self.postMessage({ type: "threshold-exceeded", wordsAboveThreshold: { [lang]: finalWords } }); // Ajout aux mots en attente pour un envoi groupé if (!pendingWords[lang]) pendingWords[lang] = [];