master
rs 43 lines 927 Bytes
Raw
1 use tauri::{
2 plugin::{Builder, TauriPlugin},
3 Manager, Runtime,
4 };
5
6 #[cfg(desktop)]
7 mod desktop;
8 #[cfg(mobile)]
9 mod mobile;
10
11 mod error;
12
13 pub use error::{Error, Result};
14
15 #[cfg(desktop)]
16 use desktop::Admob;
17 #[cfg(mobile)]
18 use mobile::Admob;
19
20 /// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the admob APIs.
21 pub trait AdmobExt<R: Runtime> {
22 fn admob(&self) -> &Admob<R>;
23 }
24
25 impl<R: Runtime, T: Manager<R>> crate::AdmobExt<R> for T {
26 fn admob(&self) -> &Admob<R> {
27 self.state::<Admob<R>>().inner()
28 }
29 }
30
31 /// Initializes the plugin.
32 pub fn init<R: Runtime>() -> TauriPlugin<R> {
33 Builder::new("admob")
34 .setup(|app, api| {
35 #[cfg(mobile)]
36 let admob = mobile::init(app, api)?;
37 #[cfg(desktop)]
38 let admob = desktop::init(app, api)?;
39 app.manage(admob);
40 Ok(())
41 })
42 .build()
43 }