Commit d1e647cc by Sebastián Katzer

Support for progressBar options for Windows

parent 3e06a827
...@@ -87,7 +87,20 @@ exports.schedule = function (success, error, args) { ...@@ -87,7 +87,20 @@ exports.schedule = function (success, error, args) {
* @return [ Void ] * @return [ Void ]
*/ */
exports.update = function (success, error, args) { exports.update = function (success, error, args) {
console.warn('LocalNotification#update is not implemented.'); var options = [];
for (var i = 0, props, opts; i < args.length; i++) {
props = args[i];
opts = exports.parseOptions(props);
options.push(opts);
}
impl.update(options);
for (i = 0; i < options.length; i++) {
exports.fireEvent('update', options[i]);
}
success(); success();
}; };
...@@ -362,7 +375,7 @@ exports.clone = function (obj) { ...@@ -362,7 +375,7 @@ exports.clone = function (obj) {
*/ */
exports.parseOptions = function (obj) { exports.parseOptions = function (obj) {
var opts = new LocalNotification.Options(), var opts = new LocalNotification.Options(),
ignore = ['actions', 'trigger']; ignore = ['progressBar', 'actions', 'trigger'];
for (var prop in opts) { for (var prop in opts) {
if (!ignore.includes(prop) && obj[prop]) { if (!ignore.includes(prop) && obj[prop]) {
...@@ -370,6 +383,9 @@ exports.parseOptions = function (obj) { ...@@ -370,6 +383,9 @@ exports.parseOptions = function (obj) {
} }
} }
var progressBar = exports.parseProgressBar(obj);
opts.progressBar = progressBar;
var trigger = exports.parseTrigger(obj); var trigger = exports.parseTrigger(obj);
opts.trigger = trigger; opts.trigger = trigger;
...@@ -433,6 +449,26 @@ exports.parseActions = function (obj) { ...@@ -433,6 +449,26 @@ exports.parseActions = function (obj) {
return actions; return actions;
}; };
/**
* Parse progressBar specs into instances of prefered types.
*
* @param [ Object ] obj The notification options map.
*
* @return [ LocalNotification.ProgressBar ]
*/
exports.parseProgressBar = function (obj) {
var bar = new LocalNotification.ProgressBar(),
spec = obj.progressBar;
if (!spec) return bar;
for (var prop in bar) {
if (spec[prop]) bar[prop] = spec[prop];
}
return bar;
};
// Handle onclick event // Handle onclick event
document.addEventListener('activated', function (e) { document.addEventListener('activated', function (e) {
if (e.kind == ActivationKind.toastNotification) { if (e.kind == ActivationKind.toastNotification) {
......
...@@ -58,6 +58,7 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -58,6 +58,7 @@ namespace LocalNotificationProxy.LocalNotification
{ {
var toast = this.InitToast(); var toast = this.InitToast();
this.AddProgressBarToToast(toast);
this.AddAttachmentsToToast(toast); this.AddAttachmentsToToast(toast);
this.AddActionsToToast(toast); this.AddActionsToToast(toast);
...@@ -116,6 +117,20 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -116,6 +117,20 @@ namespace LocalNotificationProxy.LocalNotification
} }
/// <summary> /// <summary>
/// Adds optional progress bar to the toast.
/// </summary>
/// <param name="toast">Tho toast to extend for.</param>
private void AddProgressBarToToast(ToastContent toast)
{
var progressBar = this.Content.ProgressBar;
if (progressBar != null)
{
toast.Visual.BindingGeneric.Children.Add(progressBar);
}
}
/// <summary>
/// Adds attachments to the toast. /// Adds attachments to the toast.
/// </summary> /// </summary>
/// <param name="toast">Tho toast to extend for.</param> /// <param name="toast">Tho toast to extend for.</param>
......
...@@ -59,6 +59,31 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -59,6 +59,31 @@ namespace LocalNotificationProxy.LocalNotification
} }
/// <summary> /// <summary>
/// Update notifications.
/// </summary>
/// <param name="notifications">List of key-value properties</param>
public void Update([ReadOnlyArray] Options[] notifications)
{
foreach (Options options in notifications)
{
var bar = options.ProgressBar;
if (!bar.Enabled)
{
continue;
}
var data = new NotificationData { SequenceNumber = 0 };
data.Values["progress.value"] = bar.Value.ToString();
data.Values["progress.status"] = bar.Status.ToString();
data.Values["progress.description"] = bar.Description.ToString();
ToastNotifier.Update(data, options.Id.ToString());
}
}
/// <summary>
/// Clear the notifications specified by id. /// Clear the notifications specified by id.
/// </summary> /// </summary>
/// <param name="ids">The IDs of the notification to clear.</param> /// <param name="ids">The IDs of the notification to clear.</param>
......
...@@ -262,6 +262,30 @@ ...@@ -262,6 +262,30 @@
} }
/// <summary> /// <summary>
/// Gets the progress bar widget.
/// </summary>
public AdaptiveProgressBar ProgressBar
{
get
{
var bar = this.Options.ProgressBar;
if (!bar.Enabled)
{
return null;
}
return new AdaptiveProgressBar()
{
Title = bar.Title,
Value = new BindableProgressBarValue("progress.value"),
ValueStringOverride = new BindableString("progress.description"),
Status = new BindableString("progress.status")
};
}
}
/// <summary>
/// Gets the date when to trigger the notification. /// Gets the date when to trigger the notification.
/// </summary> /// </summary>
public DateTime Date public DateTime Date
......
...@@ -33,7 +33,7 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -33,7 +33,7 @@ namespace LocalNotificationProxy.LocalNotification
/// <summary> /// <summary>
/// Gets or sets notification ID. /// Gets or sets notification ID.
/// </summary> /// </summary>
public int Id { get; set; } public int Id { get; set; } = 0;
/// <summary> /// <summary>
/// Gets or sets notification title. /// Gets or sets notification title.
...@@ -86,6 +86,11 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -86,6 +86,11 @@ namespace LocalNotificationProxy.LocalNotification
public IAction[] Actions { get; set; } public IAction[] Actions { get; set; }
/// <summary> /// <summary>
/// Gets or sets the notification progress bar.
/// </summary>
public ProgressBar ProgressBar { get; set; }
/// <summary>
/// Deserializes the XML string into an instance of Options. /// Deserializes the XML string into an instance of Options.
/// </summary> /// </summary>
/// <param name="identifier">The serialized instance of Options as an xml string.</param> /// <param name="identifier">The serialized instance of Options as an xml string.</param>
......
/*
* Apache 2.0 License
*
* Copyright (c) Sebastian Katzer 2017
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apache License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/Apache-2.0/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*/
namespace LocalNotificationProxy.LocalNotification
{
public sealed class ProgressBar
{
/// <summary>
/// Gets or sets a value indicating whether the notification has a progress bar.
/// </summary>
public bool Enabled { get; set; } = false;
/// <summary>
/// Gets or sets the title.
/// </summary>
public string Title { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the value.
/// </summary>
public double Value { get; set; } = 0;
/// <summary>
/// Gets or sets the status.
/// </summary>
public string Status { get; set; } = string.Empty;
/// <summary>
/// Gets or sets the description.
/// </summary>
public string Description { get; set; } = string.Empty;
}
}
...@@ -50,6 +50,15 @@ namespace LocalNotificationProxy ...@@ -50,6 +50,15 @@ namespace LocalNotificationProxy
} }
/// <summary> /// <summary>
/// Update notifications.
/// </summary>
/// <param name="notifications">List of key-value properties</param>
public void Update([ReadOnlyArray] Options[] notifications)
{
this.manager.Update(notifications);
}
/// <summary>
/// Clear the notifications specified by id. /// Clear the notifications specified by id.
/// </summary> /// </summary>
/// <param name="ids">The IDs of the notification to clear.</param> /// <param name="ids">The IDs of the notification to clear.</param>
......
...@@ -118,6 +118,7 @@ ...@@ -118,6 +118,7 @@
<Compile Include="LocalNotification\Input.cs" /> <Compile Include="LocalNotification\Input.cs" />
<Compile Include="LocalNotification\Manager.cs" /> <Compile Include="LocalNotification\Manager.cs" />
<Compile Include="LocalNotification\Options.cs" /> <Compile Include="LocalNotification\Options.cs" />
<Compile Include="LocalNotification\ProgressBar.cs" />
<Compile Include="LocalNotification\Trigger.cs" /> <Compile Include="LocalNotification\Trigger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
......
...@@ -30,11 +30,12 @@ exports._defaults = { ...@@ -30,11 +30,12 @@ exports._defaults = {
sound: 'res://platform_default', sound: 'res://platform_default',
badge: undefined, badge: undefined,
data: undefined, data: undefined,
silent: false, icon: undefined,
actions: [],
trigger: { type: 'calendar' }, trigger: { type: 'calendar' },
actions: [],
actionGroupId: undefined, actionGroupId: undefined,
attachments: [] attachments: [],
progressBar: false
}; };
// Listener // Listener
...@@ -142,6 +143,7 @@ exports.convertProperties = function (options) { ...@@ -142,6 +143,7 @@ exports.convertProperties = function (options) {
this.convertTrigger(options); this.convertTrigger(options);
this.convertActions(options); this.convertActions(options);
this.convertProgressBar(options);
return options; return options;
}; };
...@@ -202,9 +204,7 @@ exports.convertTrigger = function (options) { ...@@ -202,9 +204,7 @@ exports.convertTrigger = function (options) {
var isCal = trigger.type == 'calendar'; var isCal = trigger.type == 'calendar';
if (isCal && !date) { if (isCal && !date) {
date = this.getValueFor(options, 'at', 'firstAt', 'date'); date = this.getValueFor(options, 'at', 'firstAt', 'date') || new Date();
date = date || isObject && !cfg.getTime ? new Date() : options.trigger;
date = date || new Date();
} }
if (isCal) { if (isCal) {
...@@ -216,6 +216,14 @@ exports.convertTrigger = function (options) { ...@@ -216,6 +216,14 @@ exports.convertTrigger = function (options) {
trigger.every = options.every; trigger.every = options.every;
} }
if (!trigger.count && device.platform == 'windows') {
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;
...@@ -233,6 +241,23 @@ exports.convertTrigger = function (options) { ...@@ -233,6 +241,23 @@ exports.convertTrigger = function (options) {
}; };
/** /**
* Convert the passed values for the progressBar to their required type.
*
* @param [ Map ] options Set of custom values.
*
* @return [ Map ] Interaction object with trigger spec.
*/
exports.convertProgressBar = function (options) {
var cfg = options.progressBar;
if (typeof cfg === 'boolean') {
options.progressBar = { enabled: cfg };
}
return options;
};
/**
* Create a callback function to get executed within a specific scope. * Create a callback function to get executed within a specific scope.
* *
* @param [ Function ] fn The function to be exec as the callback. * @param [ Function ] fn The function to be exec as the callback.
......
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