瀏覽代碼

Support for attachments (Windows/AdaptiveImages)

Sebastián Katzer 8 年之前
父節點
當前提交
df93be14f0

+ 5 - 0
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/Builder.cs

@@ -78,6 +78,11 @@ namespace LocalNotificationProxy.LocalNotification
                 }
             };
 
+            foreach (var image in this.Options.ImageAttachments)
+            {
+                toast.Visual.BindingGeneric.Children.Add(image);
+            }
+
             var xml = toast.GetXml();
             var at = this.Options.TriggerDate;
             ScheduledToastNotification notification;

+ 55 - 0
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/Options.cs

@@ -24,6 +24,8 @@ namespace LocalNotificationProxy.LocalNotification
     using System;
     using Microsoft.Toolkit.Uwp.Notifications;
     using Windows.Data.Xml.Dom;
+    using System.Collections;
+    using System.Collections.Generic;
 
     public sealed class Options
     {
@@ -73,6 +75,11 @@ namespace LocalNotificationProxy.LocalNotification
         /// </summary>
         public string Data { get; set; }
 
+        /// <summary>
+        /// Gets or sets the notification attachments.
+        /// </summary>
+        public string[] Attachments { get; set; }
+
         /// <summary>
         /// Gets the date when to trigger the notification.
         /// </summary>
@@ -248,6 +255,54 @@ namespace LocalNotificationProxy.LocalNotification
             }
         }
 
+        /// <summary>
+        /// Gets the parsed image attachments.
+        /// </summary>
+        internal List<AdaptiveImage> ImageAttachments
+        {
+            get
+            {
+                var images = new List<AdaptiveImage>();
+
+                if (this.Attachments == null)
+                {
+                    return images;
+                }
+
+                foreach (string path in this.Attachments)
+                {
+                    var image = new AdaptiveImage();
+
+                    if (path.StartsWith("file:///") || path.StartsWith("http"))
+                    {
+                        image.Source = path;
+                    }
+                    else
+                    if (path.StartsWith("file://"))
+                    {
+                        image.Source = path.Replace("file:/", "ms-appx:///www");
+                    }
+                    else
+                    if (path.StartsWith("res://"))
+                    {
+                        image.Source = path.Replace("res://", "ms-appx:///images");
+                    }
+                    else
+                    if (path.StartsWith("app://"))
+                    {
+                        image.Source = path.Replace("app:/", "ms-appdata://local");
+                    }
+
+                    if (image.Source != null)
+                    {
+                        images.Add(image);
+                    }
+                }
+
+                return images;
+            }
+        }
+
         /// <summary>
         /// Deserializes the XML string into an instance of Options.
         /// </summary>

+ 1 - 1
www/local-notification-util.js

@@ -35,6 +35,7 @@ exports._defaults = {
     at:      undefined,
     actions: undefined,
     actionGroupId: undefined,
+    attachments: []
 };
 
 // Listener
@@ -58,7 +59,6 @@ exports.applyPlatformSpecificOptions = function () {
         defaults.color       = undefined;
         break;
     case 'iOS':
-        defaults.attachments   = undefined;
         defaults.region        = undefined;
         defaults.radius        = undefined;
         defaults.notifyOnEntry = true;