codeplay-common 4.11.41-alpha.2 → 4.11.41-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/README.md +24 -8
- package/RELEASE_NOTES.md +1 -0
- package/files/buildCodeplay/codeplayBeforeBuild.js +18 -6
- package/files/buildCodeplay/project-scripts.cjs +8 -1
- package/files/buildCodeplay/sync-capacitor9-launch-splash.cjs +59 -0
- package/files/patches/catalog/capacitor-admob-nextgen+1.6.0.patch +210 -1
- package/files/patches/catalog/capacitor-admob-nextgen+1.6.2-beta.patch +209 -0
- package/files/scripts-common/run-codeplay-sync-after.js +1 -0
- package/files/scripts-common/setup-baseline-profile.js +18 -15
- package/package.json +1 -1
- package/scripts/capacitor-9-migration.test.cjs +174 -0
- package/scripts/capacitor9-splash.test.cjs +47 -0
- package/scripts/prepare-capacitor-9.cjs +88 -5
- package/scripts/saf-mediastore-dependency.test.cjs +3 -2
- package/scripts/squeezeback-config.test.cjs +38 -4
- package/scripts/sync-files.js +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -15,6 +15,7 @@ Files changed: `package.json`, `runtime/splash-ready.mjs`, `files/buildCodeplay/
|
|
|
15
15
|
|
|
16
16
|
## Unreleased
|
|
17
17
|
|
|
18
|
+
- Apply the Capacitor 9 launch splash icon and a small XML fallback during installation, Android sync, and before-build. Preserve custom themes and reuse existing app images.
|
|
18
19
|
- Add a Huawei-only first-launch Simplified Chinese privacy consent gate from shared `buildCodeplay` files. Keep Firebase Analytics off by default in Huawei native builds, restore non-Huawei entries on the next build, and provide a Settings link and withdrawal control. Each app still needs its own published Chinese policy profile before submission.
|
|
19
20
|
- Add optional camera, autofocus and flash feature declarations after package-specific manifest updates. Warn about Amazon device exclusions for existing required camera features (including manual declarations); Enter or a 5-second timeout changes them to optional, while n/N preserves them. Avoid duplicate features on repeated builds and run package-ID preparation in every Android store build command.
|
|
20
21
|
- Invalidate the cached source-file inventory after removing replaced plugin folders or versioned files, so post-update validation scans the installed sources instead of deleted theme paths.
|
package/README.md
CHANGED
|
@@ -20,15 +20,23 @@ installs. Every build checks and reapplies the active patches before native
|
|
|
20
20
|
work. Run `node node_modules/codeplay-common/scripts/prepare-capacitor-9.cjs`
|
|
21
21
|
for a read-only report. An active patch for an absent or newer plugin stops the
|
|
22
22
|
install/build with its old and installed versions so the team can review it.
|
|
23
|
-
Existing app-specific patches for the same version are preserved. The
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
Existing app-specific patches for the same version are preserved. The AdMob
|
|
24
|
+
1.6.0 patch includes the removed `hasOption()` API fix and banner/WebView inset
|
|
25
|
+
changes. The 1.6.2-beta patch keeps only the inset changes because its API fix
|
|
26
|
+
is upstream. For a newer AdMob version, preparation verifies that both API calls
|
|
27
|
+
remain fixed and every inset patch hunk still fits. It then creates an active
|
|
28
|
+
patch named for the installed version. Changed Java code stops the build for
|
|
29
|
+
review. An older installation must first be upgraded to 1.6.0.
|
|
27
30
|
|
|
28
31
|
The migration build helper no longer rewrites Capacitor's `BridgeWebViewClient.java` or
|
|
29
|
-
`SystemBars.java`. In Capacitor 9 apps,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
`SystemBars.java`. In Capacitor 9 apps, installation also updates the standard
|
|
33
|
+
`AppTheme.NoActionBarLaunch` theme to select the app icon explicitly and creates
|
|
34
|
+
a small XML launch-window fallback for older Android and Fire OS. It reuses
|
|
35
|
+
`resources/splash_icon.png` when present, or the existing launcher icon otherwise.
|
|
36
|
+
Installation, Android sync, and before-build all run the idempotent helper. Custom
|
|
37
|
+
launch themes and drawables are preserved and reported for app-specific review.
|
|
38
|
+
Rebuild the APK to receive native splash changes; installation alone cannot
|
|
39
|
+
change an already installed app.
|
|
32
40
|
|
|
33
41
|
Version 4.11.37 adds the `/buildCodeplay` Vite alias during installation and
|
|
34
42
|
before-build setup, including upgrades of existing generated wrappers. This
|
|
@@ -222,6 +230,14 @@ All fix implementations ship under `buildCodeplay/fix-optimize-builld/`, includi
|
|
|
222
230
|
|
|
223
231
|
After installing this package update, rebuild and test each app's optimized release. Updating build tooling cannot change APKs or app-store releases already distributed to users.
|
|
224
232
|
|
|
233
|
+
## Capacitor 9 migration helpers
|
|
234
|
+
|
|
235
|
+
The server agent archive supplies `AGENTS/capacitor-8-to-9-migration.md`. Installing this package alone does not migrate an app's native projects. Use the guide in a disposable branch or test copy and review the app's custom Android and iOS code.
|
|
236
|
+
|
|
237
|
+
The installer copies exact-version plugin patches into `patches/catalog/`. On Capacitor 9 it selects matching patches into `patches/active/` and applies them. The before-sync and before-update hooks repeat that check, remove the old `setSplashAnimation.js` call, and leave Capacitor 8 projects unchanged. A mismatched active patch stops the operation for review. Apps that enable Squeezeback use AdMob NextGen 1.6.2-beta until a stable 1.6.2+ release appears, then the updater can install that stable version. Before native work, patch preparation checks the new plugin's Capacitor API calls and every banner/inset patch hunk. If unchanged, it creates a version-named active patch; otherwise it stops for review. The beta upstream release contains the Capacitor 9 `PluginCall` API fix, while its shared patch retains the banner/WebView inset behavior. Known prior patches are replaced; unknown app-specific edits stop for review. A successful patch application still requires device layout validation before publishing the app.
|
|
238
|
+
|
|
239
|
+
For apps with a baseline-profile module, installation and the Capacitor 9 before-sync/update hooks automatically run the bundled baseline helper. It selects the AGP 9 compatible baseline-profile Gradle plugin and removes duplicate module includes before native sync. Verify the native diff under each app's protected-file rules. Native template cleanup, safe-area CSS, store-specific rules, iOS SwiftUI changes, and device validation remain per-app migration steps.
|
|
240
|
+
|
|
225
241
|
## App helper folder
|
|
226
242
|
|
|
227
243
|
Application helper scripts are kept in `scripts-common/`. Installation migrates the old `scripts/` folder and package command paths automatically, preserving every existing file. A conflicting destination file stops migration before any files are moved. The plugin’s internal npm lifecycle folder remains `scripts/`.
|
|
@@ -230,7 +246,7 @@ Application helper scripts are kept in `scripts-common/`. Installation migrates
|
|
|
230
246
|
|
|
231
247
|
The plugin keeps the master build templates in files/buildCodeplay and copies them into each app's buildCodeplay folder during installation/update. Test changes in the application folder, then update these master templates for distribution to other apps.
|
|
232
248
|
|
|
233
|
-
App package scripts run local files
|
|
249
|
+
App package scripts run local files such as node buildCodeplay/codeplayBeforeBuild.js and node buildCodeplay/packageidBaseModification.js. Capacitor 8 apps can still use the legacy splash helpers; Capacitor 9 preparation removes the obsolete setSplashAnimation sync call. Filenames have no version suffixes. The versions.json plugin manifest remains alongside these scripts and is copied too.
|
|
234
250
|
|
|
235
251
|
Installation migrates both legacy versioned filenames and the temporary node_modules runner commands to these local paths. It removes only superseded versioned build scripts, preserves app-owned release configuration and splash XML overrides, and keeps screenshot data and custom helpers. The root finalrelease script is also copied as a local implementation.
|
|
236
252
|
|
package/RELEASE_NOTES.md
CHANGED
|
@@ -15,6 +15,7 @@ Files changed: `package.json`, `runtime/splash-ready.mjs`, `files/buildCodeplay/
|
|
|
15
15
|
|
|
16
16
|
## Unreleased
|
|
17
17
|
|
|
18
|
+
- Fix blank or default-icon launch splashes in Capacitor 9 apps, including older Fire OS, without adding a bitmap.
|
|
18
19
|
- Improve Amazon device compatibility by making camera features optional during build preparation. If a camera feature is required, press Enter or wait 5 seconds to make it optional, or press n to keep it required. This also checks manually added declarations and preserves existing camera permissions.
|
|
19
20
|
- Prevent builds from failing on deleted theme paths immediately after automatic plugin updates.
|
|
20
21
|
- Repair old save-file imports automatically, including imports in Framework7 pages, and keep the Vite alias aligned with the latest installed Android or iOS helper.
|
|
@@ -555,11 +555,13 @@ function checkPackageVersion() {
|
|
|
555
555
|
return;
|
|
556
556
|
}
|
|
557
557
|
const installedVersion = getInstalledVersion(packageName);
|
|
558
|
-
const
|
|
558
|
+
const registryPackage = installedVersion?.includes('-') || declaredPackage.includes('-alpha.')
|
|
559
|
+
? `${packageName}@alpha` : packageName;
|
|
560
|
+
const latestVersion = getLatestVersion(registryPackage);
|
|
559
561
|
|
|
560
562
|
if (!installedVersion) {
|
|
561
563
|
console.error(`${packageName} is not installed. Installing now...`);
|
|
562
|
-
execSync(`npm install ${
|
|
564
|
+
execSync(`npm install ${registryPackage}`, { stdio: 'inherit' });
|
|
563
565
|
return;
|
|
564
566
|
}
|
|
565
567
|
|
|
@@ -567,7 +569,7 @@ function checkPackageVersion() {
|
|
|
567
569
|
console.log(`${packageName} is outdated (installed: ${installedVersion}, latest: ${latestVersion}). Updating now...`);
|
|
568
570
|
|
|
569
571
|
try {
|
|
570
|
-
execSync(`npm install ${
|
|
572
|
+
execSync(`npm install ${registryPackage}`, { stdio: 'inherit' });
|
|
571
573
|
console.log(`${packageName} successfully updated.`);
|
|
572
574
|
} catch (err) {
|
|
573
575
|
console.error(`Failed to update ${packageName}:`, err.message);
|
|
@@ -3222,9 +3224,18 @@ const syncAdmobNextgenPackage = () => {
|
|
|
3222
3224
|
const installedAdmob = getInstalledVersion("capacitor-admob-nextgen");
|
|
3223
3225
|
const squeezebackEnabled = readJsonSafe(getAdmobJsonPath())?.config?.squeezebackEnabled;
|
|
3224
3226
|
const needsSqueezeback = [true, 1, "true", "1"].includes(squeezebackEnabled);
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3227
|
+
const latestStable = needsSqueezeback ? getLatestVersion("capacitor-admob-nextgen") : null;
|
|
3228
|
+
const fixedStable = /^\d+\.\d+\.\d+$/.test(latestStable || "") &&
|
|
3229
|
+
compareVersionStrings(latestStable, "1.6.2") >= 0;
|
|
3230
|
+
const installedBase = installedAdmob?.split("-")[0];
|
|
3231
|
+
if (!installedAdmob) {
|
|
3232
|
+
runNpmCommand(`npm install capacitor-admob-nextgen${needsSqueezeback && !fixedStable ? "@1.6.2-beta" : ""}`);
|
|
3233
|
+
} else if (needsSqueezeback && fixedStable &&
|
|
3234
|
+
(compareVersionStrings(installedBase, latestStable) < 0 ||
|
|
3235
|
+
(installedAdmob.includes("-") && compareVersionStrings(installedBase, latestStable) === 0))) {
|
|
3236
|
+
runNpmCommand(`npm install capacitor-admob-nextgen@${latestStable}`);
|
|
3237
|
+
} else if (needsSqueezeback && !fixedStable && compareVersionStrings(installedBase, "1.6.2") < 0) {
|
|
3238
|
+
runNpmCommand("npm install capacitor-admob-nextgen@1.6.2-beta");
|
|
3228
3239
|
} else {
|
|
3229
3240
|
console.log("ℹ️ Keeping the installed capacitor-admob-nextgen version.");
|
|
3230
3241
|
}
|
|
@@ -4374,6 +4385,7 @@ async function main() {
|
|
|
4374
4385
|
}
|
|
4375
4386
|
if (buildPlatform === 'android' && fs.existsSync(androidPlatformPath)) {
|
|
4376
4387
|
require('./sync-notification-large-icon.cjs').syncNotificationLargeIcon(process.cwd());
|
|
4388
|
+
require('./sync-capacitor9-launch-splash.cjs').syncCapacitor9LaunchSplash(process.cwd());
|
|
4377
4389
|
}
|
|
4378
4390
|
require('./setup-ruads.cjs').syncRuAdsSetup(process.cwd());
|
|
4379
4391
|
validateThemeFolderLocation();
|
|
@@ -9,7 +9,8 @@ const tasks = {
|
|
|
9
9
|
'apk': 'node buildCodeplay/apk-store-builder.js',
|
|
10
10
|
'final-release': 'node finalrelease',
|
|
11
11
|
};
|
|
12
|
-
const
|
|
12
|
+
const launchSplash = 'node buildCodeplay/sync-capacitor9-launch-splash.cjs';
|
|
13
|
+
const syncAfter = `${tasks.splash} && ${launchSplash} && ${tasks.manifest} && node scripts-common/setup-baseline-profile.js`;
|
|
13
14
|
function updateBuildScripts(scripts) {
|
|
14
15
|
const next = { ...scripts };
|
|
15
16
|
for (const key of Object.keys(next)) {
|
|
@@ -32,11 +33,17 @@ function updateBuildScripts(scripts) {
|
|
|
32
33
|
next['build:ios'] = next['build:ios'] || 'cross-env CODEPLAY_BUILD_PLATFORM=ios VITE_STORE_ID=6 npm run build';
|
|
33
34
|
if (!/VITE_STORE_ID=6\b/.test(next['build:ios'])) next['build:ios'] = next['build:ios'].replace('CODEPLAY_BUILD_PLATFORM=ios ', 'CODEPLAY_BUILD_PLATFORM=ios VITE_STORE_ID=6 ');
|
|
34
35
|
next['capacitor:sync:after'] = next['capacitor:sync:after'] || syncAfter;
|
|
36
|
+
if (!next['capacitor:sync:after'].includes(launchSplash) &&
|
|
37
|
+
!next['capacitor:sync:after'].includes('run-codeplay-sync-after.js')) {
|
|
38
|
+
next['capacitor:sync:after'] += ` && ${launchSplash}`;
|
|
39
|
+
}
|
|
35
40
|
const safDependency = 'node buildCodeplay/saf-mediastore-dependency.cjs';
|
|
41
|
+
const cap9Prepare = 'node node_modules/codeplay-common/scripts/prepare-capacitor-9.cjs --apply-if-cap9';
|
|
36
42
|
for (const hook of ['capacitor:sync:before', 'capacitor:update:before']) {
|
|
37
43
|
if (!(next[hook] || '').includes(safDependency)) {
|
|
38
44
|
next[hook] = next[hook] ? `${safDependency} && ${next[hook]}` : safDependency;
|
|
39
45
|
}
|
|
46
|
+
if (!next[hook].includes(cap9Prepare)) next[hook] = `${cap9Prepare} && ${next[hook]}`;
|
|
40
47
|
}
|
|
41
48
|
next['build-capacitor-android'] = next['build-capacitor-android'] || 'npm run build && npx cap copy android';
|
|
42
49
|
next['build-capacitor-ios'] = next['build-capacitor-ios']
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
function syncCapacitor9LaunchSplash(projectRoot) {
|
|
5
|
+
const packageFile = path.join(projectRoot, 'package.json');
|
|
6
|
+
if (!fs.existsSync(packageFile)) return 'no-package';
|
|
7
|
+
const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
|
|
8
|
+
const version = pkg.dependencies?.['@capacitor/core'] || pkg.devDependencies?.['@capacitor/core'] || '';
|
|
9
|
+
if (Number(version.match(/\d+/)?.[0]) !== 9) return 'not-capacitor-9';
|
|
10
|
+
|
|
11
|
+
const res = path.join(projectRoot, 'android', 'app', 'src', 'main', 'res');
|
|
12
|
+
const stylesFile = path.join(res, 'values', 'styles.xml');
|
|
13
|
+
if (!fs.existsSync(stylesFile)) return 'no-android-theme';
|
|
14
|
+
const source = fs.readFileSync(stylesFile, 'utf8');
|
|
15
|
+
const style = /<style\s+name="AppTheme\.NoActionBarLaunch"\s+parent="Theme\.SplashScreen"\s*>([\s\S]*?)<\/style>/;
|
|
16
|
+
const match = source.match(style);
|
|
17
|
+
if (!match || !source.includes('name="AppTheme.NoActionBar"')) return 'custom-theme';
|
|
18
|
+
|
|
19
|
+
const iconSource = path.join(projectRoot, 'resources', 'splash_icon.png');
|
|
20
|
+
const iconTarget = path.join(res, 'drawable-nodpi', 'splash_icon.png');
|
|
21
|
+
const icon = fs.existsSync(iconSource) || fs.existsSync(iconTarget)
|
|
22
|
+
? '@drawable/splash_icon' : '@mipmap/ic_launcher';
|
|
23
|
+
const background = path.join(res, 'drawable', 'launch_background.xml');
|
|
24
|
+
const expected = `<?xml version="1.0" encoding="utf-8"?>\n<layer-list xmlns:android="http://schemas.android.com/apk/res/android">\n <item android:drawable="@android:color/white" />\n <item\n android:drawable="${icon}"\n android:gravity="center"\n android:width="220dp"\n android:height="220dp" />\n</layer-list>\n`;
|
|
25
|
+
const body = match[1];
|
|
26
|
+
const original = /^\s*<item name="android:background">@drawable\/splash<\/item>\s*$/.test(body);
|
|
27
|
+
const managedItems = [
|
|
28
|
+
'<item name="android:background">@drawable/launch_background</item>',
|
|
29
|
+
'<item name="android:windowBackground">@drawable/launch_background</item>',
|
|
30
|
+
'<item name="windowSplashScreenBackground">@android:color/white</item>',
|
|
31
|
+
`<item name="windowSplashScreenAnimatedIcon">${icon}</item>`,
|
|
32
|
+
'<item name="postSplashScreenTheme">@style/AppTheme.NoActionBar</item>',
|
|
33
|
+
];
|
|
34
|
+
const managed = managedItems.every(item => body.includes(item)) &&
|
|
35
|
+
!body.replace(/<item\b[^>]*>[^<]*<\/item>/g, '').trim();
|
|
36
|
+
if (!original && !managed) return 'custom-theme';
|
|
37
|
+
if (fs.existsSync(background) && fs.readFileSync(background, 'utf8') !== expected) return 'custom-background';
|
|
38
|
+
|
|
39
|
+
const replacement = `<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">\n` +
|
|
40
|
+
` <item name="android:background">@drawable/launch_background</item>\n` +
|
|
41
|
+
` <item name="android:windowBackground">@drawable/launch_background</item>\n` +
|
|
42
|
+
` <item name="windowSplashScreenBackground">@android:color/white</item>\n` +
|
|
43
|
+
` <item name="windowSplashScreenAnimatedIcon">${icon}</item>\n` +
|
|
44
|
+
` <item name="postSplashScreenTheme">@style/AppTheme.NoActionBar</item>\n` +
|
|
45
|
+
` </style>`;
|
|
46
|
+
const updated = source.replace(style, replacement);
|
|
47
|
+
if (updated === source && fs.existsSync(background)) return 'unchanged';
|
|
48
|
+
fs.mkdirSync(path.dirname(background), { recursive: true });
|
|
49
|
+
if (!fs.existsSync(background)) fs.writeFileSync(background, expected);
|
|
50
|
+
if (updated !== source) fs.writeFileSync(stylesFile, updated);
|
|
51
|
+
return 'updated';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (require.main === module) {
|
|
55
|
+
const result = syncCapacitor9LaunchSplash(path.resolve(__dirname, '..'));
|
|
56
|
+
console.log(`Capacitor 9 launch splash: ${result}.`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = { syncCapacitor9LaunchSplash };
|
|
@@ -7,4 +7,213 @@ diff --git a/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/
|
|
|
7
7
|
- Boolean tagForUnderAgeOfConsent = call.hasOption("tagForUnderAgeOfConsent") ? call.getBoolean("tagForUnderAgeOfConsent") : null;
|
|
8
8
|
+ Boolean tagForChildDirectedTreatment = call.getData().has("tagForChildDirectedTreatment") ? call.getBoolean("tagForChildDirectedTreatment") : null;
|
|
9
9
|
+ Boolean tagForUnderAgeOfConsent = call.getData().has("tagForUnderAgeOfConsent") ? call.getBoolean("tagForUnderAgeOfConsent") : null;
|
|
10
|
-
Boolean isTesting = call.getBoolean("isTesting", false);
|
|
10
|
+
Boolean isTesting = call.getBoolean("isTesting", false);
|
|
11
|
+
diff --git a/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/banner/BannerExecutor.java b/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/banner/BannerExecutor.java
|
|
12
|
+
index 8b984f2..e2cf878 100644
|
|
13
|
+
--- a/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/banner/BannerExecutor.java
|
|
14
|
+
+++ b/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/banner/BannerExecutor.java
|
|
15
|
+
@@ -330,6 +330,30 @@ public class BannerExecutor {
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
+ private int getEffectiveSystemInset(int inset, boolean top) {
|
|
20
|
+
+ if (inset <= 0) return 0;
|
|
21
|
+
+
|
|
22
|
+
+ Activity activity = plugin.getActivity();
|
|
23
|
+
+ if (activity == null) return 0;
|
|
24
|
+
+
|
|
25
|
+
+ View layoutView = capacitorAdLayout != null && capacitorAdLayout.getHeight() > 0
|
|
26
|
+
+ ? capacitorAdLayout : activity.getWindow().getDecorView();
|
|
27
|
+
+ int[] location = new int[2];
|
|
28
|
+
+ layoutView.getLocationOnScreen(location);
|
|
29
|
+
+ if (top) return Math.min(inset, Math.max(0, inset - location[1]));
|
|
30
|
+
+
|
|
31
|
+
+ int screenBottom;
|
|
32
|
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
33
|
+
+ screenBottom = activity.getWindowManager().getCurrentWindowMetrics().getBounds().bottom;
|
|
34
|
+
+ } else {
|
|
35
|
+
+ android.graphics.Point screenSize = new android.graphics.Point();
|
|
36
|
+
+ activity.getWindowManager().getDefaultDisplay().getRealSize(screenSize);
|
|
37
|
+
+ screenBottom = screenSize.y;
|
|
38
|
+
+ }
|
|
39
|
+
+ int layoutBottom = location[1] + layoutView.getHeight();
|
|
40
|
+
+ return Math.min(inset, Math.max(0, layoutBottom - (screenBottom - inset)));
|
|
41
|
+
+ }
|
|
42
|
+
+
|
|
43
|
+
private void updateBannerLayout() {
|
|
44
|
+
|
|
45
|
+
if (Build.VERSION.SDK_INT < 35) {
|
|
46
|
+
@@ -346,10 +370,10 @@ public class BannerExecutor {
|
|
47
|
+
|
|
48
|
+
if ("TOP".equals(currentPosition)) {
|
|
49
|
+
bannerParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
|
50
|
+
- bannerParams.setMargins(0, systemSafeTop, 0, 0);
|
|
51
|
+
+ bannerParams.setMargins(0, getEffectiveSystemInset(systemSafeTop, true), 0, 0);
|
|
52
|
+
} else {
|
|
53
|
+
bannerParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
|
54
|
+
- bannerParams.setMargins(0, 0, 0, systemSafeBottom);
|
|
55
|
+
+ bannerParams.setMargins(0, 0, 0, getEffectiveSystemInset(systemSafeBottom, false));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
adView.setLayoutParams(bannerParams);
|
|
59
|
+
@@ -399,11 +423,11 @@ public class BannerExecutor {
|
|
60
|
+
|
|
61
|
+
if ("TOP".equals(currentPosition)) {
|
|
62
|
+
bannerParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
|
63
|
+
- int baseTop = legacyApplyBannerInsets ? topMargin : 0;
|
|
64
|
+
+ int baseTop = legacyApplyBannerInsets ? getEffectiveSystemInset(topMargin, true) : 0;
|
|
65
|
+
bannerParams.setMargins(0, baseTop + legacyMarginOffset, 0, 0);
|
|
66
|
+
} else {
|
|
67
|
+
bannerParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
|
68
|
+
- int baseBottom = legacyApplyBannerInsets ? bottomMargin : 0;
|
|
69
|
+
+ int baseBottom = legacyApplyBannerInsets ? getEffectiveSystemInset(bottomMargin, false) : 0;
|
|
70
|
+
bannerParams.setMargins(0, 0, 0, baseBottom + legacyMarginOffset);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@@ -440,8 +464,10 @@ public class BannerExecutor {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
- int baseTop = legacyApplyWebviewInsets ? topMargin : 0;
|
|
78
|
+
- int baseBottom = legacyApplyWebviewInsets ? bottomMargin : 0;
|
|
79
|
+
+ int effectiveTop = getEffectiveSystemInset(topMargin, true);
|
|
80
|
+
+ int effectiveBottom = getEffectiveSystemInset(bottomMargin, false);
|
|
81
|
+
+ int baseTop = legacyApplyWebviewInsets ? effectiveTop : 0;
|
|
82
|
+
+ int baseBottom = legacyApplyWebviewInsets ? effectiveBottom : 0;
|
|
83
|
+
|
|
84
|
+
if (!isBannerVisible) {
|
|
85
|
+
|
|
86
|
+
@@ -454,11 +480,13 @@ public class BannerExecutor {
|
|
87
|
+
} else {
|
|
88
|
+
|
|
89
|
+
if ("TOP".equals(currentPosition)) {
|
|
90
|
+
- params.topMargin = lastAdHeight + baseTop + legacyMarginOffset;
|
|
91
|
+
+ int bannerInset = legacyApplyBannerInsets && !legacyApplyWebviewInsets ? effectiveTop : 0;
|
|
92
|
+
+ params.topMargin = lastAdHeight + baseTop + bannerInset + legacyMarginOffset;
|
|
93
|
+
params.bottomMargin = baseBottom;
|
|
94
|
+
} else {
|
|
95
|
+
params.topMargin = baseTop;
|
|
96
|
+
- params.bottomMargin = lastAdHeight + baseBottom + legacyMarginOffset;
|
|
97
|
+
+ int bannerInset = legacyApplyBannerInsets && !legacyApplyWebviewInsets ? effectiveBottom : 0;
|
|
98
|
+
+ params.bottomMargin = lastAdHeight + baseBottom + bannerInset + legacyMarginOffset;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@@ -487,11 +515,11 @@ public class BannerExecutor {
|
|
103
|
+
params.bottomMargin = 0;
|
|
104
|
+
} else {
|
|
105
|
+
if ("TOP".equals(currentPosition)) {
|
|
106
|
+
- params.topMargin = lastAdHeight;
|
|
107
|
+
+ params.topMargin = lastAdHeight + getEffectiveSystemInset(systemSafeTop, true);
|
|
108
|
+
params.bottomMargin = 0;
|
|
109
|
+
} else {
|
|
110
|
+
params.topMargin = 0;
|
|
111
|
+
- params.bottomMargin = lastAdHeight;
|
|
112
|
+
+ params.bottomMargin = lastAdHeight + getEffectiveSystemInset(systemSafeBottom, false);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
diff --git a/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/preloading/BannerPreloadExecutor.java b/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/preloading/BannerPreloadExecutor.java
|
|
117
|
+
index 4a445fe..ee0a633 100644
|
|
118
|
+
--- a/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/preloading/BannerPreloadExecutor.java
|
|
119
|
+
+++ b/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/preloading/BannerPreloadExecutor.java
|
|
120
|
+
@@ -291,6 +291,30 @@ public class BannerPreloadExecutor {
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
+ private int getEffectiveSystemInset(int inset, boolean top) {
|
|
125
|
+
+ if (inset <= 0) return 0;
|
|
126
|
+
+
|
|
127
|
+
+ Activity activity = plugin.getActivity();
|
|
128
|
+
+ if (activity == null) return 0;
|
|
129
|
+
+
|
|
130
|
+
+ View layoutView = capacitorAdLayout != null && capacitorAdLayout.getHeight() > 0
|
|
131
|
+
+ ? capacitorAdLayout : activity.getWindow().getDecorView();
|
|
132
|
+
+ int[] location = new int[2];
|
|
133
|
+
+ layoutView.getLocationOnScreen(location);
|
|
134
|
+
+ if (top) return Math.min(inset, Math.max(0, inset - location[1]));
|
|
135
|
+
+
|
|
136
|
+
+ int screenBottom;
|
|
137
|
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
138
|
+
+ screenBottom = activity.getWindowManager().getCurrentWindowMetrics().getBounds().bottom;
|
|
139
|
+
+ } else {
|
|
140
|
+
+ android.graphics.Point screenSize = new android.graphics.Point();
|
|
141
|
+
+ activity.getWindowManager().getDefaultDisplay().getRealSize(screenSize);
|
|
142
|
+
+ screenBottom = screenSize.y;
|
|
143
|
+
+ }
|
|
144
|
+
+ int layoutBottom = location[1] + layoutView.getHeight();
|
|
145
|
+
+ return Math.min(inset, Math.max(0, layoutBottom - (screenBottom - inset)));
|
|
146
|
+
+ }
|
|
147
|
+
+
|
|
148
|
+
private void updateBannerLayout() {
|
|
149
|
+
|
|
150
|
+
if (Build.VERSION.SDK_INT < 35) {
|
|
151
|
+
@@ -307,10 +331,10 @@ public class BannerPreloadExecutor {
|
|
152
|
+
|
|
153
|
+
if ("TOP".equals(currentPosition)) {
|
|
154
|
+
bannerParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
|
155
|
+
- bannerParams.setMargins(0, systemSafeTop, 0, 0);
|
|
156
|
+
+ bannerParams.setMargins(0, getEffectiveSystemInset(systemSafeTop, true), 0, 0);
|
|
157
|
+
} else {
|
|
158
|
+
bannerParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
|
159
|
+
- bannerParams.setMargins(0, 0, 0, systemSafeBottom);
|
|
160
|
+
+ bannerParams.setMargins(0, 0, 0, getEffectiveSystemInset(systemSafeBottom, false));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
adView.setLayoutParams(bannerParams);
|
|
164
|
+
@@ -360,11 +384,11 @@ public class BannerPreloadExecutor {
|
|
165
|
+
|
|
166
|
+
if ("TOP".equals(currentPosition)) {
|
|
167
|
+
bannerParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
|
168
|
+
- int baseTop = legacyApplyBannerInsets ? topMargin : 0;
|
|
169
|
+
+ int baseTop = legacyApplyBannerInsets ? getEffectiveSystemInset(topMargin, true) : 0;
|
|
170
|
+
bannerParams.setMargins(0, baseTop + legacyMarginOffset, 0, 0);
|
|
171
|
+
} else {
|
|
172
|
+
bannerParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
|
173
|
+
- int baseBottom = legacyApplyBannerInsets ? bottomMargin : 0;
|
|
174
|
+
+ int baseBottom = legacyApplyBannerInsets ? getEffectiveSystemInset(bottomMargin, false) : 0;
|
|
175
|
+
bannerParams.setMargins(0, 0, 0, baseBottom + legacyMarginOffset);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
@@ -401,8 +425,10 @@ public class BannerPreloadExecutor {
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
- int baseTop = legacyApplyWebviewInsets ? topMargin : 0;
|
|
183
|
+
- int baseBottom = legacyApplyWebviewInsets ? bottomMargin : 0;
|
|
184
|
+
+ int effectiveTop = getEffectiveSystemInset(topMargin, true);
|
|
185
|
+
+ int effectiveBottom = getEffectiveSystemInset(bottomMargin, false);
|
|
186
|
+
+ int baseTop = legacyApplyWebviewInsets ? effectiveTop : 0;
|
|
187
|
+
+ int baseBottom = legacyApplyWebviewInsets ? effectiveBottom : 0;
|
|
188
|
+
|
|
189
|
+
if (!isBannerVisible) {
|
|
190
|
+
|
|
191
|
+
@@ -415,11 +441,13 @@ public class BannerPreloadExecutor {
|
|
192
|
+
} else {
|
|
193
|
+
|
|
194
|
+
if ("TOP".equals(currentPosition)) {
|
|
195
|
+
- params.topMargin = lastAdHeight + baseTop + legacyMarginOffset;
|
|
196
|
+
+ int bannerInset = legacyApplyBannerInsets && !legacyApplyWebviewInsets ? effectiveTop : 0;
|
|
197
|
+
+ params.topMargin = lastAdHeight + baseTop + bannerInset + legacyMarginOffset;
|
|
198
|
+
params.bottomMargin = baseBottom;
|
|
199
|
+
} else {
|
|
200
|
+
params.topMargin = baseTop;
|
|
201
|
+
- params.bottomMargin = lastAdHeight + baseBottom + legacyMarginOffset;
|
|
202
|
+
+ int bannerInset = legacyApplyBannerInsets && !legacyApplyWebviewInsets ? effectiveBottom : 0;
|
|
203
|
+
+ params.bottomMargin = lastAdHeight + baseBottom + bannerInset + legacyMarginOffset;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
@@ -448,10 +476,10 @@ public class BannerPreloadExecutor {
|
|
208
|
+
params.bottomMargin = 0;
|
|
209
|
+
} else {
|
|
210
|
+
if ("TOP".equals(currentPosition)) {
|
|
211
|
+
- params.topMargin = lastAdHeight;
|
|
212
|
+
+ params.topMargin = lastAdHeight + getEffectiveSystemInset(systemSafeTop, true);
|
|
213
|
+
params.bottomMargin = 0;
|
|
214
|
+
} else {
|
|
215
|
+
params.topMargin = 0;
|
|
216
|
+
- params.bottomMargin = lastAdHeight;
|
|
217
|
+
+ params.bottomMargin = lastAdHeight + getEffectiveSystemInset(systemSafeBottom, false);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
diff --git a/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/banner/BannerExecutor.java b/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/banner/BannerExecutor.java
|
|
2
|
+
index 8b984f2..e2cf878 100644
|
|
3
|
+
--- a/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/banner/BannerExecutor.java
|
|
4
|
+
+++ b/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/banner/BannerExecutor.java
|
|
5
|
+
@@ -330,6 +330,30 @@ public class BannerExecutor {
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
+ private int getEffectiveSystemInset(int inset, boolean top) {
|
|
10
|
+
+ if (inset <= 0) return 0;
|
|
11
|
+
+
|
|
12
|
+
+ Activity activity = plugin.getActivity();
|
|
13
|
+
+ if (activity == null) return 0;
|
|
14
|
+
+
|
|
15
|
+
+ View layoutView = capacitorAdLayout != null && capacitorAdLayout.getHeight() > 0
|
|
16
|
+
+ ? capacitorAdLayout : activity.getWindow().getDecorView();
|
|
17
|
+
+ int[] location = new int[2];
|
|
18
|
+
+ layoutView.getLocationOnScreen(location);
|
|
19
|
+
+ if (top) return Math.min(inset, Math.max(0, inset - location[1]));
|
|
20
|
+
+
|
|
21
|
+
+ int screenBottom;
|
|
22
|
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
23
|
+
+ screenBottom = activity.getWindowManager().getCurrentWindowMetrics().getBounds().bottom;
|
|
24
|
+
+ } else {
|
|
25
|
+
+ android.graphics.Point screenSize = new android.graphics.Point();
|
|
26
|
+
+ activity.getWindowManager().getDefaultDisplay().getRealSize(screenSize);
|
|
27
|
+
+ screenBottom = screenSize.y;
|
|
28
|
+
+ }
|
|
29
|
+
+ int layoutBottom = location[1] + layoutView.getHeight();
|
|
30
|
+
+ return Math.min(inset, Math.max(0, layoutBottom - (screenBottom - inset)));
|
|
31
|
+
+ }
|
|
32
|
+
+
|
|
33
|
+
private void updateBannerLayout() {
|
|
34
|
+
|
|
35
|
+
if (Build.VERSION.SDK_INT < 35) {
|
|
36
|
+
@@ -346,10 +370,10 @@ public class BannerExecutor {
|
|
37
|
+
|
|
38
|
+
if ("TOP".equals(currentPosition)) {
|
|
39
|
+
bannerParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
|
40
|
+
- bannerParams.setMargins(0, systemSafeTop, 0, 0);
|
|
41
|
+
+ bannerParams.setMargins(0, getEffectiveSystemInset(systemSafeTop, true), 0, 0);
|
|
42
|
+
} else {
|
|
43
|
+
bannerParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
|
44
|
+
- bannerParams.setMargins(0, 0, 0, systemSafeBottom);
|
|
45
|
+
+ bannerParams.setMargins(0, 0, 0, getEffectiveSystemInset(systemSafeBottom, false));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
adView.setLayoutParams(bannerParams);
|
|
49
|
+
@@ -399,11 +423,11 @@ public class BannerExecutor {
|
|
50
|
+
|
|
51
|
+
if ("TOP".equals(currentPosition)) {
|
|
52
|
+
bannerParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
|
53
|
+
- int baseTop = legacyApplyBannerInsets ? topMargin : 0;
|
|
54
|
+
+ int baseTop = legacyApplyBannerInsets ? getEffectiveSystemInset(topMargin, true) : 0;
|
|
55
|
+
bannerParams.setMargins(0, baseTop + legacyMarginOffset, 0, 0);
|
|
56
|
+
} else {
|
|
57
|
+
bannerParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
|
58
|
+
- int baseBottom = legacyApplyBannerInsets ? bottomMargin : 0;
|
|
59
|
+
+ int baseBottom = legacyApplyBannerInsets ? getEffectiveSystemInset(bottomMargin, false) : 0;
|
|
60
|
+
bannerParams.setMargins(0, 0, 0, baseBottom + legacyMarginOffset);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@@ -440,8 +464,10 @@ public class BannerExecutor {
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
- int baseTop = legacyApplyWebviewInsets ? topMargin : 0;
|
|
68
|
+
- int baseBottom = legacyApplyWebviewInsets ? bottomMargin : 0;
|
|
69
|
+
+ int effectiveTop = getEffectiveSystemInset(topMargin, true);
|
|
70
|
+
+ int effectiveBottom = getEffectiveSystemInset(bottomMargin, false);
|
|
71
|
+
+ int baseTop = legacyApplyWebviewInsets ? effectiveTop : 0;
|
|
72
|
+
+ int baseBottom = legacyApplyWebviewInsets ? effectiveBottom : 0;
|
|
73
|
+
|
|
74
|
+
if (!isBannerVisible) {
|
|
75
|
+
|
|
76
|
+
@@ -454,11 +480,13 @@ public class BannerExecutor {
|
|
77
|
+
} else {
|
|
78
|
+
|
|
79
|
+
if ("TOP".equals(currentPosition)) {
|
|
80
|
+
- params.topMargin = lastAdHeight + baseTop + legacyMarginOffset;
|
|
81
|
+
+ int bannerInset = legacyApplyBannerInsets && !legacyApplyWebviewInsets ? effectiveTop : 0;
|
|
82
|
+
+ params.topMargin = lastAdHeight + baseTop + bannerInset + legacyMarginOffset;
|
|
83
|
+
params.bottomMargin = baseBottom;
|
|
84
|
+
} else {
|
|
85
|
+
params.topMargin = baseTop;
|
|
86
|
+
- params.bottomMargin = lastAdHeight + baseBottom + legacyMarginOffset;
|
|
87
|
+
+ int bannerInset = legacyApplyBannerInsets && !legacyApplyWebviewInsets ? effectiveBottom : 0;
|
|
88
|
+
+ params.bottomMargin = lastAdHeight + baseBottom + bannerInset + legacyMarginOffset;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@@ -487,11 +515,11 @@ public class BannerExecutor {
|
|
93
|
+
params.bottomMargin = 0;
|
|
94
|
+
} else {
|
|
95
|
+
if ("TOP".equals(currentPosition)) {
|
|
96
|
+
- params.topMargin = lastAdHeight;
|
|
97
|
+
+ params.topMargin = lastAdHeight + getEffectiveSystemInset(systemSafeTop, true);
|
|
98
|
+
params.bottomMargin = 0;
|
|
99
|
+
} else {
|
|
100
|
+
params.topMargin = 0;
|
|
101
|
+
- params.bottomMargin = lastAdHeight;
|
|
102
|
+
+ params.bottomMargin = lastAdHeight + getEffectiveSystemInset(systemSafeBottom, false);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
diff --git a/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/preloading/BannerPreloadExecutor.java b/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/preloading/BannerPreloadExecutor.java
|
|
107
|
+
index 4a445fe..ee0a633 100644
|
|
108
|
+
--- a/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/preloading/BannerPreloadExecutor.java
|
|
109
|
+
+++ b/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/preloading/BannerPreloadExecutor.java
|
|
110
|
+
@@ -291,6 +291,30 @@ public class BannerPreloadExecutor {
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
+ private int getEffectiveSystemInset(int inset, boolean top) {
|
|
115
|
+
+ if (inset <= 0) return 0;
|
|
116
|
+
+
|
|
117
|
+
+ Activity activity = plugin.getActivity();
|
|
118
|
+
+ if (activity == null) return 0;
|
|
119
|
+
+
|
|
120
|
+
+ View layoutView = capacitorAdLayout != null && capacitorAdLayout.getHeight() > 0
|
|
121
|
+
+ ? capacitorAdLayout : activity.getWindow().getDecorView();
|
|
122
|
+
+ int[] location = new int[2];
|
|
123
|
+
+ layoutView.getLocationOnScreen(location);
|
|
124
|
+
+ if (top) return Math.min(inset, Math.max(0, inset - location[1]));
|
|
125
|
+
+
|
|
126
|
+
+ int screenBottom;
|
|
127
|
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
128
|
+
+ screenBottom = activity.getWindowManager().getCurrentWindowMetrics().getBounds().bottom;
|
|
129
|
+
+ } else {
|
|
130
|
+
+ android.graphics.Point screenSize = new android.graphics.Point();
|
|
131
|
+
+ activity.getWindowManager().getDefaultDisplay().getRealSize(screenSize);
|
|
132
|
+
+ screenBottom = screenSize.y;
|
|
133
|
+
+ }
|
|
134
|
+
+ int layoutBottom = location[1] + layoutView.getHeight();
|
|
135
|
+
+ return Math.min(inset, Math.max(0, layoutBottom - (screenBottom - inset)));
|
|
136
|
+
+ }
|
|
137
|
+
+
|
|
138
|
+
private void updateBannerLayout() {
|
|
139
|
+
|
|
140
|
+
if (Build.VERSION.SDK_INT < 35) {
|
|
141
|
+
@@ -307,10 +331,10 @@ public class BannerPreloadExecutor {
|
|
142
|
+
|
|
143
|
+
if ("TOP".equals(currentPosition)) {
|
|
144
|
+
bannerParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
|
145
|
+
- bannerParams.setMargins(0, systemSafeTop, 0, 0);
|
|
146
|
+
+ bannerParams.setMargins(0, getEffectiveSystemInset(systemSafeTop, true), 0, 0);
|
|
147
|
+
} else {
|
|
148
|
+
bannerParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
|
149
|
+
- bannerParams.setMargins(0, 0, 0, systemSafeBottom);
|
|
150
|
+
+ bannerParams.setMargins(0, 0, 0, getEffectiveSystemInset(systemSafeBottom, false));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
adView.setLayoutParams(bannerParams);
|
|
154
|
+
@@ -360,11 +384,11 @@ public class BannerPreloadExecutor {
|
|
155
|
+
|
|
156
|
+
if ("TOP".equals(currentPosition)) {
|
|
157
|
+
bannerParams.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
|
|
158
|
+
- int baseTop = legacyApplyBannerInsets ? topMargin : 0;
|
|
159
|
+
+ int baseTop = legacyApplyBannerInsets ? getEffectiveSystemInset(topMargin, true) : 0;
|
|
160
|
+
bannerParams.setMargins(0, baseTop + legacyMarginOffset, 0, 0);
|
|
161
|
+
} else {
|
|
162
|
+
bannerParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
|
|
163
|
+
- int baseBottom = legacyApplyBannerInsets ? bottomMargin : 0;
|
|
164
|
+
+ int baseBottom = legacyApplyBannerInsets ? getEffectiveSystemInset(bottomMargin, false) : 0;
|
|
165
|
+
bannerParams.setMargins(0, 0, 0, baseBottom + legacyMarginOffset);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@@ -401,8 +425,10 @@ public class BannerPreloadExecutor {
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
- int baseTop = legacyApplyWebviewInsets ? topMargin : 0;
|
|
173
|
+
- int baseBottom = legacyApplyWebviewInsets ? bottomMargin : 0;
|
|
174
|
+
+ int effectiveTop = getEffectiveSystemInset(topMargin, true);
|
|
175
|
+
+ int effectiveBottom = getEffectiveSystemInset(bottomMargin, false);
|
|
176
|
+
+ int baseTop = legacyApplyWebviewInsets ? effectiveTop : 0;
|
|
177
|
+
+ int baseBottom = legacyApplyWebviewInsets ? effectiveBottom : 0;
|
|
178
|
+
|
|
179
|
+
if (!isBannerVisible) {
|
|
180
|
+
|
|
181
|
+
@@ -415,11 +441,13 @@ public class BannerPreloadExecutor {
|
|
182
|
+
} else {
|
|
183
|
+
|
|
184
|
+
if ("TOP".equals(currentPosition)) {
|
|
185
|
+
- params.topMargin = lastAdHeight + baseTop + legacyMarginOffset;
|
|
186
|
+
+ int bannerInset = legacyApplyBannerInsets && !legacyApplyWebviewInsets ? effectiveTop : 0;
|
|
187
|
+
+ params.topMargin = lastAdHeight + baseTop + bannerInset + legacyMarginOffset;
|
|
188
|
+
params.bottomMargin = baseBottom;
|
|
189
|
+
} else {
|
|
190
|
+
params.topMargin = baseTop;
|
|
191
|
+
- params.bottomMargin = lastAdHeight + baseBottom + legacyMarginOffset;
|
|
192
|
+
+ int bannerInset = legacyApplyBannerInsets && !legacyApplyWebviewInsets ? effectiveBottom : 0;
|
|
193
|
+
+ params.bottomMargin = lastAdHeight + baseBottom + bannerInset + legacyMarginOffset;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@@ -448,10 +476,10 @@ public class BannerPreloadExecutor {
|
|
198
|
+
params.bottomMargin = 0;
|
|
199
|
+
} else {
|
|
200
|
+
if ("TOP".equals(currentPosition)) {
|
|
201
|
+
- params.topMargin = lastAdHeight;
|
|
202
|
+
+ params.topMargin = lastAdHeight + getEffectiveSystemInset(systemSafeTop, true);
|
|
203
|
+
params.bottomMargin = 0;
|
|
204
|
+
} else {
|
|
205
|
+
params.topMargin = 0;
|
|
206
|
+
- params.bottomMargin = lastAdHeight;
|
|
207
|
+
+ params.bottomMargin = lastAdHeight + getEffectiveSystemInset(systemSafeBottom, false);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -9,6 +9,7 @@ function run(scriptPath) {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
run(path.join(buildDir, 'sync-notification-large-icon.cjs'));
|
|
12
|
+
run(path.join(buildDir, 'sync-capacitor9-launch-splash.cjs'));
|
|
12
13
|
|
|
13
14
|
run(path.join(buildDir, 'manifestModification.js'));
|
|
14
15
|
run(path.join(__dirname, 'setup-baseline-profile.js'));
|
|
@@ -127,24 +127,27 @@ function getBaselineProfileGenerator(modulePackage, appId) {
|
|
|
127
127
|
|
|
128
128
|
function ensureBaselineProfilePlugin() {
|
|
129
129
|
const rootBuildGradle = path.join(androidDir, 'build.gradle');
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
130
|
+
const coreFile = path.join(rootDir, 'node_modules', '@capacitor', 'core', 'package.json');
|
|
131
|
+
const capacitor9 = fs.existsSync(coreFile) && JSON.parse(readFile(coreFile)).version.startsWith('9.');
|
|
132
|
+
const version = capacitor9 ? '1.5.0' : '1.4.1';
|
|
133
|
+
patchFile(rootBuildGradle, (content) => {
|
|
134
|
+
const plugin = /classpath ['"]androidx\.baselineprofile:androidx\.baselineprofile\.gradle\.plugin:[^'"]+['"]/;
|
|
135
|
+
const declaration = `classpath 'androidx.baselineprofile:androidx.baselineprofile.gradle.plugin:${version}'`;
|
|
136
|
+
if (plugin.test(content)) return content.replace(plugin, declaration);
|
|
137
|
+
const agp = /classpath ['"]com\.android\.tools\.build:gradle:[^'"]+['"]/;
|
|
138
|
+
if (!agp.test(content)) throw new Error('Android Gradle plugin declaration not found; baseline profile setup stopped.');
|
|
139
|
+
return content.replace(agp, match => `${match}\n ${declaration}`);
|
|
140
|
+
});
|
|
137
141
|
}
|
|
138
142
|
|
|
139
143
|
function ensureSettingsModule() {
|
|
140
144
|
const settingsGradle = path.join(androidDir, 'settings.gradle');
|
|
141
|
-
patchFile(settingsGradle, (content) =>
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
);
|
|
145
|
+
patchFile(settingsGradle, (content) => {
|
|
146
|
+
const block = "include ':baselineprofile'\nproject(':baselineprofile').projectDir = new File('./baselineprofile/')";
|
|
147
|
+
const normalized = content.replace(/^include ':baselineprofile'\r?\nproject\(':baselineprofile'\)\.projectDir = new File\('\.\/baselineprofile\/'\)\r?\n?/gm, '').replace(/\n{3,}/g, '\n\n');
|
|
148
|
+
if (!normalized.includes("include ':app'")) throw new Error('Android app module not found; baseline profile setup stopped.');
|
|
149
|
+
return normalized.replace("include ':app'", `include ':app'\n${block}`);
|
|
150
|
+
});
|
|
148
151
|
}
|
|
149
152
|
|
|
150
153
|
function ensureAppGradle() {
|
|
@@ -278,7 +281,7 @@ function main() {
|
|
|
278
281
|
console.log('Baseline Profile setup is ready.');
|
|
279
282
|
}
|
|
280
283
|
|
|
281
|
-
module.exports = { syncGeneratedProfileBackup };
|
|
284
|
+
module.exports = { main, syncGeneratedProfileBackup };
|
|
282
285
|
|
|
283
286
|
if (require.main === module) main();
|
|
284
287
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const { execFileSync } = require('node:child_process');
|
|
7
|
+
const { prepare } = require('./prepare-capacitor-9.cjs');
|
|
8
|
+
const { install } = require('./sync-files.js');
|
|
9
|
+
|
|
10
|
+
function fixture(t, coreVersion) {
|
|
11
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'codeplay-cap9-'));
|
|
12
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
13
|
+
const write = (name, value) => {
|
|
14
|
+
const target = path.join(root, name);
|
|
15
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
16
|
+
fs.writeFileSync(target, typeof value === 'string' || Buffer.isBuffer(value) ? value : JSON.stringify(value, null, 2));
|
|
17
|
+
};
|
|
18
|
+
write('package.json', {
|
|
19
|
+
name: 'migration-fixture',
|
|
20
|
+
scripts: {
|
|
21
|
+
'capacitor:sync:after': 'node buildCodeplay/setSplashAnimation.js && node scripts-common/run-codeplay-sync-after.js',
|
|
22
|
+
'legacy-only': 'node buildCodeplay/setSplashAnimation.js',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
write('node_modules/@capacitor/core/package.json', { version: coreVersion });
|
|
26
|
+
return { root, write, read: name => fs.readFileSync(path.join(root, name), 'utf8') };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function writeAdmobPatchPreimage(f) {
|
|
30
|
+
const patch = fs.readFileSync(path.resolve(__dirname, '../files/patches/catalog/capacitor-admob-nextgen+1.6.2-beta.patch'), 'utf8');
|
|
31
|
+
let file;
|
|
32
|
+
let lines = [];
|
|
33
|
+
let oldLine = -1;
|
|
34
|
+
const flush = () => { if (file) f.write(file, lines.map(line => line ?? '').join('\n') + '\n'); };
|
|
35
|
+
for (const line of patch.split('\n')) {
|
|
36
|
+
const next = line.match(/^diff --git a\/(node_modules\/[^ ]+) b\//);
|
|
37
|
+
if (next) {
|
|
38
|
+
flush();
|
|
39
|
+
file = next[1];
|
|
40
|
+
lines = [];
|
|
41
|
+
oldLine = -1;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
const hunk = line.match(/^@@ -(\d+)(?:,\d+)? \+/);
|
|
45
|
+
if (hunk) { oldLine = Number(hunk[1]) - 1; continue; }
|
|
46
|
+
if (oldLine >= 0 && (line.startsWith(' ') || line.startsWith('-'))) lines[oldLine++] = line.slice(1);
|
|
47
|
+
}
|
|
48
|
+
flush();
|
|
49
|
+
f.write('node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/AdMobNextGenPlugin.java',
|
|
50
|
+
'call.getData().has("tagForChildDirectedTreatment");\ncall.getData().has("tagForUnderAgeOfConsent");\n');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
test('Capacitor 8 preparation is a no-op', t => {
|
|
54
|
+
const f = fixture(t, '8.6.2');
|
|
55
|
+
const before = f.read('package.json');
|
|
56
|
+
assert.equal(prepare(f.root, 'if-cap9').apply, false);
|
|
57
|
+
assert.equal(f.read('package.json'), before);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('Capacitor 9 preparation removes only the obsolete splash writer', t => {
|
|
61
|
+
const f = fixture(t, '9.0.0');
|
|
62
|
+
for (let attempt = 0; attempt < 2; attempt += 1) prepare(f.root, 'if-cap9');
|
|
63
|
+
const scripts = JSON.parse(f.read('package.json')).scripts;
|
|
64
|
+
assert.equal(scripts['capacitor:sync:after'], 'node scripts-common/run-codeplay-sync-after.js');
|
|
65
|
+
assert.equal(scripts['legacy-only'], undefined);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('installing codeplay-common into a Capacitor 9 app removes the splash hook', t => {
|
|
69
|
+
const f = fixture(t, '9.0.0');
|
|
70
|
+
f.write('package.json', {
|
|
71
|
+
name: 'migration-fixture', dependencies: { '@capacitor/core': '^9.0.0' },
|
|
72
|
+
scripts: { 'capacitor:sync:after': 'node buildCodeplay/setSplashAnimation.js && node scripts-common/run-codeplay-sync-after.js' },
|
|
73
|
+
});
|
|
74
|
+
f.write('capacitor.config.json', { appId: 'org.example.app', appName: 'Fixture', webDir: 'www' });
|
|
75
|
+
install({ projectRoot: f.root });
|
|
76
|
+
const scripts = JSON.parse(f.read('package.json')).scripts;
|
|
77
|
+
assert.equal(scripts['capacitor:sync:after'], 'node scripts-common/run-codeplay-sync-after.js');
|
|
78
|
+
assert.match(scripts['capacitor:sync:before'], /prepare-capacitor-9\.cjs --apply-if-cap9/);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('beta AdMob selects the banner/inset patch without the upstream API fix', t => {
|
|
82
|
+
const f = fixture(t, '9.0.0');
|
|
83
|
+
f.write('node_modules/capacitor-admob-nextgen/package.json', { version: '1.6.2-beta' });
|
|
84
|
+
const result = prepare(f.root);
|
|
85
|
+
assert.ok(result.selected.includes('capacitor-admob-nextgen+1.6.2-beta.patch'));
|
|
86
|
+
const patch = fs.readFileSync(path.resolve(__dirname, '../files/patches/catalog/capacitor-admob-nextgen+1.6.2-beta.patch'), 'utf8');
|
|
87
|
+
assert.match(patch, /getEffectiveSystemInset/);
|
|
88
|
+
assert.doesNotMatch(patch, /hasOption\(/);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
for (const version of ['1.6.2', '1.6.3-beta', '1.7.0']) {
|
|
92
|
+
test(`AdMob ${version} without a reviewed inset patch stops migration`, t => {
|
|
93
|
+
const f = fixture(t, '9.0.0');
|
|
94
|
+
f.write('node_modules/capacitor-admob-nextgen/package.json', { version });
|
|
95
|
+
assert.throws(() => prepare(f.root, 'if-cap9'), /API or banner\/inset source differs/);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
test('newer AdMob reuses the inset patch when every Java hunk still fits', t => {
|
|
100
|
+
const f = fixture(t, '9.0.0');
|
|
101
|
+
f.write('node_modules/capacitor-admob-nextgen/package.json', { version: '1.6.3' });
|
|
102
|
+
writeAdmobPatchPreimage(f);
|
|
103
|
+
const result = prepare(f.root, 'if-cap9');
|
|
104
|
+
assert.ok(result.selected.includes('capacitor-admob-nextgen+1.6.3.patch'));
|
|
105
|
+
assert.match(result.review.join(' '), /Reused the tested banner\/inset patch/);
|
|
106
|
+
assert.ok(fs.existsSync(path.join(f.root, 'patches/active/capacitor-admob-nextgen+1.6.3.patch')));
|
|
107
|
+
assert.match(f.read('node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/banner/BannerExecutor.java'), /getEffectiveSystemInset/);
|
|
108
|
+
assert.ok(prepare(f.root, 'if-cap9').selected.includes('capacitor-admob-nextgen+1.6.3.patch'));
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('newer AdMob replaces the known beta patch after source verification', t => {
|
|
112
|
+
const f = fixture(t, '9.0.0');
|
|
113
|
+
f.write('node_modules/capacitor-admob-nextgen/package.json', { version: '1.6.3' });
|
|
114
|
+
writeAdmobPatchPreimage(f);
|
|
115
|
+
const oldName = 'capacitor-admob-nextgen+1.6.2-beta.patch';
|
|
116
|
+
f.write(`patches/active/${oldName}`, fs.readFileSync(path.resolve(__dirname, '../files/patches/catalog', oldName)));
|
|
117
|
+
prepare(f.root, 'if-cap9');
|
|
118
|
+
assert.equal(fs.existsSync(path.join(f.root, 'patches/active', oldName)), false);
|
|
119
|
+
assert.ok(fs.existsSync(path.join(f.root, 'patches/active/capacitor-admob-nextgen+1.6.3.patch')));
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('newer AdMob stops when a banner source line changes', t => {
|
|
123
|
+
const f = fixture(t, '9.0.0');
|
|
124
|
+
f.write('node_modules/capacitor-admob-nextgen/package.json', { version: '1.6.3' });
|
|
125
|
+
writeAdmobPatchPreimage(f);
|
|
126
|
+
const name = 'node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/banner/BannerExecutor.java';
|
|
127
|
+
f.write(name, f.read(name).replace('bannerParams.setMargins(0, 0, 0, systemSafeBottom);', 'bannerParams.setMargins(0, 0, 0, 99);'));
|
|
128
|
+
assert.throws(() => prepare(f.root), /API or banner\/inset source differs/);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('newer AdMob stops if the upstream Capacitor API fix is absent', t => {
|
|
132
|
+
const f = fixture(t, '9.0.0');
|
|
133
|
+
f.write('node_modules/capacitor-admob-nextgen/package.json', { version: '1.6.3' });
|
|
134
|
+
writeAdmobPatchPreimage(f);
|
|
135
|
+
const name = 'node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/AdMobNextGenPlugin.java';
|
|
136
|
+
f.write(name, f.read(name).replace('call.getData().has("tagForChildDirectedTreatment")', 'call.hasOption("tagForChildDirectedTreatment")'));
|
|
137
|
+
assert.throws(() => prepare(f.root), /API or banner\/inset source differs/);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('app-specific AdMob patch is retained for manual review', t => {
|
|
141
|
+
const f = fixture(t, '9.0.0');
|
|
142
|
+
f.write('node_modules/capacitor-admob-nextgen/package.json', { version: '1.6.2-beta' });
|
|
143
|
+
const name = 'capacitor-admob-nextgen+1.6.0.patch';
|
|
144
|
+
f.write(`patches/active/${name}`, 'custom banner changes');
|
|
145
|
+
assert.throws(() => prepare(f.root, 'if-cap9'), /unrecognized changes/);
|
|
146
|
+
assert.equal(f.read(`patches/active/${name}`), 'custom banner changes');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('baseline setup upgrades AGP 9 plugin and deduplicates module wiring', t => {
|
|
150
|
+
const f = fixture(t, '9.0.0');
|
|
151
|
+
f.write('capacitor.config.json', { appId: 'org.example.app' });
|
|
152
|
+
f.write('android/build.gradle', "dependencies {\n classpath 'com.android.tools.build:gradle:9.4.1'\n classpath 'androidx.baselineprofile:androidx.baselineprofile.gradle.plugin:1.4.1'\n}\n");
|
|
153
|
+
f.write('android/settings.gradle', "include ':app'\ninclude ':baselineprofile'\nproject(':baselineprofile').projectDir = new File('./baselineprofile/')\ninclude ':baselineprofile'\nproject(':baselineprofile').projectDir = new File('./baselineprofile/')\n");
|
|
154
|
+
f.write('android/app/build.gradle', "apply plugin: 'com.android.application'\napply from: 'capacitor.build.gradle'\ndependencies {\n}\n");
|
|
155
|
+
const script = path.resolve(__dirname, '../files/scripts-common/setup-baseline-profile.js');
|
|
156
|
+
fs.mkdirSync(path.join(f.root, 'scripts-common'), { recursive: true });
|
|
157
|
+
fs.copyFileSync(script, path.join(f.root, 'scripts-common/setup-baseline-profile.js'));
|
|
158
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
159
|
+
execFileSync(process.execPath, [path.join(f.root, 'scripts-common/setup-baseline-profile.js')], { cwd: f.root });
|
|
160
|
+
}
|
|
161
|
+
assert.match(f.read('android/build.gradle'), /androidx\.baselineprofile\.gradle\.plugin:1\.5\.0/);
|
|
162
|
+
assert.equal((f.read('android/settings.gradle').match(/include ':baselineprofile'/g) || []).length, 1);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('Capacitor 9 preparation runs the bundled baseline helper before sync', t => {
|
|
166
|
+
const f = fixture(t, '9.0.0');
|
|
167
|
+
f.write('capacitor.config.json', { appId: 'org.example.app' });
|
|
168
|
+
f.write('android/build.gradle', "dependencies { classpath 'com.android.tools.build:gradle:9.4.1' }\n");
|
|
169
|
+
f.write('android/settings.gradle', "include ':app'\ninclude ':baselineprofile'\nproject(':baselineprofile').projectDir = new File('./baselineprofile/')\n");
|
|
170
|
+
f.write('android/app/build.gradle', "apply plugin: 'com.android.application'\napply plugin: 'androidx.baselineprofile'\napply from: 'capacitor.build.gradle'\ndependencies {\n}\n");
|
|
171
|
+
f.write('scripts-common/setup-baseline-profile.js', fs.readFileSync(path.resolve(__dirname, '../files/scripts-common/setup-baseline-profile.js')));
|
|
172
|
+
prepare(f.root, 'if-cap9');
|
|
173
|
+
assert.match(f.read('android/build.gradle'), /androidx\.baselineprofile\.gradle\.plugin:1\.5\.0/);
|
|
174
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const { syncCapacitor9LaunchSplash } = require('../files/buildCodeplay/sync-capacitor9-launch-splash.cjs');
|
|
7
|
+
const { install } = require('./sync-files.js');
|
|
8
|
+
|
|
9
|
+
function fixture(t, style, withIcon = true) {
|
|
10
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'codeplay-splash9-'));
|
|
11
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
12
|
+
const write = (name, value) => {
|
|
13
|
+
const file = path.join(root, name);
|
|
14
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
15
|
+
fs.writeFileSync(file, value);
|
|
16
|
+
return file;
|
|
17
|
+
};
|
|
18
|
+
write('package.json', JSON.stringify({ name: 'splash-fixture', dependencies: { '@capacitor/core': '9.0.0' } }));
|
|
19
|
+
write('capacitor.config.json', JSON.stringify({ appId: 'splash.fixture' }));
|
|
20
|
+
write('android/app/src/main/res/values/styles.xml', `<resources>\n<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.DayNight.NoActionBar"/>\n${style}\n</resources>\n`);
|
|
21
|
+
if (withIcon) write('resources/splash_icon.png', 'existing app icon');
|
|
22
|
+
return { root, write, read: name => fs.readFileSync(path.join(root, name), 'utf8') };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const defaultStyle = '<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen"><item name="android:background">@drawable/splash</item></style>';
|
|
26
|
+
|
|
27
|
+
test('Capacitor 9 installation reuses the app icon and is idempotent', t => {
|
|
28
|
+
const f = fixture(t, defaultStyle);
|
|
29
|
+
install({ projectRoot: f.root, copyAssets: false });
|
|
30
|
+
assert.match(f.read('android/app/src/main/res/values/styles.xml'), /windowSplashScreenAnimatedIcon">@drawable\/splash_icon/);
|
|
31
|
+
assert.match(f.read('android/app/src/main/res/drawable/launch_background.xml'), /android:width="220dp"/);
|
|
32
|
+
assert.ok(fs.existsSync(path.join(f.root, 'buildCodeplay/sync-capacitor9-launch-splash.cjs')));
|
|
33
|
+
assert.match(JSON.parse(f.read('package.json')).scripts['capacitor:sync:after'], /sync-capacitor9-launch-splash\.cjs/);
|
|
34
|
+
assert.equal(syncCapacitor9LaunchSplash(f.root), 'unchanged');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('uses the existing launcher icon when no splash icon exists', t => {
|
|
38
|
+
const f = fixture(t, defaultStyle, false);
|
|
39
|
+
assert.equal(syncCapacitor9LaunchSplash(f.root), 'updated');
|
|
40
|
+
assert.match(f.read('android/app/src/main/res/drawable/launch_background.xml'), /@mipmap\/ic_launcher/);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('preserves custom launch themes and drawables', t => {
|
|
44
|
+
const f = fixture(t, '<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen"><item name="windowSplashScreenAnimatedIcon">@drawable/brand</item></style>');
|
|
45
|
+
assert.equal(syncCapacitor9LaunchSplash(f.root), 'custom-theme');
|
|
46
|
+
assert.equal(fs.existsSync(path.join(f.root, 'android/app/src/main/res/drawable/launch_background.xml')), false);
|
|
47
|
+
});
|
|
@@ -2,15 +2,53 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { execFileSync } = require('child_process');
|
|
4
4
|
|
|
5
|
+
function hasFixedAdmobApi(version) {
|
|
6
|
+
const parsed = version?.match(/^(\d+)\.(\d+)\.(\d+)(?:-[0-9A-Za-z.-]+)?$/);
|
|
7
|
+
if (!parsed) return false;
|
|
8
|
+
const [major, minor, patch] = parsed.slice(1, 4).map(Number);
|
|
9
|
+
return major > 1 || (major === 1 && (minor > 6 || (minor === 6 && patch >= 2)));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function comparableAdmobPatch(value) {
|
|
13
|
+
return value.toString().replace(/\r\n/g, '\n').replace(/^\+ +$/gm, '+')
|
|
14
|
+
.replace('@@ -448,11 +476,11 @@', '@@ -448,10 +476,10 @@')
|
|
15
|
+
.replace(/\n \n$/, '\n');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function prepareBaselineProfile(root) {
|
|
19
|
+
const android = path.join(root, 'android');
|
|
20
|
+
const module = path.join(android, 'baselineprofile');
|
|
21
|
+
const appGradle = path.join(android, 'app', 'build.gradle');
|
|
22
|
+
const usesBaseline = fs.existsSync(module) || (fs.existsSync(appGradle) && fs.readFileSync(appGradle, 'utf8').includes("apply plugin: 'androidx.baselineprofile'"));
|
|
23
|
+
if (!usesBaseline) return;
|
|
24
|
+
const helper = path.join(root, 'scripts-common', 'setup-baseline-profile.js');
|
|
25
|
+
if (!fs.existsSync(helper)) throw new Error('Baseline profile setup helper is missing; reinstall codeplay-common before Capacitor 9 sync.');
|
|
26
|
+
require(helper).main();
|
|
27
|
+
}
|
|
28
|
+
|
|
5
29
|
function prepare(root, apply = false) {
|
|
6
30
|
const packageFile = path.join(root, 'package.json');
|
|
7
31
|
const pkg = JSON.parse(fs.readFileSync(packageFile, 'utf8'));
|
|
8
32
|
const coreFile = path.join(root, 'node_modules/@capacitor/core/package.json');
|
|
9
33
|
const coreVersion = fs.existsSync(coreFile) ? JSON.parse(fs.readFileSync(coreFile, 'utf8')).version : null;
|
|
34
|
+
if (apply === 'if-cap9' && !coreVersion?.startsWith('9.')) return { selected: [], review: [], apply: false };
|
|
35
|
+
if (apply === 'if-cap9') apply = true;
|
|
10
36
|
if (apply && !coreVersion?.startsWith('9.')) throw new Error('Apply patches only after installing Capacitor 9 in this app.');
|
|
37
|
+
if (apply && pkg.scripts) {
|
|
38
|
+
for (const [key, command] of Object.entries(pkg.scripts)) {
|
|
39
|
+
if (typeof command !== 'string') continue;
|
|
40
|
+
const parts = command.split(/\s*&&\s*/);
|
|
41
|
+
const safe = parts.filter(part => !/^node\s+(?:\.\/)?buildCodeplay\/setSplashAnimation(?:-\d+(?:\.\d+)*)?\.js$/.test(part));
|
|
42
|
+
if (safe.length !== parts.length) {
|
|
43
|
+
if (safe.length) pkg.scripts[key] = safe.join(' && ');
|
|
44
|
+
else delete pkg.scripts[key];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
11
48
|
const catalog = path.resolve(__dirname, '../files/patches/catalog');
|
|
12
49
|
const active = path.join(root, 'patches/active');
|
|
13
50
|
const selected = [];
|
|
51
|
+
const selectedSources = new Map();
|
|
14
52
|
const review = [];
|
|
15
53
|
if (!coreVersion?.startsWith('9.')) review.push(`Capacitor core ${coreVersion || 'not installed'}; upgrade before applying or building.`);
|
|
16
54
|
const nativeWriters = /(?:setSplashAnimation|add-splash-screen|splash-setup)\.\w+|BridgeWebViewClient\.java|plugin\/SystemBars\.java/;
|
|
@@ -45,8 +83,36 @@ function prepare(root, apply = false) {
|
|
|
45
83
|
continue;
|
|
46
84
|
}
|
|
47
85
|
selected.push(name);
|
|
86
|
+
selectedSources.set(name, path.join(catalog, name));
|
|
87
|
+
}
|
|
88
|
+
const admobFile = path.join(root, 'node_modules/capacitor-admob-nextgen/package.json');
|
|
89
|
+
if (fs.existsSync(admobFile)) {
|
|
90
|
+
const admobVersion = JSON.parse(fs.readFileSync(admobFile, 'utf8')).version;
|
|
91
|
+
if (coreVersion?.startsWith('9.') && !selected.includes(`capacitor-admob-nextgen+${admobVersion}.patch`)) {
|
|
92
|
+
const pluginJava = path.join(root, 'node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/AdMobNextGenPlugin.java');
|
|
93
|
+
const source = fs.existsSync(pluginJava) ? fs.readFileSync(pluginJava, 'utf8') : '';
|
|
94
|
+
const apiFixed = ['tagForChildDirectedTreatment', 'tagForUnderAgeOfConsent'].every(key =>
|
|
95
|
+
source.includes(`call.getData().has("${key}")`) && !source.includes(`call.hasOption("${key}")`));
|
|
96
|
+
const template = path.join(catalog, 'capacitor-admob-nextgen+1.6.2-beta.patch');
|
|
97
|
+
let patchFits = false;
|
|
98
|
+
if (hasFixedAdmobApi(admobVersion) && apiFixed && fs.existsSync(template)) {
|
|
99
|
+
for (const direction of [[], ['--reverse']]) {
|
|
100
|
+
try {
|
|
101
|
+
execFileSync('git', ['apply', ...direction, '--check', template], { cwd: root, stdio: 'pipe' });
|
|
102
|
+
patchFits = true;
|
|
103
|
+
break;
|
|
104
|
+
} catch { /* A changed banner hunk requires manual review. */ }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (!patchFits) throw new Error(`capacitor-admob-nextgen ${admobVersion}: the Capacitor API or banner/inset source differs from the tested patch. Review this release before continuing.`);
|
|
108
|
+
const name = `capacitor-admob-nextgen+${admobVersion}.patch`;
|
|
109
|
+
selected.push(name);
|
|
110
|
+
selectedSources.set(name, template);
|
|
111
|
+
review.push(`Reused the tested banner/inset patch for AdMob ${admobVersion} after verifying its Java API and every patch hunk.`);
|
|
112
|
+
}
|
|
48
113
|
}
|
|
49
114
|
if (apply) {
|
|
115
|
+
prepareBaselineProfile(root);
|
|
50
116
|
const patchPackage = require.resolve('patch-package/index.js', { paths: [__dirname] });
|
|
51
117
|
const existing = fs.existsSync(active) ? fs.readdirSync(active) : [];
|
|
52
118
|
for (const name of existing.filter(name => name.endsWith('.patch'))) {
|
|
@@ -56,12 +122,29 @@ function prepare(root, apply = false) {
|
|
|
56
122
|
const installed = path.join(root, 'node_modules', dependency, 'package.json');
|
|
57
123
|
const installedVersion = fs.existsSync(installed) ? JSON.parse(fs.readFileSync(installed, 'utf8')).version : null;
|
|
58
124
|
if (installedVersion !== match[2]) {
|
|
125
|
+
if (dependency === 'capacitor-admob-nextgen' && selected.includes(`capacitor-admob-nextgen+${installedVersion}.patch`)) {
|
|
126
|
+
const activeFile = path.join(active, name);
|
|
127
|
+
const sharedFile = path.join(catalog, name);
|
|
128
|
+
const oldPatch = fs.readFileSync(activeFile);
|
|
129
|
+
const knownFile = fs.existsSync(sharedFile) ? sharedFile : path.join(catalog, 'capacitor-admob-nextgen+1.6.2-beta.patch');
|
|
130
|
+
const sharedPatch = fs.existsSync(knownFile) ? fs.readFileSync(knownFile) : null;
|
|
131
|
+
const bannerMarker = 'diff --git a/node_modules/capacitor-admob-nextgen/android/src/main/java/com/emi/plugins/admob/banner/BannerExecutor.java';
|
|
132
|
+
const apiOnly = match[2] === '1.6.0' ? sharedPatch?.toString().split(bannerMarker)[0] : null;
|
|
133
|
+
if (sharedPatch && (comparableAdmobPatch(oldPatch) === comparableAdmobPatch(sharedPatch) ||
|
|
134
|
+
(apiOnly && comparableAdmobPatch(oldPatch) === comparableAdmobPatch(apiOnly)))) {
|
|
135
|
+
fs.unlinkSync(activeFile);
|
|
136
|
+
existing.splice(existing.indexOf(name), 1);
|
|
137
|
+
review.push(`Replaced the known ${name} with the ${installedVersion} banner/inset patch.`);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
throw new Error(`Active ${name} contains unrecognized changes. Review and port them to ${installedVersion} before removing this patch.`);
|
|
141
|
+
}
|
|
59
142
|
throw new Error(`Active patch ${name} targets ${match[2]}, but ${dependency} is ${installedVersion || 'not installed'}. Review the newer plugin and remove or regenerate this patch before continuing.`);
|
|
60
143
|
}
|
|
61
144
|
}
|
|
62
145
|
for (const name of selected) {
|
|
63
146
|
const target = path.join(active, name);
|
|
64
|
-
const source =
|
|
147
|
+
const source = selectedSources.get(name);
|
|
65
148
|
const related = existing.filter(file => file !== name && file.startsWith(name.replace(/\+[^+]+\.patch$/, '+')) && file.endsWith('.patch'));
|
|
66
149
|
if (related.length) throw new Error(`Conflicting active patch for ${name}: ${related.join(', ')}`);
|
|
67
150
|
if (fs.existsSync(target) && !fs.readFileSync(target).equals(fs.readFileSync(source))) {
|
|
@@ -71,16 +154,16 @@ function prepare(root, apply = false) {
|
|
|
71
154
|
fs.mkdirSync(active, { recursive: true });
|
|
72
155
|
for (const name of selected) {
|
|
73
156
|
const target = path.join(active, name);
|
|
74
|
-
if (!fs.existsSync(target)) fs.copyFileSync(
|
|
157
|
+
if (!fs.existsSync(target)) fs.copyFileSync(selectedSources.get(name), target);
|
|
75
158
|
}
|
|
76
159
|
if (fs.readdirSync(active).some(name => name.endsWith('.patch'))) {
|
|
77
160
|
const command = 'node node_modules/codeplay-common/scripts/prepare-capacitor-9.cjs --apply';
|
|
78
161
|
if (!pkg.scripts) pkg.scripts = {};
|
|
79
162
|
if (!pkg.scripts.postinstall) pkg.scripts.postinstall = command;
|
|
80
163
|
else if (!pkg.scripts.postinstall.includes(command)) pkg.scripts.postinstall = `${command} && ${pkg.scripts.postinstall}`;
|
|
81
|
-
fs.writeFileSync(packageFile, JSON.stringify(pkg, null, 2) + '\n');
|
|
82
164
|
execFileSync(process.execPath, [patchPackage, '--patch-dir', 'patches/active', '--error-on-fail'], { cwd: root, stdio: 'inherit' });
|
|
83
165
|
}
|
|
166
|
+
fs.writeFileSync(packageFile, JSON.stringify(pkg, null, 2) + '\n');
|
|
84
167
|
}
|
|
85
168
|
return { selected, review, apply };
|
|
86
169
|
}
|
|
@@ -88,11 +171,11 @@ function prepare(root, apply = false) {
|
|
|
88
171
|
if (require.main === module) {
|
|
89
172
|
try {
|
|
90
173
|
const root = process.cwd();
|
|
91
|
-
const result = prepare(root, process.argv.includes('--apply'));
|
|
174
|
+
const result = prepare(root, process.argv.includes('--apply-if-cap9') ? 'if-cap9' : process.argv.includes('--apply'));
|
|
92
175
|
console.log(`${result.apply ? 'Prepared' : 'Would prepare'} ${result.selected.length} version-matched patches: ${result.selected.join(', ') || 'none'}`);
|
|
93
176
|
for (const item of result.review) console.warn(`Review: ${item}`);
|
|
94
177
|
if (result.apply) console.log('Installed matching patches in patches/active and applied them before the native build.');
|
|
95
178
|
} catch (error) { console.error(error.message); process.exitCode = 1; }
|
|
96
179
|
}
|
|
97
180
|
|
|
98
|
-
module.exports = { prepare };
|
|
181
|
+
module.exports = { prepare, hasFixedAdmobApi };
|
|
@@ -38,7 +38,8 @@ test('SAF metadata repair is conditional, preserves versions and survives repeat
|
|
|
38
38
|
|
|
39
39
|
test('sync and update hooks preserve custom commands without duplicating repair', () => {
|
|
40
40
|
const scripts = updateBuildScripts({ 'capacitor:sync:before': 'node custom.js' });
|
|
41
|
-
|
|
42
|
-
assert.equal(scripts['capacitor:
|
|
41
|
+
const prepare = 'node node_modules/codeplay-common/scripts/prepare-capacitor-9.cjs --apply-if-cap9';
|
|
42
|
+
assert.equal(scripts['capacitor:sync:before'], `${prepare} && node buildCodeplay/saf-mediastore-dependency.cjs && node custom.js`);
|
|
43
|
+
assert.equal(scripts['capacitor:update:before'], `${prepare} && node buildCodeplay/saf-mediastore-dependency.cjs`);
|
|
43
44
|
assert.deepEqual(updateBuildScripts(scripts), scripts);
|
|
44
45
|
});
|
|
@@ -58,21 +58,55 @@ test('legacy app settings are retained with current app settings taking priority
|
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
for (const enabled of [undefined, false, true]) {
|
|
61
|
-
for (const installed of [null, '1.6.0', '1.6.1-beta', '1.7.0']) {
|
|
61
|
+
for (const installed of [null, '1.6.0', '1.6.1-beta', '1.6.2-beta', '1.7.0']) {
|
|
62
62
|
test(`native plugin: installed=${installed}, squeezebackEnabled=${enabled}`, () => {
|
|
63
63
|
const commands = [];
|
|
64
64
|
const start = script.indexOf('const syncAdmobNextgenPackage =');
|
|
65
65
|
const code = script.slice(start, script.indexOf('const downloadOptionalCodeplayFile', start));
|
|
66
66
|
vm.runInNewContext(code + '\nsyncAdmobNextgenPackage();', {
|
|
67
|
-
fs: { existsSync: () => true }, packageJsonPath: 'package.json',
|
|
67
|
+
fs: { existsSync: () => true }, path, process, packageJsonPath: 'package.json',
|
|
68
68
|
isPackageAvailable: () => false, getInstalledVersion: () => installed,
|
|
69
|
+
getLatestVersion: () => '1.6.0',
|
|
69
70
|
getAdmobJsonPath: () => 'config.json', readJsonSafe: () => ({ config: { squeezebackEnabled: enabled } }),
|
|
70
71
|
compareVersionStrings: (a, b) => a.localeCompare(b, undefined, { numeric: true }),
|
|
71
72
|
runNpmCommand: command => commands.push(command), console: { log() {}, warn() {} }
|
|
72
73
|
});
|
|
73
|
-
const update = !installed || (enabled === true &&
|
|
74
|
+
const update = !installed || (enabled === true && ['1.6.0', '1.6.1-beta'].includes(installed));
|
|
74
75
|
assert.deepEqual(commands, update
|
|
75
|
-
? [`npm install capacitor-admob-nextgen${enabled === true ? '
|
|
76
|
+
? [`npm install capacitor-admob-nextgen${enabled === true ? '@1.6.2-beta' : ''}`] : []);
|
|
76
77
|
});
|
|
77
78
|
}
|
|
78
79
|
}
|
|
80
|
+
|
|
81
|
+
for (const installed of ['1.6.0', '1.6.1-beta', '1.6.2-beta', '1.6.2', '1.7.0']) {
|
|
82
|
+
test(`stable AdMob fix: installed=${installed}`, () => {
|
|
83
|
+
const commands = [];
|
|
84
|
+
const start = script.indexOf('const syncAdmobNextgenPackage =');
|
|
85
|
+
const code = script.slice(start, script.indexOf('const downloadOptionalCodeplayFile', start));
|
|
86
|
+
vm.runInNewContext(code + '\nsyncAdmobNextgenPackage();', {
|
|
87
|
+
fs: { existsSync: () => true }, path, process, packageJsonPath: 'package.json',
|
|
88
|
+
isPackageAvailable: () => false, getInstalledVersion: () => installed,
|
|
89
|
+
getLatestVersion: () => '1.6.2',
|
|
90
|
+
getAdmobJsonPath: () => 'config.json', readJsonSafe: () => ({ config: { squeezebackEnabled: true } }),
|
|
91
|
+
compareVersionStrings: (a, b) => a.localeCompare(b, undefined, { numeric: true }),
|
|
92
|
+
runNpmCommand: command => commands.push(command), console: { log() {}, warn() {} }
|
|
93
|
+
});
|
|
94
|
+
assert.deepEqual(commands, installed === '1.6.2' || installed === '1.7.0'
|
|
95
|
+
? [] : ['npm install capacitor-admob-nextgen@1.6.2']);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
test('stable AdMob is selected for source-checked patch preparation', () => {
|
|
100
|
+
const commands = [];
|
|
101
|
+
const start = script.indexOf('const syncAdmobNextgenPackage =');
|
|
102
|
+
const code = script.slice(start, script.indexOf('const downloadOptionalCodeplayFile', start));
|
|
103
|
+
vm.runInNewContext(code + '\nsyncAdmobNextgenPackage();', {
|
|
104
|
+
fs: { existsSync: value => value === 'package.json' }, path, process, packageJsonPath: 'package.json',
|
|
105
|
+
isPackageAvailable: () => false, getInstalledVersion: () => '1.6.2-beta',
|
|
106
|
+
getLatestVersion: () => '1.6.2', getAdmobJsonPath: () => 'config.json',
|
|
107
|
+
readJsonSafe: () => ({ config: { squeezebackEnabled: true } }),
|
|
108
|
+
compareVersionStrings: (a, b) => a.localeCompare(b, undefined, { numeric: true }),
|
|
109
|
+
runNpmCommand: command => commands.push(command), console: { log() {}, warn() {} }
|
|
110
|
+
});
|
|
111
|
+
assert.deepEqual(commands, ['npm install capacitor-admob-nextgen@1.6.2']);
|
|
112
|
+
});
|
package/scripts/sync-files.js
CHANGED
|
@@ -113,6 +113,11 @@ function install(options = {}) {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
if (!capacitor9) require('../files/buildCodeplay/splash-setup.cjs').syncSplashSetup(projectRoot);
|
|
116
|
+
if (capacitor9) {
|
|
117
|
+
require('../files/buildCodeplay/sync-notification-large-icon.cjs').syncNotificationLargeIcon(projectRoot);
|
|
118
|
+
const splash = require('../files/buildCodeplay/sync-capacitor9-launch-splash.cjs').syncCapacitor9LaunchSplash(projectRoot);
|
|
119
|
+
console.log(`codeplay-common: Capacitor 9 launch splash ${splash}.`);
|
|
120
|
+
}
|
|
116
121
|
require('../files/buildCodeplay/setup-ruads.cjs').syncRuAdsSetup(projectRoot, {
|
|
117
122
|
runtimeRoot: path.resolve(__dirname, '../runtime/vk-ads'),
|
|
118
123
|
});
|