diff --git a/demo/index.html b/demo/index.html index 794313f2..5e415c85 100644 --- a/demo/index.html +++ b/demo/index.html @@ -22,9 +22,18 @@
++ + +
+
++ + +
Badge Count:
@@ -42,21 +51,22 @@ var body = document.getElementById('body').value; var imageUrl = document.getElementById('image').value; var shouldFlash = document.getElementById('flash').checked; + var shouldStick = document.getElementById('sticky').checked; var color = document.getElementById('color').value; + var tag = document.getElementById('tag').value; num++; - // notfs with same groupId will replace existing notf. - var groupId = (num % 2).toString(); var notf = new SYM_API.Notification(title, { - body: (body + ' num=' + num + ' groupId=' + groupId), + body: (body + ' num=' + num + ' tag=' + tag), image: imageUrl, flash: shouldFlash, color: color || 'white', + sticky: shouldStick, data: { hello: 'hello word' }, - groupId: groupId + tag: tag }); notf.addEventListener('click', onclick); diff --git a/js/notify/electron-notify-preload.js b/js/notify/electron-notify-preload.js index e56ae49d..aa3a7dbd 100644 --- a/js/notify/electron-notify-preload.js +++ b/js/notify/electron-notify-preload.js @@ -98,7 +98,7 @@ function setContents(notificationObj) { let closeButton = notiDoc.getElementById('close'); // note: use onclick because we only want one handler, for case - // when content gets overwritten by notf with same groupId + // when content gets overwritten by notf with same tag closeButton.onclick = function(clickEvent) { clickEvent.stopPropagation() ipc.send('electron-notify-close', winId, notificationObj) diff --git a/js/notify/electron-notify.js b/js/notify/electron-notify.js index 256723d0..ed8ba00a 100644 --- a/js/notify/electron-notify.js +++ b/js/notify/electron-notify.js @@ -265,13 +265,13 @@ function showNotification(notificationObj) { return; } - // check if group id provided. should replace existing notification + // check if tag id provided. should replace existing notification // if has same grouping id. - let groupId = notificationObj.groupId; - if (groupId) { + let tag = notificationObj.tag; + if (tag) { // first check waiting items for(let i = 0; i < notificationQueue.length; i++) { - if (groupId === notificationQueue[ i ].groupId) { + if (tag === notificationQueue[ i ].tag) { notificationQueue[ i ] = notificationObj; resolve(); return; @@ -280,7 +280,7 @@ function showNotification(notificationObj) { // next check items being shown for(let i = 0; i < activeNotifications.length; i++) { - if (groupId === activeNotifications[ i ].groupId) { + if (tag === activeNotifications[ i ].tag) { let notificationWindow = activeNotifications[ i ]; // be sure to call close event for existing, so it gets @@ -322,6 +322,7 @@ function showNotification(notificationObj) { } function setNotificationContents(notfWindow, notfObj) { + // Display time per notification basis. let displayTime = notfObj.displayTime ? notfObj.displayTime : config.displayTime; @@ -329,21 +330,23 @@ function setNotificationContents(notfWindow, notfObj) { clearTimeout(notfWindow.displayTimer); } - // Set timeout to hide notification + var updatedNotificationWindow = notfWindow; + + updatedNotificationWindow.tag = notfObj.tag; + let timeoutId; let closeFunc = buildCloseNotification(notfWindow, notfObj, function() { return timeoutId }); let closeNotificationSafely = buildCloseNotificationSafely(closeFunc); - timeoutId = setTimeout(function() { - closeNotificationSafely('timeout'); - }, displayTime); - var updatedNotificationWindow = notfWindow; - - updatedNotificationWindow.displayTimer = timeoutId; - - updatedNotificationWindow.groupId = notfObj.groupId; + // don't start timer to close if we aren't sticky + if (!notfObj.sticky) { + timeoutId = setTimeout(function() { + closeNotificationSafely('timeout'); + }, displayTime); + updatedNotificationWindow.displayTimer = timeoutId; + } // Trigger onShowFunc if existent if (notfObj.onShowFunc) { diff --git a/js/notify/notifyImpl.js b/js/notify/notifyImpl.js index eac596a6..39b0c607 100644 --- a/js/notify/notifyImpl.js +++ b/js/notify/notifyImpl.js @@ -17,7 +17,8 @@ class Notify { image: options.image || options.icon, flash: options.flash, color: options.color, - groupId: options.groupId, + tag: options.tag, + sticky: options.sticky || false, onShowFunc: onShow.bind(this), onClickFunc: onClick.bind(this), onCloseFunc: onClose.bind(this), diff --git a/js/notify/notifyInterface.js b/js/notify/notifyInterface.js index afdad15f..cae82dbb 100644 --- a/js/notify/notifyInterface.js +++ b/js/notify/notifyInterface.js @@ -24,9 +24,11 @@ class Notify { * icon {string} url of image to show in notification * flash {bool} true if notification should flash (default false) * color {string} background color for notification - * groupId {string} non-empty string to unique identify notf, if another - * notification arrives with same groupId then it's content will + * tag {string} non-empty string to unique identify notf, if another + * notification arrives with same tag then it's content will * replace existing notification. + * sticky {bool} if true notification will stay until user closes. default + * is false. * data {object} arbitrary object to be stored with notification * } */