@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.
@@ -0,0 +1,319 @@
1
+ 'use strict';
2
+
3
+ var core = require('@tauri-apps/api/core');
4
+
5
+ // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
6
+ // SPDX-License-Identifier: Apache-2.0
7
+ // SPDX-License-Identifier: MIT
8
+ /**
9
+ * Send toast notifications (brief auto-expiring OS window element) to your user.
10
+ * Can also be used with the Notification Web API.
11
+ *
12
+ * @module
13
+ */
14
+ exports.ScheduleEvery = void 0;
15
+ (function (ScheduleEvery) {
16
+ ScheduleEvery["Year"] = "year";
17
+ ScheduleEvery["Month"] = "month";
18
+ ScheduleEvery["TwoWeeks"] = "twoWeeks";
19
+ ScheduleEvery["Week"] = "week";
20
+ ScheduleEvery["Day"] = "day";
21
+ ScheduleEvery["Hour"] = "hour";
22
+ ScheduleEvery["Minute"] = "minute";
23
+ /**
24
+ * Not supported on iOS.
25
+ */
26
+ ScheduleEvery["Second"] = "second";
27
+ })(exports.ScheduleEvery || (exports.ScheduleEvery = {}));
28
+ class Schedule {
29
+ static at(date, repeating = false, allowWhileIdle = false) {
30
+ return {
31
+ at: { date, repeating, allowWhileIdle },
32
+ interval: undefined,
33
+ every: undefined,
34
+ };
35
+ }
36
+ static interval(interval, allowWhileIdle = false) {
37
+ return {
38
+ at: undefined,
39
+ interval: { interval, allowWhileIdle },
40
+ every: undefined,
41
+ };
42
+ }
43
+ static every(kind, count, allowWhileIdle = false) {
44
+ return {
45
+ at: undefined,
46
+ interval: undefined,
47
+ every: { interval: kind, count, allowWhileIdle },
48
+ };
49
+ }
50
+ }
51
+ exports.Importance = void 0;
52
+ (function (Importance) {
53
+ Importance[Importance["None"] = 0] = "None";
54
+ Importance[Importance["Min"] = 1] = "Min";
55
+ Importance[Importance["Low"] = 2] = "Low";
56
+ Importance[Importance["Default"] = 3] = "Default";
57
+ Importance[Importance["High"] = 4] = "High";
58
+ })(exports.Importance || (exports.Importance = {}));
59
+ exports.Visibility = void 0;
60
+ (function (Visibility) {
61
+ Visibility[Visibility["Secret"] = -1] = "Secret";
62
+ Visibility[Visibility["Private"] = 0] = "Private";
63
+ Visibility[Visibility["Public"] = 1] = "Public";
64
+ })(exports.Visibility || (exports.Visibility = {}));
65
+ /**
66
+ * Checks if the permission to send notifications is granted.
67
+ * @example
68
+ * ```typescript
69
+ * import { isPermissionGranted } from '@tauri-apps/plugin-notification';
70
+ * const permissionGranted = await isPermissionGranted();
71
+ * ```
72
+ *
73
+ * @since 2.0.0
74
+ */
75
+ async function isPermissionGranted() {
76
+ return await core.invoke("plugin:notifications|is_permission_granted");
77
+ }
78
+ /**
79
+ * Requests the permission to send notifications.
80
+ * @example
81
+ * ```typescript
82
+ * import { isPermissionGranted, requestPermission } from '@tauri-apps/plugin-notification';
83
+ * let permissionGranted = await isPermissionGranted();
84
+ * if (!permissionGranted) {
85
+ * const permission = await requestPermission();
86
+ * permissionGranted = permission === 'granted';
87
+ * }
88
+ * ```
89
+ *
90
+ * @returns A promise resolving to whether the user granted the permission or not.
91
+ *
92
+ * @since 2.0.0
93
+ */
94
+ async function requestPermission() {
95
+ return await core.invoke("plugin:notifications|request_permission");
96
+ }
97
+ /**
98
+ * Sends a notification to the user.
99
+ * @example
100
+ * ```typescript
101
+ * import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/plugin-notification';
102
+ * let permissionGranted = await isPermissionGranted();
103
+ * if (!permissionGranted) {
104
+ * const permission = await requestPermission();
105
+ * permissionGranted = permission === 'granted';
106
+ * }
107
+ * if (permissionGranted) {
108
+ * sendNotification('Tauri is awesome!');
109
+ * sendNotification({ title: 'TAURI', body: 'Tauri is awesome!' });
110
+ * }
111
+ * ```
112
+ *
113
+ * @since 2.0.0
114
+ */
115
+ async function sendNotification(options) {
116
+ await core.invoke("plugin:notifications|notify", {
117
+ options: typeof options === "string"
118
+ ? {
119
+ title: options,
120
+ }
121
+ : options,
122
+ });
123
+ }
124
+ /**
125
+ * Register actions that are performed when the user clicks on the notification.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * import { registerActionTypes } from '@tauri-apps/plugin-notification';
130
+ * await registerActionTypes([{
131
+ * id: 'tauri',
132
+ * actions: [{
133
+ * id: 'my-action',
134
+ * title: 'Settings'
135
+ * }]
136
+ * }])
137
+ * ```
138
+ *
139
+ * @returns A promise indicating the success or failure of the operation.
140
+ *
141
+ * @since 2.0.0
142
+ */
143
+ async function registerActionTypes(types) {
144
+ await core.invoke("plugin:notifications|register_action_types", { types });
145
+ }
146
+ /**
147
+ * Retrieves the list of pending notifications.
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * import { pending } from '@tauri-apps/plugin-notification';
152
+ * const pendingNotifications = await pending();
153
+ * ```
154
+ *
155
+ * @returns A promise resolving to the list of pending notifications.
156
+ *
157
+ * @since 2.0.0
158
+ */
159
+ async function pending() {
160
+ return await core.invoke("plugin:notifications|get_pending");
161
+ }
162
+ /**
163
+ * Cancels the pending notifications with the given list of identifiers.
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * import { cancel } from '@tauri-apps/plugin-notification';
168
+ * await cancel([-34234, 23432, 4311]);
169
+ * ```
170
+ *
171
+ * @returns A promise indicating the success or failure of the operation.
172
+ *
173
+ * @since 2.0.0
174
+ */
175
+ async function cancel(notifications) {
176
+ await core.invoke("plugin:notifications|cancel", { notifications });
177
+ }
178
+ /**
179
+ * Cancels all pending notifications.
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * import { cancelAll } from '@tauri-apps/plugin-notification';
184
+ * await cancelAll();
185
+ * ```
186
+ *
187
+ * @returns A promise indicating the success or failure of the operation.
188
+ *
189
+ * @since 2.0.0
190
+ */
191
+ async function cancelAll() {
192
+ await core.invoke("plugin:notifications|cancel");
193
+ }
194
+ /**
195
+ * Retrieves the list of active notifications.
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * import { active } from '@tauri-apps/plugin-notification';
200
+ * const activeNotifications = await active();
201
+ * ```
202
+ *
203
+ * @returns A promise resolving to the list of active notifications.
204
+ *
205
+ * @since 2.0.0
206
+ */
207
+ async function active() {
208
+ return await core.invoke("plugin:notifications|get_active");
209
+ }
210
+ /**
211
+ * Removes the active notifications with the given list of identifiers.
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * import { cancel } from '@tauri-apps/plugin-notification';
216
+ * await cancel([-34234, 23432, 4311])
217
+ * ```
218
+ *
219
+ * @returns A promise indicating the success or failure of the operation.
220
+ *
221
+ * @since 2.0.0
222
+ */
223
+ async function removeActive(notifications) {
224
+ await core.invoke("plugin:notifications|remove_active", { notifications });
225
+ }
226
+ /**
227
+ * Removes all active notifications.
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * import { removeAllActive } from '@tauri-apps/plugin-notification';
232
+ * await removeAllActive()
233
+ * ```
234
+ *
235
+ * @returns A promise indicating the success or failure of the operation.
236
+ *
237
+ * @since 2.0.0
238
+ */
239
+ async function removeAllActive() {
240
+ await core.invoke("plugin:notifications|remove_active");
241
+ }
242
+ /**
243
+ * Creates a notification channel.
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * import { createChannel, Importance, Visibility } from '@tauri-apps/plugin-notification';
248
+ * await createChannel({
249
+ * id: 'new-messages',
250
+ * name: 'New Messages',
251
+ * lights: true,
252
+ * vibration: true,
253
+ * importance: Importance.Default,
254
+ * visibility: Visibility.Private
255
+ * });
256
+ * ```
257
+ *
258
+ * @returns A promise indicating the success or failure of the operation.
259
+ *
260
+ * @since 2.0.0
261
+ */
262
+ async function createChannel(channel) {
263
+ await core.invoke("plugin:notifications|create_channel", { ...channel });
264
+ }
265
+ /**
266
+ * Removes the channel with the given identifier.
267
+ *
268
+ * @example
269
+ * ```typescript
270
+ * import { removeChannel } from '@tauri-apps/plugin-notification';
271
+ * await removeChannel();
272
+ * ```
273
+ *
274
+ * @returns A promise indicating the success or failure of the operation.
275
+ *
276
+ * @since 2.0.0
277
+ */
278
+ async function removeChannel(id) {
279
+ await core.invoke("plugin:notifications|delete_channel", { id });
280
+ }
281
+ /**
282
+ * Retrieves the list of notification channels.
283
+ *
284
+ * @example
285
+ * ```typescript
286
+ * import { channels } from '@tauri-apps/plugin-notification';
287
+ * const notificationChannels = await channels();
288
+ * ```
289
+ *
290
+ * @returns A promise resolving to the list of notification channels.
291
+ *
292
+ * @since 2.0.0
293
+ */
294
+ async function channels() {
295
+ return await core.invoke("plugin:notifications|listChannels");
296
+ }
297
+ async function onNotificationReceived(cb) {
298
+ return await core.addPluginListener("notifications", "notification", cb);
299
+ }
300
+ async function onAction(cb) {
301
+ return await core.addPluginListener("notifications", "actionPerformed", cb);
302
+ }
303
+
304
+ exports.Schedule = Schedule;
305
+ exports.active = active;
306
+ exports.cancel = cancel;
307
+ exports.cancelAll = cancelAll;
308
+ exports.channels = channels;
309
+ exports.createChannel = createChannel;
310
+ exports.isPermissionGranted = isPermissionGranted;
311
+ exports.onAction = onAction;
312
+ exports.onNotificationReceived = onNotificationReceived;
313
+ exports.pending = pending;
314
+ exports.registerActionTypes = registerActionTypes;
315
+ exports.removeActive = removeActive;
316
+ exports.removeAllActive = removeAllActive;
317
+ exports.removeChannel = removeChannel;
318
+ exports.requestPermission = requestPermission;
319
+ exports.sendNotification = sendNotification;