Przeglądaj źródła

Support badge property on windows platform

Sebastián Katzer 10 lat temu
rodzic
commit
33ad4c789c
1 zmienionych plików z 20 dodań i 1 usunięć
  1. 20 1
      src/windows/LocalNotificationCore.js

+ 20 - 1
src/windows/LocalNotificationCore.js

@@ -54,8 +54,8 @@ exports.core = {
      *      'schedule' or 'update'
      */
     schedule: function (notifications) {
-
         var triggerFn = function (notification) {
+            this.updateBadge(notification.badge);
             this.fireEvent('trigger', notification);
         };
 
@@ -127,6 +127,25 @@ exports.core = {
         this.scheduleLocalNotification(notification, properties);
     },
 
+    /**
+     * Updates the badge number of the active tile.
+     *
+     * @param {Number} badge
+     *      The badge number. Zero will clean the badge.
+     */
+    updateBadge: function (badge) {
+        var notifications = Windows.UI.Notifications,
+            type = notifications.BadgeTemplateType.badgeNumber,
+            xml = notifications.BadgeUpdateManager.getTemplateContent(type),
+            attrs = xml.getElementsByTagName('badge'),
+            notification = new notifications.BadgeNotification(xml);
+
+        attrs[0].setAttribute('value', badge);
+
+        notifications.BadgeUpdateManager.createBadgeUpdaterForApplication()
+            .update(notification);
+    },
+
     /**
      * Updates a single local notification.
      *