Commit f3f4e4d5 by Sebastián Katzer

Implemented clear, clearAll, cancel and cancelAll for Windows

parent b69640e0
...@@ -102,6 +102,25 @@ exports.schedule = function (success, error, args) { ...@@ -102,6 +102,25 @@ exports.schedule = function (success, error, args) {
}; };
/** /**
* Clear the notifications specified by id.
*
* @param [ Function ] success Success callback
* @param [ Function ] error Error callback
* @param [ Array ] args Interface arguments
*
* @return [ Void ]
*/
exports.clear = function (success, error, args) {
var toasts = impl.clear(args) || [];
for (var i = 0; i < toasts.length; i++) {
exports.fireEvent('clear', toasts[i]);
}
success();
};
/**
* Clear all notifications. * Clear all notifications.
* *
* @param [ Function ] success Success callback * @param [ Function ] success Success callback
...@@ -116,6 +135,25 @@ exports.clearAll = function (success, error) { ...@@ -116,6 +135,25 @@ exports.clearAll = function (success, error) {
}; };
/** /**
* Cancel the notifications specified by id.
*
* @param [ Function ] success Success callback
* @param [ Function ] error Error callback
* @param [ Array ] args Interface arguments
*
* @return [ Void ]
*/
exports.cancel = function (success, error, args) {
var toasts = impl.cancel(args) || [];
for (var i = 0; i < toasts.length; i++) {
exports.fireEvent('cancel', toasts[i]);
}
success();
};
/**
* Cancel all notifications. * Cancel all notifications.
* *
* @param [ Function ] success Success callback * @param [ Function ] success Success callback
......
...@@ -52,6 +52,96 @@ namespace LocalNotificationProxy.LocalNotification ...@@ -52,6 +52,96 @@ namespace LocalNotificationProxy.LocalNotification
} }
/// <summary> /// <summary>
/// Clear the notifications specified by id.
/// </summary>
/// <param name="ids">The IDs of the notification to clear.</param>
/// <returns>The cleared notifications.</returns>
public List<Options> Clear(int[] ids)
{
var triggered = ToastNotificationManager.History.GetHistory();
var tags = new List<int>(ids);
var toasts = new List<Options>();
foreach (var toast in triggered)
{
var id = int.Parse(toast.Tag);
if (tags.Contains(id))
{
tags.Remove(id);
toasts.Add(new Notification(toast).Options);
ToastNotificationManager.History.Remove(toast.Tag);
}
if (tags.Count == 0)
{
break;
}
}
return toasts;
}
/// <summary>
/// Clear all notifications.
/// </summary>
public void ClearAll()
{
ToastNotificationManager.History.Clear();
}
/// <summary>
/// Cancel the notifications specified by id.
/// </summary>
/// <param name="ids">The IDs of the notification to clear.</param>
/// <returns>The cleared notifications.</returns>
public List<Options> Cancel(int[] ids)
{
var scheduled = ToastNotifier.GetScheduledToastNotifications();
var tags = new List<int>(ids);
var toasts = new List<Options>();
foreach (var toast in scheduled)
{
var id = int.Parse(toast.Tag);
if (tags.Contains(id))
{
tags.Remove(id);
toasts.Add(new Notification(toast).Options);
ToastNotifier.RemoveFromSchedule(toast);
}
if (tags.Count == 0)
{
break;
}
}
if (tags.Count > 0)
{
toasts.AddRange(this.Clear(tags.ToArray()));
}
return toasts;
}
/// <summary>
/// Cancel all notifications.
/// </summary>
public void CancelAll()
{
var toasts = ToastNotifier.GetScheduledToastNotifications();
foreach (var toast in toasts)
{
ToastNotifier.RemoveFromSchedule(toast);
}
this.ClearAll();
}
/// <summary>
/// Gets all notifications by id. /// Gets all notifications by id.
/// </summary> /// </summary>
/// <returns>List of ids</returns> /// <returns>List of ids</returns>
......
...@@ -50,6 +50,42 @@ namespace LocalNotificationProxy ...@@ -50,6 +50,42 @@ namespace LocalNotificationProxy
} }
/// <summary> /// <summary>
/// Clear the notifications specified by id.
/// </summary>
/// <param name="ids">The IDs of the notification to clear.</param>
/// <returns>The cleared notifications.</returns>
public Options[] Clear([ReadOnlyArray] int[] ids)
{
return this.manager.Clear(ids).ToArray();
}
/// <summary>
/// Clear all notifications.
/// </summary>
public void ClearAll()
{
this.manager.ClearAll();
}
/// <summary>
/// Cancel the notifications specified by id.
/// </summary>
/// <param name="ids">The IDs of the notification to clear.</param>
/// <returns>The cleared notifications.</returns>
public Options[] Cancel([ReadOnlyArray] int[] ids)
{
return this.manager.Cancel(ids).ToArray();
}
/// <summary>
/// Cancel all notifications.
/// </summary>
public void CancelAll()
{
this.manager.CancelAll();
}
/// <summary>
/// Gets the type of the notification specified by ID. /// Gets the type of the notification specified by ID.
/// </summary> /// </summary>
/// <param name="id">The ID of the notification to find for.</param> /// <param name="id">The ID of the notification to find for.</param>
......
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