浏览代码

Fix some trigger bugs and support for firstAt/after on windows

Sebastián Katzer 8 年之前
父节点
当前提交
8e645d1589

+ 2 - 2
README.md

@@ -284,7 +284,7 @@ The properties depend on the trigger type. Not all of them are supported across
 |              | every         | String  | `quarter`        | x       |     | x       |
 |              | every         | String  | `year`           | x       | x   | x       |
 |              | before        | Date    |                  |
-|              | firstAt       | Date    |                  | x       |
+|              | firstAt       | Date    |                  | x       | x   |
 | Match        |
 |              | count         | Int     |                  | x       |     | x       |
 |              | every         | Object  | `minute`         | x       | x   | x       |
@@ -298,7 +298,7 @@ The properties depend on the trigger type. Not all of them are supported across
 |              | every         | Object  | `quarter`        |         | x   |
 |              | every         | Object  | `year`           | x       | x   | x       |
 |              | before        | Date    |                  |
-|              | after         | Date    |                  | x       |
+|              | after         | Date    |                  | x       | x   |
 | Location     |
 |              | center        | Array   | `[lat, long]`    |         | x   |
 |              | radius        | Int     |                  |         | x   |

+ 57 - 17
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/Trigger.cs

@@ -34,10 +34,20 @@ namespace LocalNotificationProxy.LocalNotification
         public string Type { get; } = "calendar";
 
         /// <summary>
-        /// Gets or sets the trigger date.
+        /// Gets or sets the fix trigger date.
         /// </summary>
         public long At { get; set; } = 0;
 
+        /// <summary>
+        /// Gets or sets the first trigger date.
+        /// </summary>
+        public long FirstAt { get; set; } = 0;
+
+        /// <summary>
+        /// Gets or sets the after trigger date.
+        /// </summary>
+        public long After { get; set; } = 0;
+
         /// <summary>
         /// Gets or sets the relative trigger date from now.
         /// </summary>
@@ -116,6 +126,8 @@ namespace LocalNotificationProxy.LocalNotification
             var node = doc.DocumentElement;
 
             trigger.At = int.Parse(node.GetAttribute("at"));
+            trigger.FirstAt = int.Parse(node.GetAttribute("firstAt"));
+            trigger.After = int.Parse(node.GetAttribute("after"));
             trigger.In = int.Parse(node.GetAttribute("in"));
             trigger.Unit = node.GetAttribute("unit");
             trigger.Count = int.Parse(node.GetAttribute("count"));
@@ -138,6 +150,8 @@ namespace LocalNotificationProxy.LocalNotification
             var node = new XmlDocument().CreateElement("trigger");
 
             node.SetAttribute("at", this.At.ToString());
+            node.SetAttribute("firstAt", this.FirstAt.ToString());
+            node.SetAttribute("after", this.After.ToString());
             node.SetAttribute("in", this.In.ToString());
             node.SetAttribute("unit", this.Unit);
             node.SetAttribute("count", this.Count.ToString());
@@ -166,21 +180,21 @@ namespace LocalNotificationProxy.LocalNotification
                 case "":
                     return null;
                 case "second":
-                    return DateTime.Now.AddSeconds(ticks);
+                    return date.AddSeconds(ticks);
                 case "minute":
-                    return DateTime.Now.AddMinutes(ticks);
+                    return date.AddMinutes(ticks);
                 case "hour":
-                    return DateTime.Now.AddHours(ticks);
+                    return date.AddHours(ticks);
                 case "day":
-                    return DateTime.Now.AddDays(ticks);
+                    return date.AddDays(ticks);
                 case "week":
-                    return DateTime.Now.AddDays(ticks * 7);
+                    return date.AddDays(ticks * 7);
                 case "month":
-                    return DateTime.Now.AddMonths(ticks);
+                    return date.AddMonths(ticks);
                 case "quarter":
-                    return DateTime.Now.AddMonths(ticks * 3);
+                    return date.AddMonths(ticks * 3);
                 case "year":
-                    return DateTime.Now.AddYears(ticks);
+                    return date.AddYears(ticks);
                 default:
                     return null;
             }
@@ -192,12 +206,17 @@ namespace LocalNotificationProxy.LocalNotification
         /// <returns>The fix date specified by trigger.at or trigger.in</returns>
         private DateTime? GetFixDate()
         {
-            if (this.At == 0)
+            if (this.At != 0)
             {
-                return this.AddInterval(DateTime.Now, this.Unit, this.In);
+                return this.GetDateTime(this.At);
             }
 
-            return DateTimeOffset.FromUnixTimeMilliseconds(this.At * 1000).LocalDateTime;
+            if (this.FirstAt != 0)
+            {
+                return this.GetDateTime(this.FirstAt);
+            }
+
+            return this.AddInterval(DateTime.Now, this.Unit, this.In);
         }
 
         /// <summary>
@@ -206,6 +225,11 @@ namespace LocalNotificationProxy.LocalNotification
         /// <returns>The first matching date specified by trigger.every</returns>
         private DateTime? GetRelDate()
         {
+            if (this.After != 0)
+            {
+                return this.GetDateTime(this.After);
+            }
+
             return this.GetRelDate(DateTime.Now);
         }
 
@@ -319,16 +343,21 @@ namespace LocalNotificationProxy.LocalNotification
         /// <returns>The next valid trigger date</returns>
         private DateTime? GetNextTriggerDate()
         {
+            var every = this.Every;
+            var multiple = this.Occurrence;
             var date = this.triggerDate.Value;
-            var multiple = this.Occurrence - 1;
+            DateTime? nextDate;
 
-            if (multiple == 0)
+            if (this.Every is Every)
             {
-                return date;
+                every = (this.Every as Every).Interval;
+                multiple -= 1;
             }
 
-            var every = this.Every is Every ? (this.Every as Every).Interval : this.Every;
-            DateTime? nextDate;
+            if (every == null)
+            {
+                return date;
+            }
 
             if (every is double)
             {
@@ -353,5 +382,16 @@ namespace LocalNotificationProxy.LocalNotification
 
             return nextDate;
         }
+
+        /// <summary>
+        /// Convert the milliseconds into a date time object.
+        /// </summary>
+        /// <param name="time">The milli seconds since unix zero.</param>
+        /// <returns>The date time</returns>
+        private DateTime GetDateTime(long time)
+        {
+            return DateTimeOffset.FromUnixTimeMilliseconds(time * 1000).LocalDateTime;
+        }
     }
+
 }

+ 3 - 3
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotificationProxy.csproj

@@ -11,7 +11,7 @@
     <AssemblyName>LocalNotificationProxy</AssemblyName>
     <DefaultLanguage>de-DE</DefaultLanguage>
     <TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
-    <TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.15063.0</TargetPlatformVersion>
+    <TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.16299.0</TargetPlatformVersion>
     <TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion>
     <MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
     <FileAlignment>512</FileAlignment>
@@ -125,10 +125,10 @@
   </ItemGroup>
   <ItemGroup>
     <PackageReference Include="Microsoft.NETCore">
-      <Version>5.0.0</Version>
+      <Version>5.0.2</Version>
     </PackageReference>
     <PackageReference Include="Microsoft.NETCore.Portable.Compatibility">
-      <Version>1.0.1</Version>
+      <Version>1.0.2</Version>
     </PackageReference>
   </ItemGroup>
   <ItemGroup>

+ 0 - 4
www/local-notification-util.js

@@ -248,10 +248,6 @@ exports.convertTrigger = function (options) {
         trigger.count = trigger.every ? 5 : 1;
     }
 
-    if (trigger.every && device.platform == 'windows') {
-        trigger.every = trigger.every.toString();
-    }
-
     if (!isCal) {
         trigger.notifyOnEntry = !!trigger.notifyOnEntry;
         trigger.notifyOnExit  = trigger.notifyOnExit === true;