1use tauri::{
2 plugin::{Builder, TauriPlugin},
3 Manager, Runtime,
4};
5
6pub use models::*;
7
8#[cfg(target_os = "android")]
9mod android;
10#[cfg(any(target_os = "macos", target_os = "ios"))]
11mod apple;
12#[cfg(any(target_os = "windows", target_os = "linux"))]
13mod desktop;
14
15mod commands;
16mod error;
17mod models;
18
19pub use error::{Error, Result};
20
21#[cfg(target_os = "android")]
22use android::Iap;
23#[cfg(any(target_os = "macos", target_os = "ios"))]
24use apple::Iap;
25#[cfg(any(target_os = "windows", target_os = "linux"))]
26use desktop::Iap;
27
28pub trait IapExt<R: Runtime> {
30 fn iap(&self) -> &Iap<R>;
31}
32
33impl<R: Runtime, T: Manager<R>> crate::IapExt<R> for T {
34 fn iap(&self) -> &Iap<R> {
35 self.state::<Iap<R>>().inner()
36 }
37}
38
39pub fn init<R: Runtime>() -> TauriPlugin<R> {
41 Builder::new("iap")
42 .invoke_handler(tauri::generate_handler![
43 commands::initialize,
44 commands::get_products,
45 commands::purchase,
46 commands::restore_purchases,
47 commands::get_purchase_history,
48 commands::acknowledge_purchase,
49 ])
50 .setup(|app, api| {
51 #[cfg(target_os = "android")]
52 let iap = android::init(app, api)?;
53 #[cfg(any(target_os = "macos", target_os = "ios"))]
54 let iap = apple::init(app, api)?;
55 #[cfg(any(target_os = "windows", target_os = "linux"))]
56 let iap = desktop::init(app, api)?;
57 app.manage(iap);
58 Ok(())
59 })
60 .build()
61}