codeplay-common 4.11.38 → 4.11.40

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 (40) hide show
  1. package/README.md +1 -1
  2. package/RELEASE_NOTES.md +13 -13
  3. package/files/buildCodeplay/add-splash-screen.js +1 -1
  4. package/files/buildCodeplay/codeplayBeforeBuild.js +2 -2
  5. package/files/buildCodeplay/ensure-current-build.cjs +32 -4
  6. package/files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs +31 -31
  7. package/files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs +28 -28
  8. package/files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle +9 -9
  9. package/files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs +30 -30
  10. package/files/buildCodeplay/huawei-privacy-entry.js +135 -135
  11. package/files/buildCodeplay/huawei-privacy.css +22 -22
  12. package/files/buildCodeplay/ios-ad-consent.cjs +56 -56
  13. package/files/buildCodeplay/ios-emi-admob-modification.js +25 -25
  14. package/files/buildCodeplay/newly added.txt +89 -89
  15. package/files/buildCodeplay/non-google-billing.pro +3 -3
  16. package/files/buildCodeplay/release-sync.config.json +4 -4
  17. package/files/buildCodeplay/remove-force-kotlin-disable.js +43 -43
  18. package/files/buildCodeplay/ruads.cjs +220 -220
  19. package/files/buildCodeplay/saf-mediastore-dependency.cjs +21 -21
  20. package/files/buildCodeplay/setSplashAnimation.js +2 -2
  21. package/files/buildCodeplay/setup-ruads.cjs +62 -62
  22. package/files/buildCodeplay/splash-setup.cjs +88 -88
  23. package/files/buildCodeplay/store-billing.cjs +43 -43
  24. package/files/buildCodeplay/tests/huawei-live-reload.test.cjs +60 -60
  25. package/files/buildCodeplay/tests/huawei-privacy.test.cjs +49 -49
  26. package/files/scripts-common/collect-startup-profile.js +134 -134
  27. package/files/scripts-common/generate-baseline-profile.js +218 -218
  28. package/files/take-screen-image.js +4552 -4414
  29. package/package.json +1 -1
  30. package/runtime/splash-ready.mjs +52 -52
  31. package/runtime/vk-ads/vk-ad-configuration.json +39 -39
  32. package/scripts/baseline-profile.test.cjs +189 -189
  33. package/scripts/ensure-current-build.test.cjs +128 -28
  34. package/scripts/ios-ad-consent.test.cjs +99 -99
  35. package/scripts/ruads-install.test.cjs +197 -197
  36. package/scripts/ruads-policy.test.cjs +174 -174
  37. package/scripts/saf-mediastore-dependency.test.cjs +44 -44
  38. package/scripts/splash-setup.test.cjs +142 -142
  39. package/scripts/sync-files.js +1 -1
  40. package/scripts/vite-build-settings.test.cjs +93 -93
package/README.md CHANGED
@@ -204,7 +204,7 @@ App package scripts run local files: node buildCodeplay/codeplayBeforeBuild.js,
204
204
 
205
205
  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.
206
206
 
207
- After this update is installed, `npm run build` checks the app's `buildCodeplay/` folder for version-suffixed files before preparing the build. If any exist, it runs `npm uninstall codeplay-common` followed by `npm install codeplay-common`, then runs the refreshed before-build script before continuing. A failed command or remaining versioned files stops the build. Unrecognized legacy files must be migrated manually; they are not deleted automatically.
207
+ After this update is installed, `npm run build` checks for a missing or incomplete `codeplay-common` package and version-suffixed files in the app's `buildCodeplay/` folder before loading build dependencies. Recovery uses `npm install` for an existing dependency declaration, preserving its version range or local source; if the declaration is also missing, it uses `npm install codeplay-common`. Updates no longer uninstall the package first, so cancellation does not deliberately remove the dependency declaration. If npm skips lifecycle scripts and legacy files remain, the existing package installer refreshes the templates. The refreshed before-build script then runs in a new process. A failed command, incomplete package or remaining versioned files stops the build. Unrecognized legacy files must be migrated manually; they are not deleted automatically.
208
208
 
209
209
  Before-build includes the automatic IAP startup and Home Pro-button migrations. IAP and AdMob ZIPs are downloaded directly from https://htmlcodeplay.com/code-play-plugin/ using the existing update flow. No plugin ZIPs are bundled in this npm package. App-specific configuration and designs remain in the app.
210
210
 
package/RELEASE_NOTES.md CHANGED
@@ -1,17 +1,17 @@
1
1
  # Release notes
2
-
3
- ## 4.11.13 — 2026-11-04
4
-
5
- Version name:4.11.13. Version code/build number:not applicable to this npm package.
6
-
7
- Files changed: `package.json`, `runtime/splash-ready.mjs`, `files/buildCodeplay/splash-setup.cjs`, `files/buildCodeplay/setSplashAnimation.js`, `files/buildCodeplay/add-splash-screen.js`, `files/buildCodeplay/splashxml/codeplay_splashScreen.xml`, `files/buildCodeplay/codeplayBeforeBuild.js`, `scripts/sync-files.js`, `scripts/splash-setup.test.cjs`, `README.md`, `CHANGELOG.md`, `RELEASE_NOTES.md`.
8
-
9
- - Use a DayNight post-splash theme and migrate only the known legacy default in existing app templates; preserve custom themes.
10
- - Configure native exit animation duration,including0ms,without editing generated MainActivity;default remains1000ms.
11
- - Share the existing Framework7 page/image readiness flow with timeout,error handling and listener cleanup.
12
- - Migrate the known existing readiness handler;offer explicit opt-in for supported legacy timer handlers,with native fallback/plugin checks. Preserve unsupported custom startup code.
13
- - Run splash preparation during installation,before-build and splash setup;rebuild consuming apps to apply native changes.
14
-
2
+
3
+ ## 4.11.13 — 2026-11-04
4
+
5
+ Version name:4.11.13. Version code/build number:not applicable to this npm package.
6
+
7
+ Files changed: `package.json`, `runtime/splash-ready.mjs`, `files/buildCodeplay/splash-setup.cjs`, `files/buildCodeplay/setSplashAnimation.js`, `files/buildCodeplay/add-splash-screen.js`, `files/buildCodeplay/splashxml/codeplay_splashScreen.xml`, `files/buildCodeplay/codeplayBeforeBuild.js`, `scripts/sync-files.js`, `scripts/splash-setup.test.cjs`, `README.md`, `CHANGELOG.md`, `RELEASE_NOTES.md`.
8
+
9
+ - Use a DayNight post-splash theme and migrate only the known legacy default in existing app templates; preserve custom themes.
10
+ - Configure native exit animation duration,including0ms,without editing generated MainActivity;default remains1000ms.
11
+ - Share the existing Framework7 page/image readiness flow with timeout,error handling and listener cleanup.
12
+ - Migrate the known existing readiness handler;offer explicit opt-in for supported legacy timer handlers,with native fallback/plugin checks. Preserve unsupported custom startup code.
13
+ - Run splash preparation during installation,before-build and splash setup;rebuild consuming apps to apply native changes.
14
+
15
15
 
16
16
  ## Unreleased
17
17
 
@@ -23,7 +23,7 @@ const destinationSplashIcon = path.join(
23
23
 
24
24
 
25
25
  const appSplashXML = path.join(projectFolder, "buildCodeplay", "splashxml", "codeplay_splashScreen.xml");
26
- require('./splash-setup.cjs').syncSplashSetup(projectFolder);
26
+ require('./splash-setup.cjs').syncSplashSetup(projectFolder);
27
27
  const sourceSplashXML = fs.existsSync(appSplashXML) ? appSplashXML : path.join(__dirname, "splashxml", "codeplay_splashScreen.xml");
28
28
  const destinationSplashXML = path.join(
29
29
  projectFolder,
@@ -1,3 +1,4 @@
1
+ // Version 8.6: recover interrupted codeplay-common installations without uninstalling first.
1
2
  // Version 8.5: require the Squeezeback native plugin only for explicitly enabled apps.
2
3
  // Version 8.4: migrate Squeezeback and coarse-location configuration defaults.
3
4
  // Version 8.3: update the system-bars package to the latest npm release before migration.
@@ -19,7 +20,7 @@
19
20
  // Version 6.7: deferred IAP startup, ownership-safe ads, and unified store preparation.
20
21
  // Version 6.7: migrate AdMob files to ZIP-distributed folder packages.
21
22
  // Version 6.7: recreate failed WebViews, defer background recovery, and suppress foreground recovery toasts.
22
- // Reinstall legacy build templates before loading dependencies or changing the app.
23
+ // Restore missing dependencies and legacy templates before loading app build modules.
23
24
  try {
24
25
  if (require('./ensure-current-build.cjs').ensureCurrentBuild()) process.exit(0);
25
26
  } catch (error) {
@@ -566,7 +567,6 @@ function checkPackageVersion() {
566
567
  console.log(`${packageName} is outdated (installed: ${installedVersion}, latest: ${latestVersion}). Updating now...`);
567
568
 
568
569
  try {
569
- execSync(`npm uninstall ${packageName}`, { stdio: 'inherit' });
570
570
  execSync(`npm install ${packageName}`, { stdio: 'inherit' });
571
571
  console.log(`${packageName} successfully updated.`);
572
572
  } catch (err) {
@@ -13,12 +13,40 @@ function findVersionedBuildFiles(projectRoot) {
13
13
  function ensureCurrentBuild(options = {}) {
14
14
  const projectRoot = path.resolve(options.projectRoot || process.cwd());
15
15
  const legacyFiles = findVersionedBuildFiles(projectRoot);
16
- if (!legacyFiles.length) return false;
16
+ const packageRoot = path.join(projectRoot, 'node_modules', 'codeplay-common');
17
+ const installer = path.join(packageRoot, 'scripts', 'sync-files.js');
18
+ function isPackageInstalled() {
19
+ try {
20
+ const pkg = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
21
+ return pkg?.name === 'codeplay-common' && typeof pkg.version === 'string' && pkg.version.length > 0 && fs.existsSync(installer);
22
+ } catch (error) {
23
+ if (error.code === 'ENOENT' || error.code === 'ENOTDIR' || error instanceof SyntaxError) return false;
24
+ throw error;
25
+ }
26
+ }
27
+ if (isPackageInstalled() && !legacyFiles.length) return false;
17
28
 
18
- console.log(`Legacy buildCodeplay files found: ${legacyFiles.join(', ')}. Reinstalling codeplay-common before continuing.`);
29
+ console.log(legacyFiles.length
30
+ ? `Legacy buildCodeplay files found: ${legacyFiles.join(', ')}. Restoring codeplay-common before continuing.`
31
+ : 'codeplay-common is missing or incomplete. Restoring it before loading build dependencies.');
32
+ const appPackage = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
33
+ const declaredPackage = appPackage.dependencies?.['codeplay-common'] || appPackage.devDependencies?.['codeplay-common'] || appPackage.optionalDependencies?.['codeplay-common'];
19
34
  const runNpm = options.runNpm || (command => execSync(command, { cwd: projectRoot, stdio: 'inherit' }));
20
- runNpm('npm uninstall codeplay-common');
21
- runNpm('npm install codeplay-common');
35
+ // Preserve existing dependency specifications, including local packages. Never
36
+ // uninstall first: cancellation must not remove the manifest declaration.
37
+ runNpm(declaredPackage ? 'npm install' : 'npm install codeplay-common');
38
+ if (!isPackageInstalled()) throw new Error('codeplay-common is still missing or incomplete after npm install. Build stopped.');
39
+
40
+ // npm can skip postinstall when the installed package already satisfies the
41
+ // manifest. Run the existing installer if legacy templates still need migration.
42
+ if (findVersionedBuildFiles(projectRoot).length) {
43
+ const runInstaller = options.runInstaller || (script => execFileSync(process.execPath, [script], {
44
+ cwd: projectRoot,
45
+ env: { ...process.env, INIT_CWD: projectRoot },
46
+ stdio: 'inherit',
47
+ }));
48
+ runInstaller(installer);
49
+ }
22
50
 
23
51
  // Postinstall replaces the scripts and removes recognized legacy files.
24
52
  // Do not run stale code or retry indefinitely if migration did not finish.
@@ -1,31 +1,31 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- function syncCapacitorPermissionRules(projectRoot = path.resolve(__dirname, '../..')) {
5
- const appPath = path.join(projectRoot, 'android', 'app');
6
- if (!fs.existsSync(path.join(appPath, 'build.gradle'))) return false;
7
-
8
- const rulesPath = path.join(appPath, 'proguard-rules.pro');
9
- const original = fs.existsSync(rulesPath) ? fs.readFileSync(rulesPath, 'utf8') : '';
10
- const rules = [
11
- '-keepattributes RuntimeVisibleAnnotations,AnnotationDefault',
12
- '-keep @interface com.getcapacitor.annotation.CapacitorPlugin { *; }',
13
- '-keep @interface com.getcapacitor.annotation.Permission { *; }',
14
- ];
15
- const existing = new Set(original.split(/\r?\n/).map(line => line.trim()));
16
- const missing = rules.filter(rule => !existing.has(rule));
17
- if (!missing.length) return false;
18
-
19
- const newline = original.includes('\r\n') ? '\r\n' : '\n';
20
- fs.writeFileSync(rulesPath, `${original.trimEnd()}${newline}${newline}`
21
- + `# Preserve Capacitor permission metadata used at runtime.${newline}`
22
- + `${missing.join(newline)}${newline}`, 'utf8');
23
- return true;
24
- }
25
-
26
- if (require.main === module) {
27
- const changed = syncCapacitorPermissionRules();
28
- console.log(changed ? 'Capacitor R8 permission rules restored.' : 'Capacitor R8 permission rules unchanged.');
29
- }
30
-
31
- module.exports = { syncCapacitorPermissionRules };
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ function syncCapacitorPermissionRules(projectRoot = path.resolve(__dirname, '../..')) {
5
+ const appPath = path.join(projectRoot, 'android', 'app');
6
+ if (!fs.existsSync(path.join(appPath, 'build.gradle'))) return false;
7
+
8
+ const rulesPath = path.join(appPath, 'proguard-rules.pro');
9
+ const original = fs.existsSync(rulesPath) ? fs.readFileSync(rulesPath, 'utf8') : '';
10
+ const rules = [
11
+ '-keepattributes RuntimeVisibleAnnotations,AnnotationDefault',
12
+ '-keep @interface com.getcapacitor.annotation.CapacitorPlugin { *; }',
13
+ '-keep @interface com.getcapacitor.annotation.Permission { *; }',
14
+ ];
15
+ const existing = new Set(original.split(/\r?\n/).map(line => line.trim()));
16
+ const missing = rules.filter(rule => !existing.has(rule));
17
+ if (!missing.length) return false;
18
+
19
+ const newline = original.includes('\r\n') ? '\r\n' : '\n';
20
+ fs.writeFileSync(rulesPath, `${original.trimEnd()}${newline}${newline}`
21
+ + `# Preserve Capacitor permission metadata used at runtime.${newline}`
22
+ + `${missing.join(newline)}${newline}`, 'utf8');
23
+ return true;
24
+ }
25
+
26
+ if (require.main === module) {
27
+ const changed = syncCapacitorPermissionRules();
28
+ console.log(changed ? 'Capacitor R8 permission rules restored.' : 'Capacitor R8 permission rules unchanged.');
29
+ }
30
+
31
+ module.exports = { syncCapacitorPermissionRules };
@@ -1,28 +1,28 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
-
4
- // FFmpegKit's JNI library looks up these Java members by name at runtime.
5
- const FFMPEG_JNI_RULES = [
6
- '-keep class com.antonkarpenko.ffmpegkit.** { *; }',
7
- '-keep interface com.antonkarpenko.ffmpegkit.** { *; }',
8
- ];
9
-
10
- function syncFfmpegJniRules(projectRoot) {
11
- const pluginPath = path.join(projectRoot, 'node_modules', 'codeplay-fmpg', 'plugin.xml');
12
- const appPath = path.join(projectRoot, 'android', 'app');
13
- if (!fs.existsSync(pluginPath) || !fs.existsSync(appPath)) return false;
14
-
15
- const rulesPath = path.join(appPath, 'proguard-rules.pro');
16
- const original = fs.existsSync(rulesPath) ? fs.readFileSync(rulesPath, 'utf8') : '';
17
- const existing = new Set(original.split(/\r?\n/).map(line => line.trim()));
18
- const missing = FFMPEG_JNI_RULES.filter(rule => !existing.has(rule));
19
- if (!missing.length) return false;
20
-
21
- const newline = original.includes('\r\n') ? '\r\n' : '\n';
22
- fs.writeFileSync(rulesPath, `${original.trimEnd()}${newline}${newline}`
23
- + `# Preserve FFmpegKit JNI entry points and callbacks.${newline}`
24
- + `${missing.join(newline)}${newline}`, 'utf8');
25
- return true;
26
- }
27
-
28
- module.exports = { syncFfmpegJniRules };
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ // FFmpegKit's JNI library looks up these Java members by name at runtime.
5
+ const FFMPEG_JNI_RULES = [
6
+ '-keep class com.antonkarpenko.ffmpegkit.** { *; }',
7
+ '-keep interface com.antonkarpenko.ffmpegkit.** { *; }',
8
+ ];
9
+
10
+ function syncFfmpegJniRules(projectRoot) {
11
+ const pluginPath = path.join(projectRoot, 'node_modules', 'codeplay-fmpg', 'plugin.xml');
12
+ const appPath = path.join(projectRoot, 'android', 'app');
13
+ if (!fs.existsSync(pluginPath) || !fs.existsSync(appPath)) return false;
14
+
15
+ const rulesPath = path.join(appPath, 'proguard-rules.pro');
16
+ const original = fs.existsSync(rulesPath) ? fs.readFileSync(rulesPath, 'utf8') : '';
17
+ const existing = new Set(original.split(/\r?\n/).map(line => line.trim()));
18
+ const missing = FFMPEG_JNI_RULES.filter(rule => !existing.has(rule));
19
+ if (!missing.length) return false;
20
+
21
+ const newline = original.includes('\r\n') ? '\r\n' : '\n';
22
+ fs.writeFileSync(rulesPath, `${original.trimEnd()}${newline}${newline}`
23
+ + `# Preserve FFmpegKit JNI entry points and callbacks.${newline}`
24
+ + `${missing.join(newline)}${newline}`, 'utf8');
25
+ return true;
26
+ }
27
+
28
+ module.exports = { syncFfmpegJniRules };
@@ -1,9 +1,9 @@
1
- // Restore native metadata before Gradle configures an optimized Android build.
2
- def codeplayAppRoot = rootProject.projectDir.parentFile
3
- def codeplayRepairScript = new File(codeplayAppRoot, 'buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs')
4
- def codeplayNodeBinary = project.findProperty('codeplayNodeBinary') ?: 'node'
5
-
6
- providers.exec {
7
- workingDir codeplayAppRoot
8
- commandLine codeplayNodeBinary, codeplayRepairScript.absolutePath
9
- }.result.get().assertNormalExitValue()
1
+ // Restore native metadata before Gradle configures an optimized Android build.
2
+ def codeplayAppRoot = rootProject.projectDir.parentFile
3
+ def codeplayRepairScript = new File(codeplayAppRoot, 'buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs')
4
+ def codeplayNodeBinary = project.findProperty('codeplayNodeBinary') ?: 'node'
5
+
6
+ providers.exec {
7
+ workingDir codeplayAppRoot
8
+ commandLine codeplayNodeBinary, codeplayRepairScript.absolutePath
9
+ }.result.get().assertNormalExitValue()
@@ -1,30 +1,30 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { syncFfmpegJniRules } = require('./ffmpeg-jni-rules.cjs');
4
- const { syncCapacitorPermissionRules } = require('./android-r8-rules.cjs');
5
-
6
- function syncAndroidR8Rules(projectRoot = path.resolve(__dirname, '../..'), { installGradleHook = false } = {}) {
7
- const buildPath = path.join(projectRoot, 'android', 'app', 'build.gradle');
8
- if (!fs.existsSync(buildPath)) return false;
9
- const capacitorChanged = syncCapacitorPermissionRules(projectRoot);
10
- const ffmpegChanged = syncFfmpegJniRules(projectRoot);
11
- let hookChanged = false;
12
- if (installGradleHook) {
13
- const original = fs.readFileSync(buildPath, 'utf8');
14
- const hook = "apply from: '../../buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle'";
15
- const existingHook = /^[ \t]*apply\s+from:\s*(['"])\.\.\/\.\.\/buildCodeplay\/fix-optimize-builld\/fix-optimize-build\.gradle\1[ \t]*;?[ \t]*$/m;
16
- if (!existingHook.test(original)) {
17
- const newline = original.includes('\r\n') ? '\r\n' : '\n';
18
- fs.writeFileSync(buildPath, `${original.trimEnd()}${newline}${newline}${hook}${newline}`, 'utf8');
19
- hookChanged = true;
20
- }
21
- }
22
- return capacitorChanged || ffmpegChanged || hookChanged;
23
- }
24
-
25
- if (require.main === module) {
26
- const changed = syncAndroidR8Rules(undefined, { installGradleHook: process.argv.includes('--install-gradle-hook') });
27
- console.log(changed ? 'Android R8 keep rules restored.' : 'Android R8 keep rules unchanged; no Android app or rules already present.');
28
- }
29
-
30
- module.exports = { syncAndroidR8Rules };
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { syncFfmpegJniRules } = require('./ffmpeg-jni-rules.cjs');
4
+ const { syncCapacitorPermissionRules } = require('./android-r8-rules.cjs');
5
+
6
+ function syncAndroidR8Rules(projectRoot = path.resolve(__dirname, '../..'), { installGradleHook = false } = {}) {
7
+ const buildPath = path.join(projectRoot, 'android', 'app', 'build.gradle');
8
+ if (!fs.existsSync(buildPath)) return false;
9
+ const capacitorChanged = syncCapacitorPermissionRules(projectRoot);
10
+ const ffmpegChanged = syncFfmpegJniRules(projectRoot);
11
+ let hookChanged = false;
12
+ if (installGradleHook) {
13
+ const original = fs.readFileSync(buildPath, 'utf8');
14
+ const hook = "apply from: '../../buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle'";
15
+ const existingHook = /^[ \t]*apply\s+from:\s*(['"])\.\.\/\.\.\/buildCodeplay\/fix-optimize-builld\/fix-optimize-build\.gradle\1[ \t]*;?[ \t]*$/m;
16
+ if (!existingHook.test(original)) {
17
+ const newline = original.includes('\r\n') ? '\r\n' : '\n';
18
+ fs.writeFileSync(buildPath, `${original.trimEnd()}${newline}${newline}${hook}${newline}`, 'utf8');
19
+ hookChanged = true;
20
+ }
21
+ }
22
+ return capacitorChanged || ffmpegChanged || hookChanged;
23
+ }
24
+
25
+ if (require.main === module) {
26
+ const changed = syncAndroidR8Rules(undefined, { installGradleHook: process.argv.includes('--install-gradle-hook') });
27
+ console.log(changed ? 'Android R8 keep rules restored.' : 'Android R8 keep rules unchanged; no Android app or rules already present.');
28
+ }
29
+
30
+ module.exports = { syncAndroidR8Rules };
@@ -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
+ }