codeplay-common 4.11.35 → 4.11.38

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +115 -115
  2. package/LICENSE +21 -21
  3. package/README.md +408 -374
  4. package/RELEASE_NOTES.md +97 -97
  5. package/files/buildCodeplay/HUAWEI-PRIVACY.md +9 -9
  6. package/files/buildCodeplay/add-splash-screen.js +255 -255
  7. package/files/buildCodeplay/apk-store-builder.js +97 -97
  8. package/files/buildCodeplay/codeplayBeforeBuild.js +4793 -4793
  9. package/files/buildCodeplay/disabled-ads.mjs +53 -53
  10. package/files/buildCodeplay/ensure-current-build.cjs +42 -42
  11. package/files/buildCodeplay/fix-onesignal-plugin.js +96 -96
  12. package/files/buildCodeplay/huawei-privacy-entry.js +135 -135
  13. package/files/buildCodeplay/huawei-privacy.cjs +102 -92
  14. package/files/buildCodeplay/huawei-privacy.css +22 -22
  15. package/files/buildCodeplay/iap-alias.cjs +116 -116
  16. package/files/buildCodeplay/ios-ad-consent.cjs +56 -56
  17. package/files/buildCodeplay/ios-emi-admob-modification.js +49 -49
  18. package/files/buildCodeplay/manifestModification.js +38 -38
  19. package/files/buildCodeplay/migrate-system-bars.cjs +122 -122
  20. package/files/buildCodeplay/newly added.txt +89 -89
  21. package/files/buildCodeplay/non-google-billing.pro +3 -3
  22. package/files/buildCodeplay/packageidBaseModification.js +528 -528
  23. package/files/buildCodeplay/project-scripts.cjs +69 -69
  24. package/files/buildCodeplay/release-sync.config.json +4 -4
  25. package/files/buildCodeplay/remove-force-kotlin-disable.js +43 -43
  26. package/files/buildCodeplay/ruads.cjs +220 -211
  27. package/files/buildCodeplay/saf-mediastore-dependency.cjs +21 -21
  28. package/files/buildCodeplay/setSplashAnimation.js +226 -226
  29. package/files/buildCodeplay/setup-ruads.cjs +62 -55
  30. package/files/buildCodeplay/splashxml/codeplay_splashScreen.xml +11 -11
  31. package/files/buildCodeplay/store-billing.cjs +43 -43
  32. package/files/buildCodeplay/sync-admob-nextgen.js +219 -219
  33. package/files/buildCodeplay/tests/huawei-live-reload.test.cjs +60 -0
  34. package/files/buildCodeplay/tests/huawei-multiple-entries.test.cjs +80 -0
  35. package/files/buildCodeplay/tests/huawei-privacy.test.cjs +49 -49
  36. package/files/buildCodeplay/tests/huawei-vite.test.cjs +38 -35
  37. package/files/buildCodeplay/versions.json +28 -28
  38. package/files/finalrelease +1365 -1365
  39. package/files/generate-ai-promo-video.js +23 -23
  40. package/files/ionic.config.json +6 -6
  41. package/files/scripts-common/collect-startup-profile.js +134 -0
  42. package/files/scripts-common/generate-baseline-profile.js +194 -22
  43. package/files/scripts-common/run-codeplay-sync-after.js +21 -21
  44. package/files/scripts-common/screenshot/background-decorations.js +120 -120
  45. package/files/scripts-common/screenshot/frame-samples.js +117 -117
  46. package/files/scripts-common/setup-baseline-profile.js +291 -291
  47. package/files/take-screen-image.js +4414 -4414
  48. package/files/take-screen-video.js +644 -644
  49. package/package.json +29 -29
  50. package/runtime/vk-ads/vk-ad-configuration.json +39 -39
  51. package/scripts/baseline-profile.test.cjs +189 -0
  52. package/scripts/ensure-current-build.test.cjs +76 -76
  53. package/scripts/iap-alias.test.cjs +117 -117
  54. package/scripts/ios-ad-consent.test.cjs +99 -99
  55. package/scripts/ruads-install.test.cjs +197 -180
  56. package/scripts/ruads-policy.test.cjs +174 -174
  57. package/scripts/saf-mediastore-dependency.test.cjs +44 -44
  58. package/scripts/squeezeback-config.test.cjs +78 -78
  59. package/scripts/sync-files.js +120 -120
  60. package/scripts/system-bars-package.test.cjs +38 -38
  61. package/scripts/system-bars.test.cjs +93 -93
  62. package/scripts/uninstall.js +2 -2
  63. package/scripts/vite-build-settings.test.cjs +93 -92
@@ -1,53 +1,53 @@
1
- // Shared ad interface for builds with both native providers disabled.
2
- const ignore = () => {};
3
- const unavailable = async () => false;
4
- const hidden = async () => true;
5
- export const _isVideoLoad = false;
6
- export const _isRewardInterstitialLoad = false;
7
- export const _isNativeAdLoaded = false;
8
- export const _bannerAdHeight = 0;
9
- export const adjustWebViewForBanner = ignore;
10
- export const hideGoogleBannerAd = hidden;
11
- export const showGoogleBannerAd = unavailable;
12
- export const canRequestAppAds = () => false;
13
- export const getAdPrivacyOptionsState = () => ({ supported: false, requirementStatus: 'NOT_REQUIRED', loading: false, error: false, canRetry: false });
14
- export const isAdPrivacyOptionsRequired = () => false;
15
- export const requestAppAdConsent = unavailable;
16
- export const adsOnDeviceReady = unavailable;
17
- export const showAppAdPrivacyOptions = unavailable;
18
- export const refreshAppAdConsent = showAppAdPrivacyOptions;
19
- export async function withAdPrivacyChoices(callback) {
20
- if (typeof callback === 'function') await callback();
21
- }
22
- export const disableFor_IAP_Subscription = ignore;
23
- export const enableFor_IAP_Subscription = ignore;
24
- export const disableFor_CREDIT_Subscription = ignore;
25
- export const showRewardVideo = unavailable;
26
- export async function levelWinInterstitial(callback) {
27
- if (typeof callback === 'function') await callback();
28
- return false;
29
- }
30
- export const runInterstitialTaskTransition = levelWinInterstitial;
31
- export const disableAppOpenAd = ignore;
32
- export const enableAppOpenAd = ignore;
33
- export const noAppOpenShowUntilResume = ignore;
34
- export const showRewardInterstitial = unavailable;
35
- export const showNativeAd = unavailable;
36
- export const showNativeAdInElement = showNativeAd;
37
- export const hideNativeAd = hidden;
38
- export const hideNativeAdInElement = hideNativeAd;
39
- export const loadPictureInPictureAd = unavailable;
40
- export const showPictureInPictureAd = loadPictureInPictureAd;
41
- export const hidePictureInPictureAd = hidden;
42
- export const destroyPictureInPictureAd = hidePictureInPictureAd;
43
- export const removePictureInPictureAd = destroyPictureInPictureAd;
44
- export const getPictureInPictureAdState = () => ({ loading: false, loaded: false, showing: false, fullscreen: false, adUnitId: '', error: null });
45
- export const addPictureInPictureAdListener = () => ({ remove: ignore });
46
-
47
- export const loadSqueezebackAd = async () => false;
48
- export const showSqueezebackAd = async () => false;
49
- export const hideSqueezebackAd = async () => true;
50
- export const destroySqueezebackAd = async () => true;
51
- export const getSqueezebackAdState = () => ({
52
- loading: false, loaded: false, showing: false, fullscreen: false, adUnitId: '', error: null
53
- });
1
+ // Shared ad interface for builds with both native providers disabled.
2
+ const ignore = () => {};
3
+ const unavailable = async () => false;
4
+ const hidden = async () => true;
5
+ export const _isVideoLoad = false;
6
+ export const _isRewardInterstitialLoad = false;
7
+ export const _isNativeAdLoaded = false;
8
+ export const _bannerAdHeight = 0;
9
+ export const adjustWebViewForBanner = ignore;
10
+ export const hideGoogleBannerAd = hidden;
11
+ export const showGoogleBannerAd = unavailable;
12
+ export const canRequestAppAds = () => false;
13
+ export const getAdPrivacyOptionsState = () => ({ supported: false, requirementStatus: 'NOT_REQUIRED', loading: false, error: false, canRetry: false });
14
+ export const isAdPrivacyOptionsRequired = () => false;
15
+ export const requestAppAdConsent = unavailable;
16
+ export const adsOnDeviceReady = unavailable;
17
+ export const showAppAdPrivacyOptions = unavailable;
18
+ export const refreshAppAdConsent = showAppAdPrivacyOptions;
19
+ export async function withAdPrivacyChoices(callback) {
20
+ if (typeof callback === 'function') await callback();
21
+ }
22
+ export const disableFor_IAP_Subscription = ignore;
23
+ export const enableFor_IAP_Subscription = ignore;
24
+ export const disableFor_CREDIT_Subscription = ignore;
25
+ export const showRewardVideo = unavailable;
26
+ export async function levelWinInterstitial(callback) {
27
+ if (typeof callback === 'function') await callback();
28
+ return false;
29
+ }
30
+ export const runInterstitialTaskTransition = levelWinInterstitial;
31
+ export const disableAppOpenAd = ignore;
32
+ export const enableAppOpenAd = ignore;
33
+ export const noAppOpenShowUntilResume = ignore;
34
+ export const showRewardInterstitial = unavailable;
35
+ export const showNativeAd = unavailable;
36
+ export const showNativeAdInElement = showNativeAd;
37
+ export const hideNativeAd = hidden;
38
+ export const hideNativeAdInElement = hideNativeAd;
39
+ export const loadPictureInPictureAd = unavailable;
40
+ export const showPictureInPictureAd = loadPictureInPictureAd;
41
+ export const hidePictureInPictureAd = hidden;
42
+ export const destroyPictureInPictureAd = hidePictureInPictureAd;
43
+ export const removePictureInPictureAd = destroyPictureInPictureAd;
44
+ export const getPictureInPictureAdState = () => ({ loading: false, loaded: false, showing: false, fullscreen: false, adUnitId: '', error: null });
45
+ export const addPictureInPictureAdListener = () => ({ remove: ignore });
46
+
47
+ export const loadSqueezebackAd = async () => false;
48
+ export const showSqueezebackAd = async () => false;
49
+ export const hideSqueezebackAd = async () => true;
50
+ export const destroySqueezebackAd = async () => true;
51
+ export const getSqueezebackAdState = () => ({
52
+ loading: false, loaded: false, showing: false, fullscreen: false, adUnitId: '', error: null
53
+ });
@@ -1,42 +1,42 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { execSync, execFileSync } = require('child_process');
4
-
5
- function findVersionedBuildFiles(projectRoot) {
6
- const directory = path.join(projectRoot, 'buildCodeplay');
7
- if (!fs.existsSync(directory)) return [];
8
- return fs.readdirSync(directory, { withFileTypes: true })
9
- .filter(entry => entry.isFile() && /-\d+(?:\.\d+)*(?:-beta-\d+)?\.[^.]+$/i.test(entry.name))
10
- .map(entry => entry.name);
11
- }
12
-
13
- function ensureCurrentBuild(options = {}) {
14
- const projectRoot = path.resolve(options.projectRoot || process.cwd());
15
- const legacyFiles = findVersionedBuildFiles(projectRoot);
16
- if (!legacyFiles.length) return false;
17
-
18
- console.log(`Legacy buildCodeplay files found: ${legacyFiles.join(', ')}. Reinstalling codeplay-common before continuing.`);
19
- const runNpm = options.runNpm || (command => execSync(command, { cwd: projectRoot, stdio: 'inherit' }));
20
- runNpm('npm uninstall codeplay-common');
21
- runNpm('npm install codeplay-common');
22
-
23
- // Postinstall replaces the scripts and removes recognized legacy files.
24
- // Do not run stale code or retry indefinitely if migration did not finish.
25
- const remaining = findVersionedBuildFiles(projectRoot);
26
- if (remaining.length) {
27
- throw new Error(`Legacy buildCodeplay files remain after reinstall: ${remaining.join(', ')}. Build stopped; migrate these files before retrying.`);
28
- }
29
- const entrypoint = path.join(projectRoot, 'buildCodeplay', 'codeplayBeforeBuild.js');
30
- if (!fs.existsSync(entrypoint)) throw new Error('codeplayBeforeBuild.js is missing after reinstall. Build stopped.');
31
-
32
- // The current process loaded the old templates. Finish preparation in a fresh
33
- // process before the caller's remaining build commands are allowed to run.
34
- const runBeforeBuild = options.runBeforeBuild || (script => execFileSync(process.execPath, [script, ...process.argv.slice(2)], {
35
- cwd: projectRoot,
36
- stdio: 'inherit',
37
- }));
38
- runBeforeBuild(entrypoint);
39
- return true;
40
- }
41
-
42
- module.exports = { ensureCurrentBuild, findVersionedBuildFiles };
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { execSync, execFileSync } = require('child_process');
4
+
5
+ function findVersionedBuildFiles(projectRoot) {
6
+ const directory = path.join(projectRoot, 'buildCodeplay');
7
+ if (!fs.existsSync(directory)) return [];
8
+ return fs.readdirSync(directory, { withFileTypes: true })
9
+ .filter(entry => entry.isFile() && /-\d+(?:\.\d+)*(?:-beta-\d+)?\.[^.]+$/i.test(entry.name))
10
+ .map(entry => entry.name);
11
+ }
12
+
13
+ function ensureCurrentBuild(options = {}) {
14
+ const projectRoot = path.resolve(options.projectRoot || process.cwd());
15
+ const legacyFiles = findVersionedBuildFiles(projectRoot);
16
+ if (!legacyFiles.length) return false;
17
+
18
+ console.log(`Legacy buildCodeplay files found: ${legacyFiles.join(', ')}. Reinstalling codeplay-common before continuing.`);
19
+ const runNpm = options.runNpm || (command => execSync(command, { cwd: projectRoot, stdio: 'inherit' }));
20
+ runNpm('npm uninstall codeplay-common');
21
+ runNpm('npm install codeplay-common');
22
+
23
+ // Postinstall replaces the scripts and removes recognized legacy files.
24
+ // Do not run stale code or retry indefinitely if migration did not finish.
25
+ const remaining = findVersionedBuildFiles(projectRoot);
26
+ if (remaining.length) {
27
+ throw new Error(`Legacy buildCodeplay files remain after reinstall: ${remaining.join(', ')}. Build stopped; migrate these files before retrying.`);
28
+ }
29
+ const entrypoint = path.join(projectRoot, 'buildCodeplay', 'codeplayBeforeBuild.js');
30
+ if (!fs.existsSync(entrypoint)) throw new Error('codeplayBeforeBuild.js is missing after reinstall. Build stopped.');
31
+
32
+ // The current process loaded the old templates. Finish preparation in a fresh
33
+ // process before the caller's remaining build commands are allowed to run.
34
+ const runBeforeBuild = options.runBeforeBuild || (script => execFileSync(process.execPath, [script, ...process.argv.slice(2)], {
35
+ cwd: projectRoot,
36
+ stdio: 'inherit',
37
+ }));
38
+ runBeforeBuild(entrypoint);
39
+ return true;
40
+ }
41
+
42
+ module.exports = { ensureCurrentBuild, findVersionedBuildFiles };
@@ -1,97 +1,97 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
-
4
- const pluginPath = path.join(
5
- __dirname,
6
- "..",
7
- "node_modules",
8
- "onesignal-cordova-plugin",
9
- "plugin.xml"
10
- );
11
-
12
- if (!fs.existsSync(pluginPath)) {
13
- console.log("OneSignal plugin not found, skipping patch.");
14
- process.exit(0);
15
- }
16
-
17
- console.log("OneSignal plugin patch started.");
18
-
19
- let content = fs.readFileSync(pluginPath, "utf8");
20
-
21
- /* ---- Prevent running twice ---- */
22
- if (content.includes("buildCodeplay/fix-onesignal-plugin.js")) {
23
- console.log("OneSignal plugin already patched.");
24
- }
25
-
26
- else{
27
- /* ---- Comment Kotlin dependency ---- */
28
- content = content.replace(
29
- '<framework src="org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10" />',
30
- `<!-- Disabled: causes Kotlin version conflict with modern Gradle/Kotlin -->
31
- <!-- <framework src="org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10" /> -->`
32
- );
33
-
34
- /* ---- Add dependencies ---- */
35
- content = content.replace(
36
- '<framework src="build-extras-onesignal.gradle" custom="true" type="gradleReference" />',
37
- `<framework src="build-extras-onesignal.gradle" custom="true" type="gradleReference" />
38
-
39
- <!--Newly added content through buildCodeplay/fix-onesignal-plugin.js Start-->
40
- <framework src="com.fasterxml.jackson.core:jackson-core:2.17.2" />
41
- <framework src="com.google.auto.value:auto-value-annotations:1.11.0" scope="provided" />
42
- <!--Newly added content through buildCodeplay/fix-onesignal-plugin.js End-->`
43
- );
44
-
45
- fs.writeFileSync(pluginPath, content);
46
-
47
- console.log("OneSignal plugin patched successfully.");
48
- }
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
- //#################### ADD THE PROPER ONESIGNAL PERMISSIN TO INFO.PLIST START ###########################
58
-
59
- const iosPlistPath = path.join(
60
- __dirname,
61
- "..",
62
- "ios",
63
- "App",
64
- "App",
65
- "Info.plist"
66
- );
67
-
68
- console.log(iosPlistPath)
69
-
70
- if (fs.existsSync(iosPlistPath)) {
71
-
72
- let plist = fs.readFileSync(iosPlistPath, "utf8");
73
-
74
- const insertBlock = `
75
- <key>UIBackgroundModes</key>
76
- <array>
77
- <string>remote-notification</string>
78
- </array>
79
- `;
80
-
81
- if (!plist.includes("UIBackgroundModes")) {
82
- const lastIndex = plist.lastIndexOf("</dict>");
83
-
84
- plist =
85
- plist.slice(0, lastIndex) +
86
- insertBlock +
87
- "\n" +
88
- plist.slice(lastIndex);
89
-
90
- console.log("Inserted UIBackgroundModes correctly.");
91
- }
92
-
93
- fs.writeFileSync(iosPlistPath, plist);
94
- }
95
-
96
-
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ const pluginPath = path.join(
5
+ __dirname,
6
+ "..",
7
+ "node_modules",
8
+ "onesignal-cordova-plugin",
9
+ "plugin.xml"
10
+ );
11
+
12
+ if (!fs.existsSync(pluginPath)) {
13
+ console.log("OneSignal plugin not found, skipping patch.");
14
+ process.exit(0);
15
+ }
16
+
17
+ console.log("OneSignal plugin patch started.");
18
+
19
+ let content = fs.readFileSync(pluginPath, "utf8");
20
+
21
+ /* ---- Prevent running twice ---- */
22
+ if (content.includes("buildCodeplay/fix-onesignal-plugin.js")) {
23
+ console.log("OneSignal plugin already patched.");
24
+ }
25
+
26
+ else{
27
+ /* ---- Comment Kotlin dependency ---- */
28
+ content = content.replace(
29
+ '<framework src="org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10" />',
30
+ `<!-- Disabled: causes Kotlin version conflict with modern Gradle/Kotlin -->
31
+ <!-- <framework src="org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10" /> -->`
32
+ );
33
+
34
+ /* ---- Add dependencies ---- */
35
+ content = content.replace(
36
+ '<framework src="build-extras-onesignal.gradle" custom="true" type="gradleReference" />',
37
+ `<framework src="build-extras-onesignal.gradle" custom="true" type="gradleReference" />
38
+
39
+ <!--Newly added content through buildCodeplay/fix-onesignal-plugin.js Start-->
40
+ <framework src="com.fasterxml.jackson.core:jackson-core:2.17.2" />
41
+ <framework src="com.google.auto.value:auto-value-annotations:1.11.0" scope="provided" />
42
+ <!--Newly added content through buildCodeplay/fix-onesignal-plugin.js End-->`
43
+ );
44
+
45
+ fs.writeFileSync(pluginPath, content);
46
+
47
+ console.log("OneSignal plugin patched successfully.");
48
+ }
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+ //#################### ADD THE PROPER ONESIGNAL PERMISSIN TO INFO.PLIST START ###########################
58
+
59
+ const iosPlistPath = path.join(
60
+ __dirname,
61
+ "..",
62
+ "ios",
63
+ "App",
64
+ "App",
65
+ "Info.plist"
66
+ );
67
+
68
+ console.log(iosPlistPath)
69
+
70
+ if (fs.existsSync(iosPlistPath)) {
71
+
72
+ let plist = fs.readFileSync(iosPlistPath, "utf8");
73
+
74
+ const insertBlock = `
75
+ <key>UIBackgroundModes</key>
76
+ <array>
77
+ <string>remote-notification</string>
78
+ </array>
79
+ `;
80
+
81
+ if (!plist.includes("UIBackgroundModes")) {
82
+ const lastIndex = plist.lastIndexOf("</dict>");
83
+
84
+ plist =
85
+ plist.slice(0, lastIndex) +
86
+ insertBlock +
87
+ "\n" +
88
+ plist.slice(lastIndex);
89
+
90
+ console.log("Inserted UIBackgroundModes correctly.");
91
+ }
92
+
93
+ fs.writeFileSync(iosPlistPath, plist);
94
+ }
95
+
96
+
97
97
  //#################### ADD THE PROPER ONESIGNAL PERMISSIN TO INFO.PLIST END ###########################
@@ -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
+ }