tauri_plugin_fcm_notifications/
lib.rs1use log::info;
2pub use models::*;
3use tauri::{
4 plugin::{Builder, TauriPlugin},
5 Manager, Runtime,
6};
7use tokio::sync::Mutex;
8
9#[cfg(desktop)]
10mod desktop;
11
12mod commands;
13mod config;
14mod encrypted_file;
15mod error;
16mod models;
17mod persisted_ids;
18use crate::config::*;
19
20pub use error::{Error, Result};
21
22#[cfg(desktop)]
23use desktop::FcmNotifications;
24
25pub trait FcmNotificationsExt<R: Runtime> {
27 fn fcm_notifications(&self) -> &FcmNotifications<R>;
28}
29
30impl<R: Runtime, T: Manager<R>> crate::FcmNotificationsExt<R> for T {
31 fn fcm_notifications(&self) -> &FcmNotifications<R> {
32 self.state::<FcmNotifications<R>>().inner()
33 }
34}
35
36pub fn init<R: Runtime>() -> TauriPlugin<R, FCMConfig> {
37 info!("Initializing FCM Notifications plugin");
38
39 Builder::<R, FCMConfig>::new("fcm-notifications")
40 .invoke_handler(tauri::generate_handler![commands::start])
41 .setup(|app, api| {
42 let fcm_notifications = desktop::init(app, api)?;
43 app.manage(Mutex::new(fcm_notifications));
44 Ok(())
45 })
46 .build()
47}