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