mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-09-27 20:11:15 +02:00
refactor: notify.helpers.js logic. Add a timeout and a better notification management to avoid race condition on Unix Systems
This commit is contained in:
committed by
MasterAcnolo
parent
b9334461bf
commit
321309e294
@@ -2,6 +2,12 @@ const { Notification, shell } = require("electron");
|
||||
const { iconPaths } = require("./path.helpers");
|
||||
const { logger } = require("../logger");
|
||||
|
||||
/**
|
||||
* Set that is holding all notifications. Used to avoid Race Condition and notification crash
|
||||
* @type {Set<any>}
|
||||
*/
|
||||
const activeNotifications = new Set();
|
||||
|
||||
/**
|
||||
* Displays a system notification when a download completes successfully.
|
||||
*
|
||||
@@ -21,7 +27,27 @@ function notifyDownloadFinished(folder, notifyEnabled = true) {
|
||||
icon: iconPaths.confirm,
|
||||
});
|
||||
|
||||
notif.on("click", () => shell.openPath(folder));
|
||||
// Protect notification to garbage collection and race condition, by adding a 150ms timeout before trying to open the folder
|
||||
activeNotifications.add(notif);
|
||||
|
||||
notif.on("click", () => {
|
||||
activeNotifications.delete(notif);
|
||||
|
||||
setTimeout(() => {
|
||||
shell.openPath(folder).then((errorMessage) => {
|
||||
if (errorMessage) {
|
||||
logger.error(`Impossible d'ouvrir le dossier : ${errorMessage}`);
|
||||
}
|
||||
}).catch(err => {
|
||||
logger.error(`Erreur inattendue de shell.openPath : ${err}`);
|
||||
});
|
||||
}, 150);
|
||||
});
|
||||
|
||||
notif.on("close", () => {
|
||||
activeNotifications.delete(notif);
|
||||
});
|
||||
|
||||
notif.show();
|
||||
}
|
||||
|
||||
@@ -41,11 +67,16 @@ function notifyCookiesBrowserError(){
|
||||
icon: iconPaths.error,
|
||||
});
|
||||
|
||||
notif.on("click", () =>
|
||||
shell.openExternal(
|
||||
"https://youtube.com/shorts/cN9f4s1Mf88?si=519QCVd_-fzJqRf1"
|
||||
)
|
||||
);
|
||||
activeNotifications.add(notif);
|
||||
|
||||
notif.on("click", () => {
|
||||
shell.openExternal("https://www.firefox.com/en-US/download/");
|
||||
activeNotifications.delete(notif);
|
||||
});
|
||||
|
||||
notif.on("close", () => {
|
||||
activeNotifications.delete(notif);
|
||||
});
|
||||
|
||||
notif.show();
|
||||
}
|
||||
@@ -65,11 +96,16 @@ function notifyFirefoxBrowserMissing() {
|
||||
icon: iconPaths.error,
|
||||
});
|
||||
|
||||
notif.on("click", () =>
|
||||
shell.openExternal(
|
||||
"https://youtube.com/shorts/cN9f4s1Mf88?si=519QCVd_-fzJqRf1"
|
||||
)
|
||||
);
|
||||
activeNotifications.add(notif);
|
||||
|
||||
notif.on("click", () => {
|
||||
shell.openExternal("https://www.firefox.com/en-US/download/");
|
||||
activeNotifications.delete(notif);
|
||||
});
|
||||
|
||||
notif.on("close", () => {
|
||||
activeNotifications.delete(notif);
|
||||
});
|
||||
|
||||
notif.show();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user