Commit 8e645d15 by Sebastián Katzer

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

parent c1d033b7
...@@ -284,7 +284,7 @@ The properties depend on the trigger type. Not all of them are supported across ...@@ -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 | `quarter` | x | | x |
| | every | String | `year` | x | x | x | | | every | String | `year` | x | x | x |
| | before | Date | | | | before | Date | |
| | firstAt | Date | | x | | | firstAt | Date | | x | x |
| Match | | Match |
| | count | Int | | x | | x | | | count | Int | | x | | x |
| | every | Object | `minute` | x | 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 ...@@ -298,7 +298,7 @@ The properties depend on the trigger type. Not all of them are supported across
| | every | Object | `quarter` | | x | | | every | Object | `quarter` | | x |
| | every | Object | `year` | x | x | x | | | every | Object | `year` | x | x | x |
| | before | Date | | | | before | Date | |
| | after | Date | | x | | | after | Date | | x | x |
| Location | | Location |
| | center | Array | `[lat, long]` | | x | | | center | Array | `[lat, long]` | | x |
| | radius | Int | | | x | | | radius | Int | | | x |
......
...@@ -34,11 +34,21 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -34,11 +34,21 @@ namespace LocalNotificationProxy.LocalNotification
public string Type { get; } = "calendar"; public string Type { get; } = "calendar";
/// <summary> /// <summary>
/// Gets or sets the trigger date. /// Gets or sets the fix trigger date.
/// </summary> /// </summary>
public long At { get; set; } = 0; public long At { get; set; } = 0;
/// <summary> /// <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. /// Gets or sets the relative trigger date from now.
/// </summary> /// </summary>
public int In { get; set; } = 0; public int In { get; set; } = 0;
...@@ -116,6 +126,8 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -116,6 +126,8 @@ namespace LocalNotificationProxy.LocalNotification
var node = doc.DocumentElement; var node = doc.DocumentElement;
trigger.At = int.Parse(node.GetAttribute("at")); 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.In = int.Parse(node.GetAttribute("in"));
trigger.Unit = node.GetAttribute("unit"); trigger.Unit = node.GetAttribute("unit");
trigger.Count = int.Parse(node.GetAttribute("count")); trigger.Count = int.Parse(node.GetAttribute("count"));
...@@ -138,6 +150,8 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -138,6 +150,8 @@ namespace LocalNotificationProxy.LocalNotification
var node = new XmlDocument().CreateElement("trigger"); var node = new XmlDocument().CreateElement("trigger");
node.SetAttribute("at", this.At.ToString()); 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("in", this.In.ToString());
node.SetAttribute("unit", this.Unit); node.SetAttribute("unit", this.Unit);
node.SetAttribute("count", this.Count.ToString()); node.SetAttribute("count", this.Count.ToString());
...@@ -166,21 +180,21 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -166,21 +180,21 @@ namespace LocalNotificationProxy.LocalNotification
case "": case "":
return null; return null;
case "second": case "second":
return DateTime.Now.AddSeconds(ticks); return date.AddSeconds(ticks);
case "minute": case "minute":
return DateTime.Now.AddMinutes(ticks); return date.AddMinutes(ticks);
case "hour": case "hour":
return DateTime.Now.AddHours(ticks); return date.AddHours(ticks);
case "day": case "day":
return DateTime.Now.AddDays(ticks); return date.AddDays(ticks);
case "week": case "week":
return DateTime.Now.AddDays(ticks * 7); return date.AddDays(ticks * 7);
case "month": case "month":
return DateTime.Now.AddMonths(ticks); return date.AddMonths(ticks);
case "quarter": case "quarter":
return DateTime.Now.AddMonths(ticks * 3); return date.AddMonths(ticks * 3);
case "year": case "year":
return DateTime.Now.AddYears(ticks); return date.AddYears(ticks);
default: default:
return null; return null;
} }
...@@ -192,12 +206,17 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -192,12 +206,17 @@ namespace LocalNotificationProxy.LocalNotification
/// <returns>The fix date specified by trigger.at or trigger.in</returns> /// <returns>The fix date specified by trigger.at or trigger.in</returns>
private DateTime? GetFixDate() 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> /// <summary>
...@@ -206,6 +225,11 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -206,6 +225,11 @@ namespace LocalNotificationProxy.LocalNotification
/// <returns>The first matching date specified by trigger.every</returns> /// <returns>The first matching date specified by trigger.every</returns>
private DateTime? GetRelDate() private DateTime? GetRelDate()
{ {
if (this.After != 0)
{
return this.GetDateTime(this.After);
}
return this.GetRelDate(DateTime.Now); return this.GetRelDate(DateTime.Now);
} }
...@@ -319,16 +343,21 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -319,16 +343,21 @@ namespace LocalNotificationProxy.LocalNotification
/// <returns>The next valid trigger date</returns> /// <returns>The next valid trigger date</returns>
private DateTime? GetNextTriggerDate() private DateTime? GetNextTriggerDate()
{ {
var every = this.Every;
var multiple = this.Occurrence;
var date = this.triggerDate.Value; 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; if (every == null)
DateTime? nextDate; {
return date;
}
if (every is double) if (every is double)
{ {
...@@ -353,5 +382,16 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -353,5 +382,16 @@ namespace LocalNotificationProxy.LocalNotification
return nextDate; 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;
}
} }
} }
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<AssemblyName>LocalNotificationProxy</AssemblyName> <AssemblyName>LocalNotificationProxy</AssemblyName>
<DefaultLanguage>de-DE</DefaultLanguage> <DefaultLanguage>de-DE</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier> <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> <TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion> <MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
...@@ -125,10 +125,10 @@ ...@@ -125,10 +125,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NETCore"> <PackageReference Include="Microsoft.NETCore">
<Version>5.0.0</Version> <Version>5.0.2</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.NETCore.Portable.Compatibility"> <PackageReference Include="Microsoft.NETCore.Portable.Compatibility">
<Version>1.0.1</Version> <Version>1.0.2</Version>
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
...@@ -248,10 +248,6 @@ exports.convertTrigger = function (options) { ...@@ -248,10 +248,6 @@ exports.convertTrigger = function (options) {
trigger.count = trigger.every ? 5 : 1; trigger.count = trigger.every ? 5 : 1;
} }
if (trigger.every && device.platform == 'windows') {
trigger.every = trigger.every.toString();
}
if (!isCal) { if (!isCal) {
trigger.notifyOnEntry = !!trigger.notifyOnEntry; trigger.notifyOnEntry = !!trigger.notifyOnEntry;
trigger.notifyOnExit = trigger.notifyOnExit === true; trigger.notifyOnExit = trigger.notifyOnExit === true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment