@capacitor/local-notifications 1.0.10 → 4.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/CapacitorLocalNotifications.podspec +1 -1
  3. package/README.md +126 -30
  4. package/android/build.gradle +10 -11
  5. package/android/src/main/java/com/capacitorjs/plugins/localnotifications/DateMatch.java +45 -10
  6. package/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationManager.java +48 -32
  7. package/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationRestoreReceiver.java +2 -1
  8. package/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationSchedule.java +3 -1
  9. package/android/src/main/java/com/capacitorjs/plugins/localnotifications/LocalNotificationsPlugin.java +79 -0
  10. package/android/src/main/java/com/capacitorjs/plugins/localnotifications/NotificationChannelManager.java +2 -6
  11. package/android/src/main/java/com/capacitorjs/plugins/localnotifications/TimedNotificationPublisher.java +6 -1
  12. package/android/src/main/res/drawable/ic_transparent.xml +12 -0
  13. package/dist/docs.json +305 -23
  14. package/dist/esm/definitions.d.ts +141 -4
  15. package/dist/esm/definitions.js +13 -1
  16. package/dist/esm/definitions.js.map +1 -1
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/web.d.ts +5 -1
  19. package/dist/esm/web.js +33 -0
  20. package/dist/esm/web.js.map +1 -1
  21. package/dist/plugin.cjs.js +48 -0
  22. package/dist/plugin.cjs.js.map +1 -1
  23. package/dist/plugin.js +48 -0
  24. package/dist/plugin.js.map +1 -1
  25. package/ios/Plugin/LocalNotificationsPlugin.m +4 -1
  26. package/ios/Plugin/LocalNotificationsPlugin.swift +43 -1
  27. package/package.json +8 -8
package/dist/esm/web.d.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  import type { PermissionState } from '@capacitor/core';
3
- import type { EnabledResult, ListChannelsResult, LocalNotificationSchema, LocalNotificationsPlugin, PendingResult, PermissionStatus, ScheduleOptions, ScheduleResult } from './definitions';
3
+ import type { DeliveredNotifications, EnabledResult, ListChannelsResult, LocalNotificationSchema, LocalNotificationsPlugin, PendingResult, PermissionStatus, ScheduleOptions, ScheduleResult } from './definitions';
4
4
  export declare class LocalNotificationsWeb extends WebPlugin implements LocalNotificationsPlugin {
5
5
  protected pending: LocalNotificationSchema[];
6
+ protected deliveredNotifications: Notification[];
7
+ getDeliveredNotifications(): Promise<DeliveredNotifications>;
8
+ removeDeliveredNotifications(delivered: DeliveredNotifications): Promise<void>;
9
+ removeAllDeliveredNotifications(): Promise<void>;
6
10
  createChannel(): Promise<void>;
7
11
  deleteChannel(): Promise<void>;
8
12
  listChannels(): Promise<ListChannelsResult>;
package/dist/esm/web.js CHANGED
@@ -3,6 +3,7 @@ export class LocalNotificationsWeb extends WebPlugin {
3
3
  constructor() {
4
4
  super(...arguments);
5
5
  this.pending = [];
6
+ this.deliveredNotifications = [];
6
7
  this.hasNotificationSupport = () => {
7
8
  if (!('Notification' in window) || !Notification.requestPermission) {
8
9
  return false;
@@ -22,6 +23,33 @@ export class LocalNotificationsWeb extends WebPlugin {
22
23
  return true;
23
24
  };
24
25
  }
26
+ async getDeliveredNotifications() {
27
+ const deliveredSchemas = [];
28
+ for (const notification of this.deliveredNotifications) {
29
+ const deliveredSchema = {
30
+ title: notification.title,
31
+ id: parseInt(notification.tag),
32
+ body: notification.body,
33
+ };
34
+ deliveredSchemas.push(deliveredSchema);
35
+ }
36
+ return {
37
+ notifications: deliveredSchemas,
38
+ };
39
+ }
40
+ async removeDeliveredNotifications(delivered) {
41
+ for (const toRemove of delivered.notifications) {
42
+ const found = this.deliveredNotifications.find(n => n.tag === String(toRemove.id));
43
+ found === null || found === void 0 ? void 0 : found.close();
44
+ this.deliveredNotifications = this.deliveredNotifications.filter(() => !found);
45
+ }
46
+ }
47
+ async removeAllDeliveredNotifications() {
48
+ for (const notification of this.deliveredNotifications) {
49
+ notification.close();
50
+ }
51
+ this.deliveredNotifications = [];
52
+ }
25
53
  async createChannel() {
26
54
  throw this.unimplemented('Not implemented on web.');
27
55
  }
@@ -113,9 +141,14 @@ export class LocalNotificationsWeb extends WebPlugin {
113
141
  buildNotification(notification) {
114
142
  const localNotification = new Notification(notification.title, {
115
143
  body: notification.body,
144
+ tag: String(notification.id),
116
145
  });
117
146
  localNotification.addEventListener('click', this.onClick.bind(this, notification), false);
118
147
  localNotification.addEventListener('show', this.onShow.bind(this, notification), false);
148
+ localNotification.addEventListener('close', () => {
149
+ this.deliveredNotifications = this.deliveredNotifications.filter(() => !this);
150
+ }, false);
151
+ this.deliveredNotifications.push(localNotification);
119
152
  return localNotification;
120
153
  }
121
154
  onClick(notification) {
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAc5C,MAAM,OAAO,qBACX,SAAQ,SAAS;IADnB;;QAIY,YAAO,GAA8B,EAAE,CAAC;QA+ExC,2BAAsB,GAAG,GAAY,EAAE;YAC/C,IAAI,CAAC,CAAC,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAAE;gBAClE,OAAO,KAAK,CAAC;aACd;YAED,IAAI,YAAY,CAAC,UAAU,KAAK,SAAS,EAAE;gBACzC,2EAA2E;gBAC3E,iEAAiE;gBACjE,IAAI;oBACF,IAAI,YAAY,CAAC,EAAE,CAAC,CAAC;iBACtB;gBAAC,OAAO,CAAC,EAAE;oBACV,IAAI,CAAC,CAAC,IAAI,IAAI,WAAW,EAAE;wBACzB,OAAO,KAAK,CAAC;qBACd;iBACF;aACF;YAED,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;IA6EJ,CAAC;IA5KC,KAAK,CAAC,aAAa;QACjB,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IACtD,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AAI,YAAY,CAAC,YAAY,CAAC,KAAK,EAAE;YAC7D,IAAI,EAAE,YAAY,CAAC,IAAI;YACvB,GAAG,EAAE,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;SAC7B,CAAC,CAAC;QACH,iBAAiB,CAAC,gBAAgB,CAChC,OAAO,EACP,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,EACrC,KAAK,CACN,CAAC;QACF,iBAAiB,CAAC,gBAAgB,CAChC,MAAM,EACN,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,EACpC,KAAK,CACN,CAAC;QACF,iBAAiB,CAAC,gBAAgB,CAChC,OAAO,EACP,GAAG,EAAE;YACH,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAC9D,GAAG,EAAE,CAAC,CAAC,IAAI,CACZ,CAAC;QACJ,CAAC,EACD,KAAK,CACN,CAAC;QACF,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACpD,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAES,OAAO,CAAC,YAAqC;QACrD,MAAM,IAAI,GAAG;YACX,QAAQ,EAAE,KAAK;YACf,YAAY;SACb,CAAC;QACF,IAAI,CAAC,eAAe,CAAC,kCAAkC,EAAE,IAAI,CAAC,CAAC;IACjE,CAAC;IAES,MAAM,CAAC,YAAqC;QACpD,IAAI,CAAC,eAAe,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;IAClE,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport type { PermissionState } from '@capacitor/core';\n\nimport type {\n DeliveredNotifications,\n EnabledResult,\n ListChannelsResult,\n LocalNotificationSchema,\n LocalNotificationsPlugin,\n PendingResult,\n PermissionStatus,\n ScheduleOptions,\n ScheduleResult,\n} from './definitions';\n\nexport class LocalNotificationsWeb\n extends WebPlugin\n implements LocalNotificationsPlugin\n{\n protected pending: LocalNotificationSchema[] = [];\n protected deliveredNotifications: Notification[] = [];\n\n async getDeliveredNotifications(): Promise<DeliveredNotifications> {\n const deliveredSchemas = [];\n for (const notification of this.deliveredNotifications) {\n const deliveredSchema: LocalNotificationSchema = {\n title: notification.title,\n id: parseInt(notification.tag),\n body: notification.body,\n };\n deliveredSchemas.push(deliveredSchema);\n }\n return {\n notifications: deliveredSchemas,\n };\n }\n async removeDeliveredNotifications(\n delivered: DeliveredNotifications,\n ): Promise<void> {\n for (const toRemove of delivered.notifications) {\n const found = this.deliveredNotifications.find(\n n => n.tag === String(toRemove.id),\n );\n found?.close();\n this.deliveredNotifications = this.deliveredNotifications.filter(\n () => !found,\n );\n }\n }\n async removeAllDeliveredNotifications(): Promise<void> {\n for (const notification of this.deliveredNotifications) {\n notification.close();\n }\n this.deliveredNotifications = [];\n }\n async createChannel(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async deleteChannel(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async listChannels(): Promise<ListChannelsResult> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async schedule(options: ScheduleOptions): Promise<ScheduleResult> {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n\n for (const notification of options.notifications) {\n this.sendNotification(notification);\n }\n\n return {\n notifications: options.notifications.map(notification => ({\n id: notification.id,\n })),\n };\n }\n\n async getPending(): Promise<PendingResult> {\n return {\n notifications: this.pending,\n };\n }\n\n async registerActionTypes(): Promise<void> {\n throw this.unimplemented('Not implemented on web.');\n }\n\n async cancel(pending: ScheduleResult): Promise<void> {\n this.pending = this.pending.filter(\n notification =>\n !pending.notifications.find(n => n.id === notification.id),\n );\n }\n\n async areEnabled(): Promise<EnabledResult> {\n const { display } = await this.checkPermissions();\n\n return {\n value: display === 'granted',\n };\n }\n\n async requestPermissions(): Promise<PermissionStatus> {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n\n const display = this.transformNotificationPermission(\n await Notification.requestPermission(),\n );\n\n return { display };\n }\n\n async checkPermissions(): Promise<PermissionStatus> {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n\n const display = this.transformNotificationPermission(\n Notification.permission,\n );\n\n return { display };\n }\n\n protected hasNotificationSupport = (): boolean => {\n if (!('Notification' in window) || !Notification.requestPermission) {\n return false;\n }\n\n if (Notification.permission !== 'granted') {\n // don't test for `new Notification` if permission has already been granted\n // otherwise this sends a real notification on supported browsers\n try {\n new Notification('');\n } catch (e) {\n if (e.name == 'TypeError') {\n return false;\n }\n }\n }\n\n return true;\n };\n\n protected transformNotificationPermission(\n permission: NotificationPermission,\n ): PermissionState {\n switch (permission) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n }\n\n protected sendPending(): void {\n const toRemove: LocalNotificationSchema[] = [];\n const now = new Date().getTime();\n\n for (const notification of this.pending) {\n if (\n notification.schedule?.at &&\n notification.schedule.at.getTime() <= now\n ) {\n this.buildNotification(notification);\n toRemove.push(notification);\n }\n }\n\n this.pending = this.pending.filter(\n notification => !toRemove.find(n => n === notification),\n );\n }\n\n protected sendNotification(notification: LocalNotificationSchema): void {\n if (notification.schedule?.at) {\n const diff = notification.schedule.at.getTime() - new Date().getTime();\n\n this.pending.push(notification);\n setTimeout(() => {\n this.sendPending();\n }, diff);\n return;\n }\n this.buildNotification(notification);\n }\n\n protected buildNotification(\n notification: LocalNotificationSchema,\n ): Notification {\n const localNotification = new Notification(notification.title, {\n body: notification.body,\n tag: String(notification.id),\n });\n localNotification.addEventListener(\n 'click',\n this.onClick.bind(this, notification),\n false,\n );\n localNotification.addEventListener(\n 'show',\n this.onShow.bind(this, notification),\n false,\n );\n localNotification.addEventListener(\n 'close',\n () => {\n this.deliveredNotifications = this.deliveredNotifications.filter(\n () => !this,\n );\n },\n false,\n );\n this.deliveredNotifications.push(localNotification);\n return localNotification;\n }\n\n protected onClick(notification: LocalNotificationSchema): void {\n const data = {\n actionId: 'tap',\n notification,\n };\n this.notifyListeners('localNotificationActionPerformed', data);\n }\n\n protected onShow(notification: LocalNotificationSchema): void {\n this.notifyListeners('localNotificationReceived', notification);\n }\n}\n"]}
@@ -4,6 +4,21 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@capacitor/core');
6
6
 
7
+ /// <reference types="@capacitor/cli" />
8
+ /**
9
+ * Day of the week. Used for scheduling notifications on a particular weekday.
10
+ */
11
+ exports.Weekday = void 0;
12
+ (function (Weekday) {
13
+ Weekday[Weekday["Sunday"] = 1] = "Sunday";
14
+ Weekday[Weekday["Monday"] = 2] = "Monday";
15
+ Weekday[Weekday["Tuesday"] = 3] = "Tuesday";
16
+ Weekday[Weekday["Wednesday"] = 4] = "Wednesday";
17
+ Weekday[Weekday["Thursday"] = 5] = "Thursday";
18
+ Weekday[Weekday["Friday"] = 6] = "Friday";
19
+ Weekday[Weekday["Saturday"] = 7] = "Saturday";
20
+ })(exports.Weekday || (exports.Weekday = {}));
21
+
7
22
  const LocalNotifications = core.registerPlugin('LocalNotifications', {
8
23
  web: () => Promise.resolve().then(function () { return web; }).then(m => new m.LocalNotificationsWeb()),
9
24
  });
@@ -12,6 +27,7 @@ class LocalNotificationsWeb extends core.WebPlugin {
12
27
  constructor() {
13
28
  super(...arguments);
14
29
  this.pending = [];
30
+ this.deliveredNotifications = [];
15
31
  this.hasNotificationSupport = () => {
16
32
  if (!('Notification' in window) || !Notification.requestPermission) {
17
33
  return false;
@@ -31,6 +47,33 @@ class LocalNotificationsWeb extends core.WebPlugin {
31
47
  return true;
32
48
  };
33
49
  }
50
+ async getDeliveredNotifications() {
51
+ const deliveredSchemas = [];
52
+ for (const notification of this.deliveredNotifications) {
53
+ const deliveredSchema = {
54
+ title: notification.title,
55
+ id: parseInt(notification.tag),
56
+ body: notification.body,
57
+ };
58
+ deliveredSchemas.push(deliveredSchema);
59
+ }
60
+ return {
61
+ notifications: deliveredSchemas,
62
+ };
63
+ }
64
+ async removeDeliveredNotifications(delivered) {
65
+ for (const toRemove of delivered.notifications) {
66
+ const found = this.deliveredNotifications.find(n => n.tag === String(toRemove.id));
67
+ found === null || found === void 0 ? void 0 : found.close();
68
+ this.deliveredNotifications = this.deliveredNotifications.filter(() => !found);
69
+ }
70
+ }
71
+ async removeAllDeliveredNotifications() {
72
+ for (const notification of this.deliveredNotifications) {
73
+ notification.close();
74
+ }
75
+ this.deliveredNotifications = [];
76
+ }
34
77
  async createChannel() {
35
78
  throw this.unimplemented('Not implemented on web.');
36
79
  }
@@ -122,9 +165,14 @@ class LocalNotificationsWeb extends core.WebPlugin {
122
165
  buildNotification(notification) {
123
166
  const localNotification = new Notification(notification.title, {
124
167
  body: notification.body,
168
+ tag: String(notification.id),
125
169
  });
126
170
  localNotification.addEventListener('click', this.onClick.bind(this, notification), false);
127
171
  localNotification.addEventListener('show', this.onShow.bind(this, notification), false);
172
+ localNotification.addEventListener('close', () => {
173
+ this.deliveredNotifications = this.deliveredNotifications.filter(() => !this);
174
+ }, false);
175
+ this.deliveredNotifications.push(localNotification);
128
176
  return localNotification;
129
177
  }
130
178
  onClick(notification) {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst LocalNotifications = registerPlugin('LocalNotifications', {\n web: () => import('./web').then(m => new m.LocalNotificationsWeb()),\n});\nexport * from './definitions';\nexport { LocalNotifications };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class LocalNotificationsWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.pending = [];\n this.hasNotificationSupport = () => {\n if (!('Notification' in window) || !Notification.requestPermission) {\n return false;\n }\n if (Notification.permission !== 'granted') {\n // don't test for `new Notification` if permission has already been granted\n // otherwise this sends a real notification on supported browsers\n try {\n new Notification('');\n }\n catch (e) {\n if (e.name == 'TypeError') {\n return false;\n }\n }\n }\n return true;\n };\n }\n async createChannel() {\n throw this.unimplemented('Not implemented on web.');\n }\n async deleteChannel() {\n throw this.unimplemented('Not implemented on web.');\n }\n async listChannels() {\n throw this.unimplemented('Not implemented on web.');\n }\n async schedule(options) {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n for (const notification of options.notifications) {\n this.sendNotification(notification);\n }\n return {\n notifications: options.notifications.map(notification => ({\n id: notification.id,\n })),\n };\n }\n async getPending() {\n return {\n notifications: this.pending,\n };\n }\n async registerActionTypes() {\n throw this.unimplemented('Not implemented on web.');\n }\n async cancel(pending) {\n this.pending = this.pending.filter(notification => !pending.notifications.find(n => n.id === notification.id));\n }\n async areEnabled() {\n const { display } = await this.checkPermissions();\n return {\n value: display === 'granted',\n };\n }\n async requestPermissions() {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n const display = this.transformNotificationPermission(await Notification.requestPermission());\n return { display };\n }\n async checkPermissions() {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n const display = this.transformNotificationPermission(Notification.permission);\n return { display };\n }\n transformNotificationPermission(permission) {\n switch (permission) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n }\n sendPending() {\n var _a;\n const toRemove = [];\n const now = new Date().getTime();\n for (const notification of this.pending) {\n if (((_a = notification.schedule) === null || _a === void 0 ? void 0 : _a.at) &&\n notification.schedule.at.getTime() <= now) {\n this.buildNotification(notification);\n toRemove.push(notification);\n }\n }\n this.pending = this.pending.filter(notification => !toRemove.find(n => n === notification));\n }\n sendNotification(notification) {\n var _a;\n if ((_a = notification.schedule) === null || _a === void 0 ? void 0 : _a.at) {\n const diff = notification.schedule.at.getTime() - new Date().getTime();\n this.pending.push(notification);\n setTimeout(() => {\n this.sendPending();\n }, diff);\n return;\n }\n this.buildNotification(notification);\n }\n buildNotification(notification) {\n const localNotification = new Notification(notification.title, {\n body: notification.body,\n });\n localNotification.addEventListener('click', this.onClick.bind(this, notification), false);\n localNotification.addEventListener('show', this.onShow.bind(this, notification), false);\n return localNotification;\n }\n onClick(notification) {\n const data = {\n actionId: 'tap',\n notification,\n };\n this.notifyListeners('localNotificationActionPerformed', data);\n }\n onShow(notification) {\n this.notifyListeners('localNotificationReceived', notification);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;AAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;AACvE,CAAC;;ACFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;AACrD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC,CAAC;AAC5B,QAAQ,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;AAC1B,QAAQ,IAAI,CAAC,sBAAsB,GAAG,MAAM;AAC5C,YAAY,IAAI,EAAE,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAAE;AAChF,gBAAgB,OAAO,KAAK,CAAC;AAC7B,aAAa;AACb,YAAY,IAAI,YAAY,CAAC,UAAU,KAAK,SAAS,EAAE;AACvD;AACA;AACA,gBAAgB,IAAI;AACpB,oBAAoB,IAAI,YAAY,CAAC,EAAE,CAAC,CAAC;AACzC,iBAAiB;AACjB,gBAAgB,OAAO,CAAC,EAAE;AAC1B,oBAAoB,IAAI,CAAC,CAAC,IAAI,IAAI,WAAW,EAAE;AAC/C,wBAAwB,OAAO,KAAK,CAAC;AACrC,qBAAqB;AACrB,iBAAiB;AACjB,aAAa;AACb,YAAY,OAAO,IAAI,CAAC;AACxB,SAAS,CAAC;AACV,KAAK;AACL,IAAI,MAAM,aAAa,GAAG;AAC1B,Q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AiB,CAAC,YAAY,CAAC,CAAC;AAC7C,KAAK;AACL,IAAI,iBAAiB,CAAC,YAAY,EAAE;AACpC,QAAQ,MAAM,iBAAiB,GAAG,IAAI,YAAY,CAAC,YAAY,CAAC,KAAK,EAAE;AACvE,YAAY,IAAI,EAAE,YAAY,CAAC,IAAI;AACnC,SAAS,CAAC,CAAC;AACX,QAAQ,iBAAiB,CAAC,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE,KAAK,CAAC,CAAC;AAClG,QAAQ,iBAAiB,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,EAAE,KAAK,CAAC,CAAC;AAChG,QAAQ,OAAO,iBAAiB,CAAC;AACjC,KAAK;AACL,IAAI,OAAO,CAAC,YAAY,EAAE;AAC1B,QAAQ,MAAM,IAAI,GAAG;AACrB,YAAY,QAAQ,EAAE,KAAK;AAC3B,YAAY,YAAY;AACxB,SAAS,CAAC;AACV,QAAQ,IAAI,CAAC,eAAe,CAAC,kCAAkC,EAAE,IAAI,CAAC,CAAC;AACvE,KAAK;AACL,IAAI,MAAM,CAAC,YAAY,EAAE;AACzB,QAAQ,IAAI,CAAC,eAAe,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;AACxE,KAAK;AACL;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n/**\n * Day of the week. Used for scheduling notifications on a particular weekday.\n */\nexport var Weekday;\n(function (Weekday) {\n Weekday[Weekday[\"Sunday\"] = 1] = \"Sunday\";\n Weekday[Weekday[\"Monday\"] = 2] = \"Monday\";\n Weekday[Weekday[\"Tuesday\"] = 3] = \"Tuesday\";\n Weekday[Weekday[\"Wednesday\"] = 4] = \"Wednesday\";\n Weekday[Weekday[\"Thursday\"] = 5] = \"Thursday\";\n Weekday[Weekday[\"Friday\"] = 6] = \"Friday\";\n Weekday[Weekday[\"Saturday\"] = 7] = \"Saturday\";\n})(Weekday || (Weekday = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst LocalNotifications = registerPlugin('LocalNotifications', {\n web: () => import('./web').then(m => new m.LocalNotificationsWeb()),\n});\nexport * from './definitions';\nexport { LocalNotifications };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class LocalNotificationsWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.pending = [];\n this.deliveredNotifications = [];\n this.hasNotificationSupport = () => {\n if (!('Notification' in window) || !Notification.requestPermission) {\n return false;\n }\n if (Notification.permission !== 'granted') {\n // don't test for `new Notification` if permission has already been granted\n // otherwise this sends a real notification on supported browsers\n try {\n new Notification('');\n }\n catch (e) {\n if (e.name == 'TypeError') {\n return false;\n }\n }\n }\n return true;\n };\n }\n async getDeliveredNotifications() {\n const deliveredSchemas = [];\n for (const notification of this.deliveredNotifications) {\n const deliveredSchema = {\n title: notification.title,\n id: parseInt(notification.tag),\n body: notification.body,\n };\n deliveredSchemas.push(deliveredSchema);\n }\n return {\n notifications: deliveredSchemas,\n };\n }\n async removeDeliveredNotifications(delivered) {\n for (const toRemove of delivered.notifications) {\n const found = this.deliveredNotifications.find(n => n.tag === String(toRemove.id));\n found === null || found === void 0 ? void 0 : found.close();\n this.deliveredNotifications = this.deliveredNotifications.filter(() => !found);\n }\n }\n async removeAllDeliveredNotifications() {\n for (const notification of this.deliveredNotifications) {\n notification.close();\n }\n this.deliveredNotifications = [];\n }\n async createChannel() {\n throw this.unimplemented('Not implemented on web.');\n }\n async deleteChannel() {\n throw this.unimplemented('Not implemented on web.');\n }\n async listChannels() {\n throw this.unimplemented('Not implemented on web.');\n }\n async schedule(options) {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n for (const notification of options.notifications) {\n this.sendNotification(notification);\n }\n return {\n notifications: options.notifications.map(notification => ({\n id: notification.id,\n })),\n };\n }\n async getPending() {\n return {\n notifications: this.pending,\n };\n }\n async registerActionTypes() {\n throw this.unimplemented('Not implemented on web.');\n }\n async cancel(pending) {\n this.pending = this.pending.filter(notification => !pending.notifications.find(n => n.id === notification.id));\n }\n async areEnabled() {\n const { display } = await this.checkPermissions();\n return {\n value: display === 'granted',\n };\n }\n async requestPermissions() {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n const display = this.transformNotificationPermission(await Notification.requestPermission());\n return { display };\n }\n async checkPermissions() {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n const display = this.transformNotificationPermission(Notification.permission);\n return { display };\n }\n transformNotificationPermission(permission) {\n switch (permission) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n }\n sendPending() {\n var _a;\n const toRemove = [];\n const now = new Date().getTime();\n for (const notification of this.pending) {\n if (((_a = notification.schedule) === null || _a === void 0 ? void 0 : _a.at) &&\n notification.schedule.at.getTime() <= now) {\n this.buildNotification(notification);\n toRemove.push(notification);\n }\n }\n this.pending = this.pending.filter(notification => !toRemove.find(n => n === notification));\n }\n sendNotification(notification) {\n var _a;\n if ((_a = notification.schedule) === null || _a === void 0 ? void 0 : _a.at) {\n const diff = notification.schedule.at.getTime() - new Date().getTime();\n this.pending.push(notification);\n setTimeout(() => {\n this.sendPending();\n }, diff);\n return;\n }\n this.buildNotification(notification);\n }\n buildNotification(notification) {\n const localNotification = new Notification(notification.title, {\n body: notification.body,\n tag: String(notification.id),\n });\n localNotification.addEventListener('click', this.onClick.bind(this, notification), false);\n localNotification.addEventListener('show', this.onShow.bind(this, notification), false);\n localNotification.addEventListener('close', () => {\n this.deliveredNotifications = this.deliveredNotifications.filter(() => !this);\n }, false);\n this.deliveredNotifications.push(localNotification);\n return localNotification;\n }\n onClick(notification) {\n const data = {\n actionId: 'tap',\n notification,\n };\n this.notifyListeners('localNotificationActionPerformed', data);\n }\n onShow(notification) {\n this.notifyListeners('localNotificationReceived', notification);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["Weekday","registerPlugin","WebPlugin"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACWA,yBAAQ;AACnB,CAAC,UAAU,OAAO,EAAE;AACpB,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;AAC9C,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;AAC9C,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;AAChD,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;AACpD,IAAI,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC;AAClD,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;AAC9C,IAAI,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC;AAClD,CAAC,EAAEA,eAAO,KAAKA,eAAO,GAAG,EAAE,CAAC,CAAC;;ACZxB,MAAC,kBAAkB,GAAGC,mBAAc,CAAC,oBAAoB,EAAE;AAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;AACvE,CAAC;;ACFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;AACrD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC,CAAC;AAC5B,QAAQ,IAAI,CAAC,OAAO,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C,OAAO,EAAE,MAAM;AAC1D,YAAY,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC1F,SAAS,EAAE,KAAK,CAAC,CAAC;AAClB,QAAQ,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;AAC5D,QAAQ,OAAO,iBAAiB,CAAC;AACjC,KAAK;AACL,IAAI,OAAO,CAAC,YAAY,EAAE;AAC1B,QAAQ,MAAM,IAAI,GAAG;AACrB,YAAY,QAAQ,EAAE,KAAK;AAC3B,YAAY,YAAY;AACxB,SAAS,CAAC;AACV,QAAQ,IAAI,CAAC,eAAe,CAAC,kCAAkC,EAAE,IAAI,CAAC,CAAC;AACvE,KAAK;AACL,IAAI,MAAM,CAAC,YAAY,EAAE;AACzB,QAAQ,IAAI,CAAC,eAAe,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;AACxE,KAAK;AACL;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -1,6 +1,21 @@
1
1
  var capacitorLocalNotifications = (function (exports, core) {
2
2
  'use strict';
3
3
 
4
+ /// <reference types="@capacitor/cli" />
5
+ /**
6
+ * Day of the week. Used for scheduling notifications on a particular weekday.
7
+ */
8
+ exports.Weekday = void 0;
9
+ (function (Weekday) {
10
+ Weekday[Weekday["Sunday"] = 1] = "Sunday";
11
+ Weekday[Weekday["Monday"] = 2] = "Monday";
12
+ Weekday[Weekday["Tuesday"] = 3] = "Tuesday";
13
+ Weekday[Weekday["Wednesday"] = 4] = "Wednesday";
14
+ Weekday[Weekday["Thursday"] = 5] = "Thursday";
15
+ Weekday[Weekday["Friday"] = 6] = "Friday";
16
+ Weekday[Weekday["Saturday"] = 7] = "Saturday";
17
+ })(exports.Weekday || (exports.Weekday = {}));
18
+
4
19
  const LocalNotifications = core.registerPlugin('LocalNotifications', {
5
20
  web: () => Promise.resolve().then(function () { return web; }).then(m => new m.LocalNotificationsWeb()),
6
21
  });
@@ -9,6 +24,7 @@ var capacitorLocalNotifications = (function (exports, core) {
9
24
  constructor() {
10
25
  super(...arguments);
11
26
  this.pending = [];
27
+ this.deliveredNotifications = [];
12
28
  this.hasNotificationSupport = () => {
13
29
  if (!('Notification' in window) || !Notification.requestPermission) {
14
30
  return false;
@@ -28,6 +44,33 @@ var capacitorLocalNotifications = (function (exports, core) {
28
44
  return true;
29
45
  };
30
46
  }
47
+ async getDeliveredNotifications() {
48
+ const deliveredSchemas = [];
49
+ for (const notification of this.deliveredNotifications) {
50
+ const deliveredSchema = {
51
+ title: notification.title,
52
+ id: parseInt(notification.tag),
53
+ body: notification.body,
54
+ };
55
+ deliveredSchemas.push(deliveredSchema);
56
+ }
57
+ return {
58
+ notifications: deliveredSchemas,
59
+ };
60
+ }
61
+ async removeDeliveredNotifications(delivered) {
62
+ for (const toRemove of delivered.notifications) {
63
+ const found = this.deliveredNotifications.find(n => n.tag === String(toRemove.id));
64
+ found === null || found === void 0 ? void 0 : found.close();
65
+ this.deliveredNotifications = this.deliveredNotifications.filter(() => !found);
66
+ }
67
+ }
68
+ async removeAllDeliveredNotifications() {
69
+ for (const notification of this.deliveredNotifications) {
70
+ notification.close();
71
+ }
72
+ this.deliveredNotifications = [];
73
+ }
31
74
  async createChannel() {
32
75
  throw this.unimplemented('Not implemented on web.');
33
76
  }
@@ -119,9 +162,14 @@ var capacitorLocalNotifications = (function (exports, core) {
119
162
  buildNotification(notification) {
120
163
  const localNotification = new Notification(notification.title, {
121
164
  body: notification.body,
165
+ tag: String(notification.id),
122
166
  });
123
167
  localNotification.addEventListener('click', this.onClick.bind(this, notification), false);
124
168
  localNotification.addEventListener('show', this.onShow.bind(this, notification), false);
169
+ localNotification.addEventListener('close', () => {
170
+ this.deliveredNotifications = this.deliveredNotifications.filter(() => !this);
171
+ }, false);
172
+ this.deliveredNotifications.push(localNotification);
125
173
  return localNotification;
126
174
  }
127
175
  onClick(notification) {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst LocalNotifications = registerPlugin('LocalNotifications', {\n web: () => import('./web').then(m => new m.LocalNotificationsWeb()),\n});\nexport * from './definitions';\nexport { LocalNotifications };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class LocalNotificationsWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.pending = [];\n this.hasNotificationSupport = () => {\n if (!('Notification' in window) || !Notification.requestPermission) {\n return false;\n }\n if (Notification.permission !== 'granted') {\n // don't test for `new Notification` if permission has already been granted\n // otherwise this sends a real notification on supported browsers\n try {\n new Notification('');\n }\n catch (e) {\n if (e.name == 'TypeError') {\n return false;\n }\n }\n }\n return true;\n };\n }\n async createChannel() {\n throw this.unimplemented('Not implemented on web.');\n }\n async deleteChannel() {\n throw this.unimplemented('Not implemented on web.');\n }\n async listChannels() {\n throw this.unimplemented('Not implemented on web.');\n }\n async schedule(options) {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n for (const notification of options.notifications) {\n this.sendNotification(notification);\n }\n return {\n notifications: options.notifications.map(notification => ({\n id: notification.id,\n })),\n };\n }\n async getPending() {\n return {\n notifications: this.pending,\n };\n }\n async registerActionTypes() {\n throw this.unimplemented('Not implemented on web.');\n }\n async cancel(pending) {\n this.pending = this.pending.filter(notification => !pending.notifications.find(n => n.id === notification.id));\n }\n async areEnabled() {\n const { display } = await this.checkPermissions();\n return {\n value: display === 'granted',\n };\n }\n async requestPermissions() {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n const display = this.transformNotificationPermission(await Notification.requestPermission());\n return { display };\n }\n async checkPermissions() {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n const display = this.transformNotificationPermission(Notification.permission);\n return { display };\n }\n transformNotificationPermission(permission) {\n switch (permission) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n }\n sendPending() {\n var _a;\n const toRemove = [];\n const now = new Date().getTime();\n for (const notification of this.pending) {\n if (((_a = notification.schedule) === null || _a === void 0 ? void 0 : _a.at) &&\n notification.schedule.at.getTime() <= now) {\n this.buildNotification(notification);\n toRemove.push(notification);\n }\n }\n this.pending = this.pending.filter(notification => !toRemove.find(n => n === notification));\n }\n sendNotification(notification) {\n var _a;\n if ((_a = notification.schedule) === null || _a === void 0 ? void 0 : _a.at) {\n const diff = notification.schedule.at.getTime() - new Date().getTime();\n this.pending.push(notification);\n setTimeout(() => {\n this.sendPending();\n }, diff);\n return;\n }\n this.buildNotification(notification);\n }\n buildNotification(notification) {\n const localNotification = new Notification(notification.title, {\n body: notification.body,\n });\n localNotification.addEventListener('click', this.onClick.bind(this, notification), false);\n localNotification.addEventListener('show', this.onShow.bind(this, notification), false);\n return localNotification;\n }\n onClick(notification) {\n const data = {\n actionId: 'tap',\n notification,\n };\n this.notifyListeners('localNotificationActionPerformed', data);\n }\n onShow(notification) {\n this.notifyListeners('localNotificationReceived', notification);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;IAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;IACvE,CAAC;;ICFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;IACrD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC,CAAC;IAC5B,QAAQ,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IAC1B,QAAQ,IAAI,CAAC,sBAAsB,GAAG,MAAM;IAC5C,YAAY,IAAI,EAAE,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAA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CAAC,YAAY,EAAE;IACzB,QAAQ,IAAI,CAAC,eAAe,CAAC,2BAA2B,EAAE,YAAY,CAAC,CAAC;IACxE,KAAK;IACL;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n/**\n * Day of the week. Used for scheduling notifications on a particular weekday.\n */\nexport var Weekday;\n(function (Weekday) {\n Weekday[Weekday[\"Sunday\"] = 1] = \"Sunday\";\n Weekday[Weekday[\"Monday\"] = 2] = \"Monday\";\n Weekday[Weekday[\"Tuesday\"] = 3] = \"Tuesday\";\n Weekday[Weekday[\"Wednesday\"] = 4] = \"Wednesday\";\n Weekday[Weekday[\"Thursday\"] = 5] = \"Thursday\";\n Weekday[Weekday[\"Friday\"] = 6] = \"Friday\";\n Weekday[Weekday[\"Saturday\"] = 7] = \"Saturday\";\n})(Weekday || (Weekday = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst LocalNotifications = registerPlugin('LocalNotifications', {\n web: () => import('./web').then(m => new m.LocalNotificationsWeb()),\n});\nexport * from './definitions';\nexport { LocalNotifications };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class LocalNotificationsWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.pending = [];\n this.deliveredNotifications = [];\n this.hasNotificationSupport = () => {\n if (!('Notification' in window) || !Notification.requestPermission) {\n return false;\n }\n if (Notification.permission !== 'granted') {\n // don't test for `new Notification` if permission has already been granted\n // otherwise this sends a real notification on supported browsers\n try {\n new Notification('');\n }\n catch (e) {\n if (e.name == 'TypeError') {\n return false;\n }\n }\n }\n return true;\n };\n }\n async getDeliveredNotifications() {\n const deliveredSchemas = [];\n for (const notification of this.deliveredNotifications) {\n const deliveredSchema = {\n title: notification.title,\n id: parseInt(notification.tag),\n body: notification.body,\n };\n deliveredSchemas.push(deliveredSchema);\n }\n return {\n notifications: deliveredSchemas,\n };\n }\n async removeDeliveredNotifications(delivered) {\n for (const toRemove of delivered.notifications) {\n const found = this.deliveredNotifications.find(n => n.tag === String(toRemove.id));\n found === null || found === void 0 ? void 0 : found.close();\n this.deliveredNotifications = this.deliveredNotifications.filter(() => !found);\n }\n }\n async removeAllDeliveredNotifications() {\n for (const notification of this.deliveredNotifications) {\n notification.close();\n }\n this.deliveredNotifications = [];\n }\n async createChannel() {\n throw this.unimplemented('Not implemented on web.');\n }\n async deleteChannel() {\n throw this.unimplemented('Not implemented on web.');\n }\n async listChannels() {\n throw this.unimplemented('Not implemented on web.');\n }\n async schedule(options) {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n for (const notification of options.notifications) {\n this.sendNotification(notification);\n }\n return {\n notifications: options.notifications.map(notification => ({\n id: notification.id,\n })),\n };\n }\n async getPending() {\n return {\n notifications: this.pending,\n };\n }\n async registerActionTypes() {\n throw this.unimplemented('Not implemented on web.');\n }\n async cancel(pending) {\n this.pending = this.pending.filter(notification => !pending.notifications.find(n => n.id === notification.id));\n }\n async areEnabled() {\n const { display } = await this.checkPermissions();\n return {\n value: display === 'granted',\n };\n }\n async requestPermissions() {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n const display = this.transformNotificationPermission(await Notification.requestPermission());\n return { display };\n }\n async checkPermissions() {\n if (!this.hasNotificationSupport()) {\n throw this.unavailable('Notifications not supported in this browser.');\n }\n const display = this.transformNotificationPermission(Notification.permission);\n return { display };\n }\n transformNotificationPermission(permission) {\n switch (permission) {\n case 'granted':\n return 'granted';\n case 'denied':\n return 'denied';\n default:\n return 'prompt';\n }\n }\n sendPending() {\n var _a;\n const toRemove = [];\n const now = new Date().getTime();\n for (const notification of this.pending) {\n if (((_a = notification.schedule) === null || _a === void 0 ? void 0 : _a.at) &&\n notification.schedule.at.getTime() <= now) {\n this.buildNotification(notification);\n toRemove.push(notification);\n }\n }\n this.pending = this.pending.filter(notification => !toRemove.find(n => n === notification));\n }\n sendNotification(notification) {\n var _a;\n if ((_a = notification.schedule) === null || _a === void 0 ? void 0 : _a.at) {\n const diff = notification.schedule.at.getTime() - new Date().getTime();\n this.pending.push(notification);\n setTimeout(() => {\n this.sendPending();\n }, diff);\n return;\n }\n this.buildNotification(notification);\n }\n buildNotification(notification) {\n const localNotification = new Notification(notification.title, {\n body: notification.body,\n tag: String(notification.id),\n });\n localNotification.addEventListener('click', this.onClick.bind(this, notification), false);\n localNotification.addEventListener('show', this.onShow.bind(this, notification), false);\n localNotification.addEventListener('close', () => {\n this.deliveredNotifications = this.deliveredNotifications.filter(() => !this);\n }, false);\n this.deliveredNotifications.push(localNotification);\n return localNotification;\n }\n onClick(notification) {\n const data = {\n actionId: 'tap',\n notification,\n };\n this.notifyListeners('localNotificationActionPerformed', data);\n }\n onShow(notification) {\n this.notifyListeners('localNotificationReceived', notification);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["Weekday","registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;IACA;AACWA,6BAAQ;IACnB,CAAC,UAAU,OAAO,EAAE;IACpB,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;IAC9C,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;IAC9C,IAAI,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;IAChD,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,WAAW,CAAC;IACpD,IAAI,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC;IAClD,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC;IAC9C,IAAI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OD(registerActionTypes, CAPPluginReturnPromise);
11
11
  CAP_PLUGIN_METHOD(areEnabled, CAPPluginReturnPromise);
12
+ CAP_PLUGIN_METHOD(getDeliveredNotifications, CAPPluginReturnPromise);
13
+ CAP_PLUGIN_METHOD(removeAllDeliveredNotifications, CAPPluginReturnPromise);
14
+ CAP_PLUGIN_METHOD(removeDeliveredNotifications, CAPPluginReturnPromise);
12
15
  CAP_PLUGIN_METHOD(createChannel, CAPPluginReturnPromise);
13
16
  CAP_PLUGIN_METHOD(deleteChannel, CAPPluginReturnPromise);
14
17
  CAP_PLUGIN_METHOD(listChannels, CAPPluginReturnPromise);
15
- CAP_PLUGIN_METHOD(removeAllListeners, CAPPluginReturnNone);
18
+ CAP_PLUGIN_METHOD(removeAllListeners, CAPPluginReturnPromise);
16
19
  )
@@ -227,7 +227,7 @@ public class LocalNotificationsPlugin: CAPPlugin {
227
227
  content.threadIdentifier = threadIdentifier
228
228
  }
229
229
 
230
- if #available(iOS 12, *), let summaryArgument = notification["summaryArgument"] as? String {
230
+ if let summaryArgument = notification["summaryArgument"] as? String {
231
231
  content.summaryArgument = summaryArgument
232
232
  }
233
233
 
@@ -318,6 +318,9 @@ public class LocalNotificationsPlugin: CAPPlugin {
318
318
  if let second = at["second"] as? Int {
319
319
  dateInfo.second = second
320
320
  }
321
+ if let weekday = at["weekday"] as? Int {
322
+ dateInfo.weekday = weekday
323
+ }
321
324
  return dateInfo
322
325
  }
323
326
 
@@ -546,6 +549,45 @@ public class LocalNotificationsPlugin: CAPPlugin {
546
549
  return opts
547
550
  }
548
551
 
552
+ /**
553
+ * Get notifications in Notification Center
554
+ */
555
+ @objc func getDeliveredNotifications(_ call: CAPPluginCall) {
556
+ UNUserNotificationCenter.current().getDeliveredNotifications(completionHandler: { (notifications) in
557
+ let ret = notifications.map({ (notification) -> [String: Any] in
558
+ return self.notificationDelegationHandler.makeNotificationRequestJSObject(notification.request)
559
+ })
560
+ call.resolve([
561
+ "notifications": ret
562
+ ])
563
+ })
564
+ }
565
+
566
+ /**
567
+ * Remove specified notifications from Notification Center
568
+ */
569
+ @objc func removeDeliveredNotifications(_ call: CAPPluginCall) {
570
+ guard let notifications = call.getArray("notifications", JSObject.self) else {
571
+ call.reject("Must supply notifications to remove")
572
+ return
573
+ }
574
+
575
+ let ids = notifications.map { "\($0["id"] ?? "")" }
576
+ UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: ids)
577
+ call.resolve()
578
+ }
579
+
580
+ /**
581
+ * Remove all notifications from Notification Center
582
+ */
583
+ @objc func removeAllDeliveredNotifications(_ call: CAPPluginCall) {
584
+ UNUserNotificationCenter.current().removeAllDeliveredNotifications()
585
+ DispatchQueue.main.async(execute: {
586
+ UIApplication.shared.applicationIconBadgeNumber = 0
587
+ })
588
+ call.resolve()
589
+ }
590
+
549
591
  @objc func createChannel(_ call: CAPPluginCall) {
550
592
  call.unimplemented()
551
593
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/local-notifications",
3
- "version": "1.0.10",
3
+ "version": "4.0.0-beta.2",
4
4
  "description": "The Local Notifications API provides a way to schedule device notifications locally (i.e. without a server sending push notifications).",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "scripts": {
31
31
  "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
32
- "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..",
32
+ "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
33
33
  "verify:android": "cd android && ./gradlew clean build test && cd ..",
34
34
  "verify:web": "npm run build",
35
35
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
@@ -45,11 +45,11 @@
45
45
  "publish:cocoapod": "pod trunk push ./CapacitorLocalNotifications.podspec --allow-warnings"
46
46
  },
47
47
  "devDependencies": {
48
- "@capacitor/android": "^3.0.0",
49
- "@capacitor/cli": "^3.0.0",
50
- "@capacitor/core": "^3.0.0",
48
+ "@capacitor/android": "next",
49
+ "@capacitor/cli": "next",
50
+ "@capacitor/core": "next",
51
51
  "@capacitor/docgen": "0.0.18",
52
- "@capacitor/ios": "^3.0.0",
52
+ "@capacitor/ios": "next",
53
53
  "@ionic/eslint-config": "^0.3.0",
54
54
  "@ionic/prettier-config": "~1.0.1",
55
55
  "@ionic/swiftlint-config": "^1.1.2",
@@ -62,7 +62,7 @@
62
62
  "typescript": "~4.1.5"
63
63
  },
64
64
  "peerDependencies": {
65
- "@capacitor/core": "^3.0.0"
65
+ "@capacitor/core": "next"
66
66
  },
67
67
  "prettier": "@ionic/prettier-config",
68
68
  "swiftlint": "@ionic/swiftlint-config",
@@ -80,5 +80,5 @@
80
80
  "publishConfig": {
81
81
  "access": "public"
82
82
  },
83
- "gitHead": "e5b333320426ee120d4504c68c02bd5538b21c51"
83
+ "gitHead": "32240b675c12a774920c07a86b4483ecec7a9c8d"
84
84
  }