tauri-plugin-fcm 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-APACHE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of Your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 tauri-plugin-fcm contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/LICENSE-MIT ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tauri-plugin-fcm contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,218 @@
1
+ # tauri-plugin-fcm
2
+
3
+ [![Crates.io](https://img.shields.io/crates/v/tauri-plugin-fcm.svg)](https://crates.io/crates/tauri-plugin-fcm)
4
+ [![npm](https://img.shields.io/npm/v/tauri-plugin-fcm.svg)](https://www.npmjs.com/package/tauri-plugin-fcm)
5
+ [![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](#license)
6
+
7
+ Firebase Cloud Messaging for Tauri 2 mobile apps.
8
+
9
+ The plugin returns FCM registration tokens on both iOS and Android. On iOS it handles the APNs to FCM exchange so your app uses one token type across both platforms.
10
+
11
+ | Platform | Supported |
12
+ | --- | --- |
13
+ | Android | Yes |
14
+ | iOS | Yes |
15
+ | macOS | No |
16
+ | Windows | No |
17
+ | Linux | No |
18
+
19
+ ## Install
20
+
21
+ Add the Rust crate to `src-tauri/Cargo.toml`:
22
+
23
+ ```toml
24
+ [dependencies]
25
+ tauri-plugin-fcm = "0.1.0"
26
+ ```
27
+
28
+ Install the JavaScript guest bindings:
29
+
30
+ ```sh
31
+ pnpm add tauri-plugin-fcm
32
+ # or
33
+ bun add tauri-plugin-fcm
34
+ # or
35
+ npm add tauri-plugin-fcm
36
+ # or
37
+ yarn add tauri-plugin-fcm
38
+ ```
39
+
40
+ Register the plugin in your Tauri app:
41
+
42
+ ```rust
43
+ fn main() {
44
+ let builder = tauri::Builder::default();
45
+ #[cfg(mobile)]
46
+ let builder = builder.plugin(tauri_plugin_fcm::init());
47
+
48
+ builder
49
+ .run(tauri::generate_context!())
50
+ .expect("error while running tauri application");
51
+ }
52
+ ```
53
+
54
+ Add the capability permission:
55
+
56
+ ```json
57
+ {
58
+ "permissions": [
59
+ "fcm:default"
60
+ ]
61
+ }
62
+ ```
63
+
64
+ ## API
65
+
66
+ ```ts
67
+ import {
68
+ checkPermissions,
69
+ createChannel,
70
+ deleteToken,
71
+ getToken,
72
+ onPushError,
73
+ onTokenRefresh,
74
+ register,
75
+ requestPermissions,
76
+ sendNotification,
77
+ } from "tauri-plugin-fcm";
78
+ ```
79
+
80
+ ### Functions
81
+
82
+ - `checkPermissions(): Promise<PermissionState>`
83
+ - `requestPermissions(): Promise<PermissionState>`
84
+ - `register(): Promise<void>`
85
+ - `getToken(): Promise<{ token: string }>`
86
+ - `deleteToken(): Promise<void>`
87
+ - `createChannel(options: CreateChannelOptions): Promise<void>`
88
+ - `sendNotification(options: SendNotificationOptions): Promise<void>`
89
+ - `onTokenRefresh(handler): Promise<PluginListener>`
90
+ - `onPushError(handler): Promise<PluginListener>`
91
+
92
+ `PermissionState` comes from `@tauri-apps/api/core` and can be:
93
+
94
+ - `granted`
95
+ - `denied`
96
+ - `prompt`
97
+ - `prompt-with-rationale` (Android only)
98
+
99
+ ### Types
100
+
101
+ #### `CreateChannelOptions`
102
+
103
+ ```ts
104
+ interface CreateChannelOptions {
105
+ /** Unique identifier for the channel */
106
+ id: string;
107
+ /** Display name for the channel */
108
+ name: string;
109
+ /** Importance level for the channel (0-5) */
110
+ importance: number;
111
+ }
112
+ ```
113
+
114
+ #### `SendNotificationOptions`
115
+
116
+ ```ts
117
+ interface SendNotificationOptions {
118
+ /** Notification title */
119
+ title: string;
120
+ /** Notification body text */
121
+ body?: string;
122
+ /** Icon identifier or URL */
123
+ icon?: string;
124
+ /** Notification ID */
125
+ id?: number;
126
+ /** Channel ID (Android) */
127
+ channelId?: string;
128
+ }
129
+ ```
130
+
131
+ ## Usage
132
+
133
+ ### Basic Setup
134
+
135
+ ```ts
136
+ import {
137
+ checkPermissions,
138
+ getToken,
139
+ onPushError,
140
+ onTokenRefresh,
141
+ register,
142
+ requestPermissions,
143
+ } from "tauri-plugin-fcm";
144
+
145
+ let permission = await checkPermissions();
146
+
147
+ if (permission === "prompt" || permission === "prompt-with-rationale") {
148
+ permission = await requestPermissions();
149
+ }
150
+
151
+ if (permission === "granted") {
152
+ await register();
153
+ const { token } = await getToken();
154
+ console.log("FCM token:", token);
155
+ }
156
+
157
+ const tokenListener = await onTokenRefresh((event) => {
158
+ console.log("New FCM token:", event.token);
159
+ });
160
+
161
+ const errorListener = await onPushError((event) => {
162
+ console.error("Push error:", event.error);
163
+ });
164
+
165
+ // Later:
166
+ await tokenListener.unregister();
167
+ await errorListener.unregister();
168
+ ```
169
+
170
+ ### Sending Notifications
171
+
172
+ ```ts
173
+ import { createChannel, sendNotification } from "tauri-plugin-fcm";
174
+
175
+ // Create a notification channel (Android only, no-op on iOS)
176
+ await createChannel({
177
+ id: "default",
178
+ name: "Default Notifications",
179
+ importance: 4,
180
+ });
181
+
182
+ // Send a notification
183
+ await sendNotification({
184
+ title: "Hello",
185
+ body: "This is a test notification",
186
+ channelId: "default",
187
+ });
188
+ ```
189
+
190
+ ## Platform setup
191
+
192
+ ### iOS
193
+
194
+ 1. Add `GoogleService-Info.plist` to your generated iOS project under `src-tauri/gen/apple/<app-name>_iOS/` and make sure it is included in the iOS app target.
195
+ 2. Enable the `aps-environment` entitlement.
196
+ 3. Enable Push Notifications and Background Modes with Remote notifications.
197
+ 4. If you disable `FirebaseAppDelegateProxyEnabled`, make sure APNs callbacks still reach Firebase.
198
+
199
+ ### Android
200
+
201
+ 1. Add `google-services.json` to `src-tauri/gen/android/app`.
202
+ 2. Apply the Google Services Gradle plugin in the Android app.
203
+ 3. Keep `POST_NOTIFICATIONS` available for Android 13 and later.
204
+
205
+ ## Notes
206
+
207
+ - This is a mobile-only plugin. If you share Tauri setup code across desktop and mobile targets, gate registration with `#[cfg(mobile)]`.
208
+ - On Android, `register()` is effectively a no-op because FCM registration is automatic.
209
+ - On iOS simulators, remote notification transport is unavailable. The plugin emits `push-error` instead of crashing.
210
+ - `createChannel()` is Android-only and is a no-op on iOS.
211
+ - On Android API 26+, calling `sendNotification()` before `createChannel()` will silently drop the notification.
212
+
213
+ ## License
214
+
215
+ Licensed under either of:
216
+
217
+ - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
218
+ - MIT License ([LICENSE-MIT](LICENSE-MIT))
@@ -0,0 +1,91 @@
1
+ 'use strict';
2
+
3
+ var core = require('@tauri-apps/api/core');
4
+
5
+ /**
6
+ * Retrieves the current FCM registration token.
7
+ * @returns Promise resolving to an object containing the FCM token
8
+ * @throws Error if token retrieval fails
9
+ */
10
+ async function getToken() {
11
+ return await core.invoke("plugin:fcm|get_token");
12
+ }
13
+ /**
14
+ * Requests notification permissions from the user.
15
+ * @returns Promise resolving to the notification permission state
16
+ * @throws Error if permission request fails
17
+ */
18
+ async function requestPermissions() {
19
+ return await core.requestPermissions("fcm").then((result) => result.notification);
20
+ }
21
+ /**
22
+ * Checks the current notification permission status.
23
+ * @returns Promise resolving to the current notification permission state
24
+ * @throws Error if permission check fails
25
+ */
26
+ async function checkPermissions() {
27
+ return await core.checkPermissions("fcm").then((result) => result.notification);
28
+ }
29
+ /**
30
+ * Registers the device for push notifications.
31
+ * On iOS, this triggers the native registration flow.
32
+ * On Android, this is a no-op as FCM auto-registers.
33
+ * @returns Promise that resolves when registration is complete
34
+ * @throws Error if registration fails
35
+ */
36
+ async function register() {
37
+ await core.invoke("plugin:fcm|register");
38
+ }
39
+ /**
40
+ * Deletes the current FCM registration token.
41
+ * @returns Promise that resolves when token deletion is complete
42
+ * @throws Error if token deletion fails
43
+ */
44
+ async function deleteToken() {
45
+ await core.invoke("plugin:fcm|delete_token");
46
+ }
47
+ /**
48
+ * Registers a listener for FCM token refresh events.
49
+ * @param handler - Callback function invoked when token is refreshed
50
+ * @returns Promise resolving to a PluginListener that can be used to unlisten
51
+ */
52
+ async function onTokenRefresh(handler) {
53
+ return await core.addPluginListener("fcm", "token-refresh", handler);
54
+ }
55
+ /**
56
+ * Registers a listener for push notification error events.
57
+ * @param handler - Callback function invoked when a push error occurs
58
+ * @returns Promise resolving to a PluginListener that can be used to unlisten
59
+ */
60
+ async function onPushError(handler) {
61
+ return await core.addPluginListener("fcm", "push-error", handler);
62
+ }
63
+ /**
64
+ * Creates a notification channel (Android only, no-op on iOS).
65
+ * @param options - Channel configuration options
66
+ * @returns Promise that resolves when channel creation is complete
67
+ * @throws Error if channel creation fails
68
+ */
69
+ async function createChannel(options) {
70
+ await core.invoke("plugin:fcm|create_channel", options);
71
+ }
72
+ /**
73
+ * Sends a notification to the user.
74
+ * @param options - Notification configuration options
75
+ * @returns Promise that resolves when notification is sent
76
+ * @throws Error if notification sending fails
77
+ */
78
+ async function sendNotification(options) {
79
+ await core.invoke("plugin:fcm|send_notification", options);
80
+ }
81
+
82
+ exports.checkPermissions = checkPermissions;
83
+ exports.createChannel = createChannel;
84
+ exports.deleteToken = deleteToken;
85
+ exports.getToken = getToken;
86
+ exports.onPushError = onPushError;
87
+ exports.onTokenRefresh = onTokenRefresh;
88
+ exports.register = register;
89
+ exports.requestPermissions = requestPermissions;
90
+ exports.sendNotification = sendNotification;
91
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../guest-js/index.ts"],"sourcesContent":["import {\n addPluginListener,\n checkPermissions as checkPermissions_,\n invoke,\n type PermissionState,\n type PluginListener,\n requestPermissions as requestPermissions_,\n} from \"@tauri-apps/api/core\";\n\n/**\n * Represents an FCM token response.\n */\nexport interface FcmToken {\n /** The FCM registration token */\n token: string;\n}\n\nexport type { PermissionState } from \"@tauri-apps/api/core\";\n\n/**\n * Event emitted when FCM token is refreshed.\n */\nexport interface TokenRefreshEvent {\n /** The new FCM registration token */\n token: string;\n}\n\n/**\n * Event emitted when a push notification error occurs.\n */\nexport interface PushErrorEvent {\n /** Error message describing the push notification error */\n error: string;\n}\n\n/**\n * Options for creating a notification channel (Android only).\n */\nexport interface CreateChannelOptions extends Record<string, unknown> {\n /** Unique identifier for the channel */\n id: string;\n /** Display name for the channel */\n name: string;\n /** Importance level for the channel (0-5) */\n importance: number;\n}\n\n/**\n * Options for sending a notification.\n */\nexport interface SendNotificationOptions extends Record<string, unknown> {\n /** Notification title */\n title: string;\n /** Notification body text */\n body?: string;\n /** Icon identifier or URL */\n icon?: string;\n /** Notification ID */\n id?: number;\n /** Channel ID (Android) */\n channelId?: string;\n}\n\n/**\n * Retrieves the current FCM registration token.\n * @returns Promise resolving to an object containing the FCM token\n * @throws Error if token retrieval fails\n */\nexport async function getToken(): Promise<FcmToken> {\n return await invoke<FcmToken>(\"plugin:fcm|get_token\");\n}\n\n/**\n * Requests notification permissions from the user.\n * @returns Promise resolving to the notification permission state\n * @throws Error if permission request fails\n */\nexport async function requestPermissions(): Promise<PermissionState> {\n return await requestPermissions_<{ notification: PermissionState }>(\n \"fcm\",\n ).then((result) => result.notification);\n}\n\n/**\n * Checks the current notification permission status.\n * @returns Promise resolving to the current notification permission state\n * @throws Error if permission check fails\n */\nexport async function checkPermissions(): Promise<PermissionState> {\n return await checkPermissions_<{ notification: PermissionState }>(\"fcm\").then(\n (result) => result.notification,\n );\n}\n\n/**\n * Registers the device for push notifications.\n * On iOS, this triggers the native registration flow.\n * On Android, this is a no-op as FCM auto-registers.\n * @returns Promise that resolves when registration is complete\n * @throws Error if registration fails\n */\nexport async function register(): Promise<void> {\n await invoke(\"plugin:fcm|register\");\n}\n\n/**\n * Deletes the current FCM registration token.\n * @returns Promise that resolves when token deletion is complete\n * @throws Error if token deletion fails\n */\nexport async function deleteToken(): Promise<void> {\n await invoke(\"plugin:fcm|delete_token\");\n}\n\n/**\n * Registers a listener for FCM token refresh events.\n * @param handler - Callback function invoked when token is refreshed\n * @returns Promise resolving to a PluginListener that can be used to unlisten\n */\nexport async function onTokenRefresh(\n handler: (event: TokenRefreshEvent) => void,\n): Promise<PluginListener> {\n return await addPluginListener(\"fcm\", \"token-refresh\", handler);\n}\n\n/**\n * Registers a listener for push notification error events.\n * @param handler - Callback function invoked when a push error occurs\n * @returns Promise resolving to a PluginListener that can be used to unlisten\n */\nexport async function onPushError(\n handler: (event: PushErrorEvent) => void,\n): Promise<PluginListener> {\n return await addPluginListener(\"fcm\", \"push-error\", handler);\n}\n\n/**\n * Creates a notification channel (Android only, no-op on iOS).\n * @param options - Channel configuration options\n * @returns Promise that resolves when channel creation is complete\n * @throws Error if channel creation fails\n */\nexport async function createChannel(\n options: CreateChannelOptions,\n): Promise<void> {\n await invoke(\"plugin:fcm|create_channel\", options);\n}\n\n/**\n * Sends a notification to the user.\n * @param options - Notification configuration options\n * @returns Promise that resolves when notification is sent\n * @throws Error if notification sending fails\n */\nexport async function sendNotification(\n options: SendNotificationOptions,\n): Promise<void> {\n await invoke(\"plugin:fcm|send_notification\", options);\n}\n"],"names":["invoke","requestPermissions_","checkPermissions_","addPluginListener"],"mappings":";;;;AA+DA;;;;AAIG;AACI,eAAe,QAAQ,GAAA;AAC5B,IAAA,OAAO,MAAMA,WAAM,CAAW,sBAAsB,CAAC;AACvD;AAEA;;;;AAIG;AACI,eAAe,kBAAkB,GAAA;AACtC,IAAA,OAAO,MAAMC,uBAAmB,CAC9B,KAAK,CACN,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,YAAY,CAAC;AACzC;AAEA;;;;AAIG;AACI,eAAe,gBAAgB,GAAA;AACpC,IAAA,OAAO,MAAMC,qBAAiB,CAAoC,KAAK,CAAC,CAAC,IAAI,CAC3E,CAAC,MAAM,KAAK,MAAM,CAAC,YAAY,CAChC;AACH;AAEA;;;;;;AAMG;AACI,eAAe,QAAQ,GAAA;AAC5B,IAAA,MAAMF,WAAM,CAAC,qBAAqB,CAAC;AACrC;AAEA;;;;AAIG;AACI,eAAe,WAAW,GAAA;AAC/B,IAAA,MAAMA,WAAM,CAAC,yBAAyB,CAAC;AACzC;AAEA;;;;AAIG;AACI,eAAe,cAAc,CAClC,OAA2C,EAAA;IAE3C,OAAO,MAAMG,sBAAiB,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,CAAC;AACjE;AAEA;;;;AAIG;AACI,eAAe,WAAW,CAC/B,OAAwC,EAAA;IAExC,OAAO,MAAMA,sBAAiB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC;AAC9D;AAEA;;;;;AAKG;AACI,eAAe,aAAa,CACjC,OAA6B,EAAA;AAE7B,IAAA,MAAMH,WAAM,CAAC,2BAA2B,EAAE,OAAO,CAAC;AACpD;AAEA;;;;;AAKG;AACI,eAAe,gBAAgB,CACpC,OAAgC,EAAA;AAEhC,IAAA,MAAMA,WAAM,CAAC,8BAA8B,EAAE,OAAO,CAAC;AACvD;;;;;;;;;;;;"}
@@ -0,0 +1,107 @@
1
+ import { type PermissionState, type PluginListener } from "@tauri-apps/api/core";
2
+ /**
3
+ * Represents an FCM token response.
4
+ */
5
+ export interface FcmToken {
6
+ /** The FCM registration token */
7
+ token: string;
8
+ }
9
+ export type { PermissionState } from "@tauri-apps/api/core";
10
+ /**
11
+ * Event emitted when FCM token is refreshed.
12
+ */
13
+ export interface TokenRefreshEvent {
14
+ /** The new FCM registration token */
15
+ token: string;
16
+ }
17
+ /**
18
+ * Event emitted when a push notification error occurs.
19
+ */
20
+ export interface PushErrorEvent {
21
+ /** Error message describing the push notification error */
22
+ error: string;
23
+ }
24
+ /**
25
+ * Options for creating a notification channel (Android only).
26
+ */
27
+ export interface CreateChannelOptions extends Record<string, unknown> {
28
+ /** Unique identifier for the channel */
29
+ id: string;
30
+ /** Display name for the channel */
31
+ name: string;
32
+ /** Importance level for the channel (0-5) */
33
+ importance: number;
34
+ }
35
+ /**
36
+ * Options for sending a notification.
37
+ */
38
+ export interface SendNotificationOptions extends Record<string, unknown> {
39
+ /** Notification title */
40
+ title: string;
41
+ /** Notification body text */
42
+ body?: string;
43
+ /** Icon identifier or URL */
44
+ icon?: string;
45
+ /** Notification ID */
46
+ id?: number;
47
+ /** Channel ID (Android) */
48
+ channelId?: string;
49
+ }
50
+ /**
51
+ * Retrieves the current FCM registration token.
52
+ * @returns Promise resolving to an object containing the FCM token
53
+ * @throws Error if token retrieval fails
54
+ */
55
+ export declare function getToken(): Promise<FcmToken>;
56
+ /**
57
+ * Requests notification permissions from the user.
58
+ * @returns Promise resolving to the notification permission state
59
+ * @throws Error if permission request fails
60
+ */
61
+ export declare function requestPermissions(): Promise<PermissionState>;
62
+ /**
63
+ * Checks the current notification permission status.
64
+ * @returns Promise resolving to the current notification permission state
65
+ * @throws Error if permission check fails
66
+ */
67
+ export declare function checkPermissions(): Promise<PermissionState>;
68
+ /**
69
+ * Registers the device for push notifications.
70
+ * On iOS, this triggers the native registration flow.
71
+ * On Android, this is a no-op as FCM auto-registers.
72
+ * @returns Promise that resolves when registration is complete
73
+ * @throws Error if registration fails
74
+ */
75
+ export declare function register(): Promise<void>;
76
+ /**
77
+ * Deletes the current FCM registration token.
78
+ * @returns Promise that resolves when token deletion is complete
79
+ * @throws Error if token deletion fails
80
+ */
81
+ export declare function deleteToken(): Promise<void>;
82
+ /**
83
+ * Registers a listener for FCM token refresh events.
84
+ * @param handler - Callback function invoked when token is refreshed
85
+ * @returns Promise resolving to a PluginListener that can be used to unlisten
86
+ */
87
+ export declare function onTokenRefresh(handler: (event: TokenRefreshEvent) => void): Promise<PluginListener>;
88
+ /**
89
+ * Registers a listener for push notification error events.
90
+ * @param handler - Callback function invoked when a push error occurs
91
+ * @returns Promise resolving to a PluginListener that can be used to unlisten
92
+ */
93
+ export declare function onPushError(handler: (event: PushErrorEvent) => void): Promise<PluginListener>;
94
+ /**
95
+ * Creates a notification channel (Android only, no-op on iOS).
96
+ * @param options - Channel configuration options
97
+ * @returns Promise that resolves when channel creation is complete
98
+ * @throws Error if channel creation fails
99
+ */
100
+ export declare function createChannel(options: CreateChannelOptions): Promise<void>;
101
+ /**
102
+ * Sends a notification to the user.
103
+ * @param options - Notification configuration options
104
+ * @returns Promise that resolves when notification is sent
105
+ * @throws Error if notification sending fails
106
+ */
107
+ export declare function sendNotification(options: SendNotificationOptions): Promise<void>;
@@ -0,0 +1,81 @@
1
+ import { invoke, requestPermissions as requestPermissions$1, checkPermissions as checkPermissions$1, addPluginListener } from '@tauri-apps/api/core';
2
+
3
+ /**
4
+ * Retrieves the current FCM registration token.
5
+ * @returns Promise resolving to an object containing the FCM token
6
+ * @throws Error if token retrieval fails
7
+ */
8
+ async function getToken() {
9
+ return await invoke("plugin:fcm|get_token");
10
+ }
11
+ /**
12
+ * Requests notification permissions from the user.
13
+ * @returns Promise resolving to the notification permission state
14
+ * @throws Error if permission request fails
15
+ */
16
+ async function requestPermissions() {
17
+ return await requestPermissions$1("fcm").then((result) => result.notification);
18
+ }
19
+ /**
20
+ * Checks the current notification permission status.
21
+ * @returns Promise resolving to the current notification permission state
22
+ * @throws Error if permission check fails
23
+ */
24
+ async function checkPermissions() {
25
+ return await checkPermissions$1("fcm").then((result) => result.notification);
26
+ }
27
+ /**
28
+ * Registers the device for push notifications.
29
+ * On iOS, this triggers the native registration flow.
30
+ * On Android, this is a no-op as FCM auto-registers.
31
+ * @returns Promise that resolves when registration is complete
32
+ * @throws Error if registration fails
33
+ */
34
+ async function register() {
35
+ await invoke("plugin:fcm|register");
36
+ }
37
+ /**
38
+ * Deletes the current FCM registration token.
39
+ * @returns Promise that resolves when token deletion is complete
40
+ * @throws Error if token deletion fails
41
+ */
42
+ async function deleteToken() {
43
+ await invoke("plugin:fcm|delete_token");
44
+ }
45
+ /**
46
+ * Registers a listener for FCM token refresh events.
47
+ * @param handler - Callback function invoked when token is refreshed
48
+ * @returns Promise resolving to a PluginListener that can be used to unlisten
49
+ */
50
+ async function onTokenRefresh(handler) {
51
+ return await addPluginListener("fcm", "token-refresh", handler);
52
+ }
53
+ /**
54
+ * Registers a listener for push notification error events.
55
+ * @param handler - Callback function invoked when a push error occurs
56
+ * @returns Promise resolving to a PluginListener that can be used to unlisten
57
+ */
58
+ async function onPushError(handler) {
59
+ return await addPluginListener("fcm", "push-error", handler);
60
+ }
61
+ /**
62
+ * Creates a notification channel (Android only, no-op on iOS).
63
+ * @param options - Channel configuration options
64
+ * @returns Promise that resolves when channel creation is complete
65
+ * @throws Error if channel creation fails
66
+ */
67
+ async function createChannel(options) {
68
+ await invoke("plugin:fcm|create_channel", options);
69
+ }
70
+ /**
71
+ * Sends a notification to the user.
72
+ * @param options - Notification configuration options
73
+ * @returns Promise that resolves when notification is sent
74
+ * @throws Error if notification sending fails
75
+ */
76
+ async function sendNotification(options) {
77
+ await invoke("plugin:fcm|send_notification", options);
78
+ }
79
+
80
+ export { checkPermissions, createChannel, deleteToken, getToken, onPushError, onTokenRefresh, register, requestPermissions, sendNotification };
81
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../guest-js/index.ts"],"sourcesContent":["import {\n addPluginListener,\n checkPermissions as checkPermissions_,\n invoke,\n type PermissionState,\n type PluginListener,\n requestPermissions as requestPermissions_,\n} from \"@tauri-apps/api/core\";\n\n/**\n * Represents an FCM token response.\n */\nexport interface FcmToken {\n /** The FCM registration token */\n token: string;\n}\n\nexport type { PermissionState } from \"@tauri-apps/api/core\";\n\n/**\n * Event emitted when FCM token is refreshed.\n */\nexport interface TokenRefreshEvent {\n /** The new FCM registration token */\n token: string;\n}\n\n/**\n * Event emitted when a push notification error occurs.\n */\nexport interface PushErrorEvent {\n /** Error message describing the push notification error */\n error: string;\n}\n\n/**\n * Options for creating a notification channel (Android only).\n */\nexport interface CreateChannelOptions extends Record<string, unknown> {\n /** Unique identifier for the channel */\n id: string;\n /** Display name for the channel */\n name: string;\n /** Importance level for the channel (0-5) */\n importance: number;\n}\n\n/**\n * Options for sending a notification.\n */\nexport interface SendNotificationOptions extends Record<string, unknown> {\n /** Notification title */\n title: string;\n /** Notification body text */\n body?: string;\n /** Icon identifier or URL */\n icon?: string;\n /** Notification ID */\n id?: number;\n /** Channel ID (Android) */\n channelId?: string;\n}\n\n/**\n * Retrieves the current FCM registration token.\n * @returns Promise resolving to an object containing the FCM token\n * @throws Error if token retrieval fails\n */\nexport async function getToken(): Promise<FcmToken> {\n return await invoke<FcmToken>(\"plugin:fcm|get_token\");\n}\n\n/**\n * Requests notification permissions from the user.\n * @returns Promise resolving to the notification permission state\n * @throws Error if permission request fails\n */\nexport async function requestPermissions(): Promise<PermissionState> {\n return await requestPermissions_<{ notification: PermissionState }>(\n \"fcm\",\n ).then((result) => result.notification);\n}\n\n/**\n * Checks the current notification permission status.\n * @returns Promise resolving to the current notification permission state\n * @throws Error if permission check fails\n */\nexport async function checkPermissions(): Promise<PermissionState> {\n return await checkPermissions_<{ notification: PermissionState }>(\"fcm\").then(\n (result) => result.notification,\n );\n}\n\n/**\n * Registers the device for push notifications.\n * On iOS, this triggers the native registration flow.\n * On Android, this is a no-op as FCM auto-registers.\n * @returns Promise that resolves when registration is complete\n * @throws Error if registration fails\n */\nexport async function register(): Promise<void> {\n await invoke(\"plugin:fcm|register\");\n}\n\n/**\n * Deletes the current FCM registration token.\n * @returns Promise that resolves when token deletion is complete\n * @throws Error if token deletion fails\n */\nexport async function deleteToken(): Promise<void> {\n await invoke(\"plugin:fcm|delete_token\");\n}\n\n/**\n * Registers a listener for FCM token refresh events.\n * @param handler - Callback function invoked when token is refreshed\n * @returns Promise resolving to a PluginListener that can be used to unlisten\n */\nexport async function onTokenRefresh(\n handler: (event: TokenRefreshEvent) => void,\n): Promise<PluginListener> {\n return await addPluginListener(\"fcm\", \"token-refresh\", handler);\n}\n\n/**\n * Registers a listener for push notification error events.\n * @param handler - Callback function invoked when a push error occurs\n * @returns Promise resolving to a PluginListener that can be used to unlisten\n */\nexport async function onPushError(\n handler: (event: PushErrorEvent) => void,\n): Promise<PluginListener> {\n return await addPluginListener(\"fcm\", \"push-error\", handler);\n}\n\n/**\n * Creates a notification channel (Android only, no-op on iOS).\n * @param options - Channel configuration options\n * @returns Promise that resolves when channel creation is complete\n * @throws Error if channel creation fails\n */\nexport async function createChannel(\n options: CreateChannelOptions,\n): Promise<void> {\n await invoke(\"plugin:fcm|create_channel\", options);\n}\n\n/**\n * Sends a notification to the user.\n * @param options - Notification configuration options\n * @returns Promise that resolves when notification is sent\n * @throws Error if notification sending fails\n */\nexport async function sendNotification(\n options: SendNotificationOptions,\n): Promise<void> {\n await invoke(\"plugin:fcm|send_notification\", options);\n}\n"],"names":["requestPermissions_","checkPermissions_"],"mappings":";;AA+DA;;;;AAIG;AACI,eAAe,QAAQ,GAAA;AAC5B,IAAA,OAAO,MAAM,MAAM,CAAW,sBAAsB,CAAC;AACvD;AAEA;;;;AAIG;AACI,eAAe,kBAAkB,GAAA;AACtC,IAAA,OAAO,MAAMA,oBAAmB,CAC9B,KAAK,CACN,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,YAAY,CAAC;AACzC;AAEA;;;;AAIG;AACI,eAAe,gBAAgB,GAAA;AACpC,IAAA,OAAO,MAAMC,kBAAiB,CAAoC,KAAK,CAAC,CAAC,IAAI,CAC3E,CAAC,MAAM,KAAK,MAAM,CAAC,YAAY,CAChC;AACH;AAEA;;;;;;AAMG;AACI,eAAe,QAAQ,GAAA;AAC5B,IAAA,MAAM,MAAM,CAAC,qBAAqB,CAAC;AACrC;AAEA;;;;AAIG;AACI,eAAe,WAAW,GAAA;AAC/B,IAAA,MAAM,MAAM,CAAC,yBAAyB,CAAC;AACzC;AAEA;;;;AAIG;AACI,eAAe,cAAc,CAClC,OAA2C,EAAA;IAE3C,OAAO,MAAM,iBAAiB,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,CAAC;AACjE;AAEA;;;;AAIG;AACI,eAAe,WAAW,CAC/B,OAAwC,EAAA;IAExC,OAAO,MAAM,iBAAiB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC;AAC9D;AAEA;;;;;AAKG;AACI,eAAe,aAAa,CACjC,OAA6B,EAAA;AAE7B,IAAA,MAAM,MAAM,CAAC,2BAA2B,EAAE,OAAO,CAAC;AACpD;AAEA;;;;;AAKG;AACI,eAAe,gBAAgB,CACpC,OAAgC,EAAA;AAEhC,IAAA,MAAM,MAAM,CAAC,8BAA8B,EAAE,OAAO,CAAC;AACvD;;;;"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "tauri-plugin-fcm",
3
+ "version": "0.1.0",
4
+ "description": "Tauri 2 plugin for Firebase Cloud Messaging (FCM) — iOS APNs→FCM token exchange + Android FCM",
5
+ "license": "MIT OR Apache-2.0",
6
+ "type": "module",
7
+ "packageManager": "bun@1.3.10",
8
+ "types": "./dist-js/index.d.ts",
9
+ "main": "./dist-js/index.cjs",
10
+ "module": "./dist-js/index.js",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist-js/index.d.ts",
14
+ "import": "./dist-js/index.js",
15
+ "require": "./dist-js/index.cjs"
16
+ }
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/srod/tauri-plugin-fcm"
21
+ },
22
+ "files": [
23
+ "dist-js",
24
+ "README.md",
25
+ "LICENSE-MIT",
26
+ "LICENSE-APACHE"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "engines": {
32
+ "node": ">=18"
33
+ },
34
+ "scripts": {
35
+ "build": "rollup -c",
36
+ "lint": "bunx biome check .",
37
+ "lint:fix": "bunx biome check --write .",
38
+ "format": "bunx biome format --write .",
39
+ "format:check": "bunx biome format .",
40
+ "typecheck": "bunx tsc --noEmit --project guest-js/tsconfig.json",
41
+ "prepublishOnly": "bun run build",
42
+ "test": "bun run build && node --test"
43
+ },
44
+ "dependencies": {
45
+ "@tauri-apps/api": "^2.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@biomejs/biome": "2.4.6",
49
+ "typescript": "^5.0.0",
50
+ "@rollup/plugin-typescript": "^12.0.0",
51
+ "rollup": "^4.0.0",
52
+ "tslib": "^2.6.0"
53
+ },
54
+ "keywords": [
55
+ "tauri",
56
+ "tauri-plugin",
57
+ "fcm",
58
+ "firebase",
59
+ "push-notifications",
60
+ "ios",
61
+ "android"
62
+ ]
63
+ }