codeplay-common 4.11.29 → 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/README.md +89 -89
- package/RELEASE_NOTES.md +13 -13
- package/files/buildCodeplay/HUAWEI-PRIVACY.md +9 -9
- package/files/buildCodeplay/add-splash-screen.js +1 -1
- package/files/buildCodeplay/codeplayBeforeBuild.js +4756 -4756
- 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 -135
- package/files/buildCodeplay/huawei-privacy.cjs +92 -92
- package/files/buildCodeplay/huawei-privacy.css +22 -22
- 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 -49
- package/files/buildCodeplay/tests/huawei-vite.test.cjs +35 -35
- 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,135 +1,135 @@
|
|
|
1
|
-
import { Capacitor, registerPlugin } from '@capacitor/core';
|
|
2
|
-
import './huawei-privacy.css';
|
|
3
|
-
|
|
4
|
-
const consentKey = 'codeplayHuaweiPrivacyConsentV1';
|
|
5
|
-
const Analytics = registerPlugin('FirebaseAnalytics');
|
|
6
|
-
const Browser = registerPlugin('Browser');
|
|
7
|
-
const NativeApp = registerPlugin('App');
|
|
8
|
-
const RuAds = registerPlugin('CodeplayRuStoreAds');
|
|
9
|
-
|
|
10
|
-
function policyUrl(appId) {
|
|
11
|
-
return `https://htmlcodeplay.com/privacy/ch/${appId}`;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async function openPolicy(appId) {
|
|
15
|
-
const url = policyUrl(appId);
|
|
16
|
-
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('Browser')) {
|
|
17
|
-
await Browser.open({ url });
|
|
18
|
-
} else {
|
|
19
|
-
window.open(url, '_blank', 'noopener,noreferrer');
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async function setAnalyticsConsent(enabled) {
|
|
24
|
-
if (!Capacitor.isNativePlatform() || !Capacitor.isPluginAvailable('FirebaseAnalytics')) return;
|
|
25
|
-
try {
|
|
26
|
-
await Analytics.setConsent({ type: 'ANALYTICS_STORAGE', status: enabled ? 'GRANTED' : 'DENIED' });
|
|
27
|
-
await Analytics.setEnabled({ enabled });
|
|
28
|
-
} catch (error) {
|
|
29
|
-
// The manifest still defaults native analytics collection to disabled.
|
|
30
|
-
if (enabled) console.warn('Huawei analytics remains disabled:', error);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function button(label, className, action) {
|
|
35
|
-
const element = document.createElement('button');
|
|
36
|
-
element.type = 'button';
|
|
37
|
-
element.className = className;
|
|
38
|
-
element.textContent = label;
|
|
39
|
-
element.addEventListener('click', action);
|
|
40
|
-
return element;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function showGate({ appId, appName, startApp }) {
|
|
44
|
-
const gate = document.createElement('section');
|
|
45
|
-
gate.className = 'codeplay-huawei-privacy-gate';
|
|
46
|
-
gate.setAttribute('role', 'dialog');
|
|
47
|
-
gate.setAttribute('aria-modal', 'true');
|
|
48
|
-
gate.setAttribute('aria-label', '隐私政策');
|
|
49
|
-
const card = document.createElement('div');
|
|
50
|
-
card.className = 'codeplay-huawei-privacy-card';
|
|
51
|
-
const title = document.createElement('h1');
|
|
52
|
-
title.textContent = '请先阅读隐私政策';
|
|
53
|
-
const message = document.createElement('p');
|
|
54
|
-
message.textContent = `${appName} 会在您同意后启动应用服务。请先阅读简体中文隐私政策,了解个人信息处理、第三方服务及您的权利。`;
|
|
55
|
-
const link = button('阅读隐私政策', 'codeplay-huawei-privacy-policy', async () => {
|
|
56
|
-
try { await openPolicy(appId); }
|
|
57
|
-
catch { status.textContent = '无法打开隐私政策。请检查网络连接后重试。'; }
|
|
58
|
-
});
|
|
59
|
-
const status = document.createElement('p');
|
|
60
|
-
status.className = 'codeplay-huawei-privacy-status';
|
|
61
|
-
status.setAttribute('role', 'status');
|
|
62
|
-
const agree = button('同意并继续', 'codeplay-huawei-privacy-agree', async () => {
|
|
63
|
-
agree.disabled = true;
|
|
64
|
-
try {
|
|
65
|
-
localStorage.setItem(consentKey, 'agreed');
|
|
66
|
-
await setAnalyticsConsent(true);
|
|
67
|
-
gate.remove();
|
|
68
|
-
await startApp();
|
|
69
|
-
installSettingsControls(appId);
|
|
70
|
-
} catch {
|
|
71
|
-
localStorage.removeItem(consentKey);
|
|
72
|
-
status.textContent = '应用暂时无法启动。请重试。';
|
|
73
|
-
agree.disabled = false;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
const decline = button('不同意并退出', 'codeplay-huawei-privacy-decline', async () => {
|
|
77
|
-
await setAnalyticsConsent(false);
|
|
78
|
-
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('CodeplayRuStoreAds')) {
|
|
79
|
-
await RuAds.setEnabled({ enabled: false }).catch(() => {});
|
|
80
|
-
}
|
|
81
|
-
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('App')) {
|
|
82
|
-
await NativeApp.exitApp();
|
|
83
|
-
} else {
|
|
84
|
-
status.textContent = '您可以关闭此页面。再次打开时仍可选择是否同意。';
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
card.append(title, message, link, status, agree, decline);
|
|
88
|
-
gate.append(card);
|
|
89
|
-
document.body.append(gate);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function installSettingsControls(appId) {
|
|
93
|
-
function mount() {
|
|
94
|
-
const page = document.querySelector('.page-current[data-name="settings"] .page-content');
|
|
95
|
-
if (!page || page.querySelector('.codeplay-huawei-privacy-settings')) return;
|
|
96
|
-
const container = document.createElement('div');
|
|
97
|
-
container.className = 'codeplay-huawei-privacy-settings block';
|
|
98
|
-
const policy = button('简体中文隐私政策', 'button', async () => {
|
|
99
|
-
try { await openPolicy(appId); }
|
|
100
|
-
catch { policy.textContent = '无法打开,请重试'; }
|
|
101
|
-
});
|
|
102
|
-
const withdraw = button('撤回隐私同意', 'button', async () => {
|
|
103
|
-
const confirmed = window.confirm('撤回同意后,应用会关闭。再次打开时可重新选择。确定撤回吗?');
|
|
104
|
-
if (!confirmed) return;
|
|
105
|
-
localStorage.removeItem(consentKey);
|
|
106
|
-
await setAnalyticsConsent(false);
|
|
107
|
-
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('CodeplayRuStoreAds')) {
|
|
108
|
-
await RuAds.setEnabled({ enabled: false }).catch(() => {});
|
|
109
|
-
}
|
|
110
|
-
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('App')) await NativeApp.exitApp();
|
|
111
|
-
else location.reload();
|
|
112
|
-
});
|
|
113
|
-
container.append(policy, withdraw);
|
|
114
|
-
page.append(container);
|
|
115
|
-
}
|
|
116
|
-
document.addEventListener('page:afterin', mount);
|
|
117
|
-
document.addEventListener('page:init', mount);
|
|
118
|
-
mount();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export async function startHuaweiPrivacy(options) {
|
|
122
|
-
if (document.readyState === 'loading') {
|
|
123
|
-
await new Promise(resolve => document.addEventListener('DOMContentLoaded', resolve, { once: true }));
|
|
124
|
-
}
|
|
125
|
-
let agreed = false;
|
|
126
|
-
try { agreed = localStorage.getItem(consentKey) === 'agreed'; } catch { /* Ask again. */ }
|
|
127
|
-
if (agreed) {
|
|
128
|
-
await setAnalyticsConsent(true);
|
|
129
|
-
await options.startApp();
|
|
130
|
-
installSettingsControls(options.appId);
|
|
131
|
-
} else {
|
|
132
|
-
await setAnalyticsConsent(false);
|
|
133
|
-
showGate(options);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
1
|
+
import { Capacitor, registerPlugin } from '@capacitor/core';
|
|
2
|
+
import './huawei-privacy.css';
|
|
3
|
+
|
|
4
|
+
const consentKey = 'codeplayHuaweiPrivacyConsentV1';
|
|
5
|
+
const Analytics = registerPlugin('FirebaseAnalytics');
|
|
6
|
+
const Browser = registerPlugin('Browser');
|
|
7
|
+
const NativeApp = registerPlugin('App');
|
|
8
|
+
const RuAds = registerPlugin('CodeplayRuStoreAds');
|
|
9
|
+
|
|
10
|
+
function policyUrl(appId) {
|
|
11
|
+
return `https://htmlcodeplay.com/privacy/ch/${appId}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function openPolicy(appId) {
|
|
15
|
+
const url = policyUrl(appId);
|
|
16
|
+
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('Browser')) {
|
|
17
|
+
await Browser.open({ url });
|
|
18
|
+
} else {
|
|
19
|
+
window.open(url, '_blank', 'noopener,noreferrer');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function setAnalyticsConsent(enabled) {
|
|
24
|
+
if (!Capacitor.isNativePlatform() || !Capacitor.isPluginAvailable('FirebaseAnalytics')) return;
|
|
25
|
+
try {
|
|
26
|
+
await Analytics.setConsent({ type: 'ANALYTICS_STORAGE', status: enabled ? 'GRANTED' : 'DENIED' });
|
|
27
|
+
await Analytics.setEnabled({ enabled });
|
|
28
|
+
} catch (error) {
|
|
29
|
+
// The manifest still defaults native analytics collection to disabled.
|
|
30
|
+
if (enabled) console.warn('Huawei analytics remains disabled:', error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function button(label, className, action) {
|
|
35
|
+
const element = document.createElement('button');
|
|
36
|
+
element.type = 'button';
|
|
37
|
+
element.className = className;
|
|
38
|
+
element.textContent = label;
|
|
39
|
+
element.addEventListener('click', action);
|
|
40
|
+
return element;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function showGate({ appId, appName, startApp }) {
|
|
44
|
+
const gate = document.createElement('section');
|
|
45
|
+
gate.className = 'codeplay-huawei-privacy-gate';
|
|
46
|
+
gate.setAttribute('role', 'dialog');
|
|
47
|
+
gate.setAttribute('aria-modal', 'true');
|
|
48
|
+
gate.setAttribute('aria-label', '隐私政策');
|
|
49
|
+
const card = document.createElement('div');
|
|
50
|
+
card.className = 'codeplay-huawei-privacy-card';
|
|
51
|
+
const title = document.createElement('h1');
|
|
52
|
+
title.textContent = '请先阅读隐私政策';
|
|
53
|
+
const message = document.createElement('p');
|
|
54
|
+
message.textContent = `${appName} 会在您同意后启动应用服务。请先阅读简体中文隐私政策,了解个人信息处理、第三方服务及您的权利。`;
|
|
55
|
+
const link = button('阅读隐私政策', 'codeplay-huawei-privacy-policy', async () => {
|
|
56
|
+
try { await openPolicy(appId); }
|
|
57
|
+
catch { status.textContent = '无法打开隐私政策。请检查网络连接后重试。'; }
|
|
58
|
+
});
|
|
59
|
+
const status = document.createElement('p');
|
|
60
|
+
status.className = 'codeplay-huawei-privacy-status';
|
|
61
|
+
status.setAttribute('role', 'status');
|
|
62
|
+
const agree = button('同意并继续', 'codeplay-huawei-privacy-agree', async () => {
|
|
63
|
+
agree.disabled = true;
|
|
64
|
+
try {
|
|
65
|
+
localStorage.setItem(consentKey, 'agreed');
|
|
66
|
+
await setAnalyticsConsent(true);
|
|
67
|
+
gate.remove();
|
|
68
|
+
await startApp();
|
|
69
|
+
installSettingsControls(appId);
|
|
70
|
+
} catch {
|
|
71
|
+
localStorage.removeItem(consentKey);
|
|
72
|
+
status.textContent = '应用暂时无法启动。请重试。';
|
|
73
|
+
agree.disabled = false;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const decline = button('不同意并退出', 'codeplay-huawei-privacy-decline', async () => {
|
|
77
|
+
await setAnalyticsConsent(false);
|
|
78
|
+
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('CodeplayRuStoreAds')) {
|
|
79
|
+
await RuAds.setEnabled({ enabled: false }).catch(() => {});
|
|
80
|
+
}
|
|
81
|
+
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('App')) {
|
|
82
|
+
await NativeApp.exitApp();
|
|
83
|
+
} else {
|
|
84
|
+
status.textContent = '您可以关闭此页面。再次打开时仍可选择是否同意。';
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
card.append(title, message, link, status, agree, decline);
|
|
88
|
+
gate.append(card);
|
|
89
|
+
document.body.append(gate);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function installSettingsControls(appId) {
|
|
93
|
+
function mount() {
|
|
94
|
+
const page = document.querySelector('.page-current[data-name="settings"] .page-content');
|
|
95
|
+
if (!page || page.querySelector('.codeplay-huawei-privacy-settings')) return;
|
|
96
|
+
const container = document.createElement('div');
|
|
97
|
+
container.className = 'codeplay-huawei-privacy-settings block';
|
|
98
|
+
const policy = button('简体中文隐私政策', 'button', async () => {
|
|
99
|
+
try { await openPolicy(appId); }
|
|
100
|
+
catch { policy.textContent = '无法打开,请重试'; }
|
|
101
|
+
});
|
|
102
|
+
const withdraw = button('撤回隐私同意', 'button', async () => {
|
|
103
|
+
const confirmed = window.confirm('撤回同意后,应用会关闭。再次打开时可重新选择。确定撤回吗?');
|
|
104
|
+
if (!confirmed) return;
|
|
105
|
+
localStorage.removeItem(consentKey);
|
|
106
|
+
await setAnalyticsConsent(false);
|
|
107
|
+
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('CodeplayRuStoreAds')) {
|
|
108
|
+
await RuAds.setEnabled({ enabled: false }).catch(() => {});
|
|
109
|
+
}
|
|
110
|
+
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('App')) await NativeApp.exitApp();
|
|
111
|
+
else location.reload();
|
|
112
|
+
});
|
|
113
|
+
container.append(policy, withdraw);
|
|
114
|
+
page.append(container);
|
|
115
|
+
}
|
|
116
|
+
document.addEventListener('page:afterin', mount);
|
|
117
|
+
document.addEventListener('page:init', mount);
|
|
118
|
+
mount();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export async function startHuaweiPrivacy(options) {
|
|
122
|
+
if (document.readyState === 'loading') {
|
|
123
|
+
await new Promise(resolve => document.addEventListener('DOMContentLoaded', resolve, { once: true }));
|
|
124
|
+
}
|
|
125
|
+
let agreed = false;
|
|
126
|
+
try { agreed = localStorage.getItem(consentKey) === 'agreed'; } catch { /* Ask again. */ }
|
|
127
|
+
if (agreed) {
|
|
128
|
+
await setAnalyticsConsent(true);
|
|
129
|
+
await options.startApp();
|
|
130
|
+
installSettingsControls(options.appId);
|
|
131
|
+
} else {
|
|
132
|
+
await setAnalyticsConsent(false);
|
|
133
|
+
showGate(options);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const generatedEntry = '../buildCodeplay/huawei-privacy-generated.js';
|
|
5
|
-
const originalAttribute = 'data-codeplay-original-src';
|
|
6
|
-
const analyticsMarker = 'CODEPLAY HUAWEI ANALYTICS ORIGINAL';
|
|
7
|
-
|
|
8
|
-
function updateEntry(projectRoot, enabled, appId, appName) {
|
|
9
|
-
const indexPath = path.join(projectRoot, 'src/index.html');
|
|
10
|
-
if (!fs.existsSync(indexPath)) {
|
|
11
|
-
if (enabled) throw new Error('Huawei privacy: src/index.html was not found.');
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
const original = fs.readFileSync(indexPath, 'utf8');
|
|
15
|
-
const scripts = [...original.matchAll(/<script\b(?=[^>]*\btype\s*=\s*["']module["'])[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*><\/script>/gi)];
|
|
16
|
-
const managed = scripts.filter(match => match[0].includes(originalAttribute));
|
|
17
|
-
if (managed.length > 1) throw new Error('Huawei privacy: more than one managed app entry was found.');
|
|
18
|
-
let target = managed[0];
|
|
19
|
-
if (!target && enabled) {
|
|
20
|
-
if (scripts.length !== 1) throw new Error('Huawei privacy: expected exactly one module app entry in src/index.html.');
|
|
21
|
-
target = scripts[0];
|
|
22
|
-
}
|
|
23
|
-
if (!target) return false;
|
|
24
|
-
const saved = target[0].match(new RegExp(`${originalAttribute}=["']([^"']+)["']`));
|
|
25
|
-
const entry = saved ? saved[1] : target[1];
|
|
26
|
-
if (!/^\.\/[\w./-]+\.js$/.test(entry) || entry.includes('..')) {
|
|
27
|
-
throw new Error(`Huawei privacy: unsupported app entry ${entry}`);
|
|
28
|
-
}
|
|
29
|
-
const entryPath = path.resolve(projectRoot, 'src', entry);
|
|
30
|
-
if (!fs.existsSync(entryPath)) throw new Error(`Huawei privacy: app entry ${entry} was not found.`);
|
|
31
|
-
const tag = enabled
|
|
32
|
-
? target[0].replace(/\ssrc\s*=\s*["'][^"']+["']/, ` src="${generatedEntry}"`)
|
|
33
|
-
.replace(/<script\b/, match => saved ? match : `${match} ${originalAttribute}="${entry}"`)
|
|
34
|
-
: target[0].replace(/\ssrc\s*=\s*["'][^"']+["']/, ` src="${entry}"`)
|
|
35
|
-
.replace(new RegExp(`\\s+${originalAttribute}=["'][^"']+["']`), '');
|
|
36
|
-
const next = original.replace(target[0], tag);
|
|
37
|
-
if (next !== original) fs.writeFileSync(indexPath, next);
|
|
38
|
-
if (enabled) {
|
|
39
|
-
const wrapperPath = path.join(projectRoot, 'buildCodeplay/huawei-privacy-generated.js');
|
|
40
|
-
const importPath = `../src/${entry.slice(2)}`;
|
|
41
|
-
const wrapper = `// Generated by codeplay-common for the Huawei build.\nimport { startHuaweiPrivacy } from './huawei-privacy-entry.js';\nstartHuaweiPrivacy({ appId: ${JSON.stringify(appId)}, appName: ${JSON.stringify(appName)}, startApp: () => import(${JSON.stringify(importPath)}) });\n`;
|
|
42
|
-
if (!fs.existsSync(wrapperPath) || fs.readFileSync(wrapperPath, 'utf8') !== wrapper) fs.writeFileSync(wrapperPath, wrapper);
|
|
43
|
-
}
|
|
44
|
-
return next !== original;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function updateAnalyticsDefault(projectRoot, enabled) {
|
|
48
|
-
const manifestPath = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
|
|
49
|
-
if (!fs.existsSync(manifestPath)) {
|
|
50
|
-
if (enabled) throw new Error('Huawei privacy: AndroidManifest.xml was not found.');
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
const original = fs.readFileSync(manifestPath, 'utf8');
|
|
54
|
-
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
55
|
-
const marker = new RegExp(`(\\r?\\n)?[ \\t]*<!-- ${analyticsMarker} ([A-Za-z0-9+/=]*) -->\\r?\\n[ \\t]*<meta-data\\b(?=[^>]*\\bandroid:name=["']firebase_analytics_collection_enabled["'])[^>]*\\/\\s*>\\r?\\n?`);
|
|
56
|
-
let next = original;
|
|
57
|
-
if (marker.test(next)) {
|
|
58
|
-
if (!enabled) next = next.replace(marker, (_, leading, encoded) =>
|
|
59
|
-
encoded ? `${leading || ''}${Buffer.from(encoded, 'base64').toString('utf8')}` : '');
|
|
60
|
-
else next = next.replace(marker, match => match.replace(/android:value=["'][^"']*["']/, 'android:value="false"'));
|
|
61
|
-
} else if (enabled) {
|
|
62
|
-
const existing = /[ \t]*<meta-data\b(?=[^>]*\bandroid:name=["']firebase_analytics_collection_enabled["'])[^>]*\/\s*>\r?\n?/;
|
|
63
|
-
const prior = next.match(existing)?.[0] || '';
|
|
64
|
-
const block = ` <!-- ${analyticsMarker} ${Buffer.from(prior).toString('base64')} -->${newline} <meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />${newline}`;
|
|
65
|
-
if (!/<application\b[^>]*>/.test(next)) throw new Error('Huawei privacy: application element was not found in AndroidManifest.xml.');
|
|
66
|
-
next = prior ? next.replace(existing, block) : next.replace(/<application\b[^>]*>/, match => `${match}${newline}${block}`);
|
|
67
|
-
}
|
|
68
|
-
if (next !== original) fs.writeFileSync(manifestPath, next);
|
|
69
|
-
return next !== original;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function syncHuaweiPrivacy(projectRoot, storeId, platform = 'android') {
|
|
73
|
-
const enabled = platform === 'android' && Number(storeId) === 4;
|
|
74
|
-
const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json'), 'utf8'));
|
|
75
|
-
const appId = Number(config.android?.APP_UNIQUE_ID);
|
|
76
|
-
if (enabled && (!Number.isInteger(appId) || appId < 1)) {
|
|
77
|
-
throw new Error('Huawei privacy: capacitor.config.json needs a valid android.APP_UNIQUE_ID.');
|
|
78
|
-
}
|
|
79
|
-
// Inspect both targets before writing either one, so unsupported app layouts fail early.
|
|
80
|
-
const manifestPath = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
|
|
81
|
-
if (enabled && !fs.existsSync(manifestPath)) {
|
|
82
|
-
throw new Error('Huawei privacy: AndroidManifest.xml was not found.');
|
|
83
|
-
}
|
|
84
|
-
if (enabled && !/<application\b[^>]*>/.test(fs.readFileSync(manifestPath, 'utf8'))) {
|
|
85
|
-
throw new Error('Huawei privacy: application element was not found in AndroidManifest.xml.');
|
|
86
|
-
}
|
|
87
|
-
updateEntry(projectRoot, enabled, appId, config.appName || 'App');
|
|
88
|
-
updateAnalyticsDefault(projectRoot, enabled);
|
|
89
|
-
if (enabled) console.log(`Huawei privacy consent enabled. Verify https://htmlcodeplay.com/privacy/ch/${appId} is published before submission.`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
module.exports = { syncHuaweiPrivacy };
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const generatedEntry = '../buildCodeplay/huawei-privacy-generated.js';
|
|
5
|
+
const originalAttribute = 'data-codeplay-original-src';
|
|
6
|
+
const analyticsMarker = 'CODEPLAY HUAWEI ANALYTICS ORIGINAL';
|
|
7
|
+
|
|
8
|
+
function updateEntry(projectRoot, enabled, appId, appName) {
|
|
9
|
+
const indexPath = path.join(projectRoot, 'src/index.html');
|
|
10
|
+
if (!fs.existsSync(indexPath)) {
|
|
11
|
+
if (enabled) throw new Error('Huawei privacy: src/index.html was not found.');
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const original = fs.readFileSync(indexPath, 'utf8');
|
|
15
|
+
const scripts = [...original.matchAll(/<script\b(?=[^>]*\btype\s*=\s*["']module["'])[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*><\/script>/gi)];
|
|
16
|
+
const managed = scripts.filter(match => match[0].includes(originalAttribute));
|
|
17
|
+
if (managed.length > 1) throw new Error('Huawei privacy: more than one managed app entry was found.');
|
|
18
|
+
let target = managed[0];
|
|
19
|
+
if (!target && enabled) {
|
|
20
|
+
if (scripts.length !== 1) throw new Error('Huawei privacy: expected exactly one module app entry in src/index.html.');
|
|
21
|
+
target = scripts[0];
|
|
22
|
+
}
|
|
23
|
+
if (!target) return false;
|
|
24
|
+
const saved = target[0].match(new RegExp(`${originalAttribute}=["']([^"']+)["']`));
|
|
25
|
+
const entry = saved ? saved[1] : target[1];
|
|
26
|
+
if (!/^\.\/[\w./-]+\.js$/.test(entry) || entry.includes('..')) {
|
|
27
|
+
throw new Error(`Huawei privacy: unsupported app entry ${entry}`);
|
|
28
|
+
}
|
|
29
|
+
const entryPath = path.resolve(projectRoot, 'src', entry);
|
|
30
|
+
if (!fs.existsSync(entryPath)) throw new Error(`Huawei privacy: app entry ${entry} was not found.`);
|
|
31
|
+
const tag = enabled
|
|
32
|
+
? target[0].replace(/\ssrc\s*=\s*["'][^"']+["']/, ` src="${generatedEntry}"`)
|
|
33
|
+
.replace(/<script\b/, match => saved ? match : `${match} ${originalAttribute}="${entry}"`)
|
|
34
|
+
: target[0].replace(/\ssrc\s*=\s*["'][^"']+["']/, ` src="${entry}"`)
|
|
35
|
+
.replace(new RegExp(`\\s+${originalAttribute}=["'][^"']+["']`), '');
|
|
36
|
+
const next = original.replace(target[0], tag);
|
|
37
|
+
if (next !== original) fs.writeFileSync(indexPath, next);
|
|
38
|
+
if (enabled) {
|
|
39
|
+
const wrapperPath = path.join(projectRoot, 'buildCodeplay/huawei-privacy-generated.js');
|
|
40
|
+
const importPath = `../src/${entry.slice(2)}`;
|
|
41
|
+
const wrapper = `// Generated by codeplay-common for the Huawei build.\nimport { startHuaweiPrivacy } from './huawei-privacy-entry.js';\nstartHuaweiPrivacy({ appId: ${JSON.stringify(appId)}, appName: ${JSON.stringify(appName)}, startApp: () => import(${JSON.stringify(importPath)}) });\n`;
|
|
42
|
+
if (!fs.existsSync(wrapperPath) || fs.readFileSync(wrapperPath, 'utf8') !== wrapper) fs.writeFileSync(wrapperPath, wrapper);
|
|
43
|
+
}
|
|
44
|
+
return next !== original;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function updateAnalyticsDefault(projectRoot, enabled) {
|
|
48
|
+
const manifestPath = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
|
|
49
|
+
if (!fs.existsSync(manifestPath)) {
|
|
50
|
+
if (enabled) throw new Error('Huawei privacy: AndroidManifest.xml was not found.');
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const original = fs.readFileSync(manifestPath, 'utf8');
|
|
54
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
55
|
+
const marker = new RegExp(`(\\r?\\n)?[ \\t]*<!-- ${analyticsMarker} ([A-Za-z0-9+/=]*) -->\\r?\\n[ \\t]*<meta-data\\b(?=[^>]*\\bandroid:name=["']firebase_analytics_collection_enabled["'])[^>]*\\/\\s*>\\r?\\n?`);
|
|
56
|
+
let next = original;
|
|
57
|
+
if (marker.test(next)) {
|
|
58
|
+
if (!enabled) next = next.replace(marker, (_, leading, encoded) =>
|
|
59
|
+
encoded ? `${leading || ''}${Buffer.from(encoded, 'base64').toString('utf8')}` : '');
|
|
60
|
+
else next = next.replace(marker, match => match.replace(/android:value=["'][^"']*["']/, 'android:value="false"'));
|
|
61
|
+
} else if (enabled) {
|
|
62
|
+
const existing = /[ \t]*<meta-data\b(?=[^>]*\bandroid:name=["']firebase_analytics_collection_enabled["'])[^>]*\/\s*>\r?\n?/;
|
|
63
|
+
const prior = next.match(existing)?.[0] || '';
|
|
64
|
+
const block = ` <!-- ${analyticsMarker} ${Buffer.from(prior).toString('base64')} -->${newline} <meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />${newline}`;
|
|
65
|
+
if (!/<application\b[^>]*>/.test(next)) throw new Error('Huawei privacy: application element was not found in AndroidManifest.xml.');
|
|
66
|
+
next = prior ? next.replace(existing, block) : next.replace(/<application\b[^>]*>/, match => `${match}${newline}${block}`);
|
|
67
|
+
}
|
|
68
|
+
if (next !== original) fs.writeFileSync(manifestPath, next);
|
|
69
|
+
return next !== original;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function syncHuaweiPrivacy(projectRoot, storeId, platform = 'android') {
|
|
73
|
+
const enabled = platform === 'android' && Number(storeId) === 4;
|
|
74
|
+
const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json'), 'utf8'));
|
|
75
|
+
const appId = Number(config.android?.APP_UNIQUE_ID);
|
|
76
|
+
if (enabled && (!Number.isInteger(appId) || appId < 1)) {
|
|
77
|
+
throw new Error('Huawei privacy: capacitor.config.json needs a valid android.APP_UNIQUE_ID.');
|
|
78
|
+
}
|
|
79
|
+
// Inspect both targets before writing either one, so unsupported app layouts fail early.
|
|
80
|
+
const manifestPath = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
|
|
81
|
+
if (enabled && !fs.existsSync(manifestPath)) {
|
|
82
|
+
throw new Error('Huawei privacy: AndroidManifest.xml was not found.');
|
|
83
|
+
}
|
|
84
|
+
if (enabled && !/<application\b[^>]*>/.test(fs.readFileSync(manifestPath, 'utf8'))) {
|
|
85
|
+
throw new Error('Huawei privacy: application element was not found in AndroidManifest.xml.');
|
|
86
|
+
}
|
|
87
|
+
updateEntry(projectRoot, enabled, appId, config.appName || 'App');
|
|
88
|
+
updateAnalyticsDefault(projectRoot, enabled);
|
|
89
|
+
if (enabled) console.log(`Huawei privacy consent enabled. Verify https://htmlcodeplay.com/privacy/ch/${appId} is published before submission.`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = { syncHuaweiPrivacy };
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
.codeplay-huawei-privacy-gate {
|
|
2
|
-
position: fixed;
|
|
3
|
-
z-index: 2147483647;
|
|
4
|
-
inset: 0;
|
|
5
|
-
display: grid;
|
|
6
|
-
place-items: center;
|
|
7
|
-
overflow: auto;
|
|
8
|
-
padding: calc(24px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) calc(20px + env(safe-area-inset-left, 0px));
|
|
9
|
-
box-sizing: border-box;
|
|
10
|
-
background: #fff;
|
|
11
|
-
color: #17212b;
|
|
12
|
-
font-family: system-ui, sans-serif;
|
|
13
|
-
}
|
|
14
|
-
.codeplay-huawei-privacy-card { width: min(100%, 420px); }
|
|
15
|
-
.codeplay-huawei-privacy-card h1 { margin: 0 0 16px; font-size: 24px; line-height: 1.3; }
|
|
16
|
-
.codeplay-huawei-privacy-card p { line-height: 1.6; }
|
|
17
|
-
.codeplay-huawei-privacy-card button { display: block; width: 100%; min-height: 48px; margin-top: 12px; border-radius: 8px; font: inherit; }
|
|
18
|
-
.codeplay-huawei-privacy-policy { border: 0; background: transparent; color: #155fc6; text-decoration: underline; }
|
|
19
|
-
.codeplay-huawei-privacy-agree { border: 0; background: #155fc6; color: #fff; }
|
|
20
|
-
.codeplay-huawei-privacy-decline { border: 1px solid #8a929c; background: #fff; color: #17212b; }
|
|
21
|
-
.codeplay-huawei-privacy-status { min-height: 1.5em; color: #9b2b20; }
|
|
22
|
-
.codeplay-huawei-privacy-settings { display: flex; flex-direction: column; gap: 8px; }
|
|
1
|
+
.codeplay-huawei-privacy-gate {
|
|
2
|
+
position: fixed;
|
|
3
|
+
z-index: 2147483647;
|
|
4
|
+
inset: 0;
|
|
5
|
+
display: grid;
|
|
6
|
+
place-items: center;
|
|
7
|
+
overflow: auto;
|
|
8
|
+
padding: calc(24px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) calc(20px + env(safe-area-inset-left, 0px));
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
background: #fff;
|
|
11
|
+
color: #17212b;
|
|
12
|
+
font-family: system-ui, sans-serif;
|
|
13
|
+
}
|
|
14
|
+
.codeplay-huawei-privacy-card { width: min(100%, 420px); }
|
|
15
|
+
.codeplay-huawei-privacy-card h1 { margin: 0 0 16px; font-size: 24px; line-height: 1.3; }
|
|
16
|
+
.codeplay-huawei-privacy-card p { line-height: 1.6; }
|
|
17
|
+
.codeplay-huawei-privacy-card button { display: block; width: 100%; min-height: 48px; margin-top: 12px; border-radius: 8px; font: inherit; }
|
|
18
|
+
.codeplay-huawei-privacy-policy { border: 0; background: transparent; color: #155fc6; text-decoration: underline; }
|
|
19
|
+
.codeplay-huawei-privacy-agree { border: 0; background: #155fc6; color: #fff; }
|
|
20
|
+
.codeplay-huawei-privacy-decline { border: 1px solid #8a929c; background: #fff; color: #17212b; }
|
|
21
|
+
.codeplay-huawei-privacy-status { min-height: 1.5em; color: #9b2b20; }
|
|
22
|
+
.codeplay-huawei-privacy-settings { display: flex; flex-direction: column; gap: 8px; }
|