use tauri::{
async_runtime::Mutex, plugin::{Builder, TauriPlugin}, Manager, Runtime
};
pub use models::*;
#[cfg(desktop)]
mod desktop;
#[cfg(mobile)]
mod mobile;
mod commands;
mod error;
mod models;
mod scope;
pub use error::{Error, Result};
#[cfg(desktop)]
use desktop::Sse;
#[cfg(mobile)]
use mobile::Sse;
pub trait SseExt<R: Runtime> {
fn sse(&self) -> &Sse<R>;
}
impl<R: Runtime, T: Manager<R>> crate::SseExt<R> for T {
fn sse(&self) -> &Sse<R> {
self.state::<Sse<R>>().inner()
}
}
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("sse")
.invoke_handler(tauri::generate_handler![commands::open_sse,
commands::close_sse,
commands::add_on_message_sse,
commands::add_on_error_sse,
commands::add_event_listener_sse,
commands::remove_event_listener_sse
])
.setup(|app, api| {
#[cfg(mobile)]
let _sse = mobile::init(app, api)?;
#[cfg(desktop)]
let _sse = desktop::init(app, api)?;
app.manage(Mutex::new(commands::AppState::default()));
Ok(())
})
.build()
}