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
24/// Extensions to [`tauri::App`], [`tauri::AppHandle`], [`tauri::WebviewWindow`], [`tauri::Webview`] and [`tauri::Window`] to access the share APIs.
25pub trait ShareExt<R: Runtime> {
26    fn share(&self) -> &Share<R>;
27}
28
29impl<R: Runtime, T: Manager<R>> crate::ShareExt<R> for T {
30    fn share(&self) -> &Share<R> {
31        self.state::<Share<R>>().inner()
32    }
33}
34
35/// Initializes the plugin.
36pub fn init<R: Runtime>() -> TauriPlugin<R> {
37    Builder::new("share")
38        .setup(|app, api| {
39            #[cfg(mobile)]
40            let share = mobile::init(app, api)?;
41            #[cfg(desktop)]
42            let share = desktop::init(app, api)?;
43            app.manage(share);
44            Ok(())
45        })
46        .build()
47}