codeplay-common 4.11.14 → 4.11.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -13
- package/RELEASE_NOTES.md +13 -13
- package/files/buildCodeplay/add-splash-screen.js +1 -1
- package/files/buildCodeplay/codeplayBeforeBuild.js +62 -22
- 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/ios-emi-admob-modification.js +25 -25
- package/files/buildCodeplay/newly added.txt +89 -89
- package/files/buildCodeplay/remove-force-kotlin-disable.js +43 -43
- package/files/buildCodeplay/setSplashAnimation.js +2 -2
- package/files/buildCodeplay/splash-setup.cjs +88 -88
- package/files/scripts-common/generate-baseline-profile.js +46 -46
- package/package.json +28 -28
- package/runtime/splash-ready.mjs +52 -52
- package/scripts/ensure-current-build.test.cjs +76 -76
- package/scripts/splash-setup.test.cjs +142 -142
- package/scripts/sync-files.js +1 -1
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
Note: This changes are added with my old(current) code. Might we need to integrate this features into our new optimized code.
|
|
2
|
-
|
|
3
|
-
1) If no import(saveToGalleryAndSaveAnyFile) found it through error issue is fixed
|
|
4
|
-
// iOS Checks
|
|
5
|
-
/* if (isMac && !iosImportFound) {
|
|
6
|
-
console.warn(`⚠️ WARNING: You're on macOS but no iOS version (saveToGalleryAndSaveAnyFile-x.x-ios.js) found.`);
|
|
7
|
-
process.exit(1);
|
|
8
|
-
} else if (isMac && iosImportFound) {
|
|
9
|
-
console.log('✅ iOS version detected for macOS build.');
|
|
10
|
-
} else if (!iosImportFound) {
|
|
11
|
-
console.log('✅ No iOS-specific imports detected for non-macOS.');
|
|
12
|
-
} */
|
|
13
|
-
|
|
14
|
-
// ✅ Only care if iOS import is found in NON-mac systems
|
|
15
|
-
if (iosImportFound && !isMac) {
|
|
16
|
-
console.error(`\n❌ ERROR: iOS-specific file is imported in non-macOS environment.`);
|
|
17
|
-
process.exit(1);
|
|
18
|
-
} else if (iosImportFound && isMac) {
|
|
19
|
-
console.log('✅ iOS import detected (valid for macOS build).');
|
|
20
|
-
} else {
|
|
21
|
-
console.log('✅ No iOS-specific imports found (this is totally fine).');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
2) Statusbar color set in app startup is checked and through erro
|
|
26
|
-
|
|
27
|
-
const STATUSBAR_FILE = path.resolve(__dirname, '../src/js/common-configuration.js');
|
|
28
|
-
const STATUSBAR_REGEX = /^(?!\s*\/\/).*Capacitor\.Plugins\.StatusBar\.setStyle/m;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const ONESIGNAL_OLD_FILES = [
|
|
32
|
-
path.resolve(__dirname, '../src/js/onesignal-settings.js')
|
|
33
|
-
];
|
|
34
|
-
const ONESIGNAL_VERSION_REGEX = /^onesignal-\d+(\.\d+)*\.js$/;
|
|
35
|
-
|
|
36
|
-
....
|
|
37
|
-
....
|
|
38
|
-
....
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const JS_ROOT = path.resolve(__dirname, '../src/js');
|
|
42
|
-
const ONESIGNAL_DIR = path.join(JS_ROOT, 'onesignal');
|
|
43
|
-
|
|
44
|
-
// 🚨 Block old OneSignal file locations (ONLY in src/js root)
|
|
45
|
-
if (path.dirname(dir) === JS_ROOT) {
|
|
46
|
-
|
|
47
|
-
// ❌ onesignal-settings.js
|
|
48
|
-
if (ONESIGNAL_OLD_FILES.includes(dir)) {
|
|
49
|
-
console.error(`\n❌ ERROR: onesignal-settings.js should not be in src/js/`);
|
|
50
|
-
console.error(`📁 Move it to: src/js/onesignal/`);
|
|
51
|
-
console.error(`📄 File: ${dir}\n`);
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// ❌ onesignal-x.x.js
|
|
56
|
-
if (ONESIGNAL_VERSION_REGEX.test(baseName)) {
|
|
57
|
-
console.error(`\n❌ ERROR: ${baseName} should not be in src/js/`);
|
|
58
|
-
console.error(`📁 Move it to: src/js/onesignal/`);
|
|
59
|
-
console.error(`📄 File: ${dir}\n`);
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// 🚨 Special check ONLY for common-configuration.js
|
|
65
|
-
if (dir === STATUSBAR_FILE) {
|
|
66
|
-
let content = fs.readFileSync(dir, 'utf8');
|
|
67
|
-
|
|
68
|
-
// 🧹 Remove ALL comments (single-line + multi-line)
|
|
69
|
-
const contentWithoutComments = content
|
|
70
|
-
.replace(/\/\/.*$/gm, '') // remove // comments
|
|
71
|
-
.replace(/\/\*[\s\S]*?\*\//g, ''); // remove /* */ comments
|
|
72
|
-
|
|
73
|
-
// ✅ Now check only real code
|
|
74
|
-
if (contentWithoutComments.includes('Capacitor.Plugins.StatusBar.setStyle')) {
|
|
75
|
-
console.error(`\n❌ ERROR: StatusBar.setStyle should NOT be used in common-configuration.js`);
|
|
76
|
-
console.error(`🚫 iOS status bar is controlled via other methods. Remove this line.`);
|
|
77
|
-
console.error(`📄 File: ${dir}\n`);
|
|
78
|
-
process.exit(1);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
3) Modification in "fix-onesignal-plugin.js" file
|
|
84
|
-
Search following and that whole block added for add permission to "info.plist" file
|
|
85
|
-
INFO.PLIST START
|
|
86
|
-
|
|
87
|
-
4) In "codeplayBeforeBuild-6.1.js" file following whole method is replaced. Due to add ads related permission to info.plist file
|
|
88
|
-
updateInfoPlist()
|
|
89
|
-
|
|
1
|
+
Note: This changes are added with my old(current) code. Might we need to integrate this features into our new optimized code.
|
|
2
|
+
|
|
3
|
+
1) If no import(saveToGalleryAndSaveAnyFile) found it through error issue is fixed
|
|
4
|
+
// iOS Checks
|
|
5
|
+
/* if (isMac && !iosImportFound) {
|
|
6
|
+
console.warn(`⚠️ WARNING: You're on macOS but no iOS version (saveToGalleryAndSaveAnyFile-x.x-ios.js) found.`);
|
|
7
|
+
process.exit(1);
|
|
8
|
+
} else if (isMac && iosImportFound) {
|
|
9
|
+
console.log('✅ iOS version detected for macOS build.');
|
|
10
|
+
} else if (!iosImportFound) {
|
|
11
|
+
console.log('✅ No iOS-specific imports detected for non-macOS.');
|
|
12
|
+
} */
|
|
13
|
+
|
|
14
|
+
// ✅ Only care if iOS import is found in NON-mac systems
|
|
15
|
+
if (iosImportFound && !isMac) {
|
|
16
|
+
console.error(`\n❌ ERROR: iOS-specific file is imported in non-macOS environment.`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
} else if (iosImportFound && isMac) {
|
|
19
|
+
console.log('✅ iOS import detected (valid for macOS build).');
|
|
20
|
+
} else {
|
|
21
|
+
console.log('✅ No iOS-specific imports found (this is totally fine).');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
2) Statusbar color set in app startup is checked and through erro
|
|
26
|
+
|
|
27
|
+
const STATUSBAR_FILE = path.resolve(__dirname, '../src/js/common-configuration.js');
|
|
28
|
+
const STATUSBAR_REGEX = /^(?!\s*\/\/).*Capacitor\.Plugins\.StatusBar\.setStyle/m;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const ONESIGNAL_OLD_FILES = [
|
|
32
|
+
path.resolve(__dirname, '../src/js/onesignal-settings.js')
|
|
33
|
+
];
|
|
34
|
+
const ONESIGNAL_VERSION_REGEX = /^onesignal-\d+(\.\d+)*\.js$/;
|
|
35
|
+
|
|
36
|
+
....
|
|
37
|
+
....
|
|
38
|
+
....
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
const JS_ROOT = path.resolve(__dirname, '../src/js');
|
|
42
|
+
const ONESIGNAL_DIR = path.join(JS_ROOT, 'onesignal');
|
|
43
|
+
|
|
44
|
+
// 🚨 Block old OneSignal file locations (ONLY in src/js root)
|
|
45
|
+
if (path.dirname(dir) === JS_ROOT) {
|
|
46
|
+
|
|
47
|
+
// ❌ onesignal-settings.js
|
|
48
|
+
if (ONESIGNAL_OLD_FILES.includes(dir)) {
|
|
49
|
+
console.error(`\n❌ ERROR: onesignal-settings.js should not be in src/js/`);
|
|
50
|
+
console.error(`📁 Move it to: src/js/onesignal/`);
|
|
51
|
+
console.error(`📄 File: ${dir}\n`);
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ❌ onesignal-x.x.js
|
|
56
|
+
if (ONESIGNAL_VERSION_REGEX.test(baseName)) {
|
|
57
|
+
console.error(`\n❌ ERROR: ${baseName} should not be in src/js/`);
|
|
58
|
+
console.error(`📁 Move it to: src/js/onesignal/`);
|
|
59
|
+
console.error(`📄 File: ${dir}\n`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 🚨 Special check ONLY for common-configuration.js
|
|
65
|
+
if (dir === STATUSBAR_FILE) {
|
|
66
|
+
let content = fs.readFileSync(dir, 'utf8');
|
|
67
|
+
|
|
68
|
+
// 🧹 Remove ALL comments (single-line + multi-line)
|
|
69
|
+
const contentWithoutComments = content
|
|
70
|
+
.replace(/\/\/.*$/gm, '') // remove // comments
|
|
71
|
+
.replace(/\/\*[\s\S]*?\*\//g, ''); // remove /* */ comments
|
|
72
|
+
|
|
73
|
+
// ✅ Now check only real code
|
|
74
|
+
if (contentWithoutComments.includes('Capacitor.Plugins.StatusBar.setStyle')) {
|
|
75
|
+
console.error(`\n❌ ERROR: StatusBar.setStyle should NOT be used in common-configuration.js`);
|
|
76
|
+
console.error(`🚫 iOS status bar is controlled via other methods. Remove this line.`);
|
|
77
|
+
console.error(`📄 File: ${dir}\n`);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
3) Modification in "fix-onesignal-plugin.js" file
|
|
84
|
+
Search following and that whole block added for add permission to "info.plist" file
|
|
85
|
+
INFO.PLIST START
|
|
86
|
+
|
|
87
|
+
4) In "codeplayBeforeBuild-6.1.js" file following whole method is replaced. Due to add ads related permission to info.plist file
|
|
88
|
+
updateInfoPlist()
|
|
89
|
+
|
|
90
90
|
5) The "checkPackageVersion()" metod is updated. Now check the "codeplay-common" latest version and uninstall/install automatically.
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const legacyPluginXmlPath = path.resolve(
|
|
5
|
-
__dirname,
|
|
6
|
-
'../node_modules/emi-indo-cordova-plugin-admob/plugin.xml'
|
|
7
|
-
);
|
|
8
|
-
|
|
9
|
-
const nextGenPackagePath = path.resolve(
|
|
10
|
-
__dirname,
|
|
11
|
-
'../node_modules/capacitor-admob-nextgen/package.json'
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
if (!fs.existsSync(legacyPluginXmlPath)) {
|
|
15
|
-
if (fs.existsSync(nextGenPackagePath)) {
|
|
16
|
-
console.log('ℹ️ Skipping legacy Kotlin patch. capacitor-admob-nextgen is installed and does not use plugin.xml.');
|
|
17
|
-
process.exit(0);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
console.log('ℹ️ Legacy AdMob plugin.xml not found, skipping Kotlin patch.');
|
|
21
|
-
process.exit(0);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
fs.readFile(legacyPluginXmlPath, 'utf8', (err, data) => {
|
|
25
|
-
if (err) {
|
|
26
|
-
console.error('Error reading plugin.xml:', err);
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const modifiedData = data.replace(
|
|
31
|
-
/<framework\s+src="src\/android\/force-kotlin\.gradle"\s+custom="true"\s+type="gradleReference"\s*\/>\s*\n?/g,
|
|
32
|
-
''
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
fs.writeFile(legacyPluginXmlPath, modifiedData, 'utf8', (writeErr) => {
|
|
36
|
-
if (writeErr) {
|
|
37
|
-
console.error('Error writing plugin.xml:', writeErr);
|
|
38
|
-
process.exit(1);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
console.log('plugin.xml updated successfully.');
|
|
42
|
-
});
|
|
43
|
-
});
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const legacyPluginXmlPath = path.resolve(
|
|
5
|
+
__dirname,
|
|
6
|
+
'../node_modules/emi-indo-cordova-plugin-admob/plugin.xml'
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
const nextGenPackagePath = path.resolve(
|
|
10
|
+
__dirname,
|
|
11
|
+
'../node_modules/capacitor-admob-nextgen/package.json'
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
if (!fs.existsSync(legacyPluginXmlPath)) {
|
|
15
|
+
if (fs.existsSync(nextGenPackagePath)) {
|
|
16
|
+
console.log('ℹ️ Skipping legacy Kotlin patch. capacitor-admob-nextgen is installed and does not use plugin.xml.');
|
|
17
|
+
process.exit(0);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
console.log('ℹ️ Legacy AdMob plugin.xml not found, skipping Kotlin patch.');
|
|
21
|
+
process.exit(0);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
fs.readFile(legacyPluginXmlPath, 'utf8', (err, data) => {
|
|
25
|
+
if (err) {
|
|
26
|
+
console.error('Error reading plugin.xml:', err);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const modifiedData = data.replace(
|
|
31
|
+
/<framework\s+src="src\/android\/force-kotlin\.gradle"\s+custom="true"\s+type="gradleReference"\s*\/>\s*\n?/g,
|
|
32
|
+
''
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
fs.writeFile(legacyPluginXmlPath, modifiedData, 'utf8', (writeErr) => {
|
|
36
|
+
if (writeErr) {
|
|
37
|
+
console.error('Error writing plugin.xml:', writeErr);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log('plugin.xml updated successfully.');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const readline = require('readline');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const { readSplashOptions } = require('./splash-setup.cjs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { readSplashOptions } = require('./splash-setup.cjs');
|
|
5
5
|
const splashOptions = readSplashOptions(JSON.parse(fs.readFileSync('capacitor.config.json', 'utf8')));
|
|
6
6
|
|
|
7
7
|
// Define the root directory of the project (adjust if needed)
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const crypto = require('crypto');
|
|
4
|
-
const runtimeImport = "import { hideSplashWhenReady } from 'codeplay-common/runtime/splash-ready.mjs';";
|
|
5
|
-
const knownReadyHash = '451fd2e0ca63712e0f771ee0ed03ae5bd3a379f0ca1e75e971cd7acee0802a2b';
|
|
6
|
-
|
|
7
|
-
function readSplashOptions(config) {
|
|
8
|
-
const options = config.plugins?.CodeplaySplashScreen || {};
|
|
9
|
-
const duration = options.exitAnimationDuration ?? 1000;
|
|
10
|
-
const timeout = options.readinessTimeout ?? 8000;
|
|
11
|
-
const imageSelector = options.readyImageSelector ?? '[data-splash-ready], .t-film-art img';
|
|
12
|
-
if (!Number.isInteger(duration) || duration < 0 || duration > 10000) throw new Error('CodeplaySplashScreen.exitAnimationDuration must be an integer from0 to10000.');
|
|
13
|
-
if (!Number.isInteger(timeout) || timeout < 1 || timeout > 60000) throw new Error('CodeplaySplashScreen.readinessTimeout must be an integer from1 to60000.');
|
|
14
|
-
if (typeof imageSelector !== 'string') throw new Error('CodeplaySplashScreen.readyImageSelector must be a string.');
|
|
15
|
-
if (options.migrateLegacyReadiness !== undefined && typeof options.migrateLegacyReadiness !== 'boolean') throw new Error('CodeplaySplashScreen.migrateLegacyReadiness must be boolean.');
|
|
16
|
-
return { duration, timeout, imageSelector, migrateLegacy: options.migrateLegacyReadiness === true };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function migrateSplashTheme(content) {
|
|
20
|
-
// Repair only the known package default; preserve custom themes and styling.
|
|
21
|
-
return content.replace(/(<item\s+name=["']postSplashScreenTheme["']\s*>\s*)@style\/Theme\.AppCompat\.NoActionBar(\s*<\/item>)/g,
|
|
22
|
-
'$1@style/Theme.AppCompat.DayNight.NoActionBar$2');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function migrateReadinessSource(source, options) {
|
|
26
|
-
if (!/\b(?:var|let|const)\s+capacitorApp\s*=/.test(source)) return { source, status: 'unsupported' };
|
|
27
|
-
const handler = / handleSplashscreen:\s*function\s*\(\)\s*\{([\s\S]*?)\r?\n \},/;
|
|
28
|
-
const match = source.match(handler);
|
|
29
|
-
if (!match) return { source, status: 'unsupported' };
|
|
30
|
-
const body = match[1].replace(/\s+/g, '');
|
|
31
|
-
const isReady = crypto.createHash('sha256').update(body).digest('hex') === knownReadyHash;
|
|
32
|
-
const isManaged = /^if\(!window\.Capacitor\)return;returnhideSplashWhenReady\(\{f7:capacitorApp\.f7,hide:\(\)=>SplashScreen\.hide\(\),imageSelector:"(?:\\.|[^"\\])*",timeout:\d+\}\);$/.test(body)
|
|
33
|
-
&& source.includes(runtimeImport);
|
|
34
|
-
const isLegacy = body === "if(!window.Capacitor)return;setTimeout(()=>{if(window.Capacitor.Plugins?.SplashScreen)window.Capacitor.Plugins.SplashScreen.hide();},2000);"
|
|
35
|
-
|| body === "if(!window.Capacitor)return;setTimeout(()=>{if(window.Capacitor.Plugins&&window.Capacitor.Plugins.SplashScreen){window.Capacitor.Plugins.SplashScreen.hide();}},2000);";
|
|
36
|
-
if (!isReady && !isManaged && !(isLegacy && options.migrateLegacy)) return { source, status: isLegacy ? 'opt-in-required' : 'custom-preserved' };
|
|
37
|
-
const newline = source.includes('\r\n') ? '\r\n' : '\n';
|
|
38
|
-
const method = [
|
|
39
|
-
' handleSplashscreen: function () {',
|
|
40
|
-
' if (!window.Capacitor) return;',
|
|
41
|
-
' return hideSplashWhenReady({',
|
|
42
|
-
' f7: capacitorApp.f7,',
|
|
43
|
-
' hide: () => SplashScreen.hide(),',
|
|
44
|
-
` imageSelector: ${JSON.stringify(options.imageSelector)},`,
|
|
45
|
-
` timeout: ${options.timeout}`, ' });', ' },'
|
|
46
|
-
].join(newline);
|
|
47
|
-
let updated = source.replace(handler, () => method);
|
|
48
|
-
if (!updated.includes(runtimeImport)) updated = runtimeImport + newline + updated;
|
|
49
|
-
if (!/import\s*\{[^}]*\bSplashScreen\b[^}]*\}\s*from\s*['"]@capacitor\/splash-screen['"]/.test(updated)) {
|
|
50
|
-
updated = "import { SplashScreen } from '@capacitor/splash-screen';" + newline + updated;
|
|
51
|
-
}
|
|
52
|
-
return { source: updated, status: 'managed' };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function syncSplashSetup(projectRoot, { log = console.log } = {}) {
|
|
56
|
-
const configPath = path.join(projectRoot, 'capacitor.config.json');
|
|
57
|
-
if (!fs.existsSync(configPath)) return;
|
|
58
|
-
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
59
|
-
const options = readSplashOptions(config);
|
|
60
|
-
const theme = path.join(projectRoot, 'buildCodeplay/splashxml/codeplay_splashScreen.xml');
|
|
61
|
-
if (fs.existsSync(theme)) {
|
|
62
|
-
const content = fs.readFileSync(theme, 'utf8');
|
|
63
|
-
const updated = migrateSplashTheme(content);
|
|
64
|
-
if (updated !== content) { fs.writeFileSync(theme, updated); log('codeplay-common: repaired legacy splash DayNight theme template; Android sync applies it.'); }
|
|
65
|
-
}
|
|
66
|
-
const app = path.join(projectRoot, 'src/js/capacitor-app.js');
|
|
67
|
-
if (!fs.existsSync(app)) return;
|
|
68
|
-
const source = fs.readFileSync(app, 'utf8');
|
|
69
|
-
const migrated = migrateReadinessSource(source, options);
|
|
70
|
-
if (migrated.status === 'managed') {
|
|
71
|
-
if (source !== migrated.source) {
|
|
72
|
-
const launch = config.plugins?.SplashScreen;
|
|
73
|
-
if (launch?.launchAutoHide !== true || !(launch.launchShowDuration >= options.timeout)) {
|
|
74
|
-
log('codeplay-common: readiness migration skipped; set SplashScreen.launchAutoHide=true and launchShowDuration>=readinessTimeout for the native fallback.');
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const dependency = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
|
|
78
|
-
if (!dependency.dependencies?.['@capacitor/splash-screen'] && !dependency.devDependencies?.['@capacitor/splash-screen']) {
|
|
79
|
-
log('codeplay-common: readiness migration skipped; @capacitor/splash-screen must be installed.');
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
fs.writeFileSync(app, migrated.source);
|
|
83
|
-
log('codeplay-common: connected supported startup handler to shared splash readiness.');
|
|
84
|
-
}
|
|
85
|
-
} else log(`codeplay-common: splash readiness ${migrated.status}; app startup preserved. See shared splash setup in README.`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
module.exports = { readSplashOptions, migrateSplashTheme, migrateReadinessSource, syncSplashSetup };
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const runtimeImport = "import { hideSplashWhenReady } from 'codeplay-common/runtime/splash-ready.mjs';";
|
|
5
|
+
const knownReadyHash = '451fd2e0ca63712e0f771ee0ed03ae5bd3a379f0ca1e75e971cd7acee0802a2b';
|
|
6
|
+
|
|
7
|
+
function readSplashOptions(config) {
|
|
8
|
+
const options = config.plugins?.CodeplaySplashScreen || {};
|
|
9
|
+
const duration = options.exitAnimationDuration ?? 1000;
|
|
10
|
+
const timeout = options.readinessTimeout ?? 8000;
|
|
11
|
+
const imageSelector = options.readyImageSelector ?? '[data-splash-ready], .t-film-art img';
|
|
12
|
+
if (!Number.isInteger(duration) || duration < 0 || duration > 10000) throw new Error('CodeplaySplashScreen.exitAnimationDuration must be an integer from0 to10000.');
|
|
13
|
+
if (!Number.isInteger(timeout) || timeout < 1 || timeout > 60000) throw new Error('CodeplaySplashScreen.readinessTimeout must be an integer from1 to60000.');
|
|
14
|
+
if (typeof imageSelector !== 'string') throw new Error('CodeplaySplashScreen.readyImageSelector must be a string.');
|
|
15
|
+
if (options.migrateLegacyReadiness !== undefined && typeof options.migrateLegacyReadiness !== 'boolean') throw new Error('CodeplaySplashScreen.migrateLegacyReadiness must be boolean.');
|
|
16
|
+
return { duration, timeout, imageSelector, migrateLegacy: options.migrateLegacyReadiness === true };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function migrateSplashTheme(content) {
|
|
20
|
+
// Repair only the known package default; preserve custom themes and styling.
|
|
21
|
+
return content.replace(/(<item\s+name=["']postSplashScreenTheme["']\s*>\s*)@style\/Theme\.AppCompat\.NoActionBar(\s*<\/item>)/g,
|
|
22
|
+
'$1@style/Theme.AppCompat.DayNight.NoActionBar$2');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function migrateReadinessSource(source, options) {
|
|
26
|
+
if (!/\b(?:var|let|const)\s+capacitorApp\s*=/.test(source)) return { source, status: 'unsupported' };
|
|
27
|
+
const handler = / handleSplashscreen:\s*function\s*\(\)\s*\{([\s\S]*?)\r?\n \},/;
|
|
28
|
+
const match = source.match(handler);
|
|
29
|
+
if (!match) return { source, status: 'unsupported' };
|
|
30
|
+
const body = match[1].replace(/\s+/g, '');
|
|
31
|
+
const isReady = crypto.createHash('sha256').update(body).digest('hex') === knownReadyHash;
|
|
32
|
+
const isManaged = /^if\(!window\.Capacitor\)return;returnhideSplashWhenReady\(\{f7:capacitorApp\.f7,hide:\(\)=>SplashScreen\.hide\(\),imageSelector:"(?:\\.|[^"\\])*",timeout:\d+\}\);$/.test(body)
|
|
33
|
+
&& source.includes(runtimeImport);
|
|
34
|
+
const isLegacy = body === "if(!window.Capacitor)return;setTimeout(()=>{if(window.Capacitor.Plugins?.SplashScreen)window.Capacitor.Plugins.SplashScreen.hide();},2000);"
|
|
35
|
+
|| body === "if(!window.Capacitor)return;setTimeout(()=>{if(window.Capacitor.Plugins&&window.Capacitor.Plugins.SplashScreen){window.Capacitor.Plugins.SplashScreen.hide();}},2000);";
|
|
36
|
+
if (!isReady && !isManaged && !(isLegacy && options.migrateLegacy)) return { source, status: isLegacy ? 'opt-in-required' : 'custom-preserved' };
|
|
37
|
+
const newline = source.includes('\r\n') ? '\r\n' : '\n';
|
|
38
|
+
const method = [
|
|
39
|
+
' handleSplashscreen: function () {',
|
|
40
|
+
' if (!window.Capacitor) return;',
|
|
41
|
+
' return hideSplashWhenReady({',
|
|
42
|
+
' f7: capacitorApp.f7,',
|
|
43
|
+
' hide: () => SplashScreen.hide(),',
|
|
44
|
+
` imageSelector: ${JSON.stringify(options.imageSelector)},`,
|
|
45
|
+
` timeout: ${options.timeout}`, ' });', ' },'
|
|
46
|
+
].join(newline);
|
|
47
|
+
let updated = source.replace(handler, () => method);
|
|
48
|
+
if (!updated.includes(runtimeImport)) updated = runtimeImport + newline + updated;
|
|
49
|
+
if (!/import\s*\{[^}]*\bSplashScreen\b[^}]*\}\s*from\s*['"]@capacitor\/splash-screen['"]/.test(updated)) {
|
|
50
|
+
updated = "import { SplashScreen } from '@capacitor/splash-screen';" + newline + updated;
|
|
51
|
+
}
|
|
52
|
+
return { source: updated, status: 'managed' };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function syncSplashSetup(projectRoot, { log = console.log } = {}) {
|
|
56
|
+
const configPath = path.join(projectRoot, 'capacitor.config.json');
|
|
57
|
+
if (!fs.existsSync(configPath)) return;
|
|
58
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
59
|
+
const options = readSplashOptions(config);
|
|
60
|
+
const theme = path.join(projectRoot, 'buildCodeplay/splashxml/codeplay_splashScreen.xml');
|
|
61
|
+
if (fs.existsSync(theme)) {
|
|
62
|
+
const content = fs.readFileSync(theme, 'utf8');
|
|
63
|
+
const updated = migrateSplashTheme(content);
|
|
64
|
+
if (updated !== content) { fs.writeFileSync(theme, updated); log('codeplay-common: repaired legacy splash DayNight theme template; Android sync applies it.'); }
|
|
65
|
+
}
|
|
66
|
+
const app = path.join(projectRoot, 'src/js/capacitor-app.js');
|
|
67
|
+
if (!fs.existsSync(app)) return;
|
|
68
|
+
const source = fs.readFileSync(app, 'utf8');
|
|
69
|
+
const migrated = migrateReadinessSource(source, options);
|
|
70
|
+
if (migrated.status === 'managed') {
|
|
71
|
+
if (source !== migrated.source) {
|
|
72
|
+
const launch = config.plugins?.SplashScreen;
|
|
73
|
+
if (launch?.launchAutoHide !== true || !(launch.launchShowDuration >= options.timeout)) {
|
|
74
|
+
log('codeplay-common: readiness migration skipped; set SplashScreen.launchAutoHide=true and launchShowDuration>=readinessTimeout for the native fallback.');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const dependency = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
|
|
78
|
+
if (!dependency.dependencies?.['@capacitor/splash-screen'] && !dependency.devDependencies?.['@capacitor/splash-screen']) {
|
|
79
|
+
log('codeplay-common: readiness migration skipped; @capacitor/splash-screen must be installed.');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
fs.writeFileSync(app, migrated.source);
|
|
83
|
+
log('codeplay-common: connected supported startup handler to shared splash readiness.');
|
|
84
|
+
}
|
|
85
|
+
} else log(`codeplay-common: splash readiness ${migrated.status}; app startup preserved. See shared splash setup in README.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = { readSplashOptions, migrateSplashTheme, migrateReadinessSource, syncSplashSetup };
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
const { execFileSync, spawnSync } = require('child_process');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const { syncGeneratedProfileBackup } = require('./setup-baseline-profile.js');
|
|
4
|
-
|
|
5
|
-
function main() {
|
|
6
|
-
const devices = execFileSync('adb', ['devices'], { encoding: 'utf8' })
|
|
7
|
-
.split(/\r?\n/)
|
|
8
|
-
.map(line => line.match(/^(.+?)\tdevice\s*$/))
|
|
9
|
-
.filter(Boolean)
|
|
10
|
-
.map(match => match[1]);
|
|
11
|
-
const requestedSerial = process.env.ANDROID_SERIAL?.trim();
|
|
12
|
-
if (requestedSerial?.includes(',')) {
|
|
13
|
-
throw new Error('Set ANDROID_SERIAL to one device connection for Baseline Profile generation.');
|
|
14
|
-
}
|
|
15
|
-
const serial = requestedSerial || devices[0];
|
|
16
|
-
if (!serial || !devices.includes(serial)) {
|
|
17
|
-
throw new Error(requestedSerial
|
|
18
|
-
? `ADB device is not online: ${requestedSerial}`
|
|
19
|
-
: 'No online ADB device. Connect an Android device before generating a Baseline Profile.');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
console.log(`Generating Baseline Profile using one ADB connection: ${serial}`);
|
|
23
|
-
const args = [':app:generateBaselineProfile', '--console=plain'];
|
|
24
|
-
const result = spawnSync(
|
|
25
|
-
process.platform === 'win32' ? 'cmd.exe' : './gradlew',
|
|
26
|
-
process.platform === 'win32' ? ['/d', '/s', '/c', `gradlew.bat ${args.join(' ')}`] : args,
|
|
27
|
-
{
|
|
28
|
-
cwd: path.resolve(__dirname, '..', 'android'),
|
|
29
|
-
env: { ...process.env, ANDROID_SERIAL: serial },
|
|
30
|
-
stdio: 'inherit',
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
if (result.error) throw result.error;
|
|
34
|
-
if (result.signal) throw new Error(`Baseline Profile generation stopped by ${result.signal}.`);
|
|
35
|
-
process.exitCode = result.status ?? 1;
|
|
36
|
-
if (process.exitCode === 0) {
|
|
37
|
-
syncGeneratedProfileBackup({ backupOnly: true });
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
main();
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.error(`Baseline Profile generation failed: ${error.message}`);
|
|
45
|
-
process.exitCode = 1;
|
|
46
|
-
}
|
|
1
|
+
const { execFileSync, spawnSync } = require('child_process');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { syncGeneratedProfileBackup } = require('./setup-baseline-profile.js');
|
|
4
|
+
|
|
5
|
+
function main() {
|
|
6
|
+
const devices = execFileSync('adb', ['devices'], { encoding: 'utf8' })
|
|
7
|
+
.split(/\r?\n/)
|
|
8
|
+
.map(line => line.match(/^(.+?)\tdevice\s*$/))
|
|
9
|
+
.filter(Boolean)
|
|
10
|
+
.map(match => match[1]);
|
|
11
|
+
const requestedSerial = process.env.ANDROID_SERIAL?.trim();
|
|
12
|
+
if (requestedSerial?.includes(',')) {
|
|
13
|
+
throw new Error('Set ANDROID_SERIAL to one device connection for Baseline Profile generation.');
|
|
14
|
+
}
|
|
15
|
+
const serial = requestedSerial || devices[0];
|
|
16
|
+
if (!serial || !devices.includes(serial)) {
|
|
17
|
+
throw new Error(requestedSerial
|
|
18
|
+
? `ADB device is not online: ${requestedSerial}`
|
|
19
|
+
: 'No online ADB device. Connect an Android device before generating a Baseline Profile.');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
console.log(`Generating Baseline Profile using one ADB connection: ${serial}`);
|
|
23
|
+
const args = [':app:generateBaselineProfile', '--console=plain'];
|
|
24
|
+
const result = spawnSync(
|
|
25
|
+
process.platform === 'win32' ? 'cmd.exe' : './gradlew',
|
|
26
|
+
process.platform === 'win32' ? ['/d', '/s', '/c', `gradlew.bat ${args.join(' ')}`] : args,
|
|
27
|
+
{
|
|
28
|
+
cwd: path.resolve(__dirname, '..', 'android'),
|
|
29
|
+
env: { ...process.env, ANDROID_SERIAL: serial },
|
|
30
|
+
stdio: 'inherit',
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
if (result.error) throw result.error;
|
|
34
|
+
if (result.signal) throw new Error(`Baseline Profile generation stopped by ${result.signal}.`);
|
|
35
|
+
process.exitCode = result.status ?? 1;
|
|
36
|
+
if (process.exitCode === 0) {
|
|
37
|
+
syncGeneratedProfileBackup({ backupOnly: true });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
main();
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error(`Baseline Profile generation failed: ${error.message}`);
|
|
45
|
+
process.exitCode = 1;
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "codeplay-common",
|
|
3
|
-
"version": "4.11.
|
|
4
|
-
"description": "Common build scripts and files",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"postinstall": "node scripts/sync-files.js",
|
|
7
|
-
"preinstall": "node scripts/uninstall.js"
|
|
8
|
-
},
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"adm-zip": "^0.6.1",
|
|
11
|
-
"plist": "^3.1.0"
|
|
12
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "https://github.com/merbin2012/codeplay-common.git"
|
|
16
|
-
},
|
|
17
|
-
"author": "Codeplay Technologies",
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"files": [
|
|
20
|
-
"files/",
|
|
21
|
-
"scripts/",
|
|
22
|
-
"README.md",
|
|
23
|
-
"CHANGELOG.md",
|
|
24
|
-
"RELEASE_NOTES.md",
|
|
25
|
-
"LICENSE",
|
|
26
|
-
"runtime/"
|
|
27
|
-
]
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "codeplay-common",
|
|
3
|
+
"version": "4.11.16",
|
|
4
|
+
"description": "Common build scripts and files",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"postinstall": "node scripts/sync-files.js",
|
|
7
|
+
"preinstall": "node scripts/uninstall.js"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"adm-zip": "^0.6.1",
|
|
11
|
+
"plist": "^3.1.0"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/merbin2012/codeplay-common.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "Codeplay Technologies",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"files": [
|
|
20
|
+
"files/",
|
|
21
|
+
"scripts/",
|
|
22
|
+
"README.md",
|
|
23
|
+
"CHANGELOG.md",
|
|
24
|
+
"RELEASE_NOTES.md",
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"runtime/"
|
|
27
|
+
]
|
|
28
|
+
}
|