Browse Source

Fix issue and missing id in clear and cancel for windows

Sebastián Katzer 10 năm trước cách đây
mục cha
commit
21d27bc1ec
2 tập tin đã thay đổi với 26 bổ sung5 xóa
  1. 10 5
      src/windows/LocalNotificationCore.js
  2. 16 0
      src/windows/LocalNotificationUtil.js

+ 10 - 5
src/windows/LocalNotificationCore.js

@@ -62,10 +62,8 @@ exports.core = {
                 notification = this.build(options);
 
             this.cancelLocalNotification(options.id);
-
             this.scheduleLocalNotification(notification, options);
             this.scheduleBackupNotification(notification, options);
-
             this.fireEvent('schedule', options);
             this.callOnTrigger(options, triggerFn);
         }
@@ -185,9 +183,10 @@ exports.core = {
      */
     clear: function (ids) {
         for (var i = 0; i < ids.length; i++) {
-            var notification = this.getAll([id])[0];
+            var id = ids[i],
+                notification = this.getAll([id])[0];
 
-            this.clearLocalNotification(ids[i]);
+            this.clearLocalNotification(id);
             this.fireEvent('clear', notification);
         }
     },
@@ -199,8 +198,13 @@ exports.core = {
      *      Local notification ID
      */
     clearLocalNotification: function (id) {
+        var notification = this.getAll([id])[0];
+
         this.getToastHistory().remove('Toast' + id);
 
+        if (this.isRepeating(notification))
+            return;
+
         if (this.isTriggered(id) && !this.isScheduled(id)) {
             this.cancelLocalNotification(id);
         }
@@ -228,7 +232,8 @@ exports.core = {
      */
     cancel: function (ids) {
         for (var i = 0; i < ids.length; i++) {
-            var notification = this.getAll([id])[0];
+            var id = ids[i],
+                notification = this.getAll([id])[0];
 
             this.cancelLocalNotification(ids[i]);
             this.fireEvent('cancel', notification);

+ 16 - 0
src/windows/LocalNotificationUtil.js

@@ -68,6 +68,18 @@ exports.getRepeatInterval = function (every) {
     return 0;
 };
 
+/**
+ * If the notification is repeating.
+ *
+ * @param {Object} notification
+ *      Local notification object
+ *
+ * @return Boolean
+ */
+exports.isRepeating = function (notification) {
+    return this.getRepeatInterval(notification.every) !== 0;
+};
+
 /**
  * Parses sound file path.
  *
@@ -363,7 +375,11 @@ WinJS.Application.addEventListener('activated', function (args) {
         return;
 
     exports.clearLocalNotification(id);
+
+    var repeating = exports.isRepeating(notification);
+
     exports.fireEvent('click', notification);
+    exports.fireEvent(repeating ? 'clear' : 'cancel', notification);
 }, false);
 
 // App is running in background