@choochmeque/tauri-plugin-notifications-api 0.3.1 → 0.4.0

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/README.md CHANGED
@@ -45,7 +45,7 @@ Add the plugin to your Tauri project's `Cargo.toml`:
45
45
 
46
46
  ```toml
47
47
  [dependencies]
48
- tauri-plugin-notifications = "0.3"
48
+ tauri-plugin-notifications = "0.4"
49
49
  ```
50
50
 
51
51
  ### Push Notifications Feature
@@ -68,6 +68,33 @@ Without this feature enabled:
68
68
  - Push notification registration code is disabled
69
69
  - The `registerForPushNotifications()` function will return an error if called
70
70
 
71
+ ### Desktop Notification Backend (notify-rust)
72
+
73
+ The `notify-rust` feature is **enabled by default** and provides cross-platform desktop notifications using the [notify-rust](https://crates.io/crates/notify-rust) crate.
74
+
75
+ **When to use notify-rust (default):**
76
+ - Simple notifications on Linux, macOS, and Windows
77
+ - Cross-platform consistency
78
+ - Basic notification features (title, body, icon)
79
+
80
+ **When to disable notify-rust:**
81
+ - You need native Windows toast notifications with advanced features (actions, hero images, scheduling)
82
+ - You want platform-specific notification features on macOS/Windows
83
+
84
+ To disable `notify-rust` and use native platform implementations:
85
+
86
+ ```toml
87
+ [dependencies]
88
+ tauri-plugin-notifications = { version = "0.3", default-features = false }
89
+ ```
90
+
91
+ To disable `notify-rust` and enable push notifications:
92
+
93
+ ```toml
94
+ [dependencies]
95
+ tauri-plugin-notifications = { version = "0.3", default-features = false, features = ["push-notifications"] }
96
+ ```
97
+
71
98
  Configure the plugin permissions in your `capabilities/default.json`:
72
99
 
73
100
  ```json
@@ -89,6 +116,24 @@ fn main() {
89
116
  }
90
117
  ```
91
118
 
119
+ ## Example App
120
+
121
+ An example app is available in [`examples/notifications-demo`](examples/notifications-demo) demonstrating all plugin features:
122
+
123
+ - Permission management and push notifications (mobile)
124
+ - Basic, scheduled, and styled notifications
125
+ - Interactive notifications with action buttons
126
+ - Notification channels (Android)
127
+ - Pending and active notification management
128
+ - Event listeners with logging
129
+
130
+ **Run it:**
131
+ ```bash
132
+ cd examples/notifications-demo
133
+ pnpm install
134
+ pnpm tauri dev
135
+ ```
136
+
92
137
  ## Usage
93
138
 
94
139
  ### JavaScript/TypeScript
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
@@ -230,7 +248,7 @@ async function cancel(notifications) {
230
248
  * @returns A promise indicating the success or failure of the operation.
231
249
  */
232
250
  async function cancelAll() {
233
- await core.invoke("plugin:notifications|cancel");
251
+ await core.invoke("plugin:notifications|cancel_all");
234
252
  }
235
253
  /**
236
254
  * Retrieves the list of active notifications.
@@ -293,7 +311,7 @@ async function removeAllActive() {
293
311
  * @returns A promise indicating the success or failure of the operation.
294
312
  */
295
313
  async function createChannel(channel) {
296
- await core.invoke("plugin:notifications|create_channel", { ...channel });
314
+ await core.invoke("plugin:notifications|create_channel", { channel });
297
315
  }
298
316
  /**
299
317
  * Removes the channel with the given identifier.
@@ -321,7 +339,7 @@ async function removeChannel(id) {
321
339
  * @returns A promise resolving to the list of notification channels.
322
340
  */
323
341
  async function channels() {
324
- return await core.invoke("plugin:notifications|listChannels");
342
+ return await core.invoke("plugin:notifications|list_channels");
325
343
  }
326
344
  /**
327
345
  * Registers a listener for incoming notifications.
@@ -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
@@ -228,7 +246,7 @@ async function cancel(notifications) {
228
246
  * @returns A promise indicating the success or failure of the operation.
229
247
  */
230
248
  async function cancelAll() {
231
- await invoke("plugin:notifications|cancel");
249
+ await invoke("plugin:notifications|cancel_all");
232
250
  }
233
251
  /**
234
252
  * Retrieves the list of active notifications.
@@ -291,7 +309,7 @@ async function removeAllActive() {
291
309
  * @returns A promise indicating the success or failure of the operation.
292
310
  */
293
311
  async function createChannel(channel) {
294
- await invoke("plugin:notifications|create_channel", { ...channel });
312
+ await invoke("plugin:notifications|create_channel", { channel });
295
313
  }
296
314
  /**
297
315
  * Removes the channel with the given identifier.
@@ -319,7 +337,7 @@ async function removeChannel(id) {
319
337
  * @returns A promise resolving to the list of notification channels.
320
338
  */
321
339
  async function channels() {
322
- return await invoke("plugin:notifications|listChannels");
340
+ return await invoke("plugin:notifications|list_channels");
323
341
  }
324
342
  /**
325
343
  * Registers a listener for incoming notifications.
@@ -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.1",
3
+ "version": "0.4.0",
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": {