chore: update tauri (#1)
* updated the rust files to match rust files in the latest plugin template * formatted ts files * updating package.json to match the latest template * added post install script * check including the build * removed post install script * clarified how to install the plugin using github link, and added an example on how to use it * updated terminal command in readme * updated Readme file * added a comment * updated readme file * removed dist-js from gitignore
Mohamed Eliwa committed
Mar 23, 2025 at 12:25 UTC
b3e5007fa455b2ac22b7b86ad2d7b9a0bd3c1e8a
9 files changed
+107
-38
.gitignore
+1
@@ -14,6 +14,7 @@ yarn.lock
14
Cargo.lock
15
node_modules/
16
17
+# Added this directory to the git repo, bcz the plugin is not published yet to any registery
18
dist-js
19
dist
20
Cargo.toml
+4
-4
@@ -5,13 +5,13 @@ authors = [ "You" ]
5
description = ""
6
edition = "2021"
7
rust-version = "1.70"
8
-exclude = ["/examples", "/webview-dist", "/webview-src", "/node_modules"]
8
+exclude = ["/examples", "/dist-js", "/guest-js", "/node_modules"]
9
links = "tauri-plugin-admob"
10
11
[dependencies]
12
-tauri = { version = "2.0.0-beta.24" }
12
+tauri = { version = "2.4.0" }
13
serde = "1.0"
14
-thiserror = "1.0"
14
+thiserror = "2"
15
16
[build-dependencies]
17
-tauri-plugin = { version = "2.0.0-beta.19", features = ["build"] }
17
+tauri-plugin = { version = "2.1.0", features = ["build"] }
README.md
+37
-4
@@ -2,9 +2,27 @@
2
3
> For now this is just a copy of [admob-plus](https://github.com/admob-plus/admob-plus) in the future I would like to refactor the code to be more Tauri friendly.
4
5
-### How to install
5
+> The plugin currently only supports android. If you want iOS support, please feel free to create a pull request
6
7
-1. Since google library uses different Kotlin version than Tauri you may need to add the following compiler
7
+## How to install
8
+
9
+Since this plugin is yet not published to crates.io or npm registery, we can install it using github link directly.
10
+
11
+1. Inside your root directory run this command
12
+
13
+```bash
14
+npm i https://github.com/Dreaming-Codes/tauri-plugin-admob.git
15
+```
16
+
17
+> You might need to update your tauri version to "2.4.0" or more
18
+
19
+2. Inside your `src-tauri` directory run this command
20
+
21
+```bash
22
+cargo add tauri-plugin-admob --git https://github.com/Dreaming-Codes/tauri-plugin-admob.git
23
+```
24
+
25
+3. Since google library uses different Kotlin version than Tauri you may need to add the following compiler
26
arg: `-Xskip-metadata-version-check`
27
28
```kotlin
@@ -15,7 +33,7 @@ kotlinOptions {
33
}
34
```
35
18
-2. Add your AdMob app ID, as [identified in the AdMob web interface](https://support.google.com/admob/answer/7356431),
36
+4. Add your AdMob app ID, as [identified in the AdMob web interface](https://support.google.com/admob/answer/7356431),
37
to your app's AndroidManifest.xml.
38
To do so, add a `<meta-data>` tag with `android:name="com.google.android.gms.ads.APPLICATION_ID"`. You can find your
39
**app ID** in the AdMob web interface. For `android:value`, insert your own AdMob app ID, surrounded by quotation
@@ -36,4 +54,19 @@ kotlinOptions {
54
</manifest>
55
```
56
39
-3. Install this plugin as any other Tauri plugin
57
+## How to use
58
+
59
+```ts
60
+import { BannerAd } from "tauri-plugin-admob-api";
61
+
62
+const showBanner = async () => {
63
+ const banner = new BannerAd({
64
+ adUnitId: "ca-app-pub-3940256099942544/9214589741",
65
+ position: "bottom",
66
+ });
67
+ await banner.load();
68
+ await banner.show();
69
+};
70
+```
71
+
72
+> For more details on how to use it check the documentation of [admob-plus](https://github.com/admob-plus/admob-plus)
build.rs
+18
-5
@@ -1,8 +1,21 @@
1
-const COMMANDS: &[&str] = &["trackingAuthorizationStatus", "requestTrackingAuthorization", "configure", "configRequest", "adCreate", "adIsLoaded", "adLoad", "adShow", "adHide", "isPrivacyOptionsRequired", "showPrivacyOptionsForm", "register_listener"];
1
+const COMMANDS: &[&str] = &[
2
+ "trackingAuthorizationStatus",
3
+ "requestTrackingAuthorization",
4
+ "configure",
5
+ "configRequest",
6
+ "adCreate",
7
+ "adIsLoaded",
8
+ "adLoad",
9
+ "adShow",
10
+ "adHide",
11
+ "isPrivacyOptionsRequired",
12
+ "showPrivacyOptionsForm",
13
+ "register_listener",
14
+];
15
16
fn main() {
4
- tauri_plugin::Builder::new(COMMANDS)
5
- .android_path("android")
6
- .ios_path("ios")
7
- .build();
17
+ tauri_plugin::Builder::new(COMMANDS)
18
+ .android_path("android")
19
+ .ios_path("ios")
20
+ .build();
21
}
package.json
+1
-1
@@ -25,7 +25,7 @@
25
"check": "biome check"
26
},
27
"dependencies": {
28
- "@tauri-apps/api": "^2.0.0-beta.15"
28
+ "@tauri-apps/api": ">=2.0.0-beta.6"
29
},
30
"devDependencies": {
31
"@biomejs/biome": "1.9.4",
permissions/autogenerated/reference.md
+1
-1
@@ -14,7 +14,7 @@ Default permissions for the plugin
14
- `allow-isPrivacyOptionsRequired`
15
- `allow-showPrivacyOptionsForm`
16
17
-## Permission Table
17
+## Permission Table
18
19
<table>
20
<tr>
src/desktop.rs
new
+12
@@ -0,0 +1,12 @@
1
+use serde::de::DeserializeOwned;
2
+use tauri::{plugin::PluginApi, AppHandle, Runtime};
3
+
4
+pub fn init<R: Runtime, C: DeserializeOwned>(
5
+ app: &AppHandle<R>,
6
+ _api: PluginApi<R, C>,
7
+) -> crate::Result<Admob<R>> {
8
+ Ok(Admob(app.clone()))
9
+}
10
+
11
+/// Access to the Admob APIs.
12
+pub struct Admob<R: Runtime>(AppHandle<R>);
src/error.rs
+11
-8
@@ -4,15 +4,18 @@ pub type Result<T> = std::result::Result<T, Error>;
4
5
#[derive(Debug, thiserror::Error)]
6
pub enum Error {
7
- #[error(transparent)]
8
- PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
7
+ #[error(transparent)]
8
+ Io(#[from] std::io::Error),
9
+ #[cfg(mobile)]
10
+ #[error(transparent)]
11
+ PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
12
}
13
14
impl Serialize for Error {
12
- fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
13
- where
14
- S: Serializer,
15
- {
16
- serializer.serialize_str(self.to_string().as_ref())
17
- }
15
+ fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
16
+ where
17
+ S: Serializer,
18
+ {
19
+ serializer.serialize_str(self.to_string().as_ref())
20
+ }
21
}
src/lib.rs
+22
-15
@@ -1,36 +1,43 @@
1
-#![cfg(mobile)]
2
-
1
use tauri::{
4
- plugin::{Builder, TauriPlugin},
5
- Manager, Runtime,
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> {
18
- fn admob(&self) -> &Admob<R>;
22
+ fn admob(&self) -> &Admob<R>;
23
}
24
25
impl<R: Runtime, T: Manager<R>> crate::AdmobExt<R> for T {
22
- fn admob(&self) -> &Admob<R> {
23
- self.state::<Admob<R>>().inner()
24
- }
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> {
29
- Builder::new("admob")
30
- .setup(|app, api| {
31
- let admob = mobile::init(app, api)?;
32
- app.manage(admob);
33
- Ok(())
34
- })
35
- .build()
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
}