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