tauri_plugin_sharetarget/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use tauri::{
    Runtime, Manager,
    plugin::{TauriPlugin, Builder},
};
pub use models::*;

#[cfg(desktop)]
mod desktop;
#[cfg(mobile)]
mod mobile;

mod commands;
mod error;
mod models;

pub use error::{Error, Result};

#[cfg(desktop)]
use desktop::ShareTarget;
#[cfg(mobile)]
use mobile::ShareTarget;


/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the sharetarget APIs.
pub trait ShareTargetExt<R: Runtime> {
    fn sharetarget(&self) -> &ShareTarget<R>;
}

impl<R: Runtime, T: Manager<R>> crate::ShareTargetExt<R> for T {
    /// Get the `ShareTarget` handler.
    fn sharetarget(&self) -> &ShareTarget<R> {
        self.state::<ShareTarget<R>>().inner()
    }
}

/// Initialize the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
    Builder::new("sharetarget")
        .invoke_handler(tauri::generate_handler![commands::ping])
        .setup(|app, api| {
            #[cfg(mobile)]
            let sharetarget = mobile::init(app, api)?;
            #[cfg(desktop)]
            let sharetarget = desktop::init(app, api)?;
            app.manage(sharetarget);
            Ok(())
        })
        .build()
}