@choochmeque/tauri-plugin-notifications-api 0.1.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/LICENSE +21 -0
- package/README.md +550 -0
- package/dist-js/index.cjs +319 -0
- package/dist-js/index.d.ts +456 -0
- package/dist-js/index.js +302 -0
- package/package.json +51 -0
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Send toast notifications (brief auto-expiring OS window element) to your user.
|
|
3
|
+
* Can also be used with the Notification Web API.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { type PluginListener } from "@tauri-apps/api/core";
|
|
8
|
+
export type { PermissionState } from "@tauri-apps/api/core";
|
|
9
|
+
/**
|
|
10
|
+
* Options to send a notification.
|
|
11
|
+
*
|
|
12
|
+
* @since 2.0.0
|
|
13
|
+
*/
|
|
14
|
+
interface Options {
|
|
15
|
+
/**
|
|
16
|
+
* The notification identifier to reference this object later. Must be a 32-bit integer.
|
|
17
|
+
*/
|
|
18
|
+
id?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Identifier of the {@link Channel} that deliveres this notification.
|
|
21
|
+
*
|
|
22
|
+
* If the channel does not exist, the notification won't fire.
|
|
23
|
+
* Make sure the channel exists with {@link listChannels} and {@link createChannel}.
|
|
24
|
+
*/
|
|
25
|
+
channelId?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Notification title.
|
|
28
|
+
*/
|
|
29
|
+
title: string;
|
|
30
|
+
/**
|
|
31
|
+
* Optional notification body.
|
|
32
|
+
* */
|
|
33
|
+
body?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Schedule this notification to fire on a later time or a fixed interval.
|
|
36
|
+
*/
|
|
37
|
+
schedule?: Schedule;
|
|
38
|
+
/**
|
|
39
|
+
* Multiline text.
|
|
40
|
+
* Changes the notification style to big text.
|
|
41
|
+
* Cannot be used with `inboxLines`.
|
|
42
|
+
*/
|
|
43
|
+
largeBody?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Detail text for the notification with `largeBody`, `inboxLines` or `groupSummary`.
|
|
46
|
+
*/
|
|
47
|
+
summary?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Defines an action type for this notification.
|
|
50
|
+
*/
|
|
51
|
+
actionTypeId?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Identifier used to group multiple notifications.
|
|
54
|
+
*
|
|
55
|
+
* https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent/1649872-threadidentifier
|
|
56
|
+
*/
|
|
57
|
+
group?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Instructs the system that this notification is the summary of a group on Android.
|
|
60
|
+
*/
|
|
61
|
+
groupSummary?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* The sound resource name. Only available on mobile.
|
|
64
|
+
*/
|
|
65
|
+
sound?: string;
|
|
66
|
+
/**
|
|
67
|
+
* List of lines to add to the notification.
|
|
68
|
+
* Changes the notification style to inbox.
|
|
69
|
+
* Cannot be used with `largeBody`.
|
|
70
|
+
*
|
|
71
|
+
* Only supports up to 5 lines.
|
|
72
|
+
*/
|
|
73
|
+
inboxLines?: string[];
|
|
74
|
+
/**
|
|
75
|
+
* Notification icon.
|
|
76
|
+
*
|
|
77
|
+
* On Android the icon must be placed in the app's `res/drawable` folder.
|
|
78
|
+
*/
|
|
79
|
+
icon?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Notification large icon (Android).
|
|
82
|
+
*
|
|
83
|
+
* The icon must be placed in the app's `res/drawable` folder.
|
|
84
|
+
*/
|
|
85
|
+
largeIcon?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Icon color on Android.
|
|
88
|
+
*/
|
|
89
|
+
iconColor?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Notification attachments.
|
|
92
|
+
*/
|
|
93
|
+
attachments?: Attachment[];
|
|
94
|
+
/**
|
|
95
|
+
* Extra payload to store in the notification.
|
|
96
|
+
*/
|
|
97
|
+
extra?: Record<string, unknown>;
|
|
98
|
+
/**
|
|
99
|
+
* If true, the notification cannot be dismissed by the user on Android.
|
|
100
|
+
*
|
|
101
|
+
* An application service must manage the dismissal of the notification.
|
|
102
|
+
* It is typically used to indicate a background task that is pending (e.g. a file download)
|
|
103
|
+
* or the user is engaged with (e.g. playing music).
|
|
104
|
+
*/
|
|
105
|
+
ongoing?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Automatically cancel the notification when the user clicks on it.
|
|
108
|
+
*/
|
|
109
|
+
autoCancel?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Changes the notification presentation to be silent on iOS (no badge, no sound, not listed).
|
|
112
|
+
*/
|
|
113
|
+
silent?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Notification visibility.
|
|
116
|
+
*/
|
|
117
|
+
visibility?: Visibility;
|
|
118
|
+
/**
|
|
119
|
+
* Sets the number of items this notification represents on Android.
|
|
120
|
+
*/
|
|
121
|
+
number?: number;
|
|
122
|
+
}
|
|
123
|
+
interface ScheduleInterval {
|
|
124
|
+
year?: number;
|
|
125
|
+
month?: number;
|
|
126
|
+
day?: number;
|
|
127
|
+
/**
|
|
128
|
+
* 1 - Sunday
|
|
129
|
+
* 2 - Monday
|
|
130
|
+
* 3 - Tuesday
|
|
131
|
+
* 4 - Wednesday
|
|
132
|
+
* 5 - Thursday
|
|
133
|
+
* 6 - Friday
|
|
134
|
+
* 7 - Saturday
|
|
135
|
+
*/
|
|
136
|
+
weekday?: number;
|
|
137
|
+
hour?: number;
|
|
138
|
+
minute?: number;
|
|
139
|
+
second?: number;
|
|
140
|
+
}
|
|
141
|
+
declare enum ScheduleEvery {
|
|
142
|
+
Year = "year",
|
|
143
|
+
Month = "month",
|
|
144
|
+
TwoWeeks = "twoWeeks",
|
|
145
|
+
Week = "week",
|
|
146
|
+
Day = "day",
|
|
147
|
+
Hour = "hour",
|
|
148
|
+
Minute = "minute",
|
|
149
|
+
/**
|
|
150
|
+
* Not supported on iOS.
|
|
151
|
+
*/
|
|
152
|
+
Second = "second"
|
|
153
|
+
}
|
|
154
|
+
declare class Schedule {
|
|
155
|
+
at: {
|
|
156
|
+
date: Date;
|
|
157
|
+
repeating: boolean;
|
|
158
|
+
allowWhileIdle: boolean;
|
|
159
|
+
} | undefined;
|
|
160
|
+
interval: {
|
|
161
|
+
interval: ScheduleInterval;
|
|
162
|
+
allowWhileIdle: boolean;
|
|
163
|
+
} | undefined;
|
|
164
|
+
every: {
|
|
165
|
+
interval: ScheduleEvery;
|
|
166
|
+
count: number;
|
|
167
|
+
allowWhileIdle: boolean;
|
|
168
|
+
} | undefined;
|
|
169
|
+
static at(date: Date, repeating?: boolean, allowWhileIdle?: boolean): Schedule;
|
|
170
|
+
static interval(interval: ScheduleInterval, allowWhileIdle?: boolean): Schedule;
|
|
171
|
+
static every(kind: ScheduleEvery, count: number, allowWhileIdle?: boolean): Schedule;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Attachment of a notification.
|
|
175
|
+
*/
|
|
176
|
+
interface Attachment {
|
|
177
|
+
/** Attachment identifier. */
|
|
178
|
+
id: string;
|
|
179
|
+
/** Attachment URL. Accepts the `asset` and `file` protocols. */
|
|
180
|
+
url: string;
|
|
181
|
+
}
|
|
182
|
+
interface Action {
|
|
183
|
+
id: string;
|
|
184
|
+
title: string;
|
|
185
|
+
requiresAuthentication?: boolean;
|
|
186
|
+
foreground?: boolean;
|
|
187
|
+
destructive?: boolean;
|
|
188
|
+
input?: boolean;
|
|
189
|
+
inputButtonTitle?: string;
|
|
190
|
+
inputPlaceholder?: string;
|
|
191
|
+
}
|
|
192
|
+
interface ActionType {
|
|
193
|
+
/**
|
|
194
|
+
* The identifier of this action type
|
|
195
|
+
*/
|
|
196
|
+
id: string;
|
|
197
|
+
/**
|
|
198
|
+
* The list of associated actions
|
|
199
|
+
*/
|
|
200
|
+
actions: Action[];
|
|
201
|
+
hiddenPreviewsBodyPlaceholder?: string;
|
|
202
|
+
customDismissAction?: boolean;
|
|
203
|
+
allowInCarPlay?: boolean;
|
|
204
|
+
hiddenPreviewsShowTitle?: boolean;
|
|
205
|
+
hiddenPreviewsShowSubtitle?: boolean;
|
|
206
|
+
}
|
|
207
|
+
interface PendingNotification {
|
|
208
|
+
id: number;
|
|
209
|
+
title?: string;
|
|
210
|
+
body?: string;
|
|
211
|
+
schedule: Schedule;
|
|
212
|
+
}
|
|
213
|
+
interface ActiveNotification {
|
|
214
|
+
id: number;
|
|
215
|
+
tag?: string;
|
|
216
|
+
title?: string;
|
|
217
|
+
body?: string;
|
|
218
|
+
group?: string;
|
|
219
|
+
groupSummary: boolean;
|
|
220
|
+
data: Record<string, string>;
|
|
221
|
+
extra: Record<string, unknown>;
|
|
222
|
+
attachments: Attachment[];
|
|
223
|
+
actionTypeId?: string;
|
|
224
|
+
schedule?: Schedule;
|
|
225
|
+
sound?: string;
|
|
226
|
+
}
|
|
227
|
+
declare enum Importance {
|
|
228
|
+
None = 0,
|
|
229
|
+
Min = 1,
|
|
230
|
+
Low = 2,
|
|
231
|
+
Default = 3,
|
|
232
|
+
High = 4
|
|
233
|
+
}
|
|
234
|
+
declare enum Visibility {
|
|
235
|
+
Secret = -1,
|
|
236
|
+
Private = 0,
|
|
237
|
+
Public = 1
|
|
238
|
+
}
|
|
239
|
+
interface Channel {
|
|
240
|
+
id: string;
|
|
241
|
+
name: string;
|
|
242
|
+
description?: string;
|
|
243
|
+
sound?: string;
|
|
244
|
+
lights?: boolean;
|
|
245
|
+
lightColor?: string;
|
|
246
|
+
vibration?: boolean;
|
|
247
|
+
importance?: Importance;
|
|
248
|
+
visibility?: Visibility;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Checks if the permission to send notifications is granted.
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* import { isPermissionGranted } from '@tauri-apps/plugin-notification';
|
|
255
|
+
* const permissionGranted = await isPermissionGranted();
|
|
256
|
+
* ```
|
|
257
|
+
*
|
|
258
|
+
* @since 2.0.0
|
|
259
|
+
*/
|
|
260
|
+
declare function isPermissionGranted(): Promise<boolean>;
|
|
261
|
+
/**
|
|
262
|
+
* Requests the permission to send notifications.
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* import { isPermissionGranted, requestPermission } from '@tauri-apps/plugin-notification';
|
|
266
|
+
* let permissionGranted = await isPermissionGranted();
|
|
267
|
+
* if (!permissionGranted) {
|
|
268
|
+
* const permission = await requestPermission();
|
|
269
|
+
* permissionGranted = permission === 'granted';
|
|
270
|
+
* }
|
|
271
|
+
* ```
|
|
272
|
+
*
|
|
273
|
+
* @returns A promise resolving to whether the user granted the permission or not.
|
|
274
|
+
*
|
|
275
|
+
* @since 2.0.0
|
|
276
|
+
*/
|
|
277
|
+
declare function requestPermission(): Promise<NotificationPermission>;
|
|
278
|
+
/**
|
|
279
|
+
* Sends a notification to the user.
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/plugin-notification';
|
|
283
|
+
* let permissionGranted = await isPermissionGranted();
|
|
284
|
+
* if (!permissionGranted) {
|
|
285
|
+
* const permission = await requestPermission();
|
|
286
|
+
* permissionGranted = permission === 'granted';
|
|
287
|
+
* }
|
|
288
|
+
* if (permissionGranted) {
|
|
289
|
+
* sendNotification('Tauri is awesome!');
|
|
290
|
+
* sendNotification({ title: 'TAURI', body: 'Tauri is awesome!' });
|
|
291
|
+
* }
|
|
292
|
+
* ```
|
|
293
|
+
*
|
|
294
|
+
* @since 2.0.0
|
|
295
|
+
*/
|
|
296
|
+
declare function sendNotification(options: Options | string): Promise<void>;
|
|
297
|
+
/**
|
|
298
|
+
* Register actions that are performed when the user clicks on the notification.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```typescript
|
|
302
|
+
* import { registerActionTypes } from '@tauri-apps/plugin-notification';
|
|
303
|
+
* await registerActionTypes([{
|
|
304
|
+
* id: 'tauri',
|
|
305
|
+
* actions: [{
|
|
306
|
+
* id: 'my-action',
|
|
307
|
+
* title: 'Settings'
|
|
308
|
+
* }]
|
|
309
|
+
* }])
|
|
310
|
+
* ```
|
|
311
|
+
*
|
|
312
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
313
|
+
*
|
|
314
|
+
* @since 2.0.0
|
|
315
|
+
*/
|
|
316
|
+
declare function registerActionTypes(types: ActionType[]): Promise<void>;
|
|
317
|
+
/**
|
|
318
|
+
* Retrieves the list of pending notifications.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```typescript
|
|
322
|
+
* import { pending } from '@tauri-apps/plugin-notification';
|
|
323
|
+
* const pendingNotifications = await pending();
|
|
324
|
+
* ```
|
|
325
|
+
*
|
|
326
|
+
* @returns A promise resolving to the list of pending notifications.
|
|
327
|
+
*
|
|
328
|
+
* @since 2.0.0
|
|
329
|
+
*/
|
|
330
|
+
declare function pending(): Promise<PendingNotification[]>;
|
|
331
|
+
/**
|
|
332
|
+
* Cancels the pending notifications with the given list of identifiers.
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* import { cancel } from '@tauri-apps/plugin-notification';
|
|
337
|
+
* await cancel([-34234, 23432, 4311]);
|
|
338
|
+
* ```
|
|
339
|
+
*
|
|
340
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
341
|
+
*
|
|
342
|
+
* @since 2.0.0
|
|
343
|
+
*/
|
|
344
|
+
declare function cancel(notifications: number[]): Promise<void>;
|
|
345
|
+
/**
|
|
346
|
+
* Cancels all pending notifications.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```typescript
|
|
350
|
+
* import { cancelAll } from '@tauri-apps/plugin-notification';
|
|
351
|
+
* await cancelAll();
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
355
|
+
*
|
|
356
|
+
* @since 2.0.0
|
|
357
|
+
*/
|
|
358
|
+
declare function cancelAll(): Promise<void>;
|
|
359
|
+
/**
|
|
360
|
+
* Retrieves the list of active notifications.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```typescript
|
|
364
|
+
* import { active } from '@tauri-apps/plugin-notification';
|
|
365
|
+
* const activeNotifications = await active();
|
|
366
|
+
* ```
|
|
367
|
+
*
|
|
368
|
+
* @returns A promise resolving to the list of active notifications.
|
|
369
|
+
*
|
|
370
|
+
* @since 2.0.0
|
|
371
|
+
*/
|
|
372
|
+
declare function active(): Promise<ActiveNotification[]>;
|
|
373
|
+
/**
|
|
374
|
+
* Removes the active notifications with the given list of identifiers.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```typescript
|
|
378
|
+
* import { cancel } from '@tauri-apps/plugin-notification';
|
|
379
|
+
* await cancel([-34234, 23432, 4311])
|
|
380
|
+
* ```
|
|
381
|
+
*
|
|
382
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
383
|
+
*
|
|
384
|
+
* @since 2.0.0
|
|
385
|
+
*/
|
|
386
|
+
declare function removeActive(notifications: Array<{
|
|
387
|
+
id: number;
|
|
388
|
+
tag?: string;
|
|
389
|
+
}>): Promise<void>;
|
|
390
|
+
/**
|
|
391
|
+
* Removes all active notifications.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```typescript
|
|
395
|
+
* import { removeAllActive } from '@tauri-apps/plugin-notification';
|
|
396
|
+
* await removeAllActive()
|
|
397
|
+
* ```
|
|
398
|
+
*
|
|
399
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
400
|
+
*
|
|
401
|
+
* @since 2.0.0
|
|
402
|
+
*/
|
|
403
|
+
declare function removeAllActive(): Promise<void>;
|
|
404
|
+
/**
|
|
405
|
+
* Creates a notification channel.
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* ```typescript
|
|
409
|
+
* import { createChannel, Importance, Visibility } from '@tauri-apps/plugin-notification';
|
|
410
|
+
* await createChannel({
|
|
411
|
+
* id: 'new-messages',
|
|
412
|
+
* name: 'New Messages',
|
|
413
|
+
* lights: true,
|
|
414
|
+
* vibration: true,
|
|
415
|
+
* importance: Importance.Default,
|
|
416
|
+
* visibility: Visibility.Private
|
|
417
|
+
* });
|
|
418
|
+
* ```
|
|
419
|
+
*
|
|
420
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
421
|
+
*
|
|
422
|
+
* @since 2.0.0
|
|
423
|
+
*/
|
|
424
|
+
declare function createChannel(channel: Channel): Promise<void>;
|
|
425
|
+
/**
|
|
426
|
+
* Removes the channel with the given identifier.
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```typescript
|
|
430
|
+
* import { removeChannel } from '@tauri-apps/plugin-notification';
|
|
431
|
+
* await removeChannel();
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* @returns A promise indicating the success or failure of the operation.
|
|
435
|
+
*
|
|
436
|
+
* @since 2.0.0
|
|
437
|
+
*/
|
|
438
|
+
declare function removeChannel(id: string): Promise<void>;
|
|
439
|
+
/**
|
|
440
|
+
* Retrieves the list of notification channels.
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```typescript
|
|
444
|
+
* import { channels } from '@tauri-apps/plugin-notification';
|
|
445
|
+
* const notificationChannels = await channels();
|
|
446
|
+
* ```
|
|
447
|
+
*
|
|
448
|
+
* @returns A promise resolving to the list of notification channels.
|
|
449
|
+
*
|
|
450
|
+
* @since 2.0.0
|
|
451
|
+
*/
|
|
452
|
+
declare function channels(): Promise<Channel[]>;
|
|
453
|
+
declare function onNotificationReceived(cb: (notification: Options) => void): Promise<PluginListener>;
|
|
454
|
+
declare function onAction(cb: (notification: Options) => void): Promise<PluginListener>;
|
|
455
|
+
export type { Attachment, Options, Action, ActionType, PendingNotification, ActiveNotification, Channel, ScheduleInterval, };
|
|
456
|
+
export { Importance, Visibility, sendNotification, requestPermission, isPermissionGranted, registerActionTypes, pending, cancel, cancelAll, active, removeActive, removeAllActive, createChannel, removeChannel, channels, onNotificationReceived, onAction, Schedule, ScheduleEvery, };
|