tauri_plugin_sharekit/
lib.rs

1use tauri::{
2    plugin::{Builder, TauriPlugin},
3    Manager, Runtime,
4};
5
6pub use models::*;
7
8#[cfg(desktop)]
9mod desktop;
10#[cfg(mobile)]
11mod mobile;
12
13mod error;
14mod models;
15
16pub use error::{Error, Result};
17
18#[cfg(desktop)]
19use desktop::Share;
20#[cfg(mobile)]
21use mobile::Share;
22
23/// Extensions to [`tauri::App`], [`tauri::AppHandle`], [`tauri::WebviewWindow`], [`tauri::Webview`] and [`tauri::Window`] to access the share APIs.
24pub trait ShareExt<R: Runtime> {
25    fn share(&self) -> &Share<R>;
26}
27
28impl<R: Runtime, T: Manager<R>> crate::ShareExt<R> for T {
29    fn share(&self) -> &Share<R> {
30        self.state::<Share<R>>().inner()
31    }
32}
33
34/// Initializes the plugin.
35pub fn init<R: Runtime>() -> TauriPlugin<R> {
36    Builder::new("share")
37        .setup(|app, api| {
38            #[cfg(mobile)]
39            let share = mobile::init(app, api)?;
40            #[cfg(desktop)]
41            let share = desktop::init(app, api)?;
42            app.manage(share);
43            Ok(())
44        })
45        .build()
46}