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() }); };