From e0ecffed849bd53ef31c932e296226aea0d89512 Mon Sep 17 00:00:00 2001 From: "Yasmin Seidel (JasminDreasond)" Date: Tue, 15 Aug 2023 21:22:35 -0300 Subject: [PATCH] notification timeout added --- electron/main/notification/index.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/electron/main/notification/index.js b/electron/main/notification/index.js index 0a332bd33..8aeaeece1 100644 --- a/electron/main/notification/index.js +++ b/electron/main/notification/index.js @@ -24,11 +24,18 @@ export default function startNotifications(ipcMain) { const tinyData = {}; const tag = data.tag; for (const item in data) { - if (item !== 'tag') { + if (item !== 'tag' && item !== 'timeout') { tinyData[item] = data[item]; } } + let timeout = data.timeout; + if (typeof timeout !== 'number' || Number.isNaN(timeout) || !Number.isFinite(timeout)) { + timeout = 15000; + } else if (timeout < 0) { + timeout = 0; + } + // Create Item notifications[tag] = new Notification(tinyData); @@ -72,6 +79,13 @@ export default function startNotifications(ipcMain) { notifications[tag].on('close', closeNoti); + // Close + setTimeout(() => { + if (notifications[tag]) { notifications[tag].close(); } else { + closeNoti({}); + } + }, timeout); + e.reply('tiny-notification-create-confirm', { tag, isSupported: Notification.isSupported() }); };