codeplay-common 4.11.28 → 4.11.30
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 +89 -89
- package/RELEASE_NOTES.md +13 -13
- package/files/buildCodeplay/HUAWEI-PRIVACY.md +9 -0
- package/files/buildCodeplay/add-splash-screen.js +1 -1
- package/files/buildCodeplay/codeplayBeforeBuild.js +4756 -4755
- package/files/buildCodeplay/disabled-ads.mjs +45 -45
- package/files/buildCodeplay/ensure-current-build.cjs +42 -42
- package/files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs +31 -31
- package/files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs +28 -28
- package/files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle +9 -9
- package/files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs +30 -30
- package/files/buildCodeplay/huawei-privacy-entry.js +135 -0
- package/files/buildCodeplay/huawei-privacy.cjs +92 -0
- package/files/buildCodeplay/huawei-privacy.css +22 -0
- package/files/buildCodeplay/iap-alias.cjs +116 -108
- package/files/buildCodeplay/ios-ad-consent.cjs +56 -56
- package/files/buildCodeplay/ios-emi-admob-modification.js +25 -25
- package/files/buildCodeplay/migrate-system-bars.cjs +115 -115
- package/files/buildCodeplay/newly added.txt +89 -89
- package/files/buildCodeplay/non-google-billing.pro +3 -3
- package/files/buildCodeplay/release-sync.config.json +4 -4
- package/files/buildCodeplay/remove-force-kotlin-disable.js +43 -43
- package/files/buildCodeplay/ruads.cjs +211 -211
- package/files/buildCodeplay/saf-mediastore-dependency.cjs +21 -21
- package/files/buildCodeplay/setSplashAnimation.js +2 -2
- package/files/buildCodeplay/setup-ruads.cjs +55 -55
- package/files/buildCodeplay/splash-setup.cjs +88 -88
- package/files/buildCodeplay/store-billing.cjs +43 -43
- package/files/buildCodeplay/tests/huawei-privacy.test.cjs +49 -0
- package/files/buildCodeplay/tests/huawei-vite.test.cjs +35 -0
- package/files/scripts-common/generate-baseline-profile.js +46 -46
- package/files/take-screen-image.js +4414 -4414
- package/package.json +28 -28
- package/runtime/splash-ready.mjs +52 -52
- package/runtime/vk-ads/vk-ad-configuration.json +39 -39
- package/scripts/ensure-current-build.test.cjs +76 -76
- package/scripts/iap-alias.test.cjs +117 -78
- package/scripts/ios-ad-consent.test.cjs +99 -99
- package/scripts/ruads-install.test.cjs +180 -180
- package/scripts/ruads-policy.test.cjs +174 -174
- package/scripts/saf-mediastore-dependency.test.cjs +44 -44
- package/scripts/splash-setup.test.cjs +142 -142
- package/scripts/sync-files.js +1 -1
- package/scripts/system-bars.test.cjs +77 -77
- package/scripts/vite-build-settings.test.cjs +92 -92
|
@@ -1,108 +1,116 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
function findLatestIapDirectory(projectRoot = process.cwd()) {
|
|
5
|
-
const ads = path.join(projectRoot, 'src/js/Ads');
|
|
6
|
-
if (!fs.existsSync(ads)) return null;
|
|
7
|
-
const folder = fs.readdirSync(ads, { withFileTypes: true })
|
|
8
|
-
.filter(entry => entry.isDirectory() && /^IAP-\d+(?:\.\d+)*$/.test(entry.name)
|
|
9
|
-
&& fs.existsSync(path.join(ads, entry.name, 'IAP-state.js'))
|
|
10
|
-
&& fs.statSync(path.join(ads, entry.name, 'IAP-state.js')).isFile())
|
|
11
|
-
.map(entry => entry.name).sort((a, b) => b.localeCompare(a, undefined, { numeric: true }))[0];
|
|
12
|
-
return folder ? path.join(ads, folder) : null;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Resolve old protected controllers without rewriting their source or version.
|
|
16
|
-
function legacyIapPlugin(projectRoot = process.cwd()) {
|
|
17
|
-
return {
|
|
18
|
-
name: 'codeplay-legacy-iap-imports',
|
|
19
|
-
enforce: 'pre',
|
|
20
|
-
async resolveId(source, importer) {
|
|
21
|
-
const match = /^(?:(?:\.\.?\/)+|@\/|\/src\/)(?:[^?#]*\/)?IAP-\d+(?:\.\d+)*\/([^?#]+)([?#].*)?$/.exec(source);
|
|
22
|
-
if (!match) return null;
|
|
23
|
-
const directory = findLatestIapDirectory(projectRoot);
|
|
24
|
-
if (!directory) throw new Error('Cannot resolve legacy IAP import: no installed IAP-state.js.');
|
|
25
|
-
const target = path.resolve(directory, match[1]);
|
|
26
|
-
if (!target.startsWith(directory + path.sep) || !fs.existsSync(target) || !fs.statSync(target).isFile()) throw new Error(`Missing IAP module: ${source}`);
|
|
27
|
-
return this.resolve(target + (match[2] || ''), importer, { skipSelf: true });
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Reuse the before-build source inventory and gallery migration's import scanner.
|
|
33
|
-
// Only module specifiers are changed; comments, text and F7 markup are preserved.
|
|
34
|
-
function syncIapAliases(projectRoot = process.cwd(), files = []) {
|
|
35
|
-
const directory = findLatestIapDirectory(projectRoot);
|
|
36
|
-
const plans = [];
|
|
37
|
-
for (const file of files) {
|
|
38
|
-
if (file.split(path.sep).some(part => /^admob-nextgen-\d+(?:\.\d+)*$/.test(part)) || /^admob-emi-nextgen-\d+(?:\.\d+)*\.js$/.test(path.basename(file))) continue;
|
|
39
|
-
if (!/\.(?:js|mjs|cjs|ts|tsx|jsx|f7|vue)$/.test(file) || file.endsWith('.min.js')) continue;
|
|
40
|
-
const original = fs.readFileSync(file, 'utf8');
|
|
41
|
-
let script = original;
|
|
42
|
-
if (/\.(f7|vue)$/.test(file)) {
|
|
43
|
-
script = original.replace(/[^\r\n]/g, ' ');
|
|
44
|
-
for (const match of original.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script\s*>/gi)) {
|
|
45
|
-
const start = match.index + match[0].indexOf('>') + 1;
|
|
46
|
-
script = script.slice(0, start) + match[1] + script.slice(start + match[1].length);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const code = script.replace(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1/g,
|
|
50
|
-
(match, quote) => quote ? match : match.replace(/[^\r\n]/g, ' '));
|
|
51
|
-
const imports = /(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1|\b(?:import\s+(?:[^;'"`]*?\s+from\s*)?|export\s+[^;'"`]*?\s+from\s*|(?:import|require)\s*\(\s*)(['"])([^'"\r\n]+)\2/g;
|
|
52
|
-
const replacements = [];
|
|
53
|
-
for (const match of code.matchAll(imports)) {
|
|
54
|
-
const specifier = match[3];
|
|
55
|
-
if (!specifier) continue;
|
|
56
|
-
const versioned = /^(?:(?:\.\.?\/)+|@\/|\/src\/)(?:[^?#]*\/)?IAP-\d+(?:\.\d+)*\/([^?#]+)([?#].*)?$/.exec(specifier);
|
|
57
|
-
const aliased = /^@iap\/([^?#]+)([?#].*)?$/.exec(specifier);
|
|
58
|
-
if (!versioned && !aliased) continue;
|
|
59
|
-
if (!directory) throw new Error(`Cannot configure @iap: no installed IAP folder with IAP-state.js (${file}).`);
|
|
60
|
-
const module = (versioned || aliased)[1];
|
|
61
|
-
const target = path.resolve(directory, module);
|
|
62
|
-
if (!target.startsWith(directory + path.sep) || !fs.existsSync(target) || !fs.statSync(target).isFile()) throw new Error(`Missing @iap/${module} in ${directory}; update the compatible IAP package first.`);
|
|
63
|
-
if (versioned) {
|
|
64
|
-
const start = match.index + match[0].lastIndexOf(specifier);
|
|
65
|
-
replacements.push({ start, length: specifier.length, value: `@iap/${module}${versioned[2] || ''}` });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
let updated = original;
|
|
69
|
-
for (const edit of replacements.reverse()) updated = updated.slice(0, edit.start) + edit.value + updated.slice(edit.start + edit.length);
|
|
70
|
-
if (updated !== original) plans.push({ file, updated });
|
|
71
|
-
}
|
|
72
|
-
const vite = ['vite.config.mjs', 'vite.config.js'].map(name => path.join(projectRoot, name)).find(file => fs.existsSync(file));
|
|
73
|
-
if (directory && vite) {
|
|
74
|
-
let original = fs.readFileSync(vite, 'utf8');
|
|
75
|
-
const saved = original;
|
|
76
|
-
if (!original.includes('codeplayIapAliases.findLatestIapDirectory(')) {
|
|
77
|
-
const code = original.replace(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1/g,
|
|
78
|
-
(match, quote) => quote ? match : match.replace(/[^\r\n]/g, ' '));
|
|
79
|
-
const header = /\balias\s*:\s*([\[{])/.exec(code);
|
|
80
|
-
if (!header) throw new Error('Cannot configure @iap: Vite needs a resolve.alias object or array.');
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
function findLatestIapDirectory(projectRoot = process.cwd()) {
|
|
5
|
+
const ads = path.join(projectRoot, 'src/js/Ads');
|
|
6
|
+
if (!fs.existsSync(ads)) return null;
|
|
7
|
+
const folder = fs.readdirSync(ads, { withFileTypes: true })
|
|
8
|
+
.filter(entry => entry.isDirectory() && /^IAP-\d+(?:\.\d+)*$/.test(entry.name)
|
|
9
|
+
&& fs.existsSync(path.join(ads, entry.name, 'IAP-state.js'))
|
|
10
|
+
&& fs.statSync(path.join(ads, entry.name, 'IAP-state.js')).isFile())
|
|
11
|
+
.map(entry => entry.name).sort((a, b) => b.localeCompare(a, undefined, { numeric: true }))[0];
|
|
12
|
+
return folder ? path.join(ads, folder) : null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Resolve old protected controllers without rewriting their source or version.
|
|
16
|
+
function legacyIapPlugin(projectRoot = process.cwd()) {
|
|
17
|
+
return {
|
|
18
|
+
name: 'codeplay-legacy-iap-imports',
|
|
19
|
+
enforce: 'pre',
|
|
20
|
+
async resolveId(source, importer) {
|
|
21
|
+
const match = /^(?:(?:\.\.?\/)+|@\/|\/src\/)(?:[^?#]*\/)?IAP-\d+(?:\.\d+)*\/([^?#]+)([?#].*)?$/.exec(source);
|
|
22
|
+
if (!match) return null;
|
|
23
|
+
const directory = findLatestIapDirectory(projectRoot);
|
|
24
|
+
if (!directory) throw new Error('Cannot resolve legacy IAP import: no installed IAP-state.js.');
|
|
25
|
+
const target = path.resolve(directory, match[1]);
|
|
26
|
+
if (!target.startsWith(directory + path.sep) || !fs.existsSync(target) || !fs.statSync(target).isFile()) throw new Error(`Missing IAP module: ${source}`);
|
|
27
|
+
return this.resolve(target + (match[2] || ''), importer, { skipSelf: true });
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Reuse the before-build source inventory and gallery migration's import scanner.
|
|
33
|
+
// Only module specifiers are changed; comments, text and F7 markup are preserved.
|
|
34
|
+
function syncIapAliases(projectRoot = process.cwd(), files = []) {
|
|
35
|
+
const directory = findLatestIapDirectory(projectRoot);
|
|
36
|
+
const plans = [];
|
|
37
|
+
for (const file of files) {
|
|
38
|
+
if (file.split(path.sep).some(part => /^admob-nextgen-\d+(?:\.\d+)*$/.test(part)) || /^admob-emi-nextgen-\d+(?:\.\d+)*\.js$/.test(path.basename(file))) continue;
|
|
39
|
+
if (!/\.(?:js|mjs|cjs|ts|tsx|jsx|f7|vue)$/.test(file) || file.endsWith('.min.js')) continue;
|
|
40
|
+
const original = fs.readFileSync(file, 'utf8');
|
|
41
|
+
let script = original;
|
|
42
|
+
if (/\.(f7|vue)$/.test(file)) {
|
|
43
|
+
script = original.replace(/[^\r\n]/g, ' ');
|
|
44
|
+
for (const match of original.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script\s*>/gi)) {
|
|
45
|
+
const start = match.index + match[0].indexOf('>') + 1;
|
|
46
|
+
script = script.slice(0, start) + match[1] + script.slice(start + match[1].length);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const code = script.replace(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1/g,
|
|
50
|
+
(match, quote) => quote ? match : match.replace(/[^\r\n]/g, ' '));
|
|
51
|
+
const imports = /(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1|\b(?:import\s+(?:[^;'"`]*?\s+from\s*)?|export\s+[^;'"`]*?\s+from\s*|(?:import|require)\s*\(\s*)(['"])([^'"\r\n]+)\2/g;
|
|
52
|
+
const replacements = [];
|
|
53
|
+
for (const match of code.matchAll(imports)) {
|
|
54
|
+
const specifier = match[3];
|
|
55
|
+
if (!specifier) continue;
|
|
56
|
+
const versioned = /^(?:(?:\.\.?\/)+|@\/|\/src\/)(?:[^?#]*\/)?IAP-\d+(?:\.\d+)*\/([^?#]+)([?#].*)?$/.exec(specifier);
|
|
57
|
+
const aliased = /^@iap\/([^?#]+)([?#].*)?$/.exec(specifier);
|
|
58
|
+
if (!versioned && !aliased) continue;
|
|
59
|
+
if (!directory) throw new Error(`Cannot configure @iap: no installed IAP folder with IAP-state.js (${file}).`);
|
|
60
|
+
const module = (versioned || aliased)[1];
|
|
61
|
+
const target = path.resolve(directory, module);
|
|
62
|
+
if (!target.startsWith(directory + path.sep) || !fs.existsSync(target) || !fs.statSync(target).isFile()) throw new Error(`Missing @iap/${module} in ${directory}; update the compatible IAP package first.`);
|
|
63
|
+
if (versioned) {
|
|
64
|
+
const start = match.index + match[0].lastIndexOf(specifier);
|
|
65
|
+
replacements.push({ start, length: specifier.length, value: `@iap/${module}${versioned[2] || ''}` });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
let updated = original;
|
|
69
|
+
for (const edit of replacements.reverse()) updated = updated.slice(0, edit.start) + edit.value + updated.slice(edit.start + edit.length);
|
|
70
|
+
if (updated !== original) plans.push({ file, updated });
|
|
71
|
+
}
|
|
72
|
+
const vite = ['vite.config.mjs', 'vite.config.js'].map(name => path.join(projectRoot, name)).find(file => fs.existsSync(file));
|
|
73
|
+
if (directory && vite) {
|
|
74
|
+
let original = fs.readFileSync(vite, 'utf8');
|
|
75
|
+
const saved = original;
|
|
76
|
+
if (!original.includes('codeplayIapAliases.findLatestIapDirectory(')) {
|
|
77
|
+
const code = original.replace(/\/\/[^\r\n]*|\/\*[\s\S]*?\*\/|(['"`])(?:\\[\s\S]|(?!\1)[^\\])*\1/g,
|
|
78
|
+
(match, quote) => quote ? match : match.replace(/[^\r\n]/g, ' '));
|
|
79
|
+
const header = /\balias\s*:\s*([\[{])/.exec(code);
|
|
80
|
+
if (!header) throw new Error('Cannot configure @iap: Vite needs a resolve.alias object or array.');
|
|
81
|
+
// Migrate only the standard versioned app directory; never evaluate config code.
|
|
82
|
+
const existing = /['"]@iap['"]\s*[:,]/.test(code);
|
|
83
|
+
const standard = /(['"]@iap['"]\s*:\s*|\bfind\s*:\s*['"]@iap['"]\s*,\s*replacement\s*:\s*)((?:path\.)?resolve\s*\(\s*__dirname\s*,\s*(['"])(?:\.\/)?src\/js\/Ads\/IAP-\d+(?:\.\d+)*\/?\3\s*\))(?=\s*[,}])/g;
|
|
84
|
+
const matches = [...code.matchAll(standard)];
|
|
85
|
+
if (existing && matches.length !== 1) throw new Error('Cannot replace a custom @iap alias automatically; use codeplayIapAliases.findLatestIapDirectory().');
|
|
86
|
+
const entry = header[1] === '{'
|
|
87
|
+
? "'@iap': codeplayIapAliases.findLatestIapDirectory(),"
|
|
88
|
+
: "{ find: '@iap', replacement: codeplayIapAliases.findLatestIapDirectory() },";
|
|
89
|
+
const offset = header.index + header[0].length;
|
|
90
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
91
|
+
const match = matches[0];
|
|
92
|
+
const start = match && match.index + match[1].length;
|
|
93
|
+
const updated = existing
|
|
94
|
+
? original.slice(0, start) + 'codeplayIapAliases.findLatestIapDirectory()' + original.slice(start + match[2].length)
|
|
95
|
+
: original.slice(0, offset) + newline + ' ' + entry + original.slice(offset);
|
|
96
|
+
original = `import codeplayIapAliases from './buildCodeplay/iap-alias.cjs';${newline}${updated}`;
|
|
97
|
+
}
|
|
98
|
+
if (!original.includes('codeplayIapAliases.legacyIapPlugin(')) {
|
|
99
|
+
const plugins = /\bplugins\s*:\s*\[/.exec(original);
|
|
100
|
+
if (plugins) {
|
|
101
|
+
const offset = plugins.index + plugins[0].length;
|
|
102
|
+
original = original.slice(0, offset) + '\n codeplayIapAliases.legacyIapPlugin(),' + original.slice(offset);
|
|
103
|
+
} else {
|
|
104
|
+
const resolve = /\bresolve\s*:/.exec(original);
|
|
105
|
+
if (!resolve) throw new Error('Cannot configure legacy IAP resolution: Vite resolve settings missing.');
|
|
106
|
+
original = original.slice(0, resolve.index) + 'plugins: [codeplayIapAliases.legacyIapPlugin()],\n' + original.slice(resolve.index);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (saved !== original) plans.push({ file: vite, updated: original });
|
|
110
|
+
}
|
|
111
|
+
// Validate the complete migration before writing. No confirmation is needed.
|
|
112
|
+
for (const plan of plans) fs.writeFileSync(plan.file, plan.updated);
|
|
113
|
+
return plans.map(plan => path.relative(projectRoot, plan.file));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
module.exports = { findLatestIapDirectory, legacyIapPlugin, syncIapAliases };
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
// Version 1.0: keep native app lifecycle callbacks out of the UMP/ATT flow.
|
|
2
|
-
const fs = require('node:fs');
|
|
3
|
-
const path = require('node:path');
|
|
4
|
-
|
|
5
|
-
// Only remove the known block generated by older builds. Any other native
|
|
6
|
-
// request needs an explicit correction rather than deleting custom app code.
|
|
7
|
-
const legacyRequest = [
|
|
8
|
-
'if ATTrackingManager.trackingAuthorizationStatus == .notDetermined &&',
|
|
9
|
-
'!isTrackingAuthorizationRequestScheduled {',
|
|
10
|
-
'isTrackingAuthorizationRequestScheduled = true',
|
|
11
|
-
'DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in',
|
|
12
|
-
'self?.isTrackingAuthorizationRequestScheduled = false',
|
|
13
|
-
'guard UIApplication.shared.applicationState == .active,',
|
|
14
|
-
'ATTrackingManager.trackingAuthorizationStatus == .notDetermined else { return }',
|
|
15
|
-
'ATTrackingManager.requestTrackingAuthorization { _ in }',
|
|
16
|
-
'}',
|
|
17
|
-
'}',
|
|
18
|
-
].map(line => line.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/ +/g, '\\s+')).join('\\s*');
|
|
19
|
-
|
|
20
|
-
function nativeSources(directory) {
|
|
21
|
-
if (!fs.existsSync(directory)) return [];
|
|
22
|
-
return fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
|
|
23
|
-
const file = path.join(directory, entry.name);
|
|
24
|
-
if (entry.isDirectory()) return nativeSources(file);
|
|
25
|
-
return entry.isFile() && /\.(?:swift|m|mm)$/.test(entry.name) ? [file] : [];
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function prepareIOSAdConsent(projectRoot, log = console.log) {
|
|
30
|
-
const appDirectory = path.join(projectRoot, 'ios', 'App', 'App');
|
|
31
|
-
const updates = [];
|
|
32
|
-
for (const file of nativeSources(appDirectory)) {
|
|
33
|
-
const original = fs.readFileSync(file, 'utf8');
|
|
34
|
-
let content = original;
|
|
35
|
-
if (path.basename(file) === 'SceneDelegate.swift') {
|
|
36
|
-
content = content.replace(new RegExp(legacyRequest, 'g'), '');
|
|
37
|
-
content = content.replace(/^[ \t]*private var isTrackingAuthorizationRequestScheduled = false\r?\n/gm, '');
|
|
38
|
-
if (!content.includes('ATTrackingManager')) {
|
|
39
|
-
content = content.replace(/^import AppTrackingTransparency\r?\n/gm, '');
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// Check AppDelegate and other app-owned startup code even when this app
|
|
43
|
-
// has no SceneDelegate. The Capacitor plugin remains the single ATT owner.
|
|
44
|
-
const executable = content.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/[^\r\n]*/g, '');
|
|
45
|
-
if (/\bATTrackingManager\s*(?:\.\s*|\s+)requestTrackingAuthorization(?:WithCompletionHandler)?\b/.test(executable)) {
|
|
46
|
-
throw new Error(`${path.relative(projectRoot, file)} requests ATT outside the regional consent flow. Remove the native startup request; @admob requests ATT after UMP completes.`);
|
|
47
|
-
}
|
|
48
|
-
if (content !== original) updates.push({ file, content });
|
|
49
|
-
}
|
|
50
|
-
// Validate every source before changing any file.
|
|
51
|
-
for (const { file, content } of updates) fs.writeFileSync(file, content, 'utf8');
|
|
52
|
-
log('iOS native startup checked; the ad consent flow controls ATT after UMP.');
|
|
53
|
-
return updates.map(({ file }) => path.relative(projectRoot, file));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
module.exports = { prepareIOSAdConsent };
|
|
1
|
+
// Version 1.0: keep native app lifecycle callbacks out of the UMP/ATT flow.
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
|
|
5
|
+
// Only remove the known block generated by older builds. Any other native
|
|
6
|
+
// request needs an explicit correction rather than deleting custom app code.
|
|
7
|
+
const legacyRequest = [
|
|
8
|
+
'if ATTrackingManager.trackingAuthorizationStatus == .notDetermined &&',
|
|
9
|
+
'!isTrackingAuthorizationRequestScheduled {',
|
|
10
|
+
'isTrackingAuthorizationRequestScheduled = true',
|
|
11
|
+
'DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in',
|
|
12
|
+
'self?.isTrackingAuthorizationRequestScheduled = false',
|
|
13
|
+
'guard UIApplication.shared.applicationState == .active,',
|
|
14
|
+
'ATTrackingManager.trackingAuthorizationStatus == .notDetermined else { return }',
|
|
15
|
+
'ATTrackingManager.requestTrackingAuthorization { _ in }',
|
|
16
|
+
'}',
|
|
17
|
+
'}',
|
|
18
|
+
].map(line => line.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(/ +/g, '\\s+')).join('\\s*');
|
|
19
|
+
|
|
20
|
+
function nativeSources(directory) {
|
|
21
|
+
if (!fs.existsSync(directory)) return [];
|
|
22
|
+
return fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
|
|
23
|
+
const file = path.join(directory, entry.name);
|
|
24
|
+
if (entry.isDirectory()) return nativeSources(file);
|
|
25
|
+
return entry.isFile() && /\.(?:swift|m|mm)$/.test(entry.name) ? [file] : [];
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function prepareIOSAdConsent(projectRoot, log = console.log) {
|
|
30
|
+
const appDirectory = path.join(projectRoot, 'ios', 'App', 'App');
|
|
31
|
+
const updates = [];
|
|
32
|
+
for (const file of nativeSources(appDirectory)) {
|
|
33
|
+
const original = fs.readFileSync(file, 'utf8');
|
|
34
|
+
let content = original;
|
|
35
|
+
if (path.basename(file) === 'SceneDelegate.swift') {
|
|
36
|
+
content = content.replace(new RegExp(legacyRequest, 'g'), '');
|
|
37
|
+
content = content.replace(/^[ \t]*private var isTrackingAuthorizationRequestScheduled = false\r?\n/gm, '');
|
|
38
|
+
if (!content.includes('ATTrackingManager')) {
|
|
39
|
+
content = content.replace(/^import AppTrackingTransparency\r?\n/gm, '');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Check AppDelegate and other app-owned startup code even when this app
|
|
43
|
+
// has no SceneDelegate. The Capacitor plugin remains the single ATT owner.
|
|
44
|
+
const executable = content.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/[^\r\n]*/g, '');
|
|
45
|
+
if (/\bATTrackingManager\s*(?:\.\s*|\s+)requestTrackingAuthorization(?:WithCompletionHandler)?\b/.test(executable)) {
|
|
46
|
+
throw new Error(`${path.relative(projectRoot, file)} requests ATT outside the regional consent flow. Remove the native startup request; @admob requests ATT after UMP completes.`);
|
|
47
|
+
}
|
|
48
|
+
if (content !== original) updates.push({ file, content });
|
|
49
|
+
}
|
|
50
|
+
// Validate every source before changing any file.
|
|
51
|
+
for (const { file, content } of updates) fs.writeFileSync(file, content, 'utf8');
|
|
52
|
+
log('iOS native startup checked; the ad consent flow controls ATT after UMP.');
|
|
53
|
+
return updates.map(({ file }) => path.relative(projectRoot, file));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { prepareIOSAdConsent };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const replaceEmiPluginCode=()=>
|
|
5
|
-
{
|
|
6
|
-
// path to your .m file
|
|
7
|
-
const filePath = path.join(__dirname, '../ios/capacitor-cordova-ios-plugins/sourcesstatic/EmiIndoCordovaPluginAdmob/emiAdmobPlugin.m');
|
|
8
|
-
const nextGenPackagePath = path.join(__dirname, '../node_modules/capacitor-admob-nextgen/package.json');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (fs.existsSync(filePath)) {
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const replaceEmiPluginCode=()=>
|
|
5
|
+
{
|
|
6
|
+
// path to your .m file
|
|
7
|
+
const filePath = path.join(__dirname, '../ios/capacitor-cordova-ios-plugins/sourcesstatic/EmiIndoCordovaPluginAdmob/emiAdmobPlugin.m');
|
|
8
|
+
const nextGenPackagePath = path.join(__dirname, '../node_modules/capacitor-admob-nextgen/package.json');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
if (fs.existsSync(filePath)) {
|
|
12
12
|
let fileContent = fs.readFileSync(filePath, 'utf8');
|
|
13
13
|
|
|
14
14
|
// match the hideBannerAd method
|
|
@@ -33,17 +33,17 @@ const replaceEmiPluginCode=()=>
|
|
|
33
33
|
fileContent.slice(match.index + match[0].length);
|
|
34
34
|
|
|
35
35
|
fs.writeFileSync(filePath, updatedFileContent, 'utf8');
|
|
36
|
-
console.log(
|
|
37
|
-
'✅ Successfully ensured [self resetWebViewHeight]; is commented only inside hideBannerAd in emiAdmobPlugin.m'
|
|
38
|
-
);
|
|
39
|
-
} else {
|
|
40
|
-
console.log('⚠️ hideBannerAd method not found.');
|
|
41
|
-
}
|
|
42
|
-
} else if (fs.existsSync(nextGenPackagePath)) {
|
|
43
|
-
console.log('ℹ️ Skipping legacy iOS EMI AdMob patch. capacitor-admob-nextgen does not use emiAdmobPlugin.m.');
|
|
44
|
-
} else {
|
|
45
|
-
console.log('ℹ️ emiAdmobPlugin.m file not found, skipping modification.');
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
replaceEmiPluginCode();
|
|
36
|
+
console.log(
|
|
37
|
+
'✅ Successfully ensured [self resetWebViewHeight]; is commented only inside hideBannerAd in emiAdmobPlugin.m'
|
|
38
|
+
);
|
|
39
|
+
} else {
|
|
40
|
+
console.log('⚠️ hideBannerAd method not found.');
|
|
41
|
+
}
|
|
42
|
+
} else if (fs.existsSync(nextGenPackagePath)) {
|
|
43
|
+
console.log('ℹ️ Skipping legacy iOS EMI AdMob patch. capacitor-admob-nextgen does not use emiAdmobPlugin.m.');
|
|
44
|
+
} else {
|
|
45
|
+
console.log('ℹ️ emiAdmobPlugin.m file not found, skipping modification.');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
replaceEmiPluginCode();
|