@choochmeque/tauri-plugin-notifications-api 0.3.0 → 0.3.4

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.
package/dist-js/index.cjs CHANGED
@@ -145,6 +145,24 @@ async function requestPermission() {
145
145
  async function registerForPushNotifications() {
146
146
  return await core.invoke("plugin:notifications|register_for_push_notifications");
147
147
  }
148
+ /**
149
+ * Unregisters the app from push notifications (mobile).
150
+ *
151
+ * This removes the device's push notification token and stops receiving
152
+ * remote push notifications.
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * import { unregisterForPushNotifications } from '@choochmeque/tauri-plugin-notifications-api';
157
+ * await unregisterForPushNotifications();
158
+ * console.log('Unregistered from push notifications');
159
+ * ```
160
+ *
161
+ * @returns A promise resolving when unregistration is complete.
162
+ */
163
+ async function unregisterForPushNotifications() {
164
+ return await core.invoke("plugin:notifications|unregister_for_push_notifications");
165
+ }
148
166
  /**
149
167
  * Sends a notification to the user.
150
168
  * @example
@@ -361,6 +379,42 @@ async function onNotificationReceived(cb) {
361
379
  async function onAction(cb) {
362
380
  return await core.addPluginListener("notifications", "actionPerformed", cb);
363
381
  }
382
+ /**
383
+ * Registers a listener for notification click/tap events.
384
+ * This fires when the user taps on a notification (both push and local).
385
+ *
386
+ * This function handles cold-start scenarios where the app is launched by
387
+ * tapping a notification. Any pending notification click data is automatically
388
+ * delivered when the listener is registered.
389
+ *
390
+ * @example
391
+ * ```typescript
392
+ * import { onNotificationClicked } from '@choochmeque/tauri-plugin-notifications-api';
393
+ * const unlisten = await onNotificationClicked((data) => {
394
+ * console.log('Notification clicked, id:', data.id);
395
+ * console.log('Custom data:', data.data);
396
+ * });
397
+ * ```
398
+ *
399
+ * @param cb - Callback function to handle notification clicks.
400
+ * @returns A promise resolving to a function that removes the listener.
401
+ */
402
+ async function onNotificationClicked(cb) {
403
+ const listener = await core.addPluginListener("notifications", "notificationClicked", cb);
404
+ // Tell native side listener is active (triggers pending if any)
405
+ await core.invoke("plugin:notifications|set_click_listener_active", {
406
+ active: true,
407
+ });
408
+ // Return wrapped listener that notifies native side on unregister
409
+ return {
410
+ unregister: async () => {
411
+ await core.invoke("plugin:notifications|set_click_listener_active", {
412
+ active: false,
413
+ });
414
+ return listener.unregister();
415
+ },
416
+ };
417
+ }
364
418
 
365
419
  exports.Schedule = Schedule;
366
420
  exports.active = active;
@@ -370,6 +424,7 @@ exports.channels = channels;
370
424
  exports.createChannel = createChannel;
371
425
  exports.isPermissionGranted = isPermissionGranted;
372
426
  exports.onAction = onAction;
427
+ exports.onNotificationClicked = onNotificationClicked;
373
428
  exports.onNotificationReceived = onNotificationReceived;
374
429
  exports.pending = pending;
375
430
  exports.registerActionTypes = registerActionTypes;
@@ -379,3 +434,4 @@ exports.removeAllActive = removeAllActive;
379
434
  exports.removeChannel = removeChannel;
380
435
  exports.requestPermission = requestPermission;
381
436
  exports.sendNotification = sendNotification;
437
+ exports.unregisterForPushNotifications = unregisterForPushNotifications;
@@ -387,6 +387,22 @@ declare function requestPermission(): Promise<NotificationPermission>;
387
387
  * @returns A promise resolving to the device push token.
388
388
  */
389
389
  declare function registerForPushNotifications(): Promise<string>;
390
+ /**
391
+ * Unregisters the app from push notifications (mobile).
392
+ *
393
+ * This removes the device's push notification token and stops receiving
394
+ * remote push notifications.
395
+ *
396
+ * @example
397
+ * ```typescript
398
+ * import { unregisterForPushNotifications } from '@choochmeque/tauri-plugin-notifications-api';
399
+ * await unregisterForPushNotifications();
400
+ * console.log('Unregistered from push notifications');
401
+ * ```
402
+ *
403
+ * @returns A promise resolving when unregistration is complete.
404
+ */
405
+ declare function unregisterForPushNotifications(): Promise<string>;
390
406
  /**
391
407
  * Sends a notification to the user.
392
408
  * @example
@@ -574,5 +590,35 @@ declare function onNotificationReceived(cb: (notification: Options) => void): Pr
574
590
  * @returns A promise resolving to a function that removes the listener.
575
591
  */
576
592
  declare function onAction(cb: (notification: Options) => void): Promise<PluginListener>;
577
- export type { Attachment, Options, Action, ActionType, PendingNotification, ActiveNotification, Channel, ScheduleInterval, };
578
- export { Importance, Visibility, sendNotification, requestPermission, isPermissionGranted, registerForPushNotifications, registerActionTypes, pending, cancel, cancelAll, active, removeActive, removeAllActive, createChannel, removeChannel, channels, onNotificationReceived, onAction, Schedule, ScheduleEvery, };
593
+ /**
594
+ * Data received when a notification is clicked/tapped.
595
+ */
596
+ interface NotificationClickedData {
597
+ /** Notification ID */
598
+ id: number;
599
+ /** Custom data payload attached to the notification */
600
+ data?: Record<string, string>;
601
+ }
602
+ /**
603
+ * Registers a listener for notification click/tap events.
604
+ * This fires when the user taps on a notification (both push and local).
605
+ *
606
+ * This function handles cold-start scenarios where the app is launched by
607
+ * tapping a notification. Any pending notification click data is automatically
608
+ * delivered when the listener is registered.
609
+ *
610
+ * @example
611
+ * ```typescript
612
+ * import { onNotificationClicked } from '@choochmeque/tauri-plugin-notifications-api';
613
+ * const unlisten = await onNotificationClicked((data) => {
614
+ * console.log('Notification clicked, id:', data.id);
615
+ * console.log('Custom data:', data.data);
616
+ * });
617
+ * ```
618
+ *
619
+ * @param cb - Callback function to handle notification clicks.
620
+ * @returns A promise resolving to a function that removes the listener.
621
+ */
622
+ declare function onNotificationClicked(cb: (data: NotificationClickedData) => void): Promise<PluginListener>;
623
+ export type { Attachment, Options, Action, ActionType, PendingNotification, ActiveNotification, Channel, ScheduleInterval, NotificationClickedData, };
624
+ export { Importance, Visibility, sendNotification, requestPermission, isPermissionGranted, registerForPushNotifications, unregisterForPushNotifications, registerActionTypes, pending, cancel, cancelAll, active, removeActive, removeAllActive, createChannel, removeChannel, channels, onNotificationReceived, onAction, onNotificationClicked, Schedule, ScheduleEvery, };
package/dist-js/index.js CHANGED
@@ -143,6 +143,24 @@ async function requestPermission() {
143
143
  async function registerForPushNotifications() {
144
144
  return await invoke("plugin:notifications|register_for_push_notifications");
145
145
  }
146
+ /**
147
+ * Unregisters the app from push notifications (mobile).
148
+ *
149
+ * This removes the device's push notification token and stops receiving
150
+ * remote push notifications.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * import { unregisterForPushNotifications } from '@choochmeque/tauri-plugin-notifications-api';
155
+ * await unregisterForPushNotifications();
156
+ * console.log('Unregistered from push notifications');
157
+ * ```
158
+ *
159
+ * @returns A promise resolving when unregistration is complete.
160
+ */
161
+ async function unregisterForPushNotifications() {
162
+ return await invoke("plugin:notifications|unregister_for_push_notifications");
163
+ }
146
164
  /**
147
165
  * Sends a notification to the user.
148
166
  * @example
@@ -359,5 +377,41 @@ async function onNotificationReceived(cb) {
359
377
  async function onAction(cb) {
360
378
  return await addPluginListener("notifications", "actionPerformed", cb);
361
379
  }
380
+ /**
381
+ * Registers a listener for notification click/tap events.
382
+ * This fires when the user taps on a notification (both push and local).
383
+ *
384
+ * This function handles cold-start scenarios where the app is launched by
385
+ * tapping a notification. Any pending notification click data is automatically
386
+ * delivered when the listener is registered.
387
+ *
388
+ * @example
389
+ * ```typescript
390
+ * import { onNotificationClicked } from '@choochmeque/tauri-plugin-notifications-api';
391
+ * const unlisten = await onNotificationClicked((data) => {
392
+ * console.log('Notification clicked, id:', data.id);
393
+ * console.log('Custom data:', data.data);
394
+ * });
395
+ * ```
396
+ *
397
+ * @param cb - Callback function to handle notification clicks.
398
+ * @returns A promise resolving to a function that removes the listener.
399
+ */
400
+ async function onNotificationClicked(cb) {
401
+ const listener = await addPluginListener("notifications", "notificationClicked", cb);
402
+ // Tell native side listener is active (triggers pending if any)
403
+ await invoke("plugin:notifications|set_click_listener_active", {
404
+ active: true,
405
+ });
406
+ // Return wrapped listener that notifies native side on unregister
407
+ return {
408
+ unregister: async () => {
409
+ await invoke("plugin:notifications|set_click_listener_active", {
410
+ active: false,
411
+ });
412
+ return listener.unregister();
413
+ },
414
+ };
415
+ }
362
416
 
363
- export { Importance, Schedule, ScheduleEvery, Visibility, active, cancel, cancelAll, channels, createChannel, isPermissionGranted, onAction, onNotificationReceived, pending, registerActionTypes, registerForPushNotifications, removeActive, removeAllActive, removeChannel, requestPermission, sendNotification };
417
+ export { Importance, Schedule, ScheduleEvery, Visibility, active, cancel, cancelAll, channels, createChannel, isPermissionGranted, onAction, onNotificationClicked, onNotificationReceived, pending, registerActionTypes, registerForPushNotifications, removeActive, removeAllActive, removeChannel, requestPermission, sendNotification, unregisterForPushNotifications };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@choochmeque/tauri-plugin-notifications-api",
3
- "version": "0.3.0",
3
+ "version": "0.3.4",
4
4
  "license": "MIT",
5
5
  "author": "You",
6
6
  "description": "A Tauri v2 plugin for sending notifications on desktop and mobile platforms with support for system notifications and push delivery via FCM and APNs.",
@@ -41,7 +41,7 @@
41
41
  "rollup": "^4.52.4",
42
42
  "tslib": "^2.6.2",
43
43
  "typescript": "^5.3.3",
44
- "prettier": "3.7.3",
44
+ "prettier": "3.7.4",
45
45
  "vitest": "^2.1.8"
46
46
  },
47
47
  "scripts": {