Skip to content

Commit

Permalink
notification timeout added
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminDreasond committed Aug 16, 2023
1 parent cec763a commit e0ecffe
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion electron/main/notification/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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() });

};
Expand Down

0 comments on commit e0ecffe

Please sign in to comment.