Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cordova-plugin-local-notifications
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nabil Sadki
cordova-plugin-local-notifications
Commits
25a4cdcd
Commit
25a4cdcd
authored
Aug 15, 2017
by
Sebastián Katzer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ids(), triggeredIds() and scheduledIds() for Windows
parent
ad102c3e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
216 additions
and
24 deletions
+216
-24
LocalNotificationProxy.js
src/windows/LocalNotificationProxy.js
+42
-0
Builder.cs
...Proxy/LocalNotificationProxy/LocalNotification/Builder.cs
+8
-8
Manager.cs
...Proxy/LocalNotificationProxy/LocalNotification/Manager.cs
+113
-0
Notification.cs
.../LocalNotificationProxy/LocalNotification/Notification.cs
+20
-6
LocalNotificationProxy.cs
...ionProxy/LocalNotificationProxy/LocalNotificationProxy.cs
+31
-9
LocalNotificationProxy.csproj
...roxy/LocalNotificationProxy/LocalNotificationProxy.csproj
+2
-1
No files found.
src/windows/LocalNotificationProxy.js
View file @
25a4cdcd
...
@@ -98,6 +98,48 @@ exports.schedule = function (success, error, args) {
...
@@ -98,6 +98,48 @@ exports.schedule = function (success, error, args) {
};
};
/**
/**
* List of all notification ids.
*
* @param [ Function ] success Success callback
* @param [ Function ] error Error callback
*
* @return [ Void ]
*/
exports
.
ids
=
function
(
success
,
error
)
{
var
ids
=
impl
.
ids
()
||
[];
success
(
ids
);
};
/**
* List of all scheduled notification ids.
*
* @param [ Function ] success Success callback
* @param [ Function ] error Error callback
*
* @return [ Void ]
*/
exports
.
scheduledIds
=
function
(
success
,
error
)
{
var
ids
=
impl
.
scheduledIds
()
||
[];
success
(
ids
);
};
/**
* List of all triggered notification ids.
*
* @param [ Function ] success Success callback
* @param [ Function ] error Error callback
*
* @return [ Void ]
*/
exports
.
triggeredIds
=
function
(
success
,
error
)
{
var
ids
=
impl
.
triggeredIds
()
||
[];
success
(
ids
);
};
/**
* Inform the user through the click event that a notification was clicked.
* Inform the user through the click event that a notification was clicked.
*
*
* @param [ String ] xml The launch identifier.
* @param [ String ] xml The launch identifier.
...
...
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/Builder.cs
View file @
25a4cdcd
...
@@ -32,13 +32,13 @@ namespace LocalNotificationProxy.LocalNotification
...
@@ -32,13 +32,13 @@ namespace LocalNotificationProxy.LocalNotification
/// <param name="options">Notification properties to set.</param>
/// <param name="options">Notification properties to set.</param>
internal
Builder
(
Options
options
)
internal
Builder
(
Options
options
)
{
{
this
.
Content
=
new
Content
(
options
);
this
.
Content
=
new
Notification
(
options
);
}
}
/// <summary>
/// <summary>
/// Gets content
/// Gets content
/// </summary>
/// </summary>
public
Content
Content
{
get
;
private
set
;
}
public
Notification
Content
{
get
;
private
set
;
}
/// <summary>
/// <summary>
/// Gets options
/// Gets options
...
@@ -53,10 +53,10 @@ namespace LocalNotificationProxy.LocalNotification
...
@@ -53,10 +53,10 @@ namespace LocalNotificationProxy.LocalNotification
{
{
var
toast
=
this
.
InitToast
();
var
toast
=
this
.
InitToast
();
this
.
AddAttachments
(
toast
);
this
.
AddAttachments
ToToast
(
toast
);
this
.
AddActions
(
toast
);
this
.
AddActions
ToToast
(
toast
);
return
this
.
Get
Notification
(
toast
);
return
this
.
ConvertToastTo
Notification
(
toast
);
}
}
/// <summary>
/// <summary>
...
@@ -103,7 +103,7 @@ namespace LocalNotificationProxy.LocalNotification
...
@@ -103,7 +103,7 @@ namespace LocalNotificationProxy.LocalNotification
/// 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>
private
void
AddAttachments
(
ToastContent
toast
)
private
void
AddAttachments
ToToast
(
ToastContent
toast
)
{
{
foreach
(
var
image
in
this
.
Content
.
Attachments
)
foreach
(
var
image
in
this
.
Content
.
Attachments
)
{
{
...
@@ -115,7 +115,7 @@ namespace LocalNotificationProxy.LocalNotification
...
@@ -115,7 +115,7 @@ namespace LocalNotificationProxy.LocalNotification
/// Adds buttons and input fields to the toast.
/// Adds buttons and input fields to the toast.
/// </summary>
/// </summary>
/// <param name="toast">Tho toast to extend for.</param>
/// <param name="toast">Tho toast to extend for.</param>
private
void
AddActions
(
ToastContent
toast
)
private
void
AddActions
ToToast
(
ToastContent
toast
)
{
{
foreach
(
var
btn
in
this
.
Content
.
Inputs
)
foreach
(
var
btn
in
this
.
Content
.
Inputs
)
{
{
...
@@ -133,7 +133,7 @@ namespace LocalNotificationProxy.LocalNotification
...
@@ -133,7 +133,7 @@ namespace LocalNotificationProxy.LocalNotification
/// </summary>
/// </summary>
/// <param name="toast">The toast to convert.</param>
/// <param name="toast">The toast to convert.</param>
/// <returns>A notification ready to schedule.</returns>
/// <returns>A notification ready to schedule.</returns>
private
ScheduledToastNotification
Get
Notification
(
ToastContent
toast
)
private
ScheduledToastNotification
ConvertToastTo
Notification
(
ToastContent
toast
)
{
{
var
xml
=
toast
.
GetXml
();
var
xml
=
toast
.
GetXml
();
var
at
=
this
.
Content
.
Date
;
var
at
=
this
.
Content
.
Date
;
...
...
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/Manager.cs
0 → 100644
View file @
25a4cdcd
/*
* 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
{
using
System.Collections.Generic
;
using
System.Runtime.InteropServices.WindowsRuntime
;
using
Windows.UI.Notifications
;
internal
class
Manager
{
/// <summary>
/// Gets a value indicating whether the permission to schedule notifications is enabled.
/// </summary>
/// <returns>True if settings are enabled</returns>
public
bool
Enabled
=>
ToastNotifier
.
Setting
==
NotificationSetting
.
Enabled
;
/// <summary>
/// Gets the default toast notifier.
/// </summary>
internal
static
ToastNotifier
ToastNotifier
=>
ToastNotificationManager
.
CreateToastNotifier
();
/// <summary>
/// Schedule notifications.
/// </summary>
/// <param name="notifications">List of key-value properties</param>
public
void
Schedule
([
ReadOnlyArray
]
Options
[]
notifications
)
{
foreach
(
Options
options
in
notifications
)
{
var
toast
=
new
Builder
(
options
).
Build
();
ToastNotifier
.
AddToSchedule
(
toast
);
}
}
/// <summary>
/// Gets all notifications by id.
/// </summary>
/// <returns>List of ids</returns>
public
List
<
int
>
GetIds
()
{
return
this
.
GetIdsByType
(
Notification
.
Type
.
All
);
}
/// <summary>
/// Gets all notifications by id for given type.
/// </summary>
/// <param name="type">The type of notification.</param>
/// <returns>List of ids</returns>
public
List
<
int
>
GetIdsByType
(
Notification
.
Type
type
)
{
var
ids
=
new
List
<
int
>();
if
(
type
==
Notification
.
Type
.
All
||
type
==
Notification
.
Type
.
Scheduled
)
{
var
toasts
=
ToastNotifier
.
GetScheduledToastNotifications
();
foreach
(
var
toast
in
toasts
)
{
ids
.
Add
(
int
.
Parse
(
toast
.
Tag
));
}
}
if
(
type
==
Notification
.
Type
.
All
||
type
==
Notification
.
Type
.
Triggered
)
{
var
toasts
=
ToastNotificationManager
.
History
.
GetHistory
();
foreach
(
var
toast
in
toasts
)
{
ids
.
Add
(
int
.
Parse
(
toast
.
Tag
));
}
}
return
ids
;
}
/// <summary>
/// Gets the notification by ID.
/// </summary>
/// <param name="id">The ID of the notification to find.</param>
/// <returns>The found instance or null.</returns>
private
Notification
Get
(
string
id
)
{
foreach
(
var
toast
in
ToastNotifier
.
GetScheduledToastNotifications
())
{
if
(
toast
.
Id
==
id
)
{
return
new
Notification
(
toast
);
}
}
return
null
;
}
}
}
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/
Content
.cs
→
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotification/
Notification
.cs
View file @
25a4cdcd
...
@@ -3,28 +3,42 @@
...
@@ -3,28 +3,42 @@
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
Microsoft.Toolkit.Uwp.Notifications
;
using
Microsoft.Toolkit.Uwp.Notifications
;
using
Windows.
Data.Xml.Dom
;
using
Windows.
UI.Notifications
;
internal
class
Content
internal
class
Notification
{
{
/// <summary>
/// <summary>
/// Initializes a new instance of the <see cref="
Content
"/> class.
/// Initializes a new instance of the <see cref="
Notification
"/> class.
/// </summary>
/// </summary>
/// <param name="options">The options hash map from JS side.</param>
/// <param name="options">The options hash map from JS side.</param>
public
Content
(
Options
options
)
public
Notification
(
Options
options
)
{
{
this
.
Options
=
options
;
this
.
Options
=
options
;
}
}
/// <summary>
/// <summary>
/// Initializes a new instance of the <see cref="
Content
"/> class.
/// Initializes a new instance of the <see cref="
Notification
"/> class.
/// </summary>
/// </summary>
/// <param name="xml">The options as a xml string.</param>
/// <param name="xml">The options as a xml string.</param>
public
Content
(
string
xml
)
public
Notification
(
string
xml
)
{
{
this
.
Options
=
Options
.
Parse
(
xml
);
this
.
Options
=
Options
.
Parse
(
xml
);
}
}
/// <summary>
/// Initializes a new instance of the <see cref="Notification"/> class.
/// </summary>
/// <param name="toast">The options as a toast object.</param>
public
Notification
(
ScheduledToastNotification
toast
)
{
this
.
Options
=
Options
.
Parse
(
toast
.
Content
.
GetXml
());
}
public
enum
Type
{
All
,
Scheduled
,
Triggered
}
public
Options
Options
{
get
;
private
set
;
}
public
Options
Options
{
get
;
private
set
;
}
/// <summary>
/// <summary>
...
...
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotificationProxy.cs
View file @
25a4cdcd
...
@@ -23,19 +23,18 @@ namespace LocalNotificationProxy
...
@@ -23,19 +23,18 @@ namespace LocalNotificationProxy
{
{
using
System.Runtime.InteropServices.WindowsRuntime
;
using
System.Runtime.InteropServices.WindowsRuntime
;
using
LocalNotification
;
using
LocalNotification
;
using
Windows.UI.Notifications
;
using
Windows.UI.WebUI
;
public
sealed
class
LocalNotificationProxy
public
sealed
class
LocalNotificationProxy
{
{
private
Manager
manager
=
new
Manager
();
/// <summary>
/// <summary>
/// Check permission to schedule notifications.
/// Check permission to schedule notifications.
/// </summary>
/// </summary>
/// <returns>True if settings are enabled</returns>
/// <returns>True if settings are enabled</returns>
public
bool
HasPermission
()
public
bool
HasPermission
()
{
{
NotificationSetting
settings
=
ToastNotificationManager
.
CreateToastNotifier
().
Setting
;
return
this
.
manager
.
Enabled
;
return
settings
==
NotificationSetting
.
Enabled
;
}
}
/// <summary>
/// <summary>
...
@@ -44,11 +43,34 @@ namespace LocalNotificationProxy
...
@@ -44,11 +43,34 @@ namespace LocalNotificationProxy
/// <param name="notifications">List of key-value properties</param>
/// <param name="notifications">List of key-value properties</param>
public
void
Schedule
([
ReadOnlyArray
]
Options
[]
notifications
)
public
void
Schedule
([
ReadOnlyArray
]
Options
[]
notifications
)
{
{
foreach
(
Options
options
in
notifications
)
this
.
manager
.
Schedule
(
notifications
);
{
}
ScheduledToastNotification
notification
=
new
Builder
(
options
).
Build
();
ToastNotificationManager
.
CreateToastNotifier
().
AddToSchedule
(
notification
);
/// <summary>
}
/// List of all notifiation by id.
/// </summary>
/// <returns>List of numbers</returns>
public
int
[]
Ids
()
{
return
this
.
manager
.
GetIds
().
ToArray
();
}
/// <summary>
/// List of all scheduled notifiation by id.
/// </summary>
/// <returns>List of numbers</returns>
public
int
[]
ScheduledIds
()
{
return
this
.
manager
.
GetIdsByType
(
Notification
.
Type
.
Scheduled
).
ToArray
();
}
/// <summary>
/// List of all triggered notifiation by id.
/// </summary>
/// <returns>List of numbers</returns>
public
int
[]
TriggeredIds
()
{
return
this
.
manager
.
GetIdsByType
(
Notification
.
Type
.
Triggered
).
ToArray
();
}
}
}
}
}
}
src/windows/LocalNotificationProxy/LocalNotificationProxy/LocalNotificationProxy.csproj
View file @
25a4cdcd
...
@@ -113,9 +113,10 @@
...
@@ -113,9 +113,10 @@
<Compile Include="LocalNotificationProxy.cs" />
<Compile Include="LocalNotificationProxy.cs" />
<Compile Include="LocalNotification\Builder.cs" />
<Compile Include="LocalNotification\Builder.cs" />
<Compile Include="LocalNotification\Button.cs" />
<Compile Include="LocalNotification\Button.cs" />
<Compile Include="LocalNotification\
Content
.cs" />
<Compile Include="LocalNotification\
Notification
.cs" />
<Compile Include="LocalNotification\IAction.cs" />
<Compile Include="LocalNotification\IAction.cs" />
<Compile Include="LocalNotification\Input.cs" />
<Compile Include="LocalNotification\Input.cs" />
<Compile Include="LocalNotification\Manager.cs" />
<Compile Include="LocalNotification\Options.cs" />
<Compile Include="LocalNotification\Options.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
</ItemGroup>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment