Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ yarn.lock
Cargo.lock
node_modules/

# Added this directory to the git repo, bcz the plugin is not published yet to any registery
dist-js
dist

# Project exclude paths
/android/.gradle/

# Editor
.zed
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tauri-plugin-admob"
version = "0.0.4"
authors = [ "You" ]
authors = [ "Tauri plugin admob authors" ]
description = "Tauri Plugin admob"
license = "MIT"
edition = "2021"
Expand All @@ -10,9 +10,9 @@ exclude = ["/examples", "/dist-js", "/guest-js", "/node_modules"]
links = "tauri-plugin-admob"

[dependencies]
tauri = { version = "2.4.0" }
serde = "1.0"
tauri = { version = "2" }
serde = "1"
thiserror = "2"

[build-dependencies]
tauri-plugin = { version = "2.1.0", features = ["build"] }
tauri-plugin = { version = "2", features = ["build"] }
3 changes: 3 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/build
/.tauri

# Android Studio
*.properties
16 changes: 8 additions & 8 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

android {
namespace = "com.plugin.admob"
compileSdk = 34
compileSdk = 36

defaultConfig {
minSdk = 21
Expand Down Expand Up @@ -36,13 +36,13 @@ android {

dependencies {
// admob plugin
implementation("com.google.android.gms:play-services-ads:23.2.0")
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.6.0")
implementation("com.google.android.material:material:1.7.0")
implementation("com.google.android.ump:user-messaging-platform:2.2.0")
implementation("com.google.android.gms:play-services-ads:24.5.0")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build fails from 24.6.0 onwards

implementation("androidx.core:core-ktx:1.17.0")
implementation("androidx.appcompat:appcompat:1.7.1")
implementation("com.google.android.material:material:1.13.0")
implementation("com.google.android.ump:user-messaging-platform:4.0.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation("androidx.test.ext:junit:1.3.0")
androidTestImplementation("androidx.test.espresso:espresso-core:3.7.0")
implementation(project(":tauri-android"))
}
Binary file modified bun.lockb
Binary file not shown.
14 changes: 14 additions & 0 deletions dist-js/ads/banner.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MobileAd, type MobileAdOptions } from "./common";
export declare class BannerAd extends MobileAd<BannerAdOptions> {
#private;
static cls: string;
constructor(opts: BannerAdOptions);
isLoaded(): Promise<unknown>;
load(): Promise<void>;
show(): Promise<void>;
hide(): Promise<void>;
}
export type BannerPosition = "top" | "bottom";
export interface BannerAdOptions extends MobileAdOptions {
position?: BannerPosition;
}
20 changes: 20 additions & 0 deletions dist-js/ads/common.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export declare function isPrivacyOptionsRequired(): Promise<boolean>;
export declare function showPrivacyOptionsForm(): Promise<void>;
export declare class MobileAd<T extends MobileAdOptions = MobileAdOptions> {
#private;
private static allAdds;
private static idCounter;
readonly id: number;
protected readonly opts: T;
constructor(opts: T);
private static nextId;
get adUnitId(): string;
protected isLoaded(): Promise<unknown>;
protected load(): Promise<void>;
protected show(): Promise<void>;
protected hide(): Promise<void>;
protected init(): Promise<void>;
}
export interface MobileAdOptions {
adUnitId: string;
}
7 changes: 7 additions & 0 deletions dist-js/ads/interstitial.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { MobileAd } from "./common";
export declare class InterstitialAd extends MobileAd {
static cls: string;
isLoaded(): Promise<unknown>;
load(): Promise<void>;
show(): Promise<void>;
}
19 changes: 19 additions & 0 deletions dist-js/ads/rewarded.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MobileAd, type MobileAdOptions } from "./common";
export declare class RewardedAd extends MobileAd<RewardedAdOptions> {
static cls: string;
isLoaded(): Promise<unknown>;
load(): Promise<void>;
show(): Promise<void>;
}
export declare class RewardedInterstitialAd extends MobileAd<RewardedAdOptions> {
static cls: string;
isLoaded(): Promise<unknown>;
load(): Promise<void>;
show(): Promise<void>;
}
export interface RewardedAdOptions extends MobileAdOptions {
serverSideVerification?: {
userId?: string;
customData?: string;
};
}
154 changes: 154 additions & 0 deletions dist-js/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
let __tauri_apps_api_core = require("@tauri-apps/api/core");

//#region node_modules/.pnpm/@rollup+plugin-typescript@11.1.6_rollup@2.79.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js
function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}
function __classPrivateFieldSet(receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
}

//#endregion
//#region guest-js/ads/common.ts
var _MobileAd_created, _MobileAd_init;
async function isPrivacyOptionsRequired() {
return (await (0, __tauri_apps_api_core.invoke)("plugin:admob|isPrivacyOptionsRequired")).isPrivacyOptionsRequired;
}
async function showPrivacyOptionsForm() {
await (0, __tauri_apps_api_core.invoke)("plugin:admob|showPrivacyOptionsForm");
}
var MobileAd = class MobileAd {
constructor(opts) {
_MobileAd_created.set(this, false);
_MobileAd_init.set(this, null);
this.opts = opts;
this.id = MobileAd.nextId();
MobileAd.allAdds[this.id] = this;
}
static nextId() {
return MobileAd.idCounter++;
}
get adUnitId() {
return this.opts.adUnitId;
}
async isLoaded() {
await this.init();
return await (0, __tauri_apps_api_core.invoke)("plugin:admob|adIsLoaded", { id: this.id });
}
async load() {
await this.init();
await (0, __tauri_apps_api_core.invoke)("plugin:admob|adLoad", {
...this.opts,
id: this.id
});
}
async show() {
await this.init();
await (0, __tauri_apps_api_core.invoke)("plugin:admob|adShow", { id: this.id });
}
async hide() {
await this.init();
await (0, __tauri_apps_api_core.invoke)("plugin:admob|adHide", { id: this.id });
}
async init() {
if (__classPrivateFieldGet(this, _MobileAd_created, "f")) return;
if (__classPrivateFieldGet(this, _MobileAd_init, "f") === null) {
const cls = this.constructor.cls ?? this.constructor.name;
await (0, __tauri_apps_api_core.invoke)("plugin:admob|adCreate", {
...this.opts,
id: this.id,
cls
});
}
await __classPrivateFieldGet(this, _MobileAd_init, "f");
__classPrivateFieldSet(this, _MobileAd_created, true, "f");
}
};
_MobileAd_created = /* @__PURE__ */ new WeakMap(), _MobileAd_init = /* @__PURE__ */ new WeakMap();
MobileAd.allAdds = {};
MobileAd.idCounter = 0;

//#endregion
//#region guest-js/ads/banner.ts
var _BannerAd_loaded;
var BannerAd = class extends MobileAd {
constructor(opts) {
super({
position: "bottom",
...opts
});
_BannerAd_loaded.set(this, false);
}
isLoaded() {
return super.isLoaded();
}
async load() {
await super.load();
__classPrivateFieldSet(this, _BannerAd_loaded, true, "f");
}
async show() {
if (!__classPrivateFieldGet(this, _BannerAd_loaded, "f")) await this.load();
await super.show();
}
hide() {
return super.hide();
}
};
_BannerAd_loaded = /* @__PURE__ */ new WeakMap();
BannerAd.cls = "BannerAd";

//#endregion
//#region guest-js/ads/interstitial.ts
var InterstitialAd = class extends MobileAd {
isLoaded() {
return super.isLoaded();
}
async load() {
return super.load();
}
async show() {
return super.show();
}
};
InterstitialAd.cls = "InterstitialAd";

//#endregion
//#region guest-js/ads/rewarded.ts
var RewardedAd = class extends MobileAd {
isLoaded() {
return super.isLoaded();
}
async load() {
return super.load();
}
async show() {
return super.show();
}
};
RewardedAd.cls = "RewardedAd";
var RewardedInterstitialAd = class extends MobileAd {
isLoaded() {
return super.isLoaded();
}
async load() {
return super.load();
}
async show() {
return super.show();
}
};
RewardedInterstitialAd.cls = "RewardedInterstitialAd";

//#endregion
exports.BannerAd = BannerAd;
exports.InterstitialAd = InterstitialAd;
exports.MobileAd = MobileAd;
exports.RewardedAd = RewardedAd;
exports.RewardedInterstitialAd = RewardedInterstitialAd;
exports.isPrivacyOptionsRequired = isPrivacyOptionsRequired;
exports.showPrivacyOptionsForm = showPrivacyOptionsForm;
4 changes: 4 additions & 0 deletions dist-js/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from "./ads/common";
export * from "./ads/banner";
export * from "./ads/interstitial";
export * from "./ads/rewarded";
Loading