Skip to main content

tauri_plugin_google_admob/
lib.rs

1use 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::GoogleAdmob;
21#[cfg(mobile)]
22use mobile::GoogleAdmob;
23
24/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the google-admob APIs.
25pub trait GoogleAdmobExt<R: Runtime> {
26    fn google_admob(&self) -> &GoogleAdmob<R>;
27}
28
29impl<R: Runtime, T: Manager<R>> crate::GoogleAdmobExt<R> for T {
30    fn google_admob(&self) -> &GoogleAdmob<R> {
31        self.state::<GoogleAdmob<R>>().inner()
32    }
33}
34
35/// Initializes the plugin.
36pub fn init<R: Runtime>() -> TauriPlugin<R> {
37    Builder::new("google-admob")
38        .invoke_handler(tauri::generate_handler![
39            commands::ping,
40            commands::initialize,
41            commands::show_banner,
42            commands::hide_banner,
43            commands::prepare_interstitial,
44            commands::show_interstitial,
45            commands::prepare_rewarded,
46            commands::show_rewarded,
47            commands::prepare_rewarded_interstitial,
48            commands::show_rewarded_interstitial,
49            commands::prepare_app_open,
50            commands::show_app_open,
51        ])
52        .setup(|app, api| {
53            #[cfg(mobile)]
54            let google_admob = mobile::init(app, api)?;
55            #[cfg(desktop)]
56            let google_admob = desktop::init(app, api)?;
57            app.manage(google_admob);
58            Ok(())
59        })
60        .build()
61}