tauri_plugin_pliap/
lib.rs1use 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 commands;
14mod error;
15mod models;
16
17pub use error::{Error, Result};
18
19#[cfg(desktop)]
20use desktop::Pliap;
21#[cfg(mobile)]
22use mobile::Pliap;
23
24pub trait PliapExt<R: Runtime> {
26 fn pliap(&self) -> &Pliap<R>;
27}
28
29impl<R: Runtime, T: Manager<R>> crate::PliapExt<R> for T {
30 fn pliap(&self) -> &Pliap<R> {
31 self.state::<Pliap<R>>().inner()
32 }
33}
34
35pub fn init<R: Runtime>() -> TauriPlugin<R> {
37 Builder::new("pliap")
38 .invoke_handler(tauri::generate_handler![
39 commands::ping,
40 commands::create_purchase,
41 commands::create_purchase_subscription,
42 commands::consume,
43 commands::get_product,
44 commands::get_all_purchases,
45 commands::get_subscription,
46 commands::get_list_subscription,
47 ])
48 .setup(|app, api| {
49 #[cfg(mobile)]
50 let pliap = mobile::init(app, api)?;
51 #[cfg(desktop)]
52 let pliap = desktop::init(app, api)?;
53 app.manage(pliap);
54 Ok(())
55 })
56 .build()
57}