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
package/runtime/splash-ready.mjs
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
// Framework7 and Capacitor stay owned by the consuming app; no extra dependency.
|
|
2
|
-
const registrations = new WeakMap();
|
|
3
|
-
|
|
4
|
-
export function hideSplashWhenReady({ f7, hide, imageSelector = '[data-splash-ready], .t-film-art img', timeout = 8000 }) {
|
|
5
|
-
if (!f7 || typeof f7.on !== 'function' || typeof f7.off !== 'function' || typeof hide !== 'function') {
|
|
6
|
-
throw new TypeError('Splash readiness requires Framework7 and a hide callback.');
|
|
7
|
-
}
|
|
8
|
-
if (!Number.isInteger(timeout) || timeout < 1 || timeout > 60000) throw new TypeError('Invalid splash readiness timeout.');
|
|
9
|
-
if (typeof imageSelector !== 'string') throw new TypeError('Invalid splash image selector.');
|
|
10
|
-
if (registrations.has(f7)) return registrations.get(f7);
|
|
11
|
-
let finished = false;
|
|
12
|
-
let preparing = false;
|
|
13
|
-
let image;
|
|
14
|
-
const detachImage = () => {
|
|
15
|
-
image?.removeEventListener('load', onImageReady);
|
|
16
|
-
image?.removeEventListener('error', onImageReady);
|
|
17
|
-
};
|
|
18
|
-
const finish = () => {
|
|
19
|
-
if (finished) return;
|
|
20
|
-
finished = true;
|
|
21
|
-
clearTimeout(fallback);
|
|
22
|
-
f7.off('pageAfterIn', onPageReady);
|
|
23
|
-
detachImage();
|
|
24
|
-
// Plugin availability differs by platform; failed native hiding must not
|
|
25
|
-
// create an unhandled rejection. The native launch timeout is the backup.
|
|
26
|
-
try { Promise.resolve(hide()).catch(() => {}); } catch {}
|
|
27
|
-
};
|
|
28
|
-
const onImageReady = () => {
|
|
29
|
-
if (finished) return;
|
|
30
|
-
detachImage();
|
|
31
|
-
if (image.naturalWidth > 0 && typeof image.decode === 'function') {
|
|
32
|
-
Promise.resolve().then(() => image.decode()).catch(() => {}).then(finish);
|
|
33
|
-
} else finish();
|
|
34
|
-
};
|
|
35
|
-
const onPageReady = page => {
|
|
36
|
-
if (finished || preparing || !page?.el?.closest('.view-main')) return;
|
|
37
|
-
preparing = true;
|
|
38
|
-
try { image = imageSelector ? page.el.querySelector(imageSelector) : null; } catch { finish(); return; }
|
|
39
|
-
if (!image) finish();
|
|
40
|
-
else if (image.complete) onImageReady();
|
|
41
|
-
else {
|
|
42
|
-
image.addEventListener('load', onImageReady, { once: true });
|
|
43
|
-
image.addEventListener('error', onImageReady, { once: true });
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const fallback = setTimeout(finish, timeout);
|
|
47
|
-
registrations.set(f7, finish);
|
|
48
|
-
f7.on('pageAfterIn', onPageReady);
|
|
49
|
-
const currentPage = f7.views?.main?.router?.currentPageEl;
|
|
50
|
-
if (currentPage) onPageReady({ el: currentPage });
|
|
51
|
-
return finish;
|
|
52
|
-
}
|
|
1
|
+
// Framework7 and Capacitor stay owned by the consuming app; no extra dependency.
|
|
2
|
+
const registrations = new WeakMap();
|
|
3
|
+
|
|
4
|
+
export function hideSplashWhenReady({ f7, hide, imageSelector = '[data-splash-ready], .t-film-art img', timeout = 8000 }) {
|
|
5
|
+
if (!f7 || typeof f7.on !== 'function' || typeof f7.off !== 'function' || typeof hide !== 'function') {
|
|
6
|
+
throw new TypeError('Splash readiness requires Framework7 and a hide callback.');
|
|
7
|
+
}
|
|
8
|
+
if (!Number.isInteger(timeout) || timeout < 1 || timeout > 60000) throw new TypeError('Invalid splash readiness timeout.');
|
|
9
|
+
if (typeof imageSelector !== 'string') throw new TypeError('Invalid splash image selector.');
|
|
10
|
+
if (registrations.has(f7)) return registrations.get(f7);
|
|
11
|
+
let finished = false;
|
|
12
|
+
let preparing = false;
|
|
13
|
+
let image;
|
|
14
|
+
const detachImage = () => {
|
|
15
|
+
image?.removeEventListener('load', onImageReady);
|
|
16
|
+
image?.removeEventListener('error', onImageReady);
|
|
17
|
+
};
|
|
18
|
+
const finish = () => {
|
|
19
|
+
if (finished) return;
|
|
20
|
+
finished = true;
|
|
21
|
+
clearTimeout(fallback);
|
|
22
|
+
f7.off('pageAfterIn', onPageReady);
|
|
23
|
+
detachImage();
|
|
24
|
+
// Plugin availability differs by platform; failed native hiding must not
|
|
25
|
+
// create an unhandled rejection. The native launch timeout is the backup.
|
|
26
|
+
try { Promise.resolve(hide()).catch(() => {}); } catch {}
|
|
27
|
+
};
|
|
28
|
+
const onImageReady = () => {
|
|
29
|
+
if (finished) return;
|
|
30
|
+
detachImage();
|
|
31
|
+
if (image.naturalWidth > 0 && typeof image.decode === 'function') {
|
|
32
|
+
Promise.resolve().then(() => image.decode()).catch(() => {}).then(finish);
|
|
33
|
+
} else finish();
|
|
34
|
+
};
|
|
35
|
+
const onPageReady = page => {
|
|
36
|
+
if (finished || preparing || !page?.el?.closest('.view-main')) return;
|
|
37
|
+
preparing = true;
|
|
38
|
+
try { image = imageSelector ? page.el.querySelector(imageSelector) : null; } catch { finish(); return; }
|
|
39
|
+
if (!image) finish();
|
|
40
|
+
else if (image.complete) onImageReady();
|
|
41
|
+
else {
|
|
42
|
+
image.addEventListener('load', onImageReady, { once: true });
|
|
43
|
+
image.addEventListener('error', onImageReady, { once: true });
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const fallback = setTimeout(finish, timeout);
|
|
47
|
+
registrations.set(f7, finish);
|
|
48
|
+
f7.on('pageAfterIn', onPageReady);
|
|
49
|
+
const currentPage = f7.views?.main?.router?.currentPageEl;
|
|
50
|
+
if (currentPage) onPageReady({ el: currentPage });
|
|
51
|
+
return finish;
|
|
52
|
+
}
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
const { test } = require('node:test');
|
|
2
|
-
const assert = require('node:assert/strict');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const os = require('os');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const { ensureCurrentBuild } = require('../files/buildCodeplay/ensure-current-build.cjs');
|
|
7
|
-
const { removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
|
|
8
|
-
|
|
9
|
-
function fixture(t, names = []) {
|
|
10
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'codeplay-legacy-build-'));
|
|
11
|
-
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
12
|
-
fs.mkdirSync(path.join(root, 'buildCodeplay'));
|
|
13
|
-
for (const name of ['codeplayBeforeBuild.js', ...names]) fs.writeFileSync(path.join(root, 'buildCodeplay', name), '');
|
|
14
|
-
return root;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
test('current structure continues without npm commands', t => {
|
|
18
|
-
const projectRoot = fixture(t, ['versions.json', 'custom-helper.js']);
|
|
19
|
-
assert.equal(ensureCurrentBuild({ projectRoot, runNpm: () => assert.fail('unexpected npm command') }), false);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('legacy files force ordered reinstall and fresh preparation before continuing', t => {
|
|
23
|
-
const projectRoot = fixture(t, ['codeplayBeforeBuild-6.7.js', 'setSplashAnimation-1.2.mjs']);
|
|
24
|
-
const calls = [];
|
|
25
|
-
assert.equal(ensureCurrentBuild({
|
|
26
|
-
projectRoot,
|
|
27
|
-
runNpm(command) {
|
|
28
|
-
calls.push(command);
|
|
29
|
-
if (command === 'npm install codeplay-common') removeVersionedBuildScripts(projectRoot);
|
|
30
|
-
},
|
|
31
|
-
runBeforeBuild(script) {
|
|
32
|
-
assert.equal(script, path.join(projectRoot, 'buildCodeplay', 'codeplayBeforeBuild.js'));
|
|
33
|
-
calls.push('fresh preparation');
|
|
34
|
-
},
|
|
35
|
-
}), true);
|
|
36
|
-
assert.deepEqual(calls, ['npm uninstall codeplay-common', 'npm install codeplay-common', 'fresh preparation']);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
for (const failedCommand of ['npm uninstall codeplay-common', 'npm install codeplay-common']) {
|
|
40
|
-
test(`failure of ${failedCommand} stops preparation`, t => {
|
|
41
|
-
const projectRoot = fixture(t, ['add-splash-screen-1.0.js']);
|
|
42
|
-
const calls = [];
|
|
43
|
-
assert.throws(() => ensureCurrentBuild({
|
|
44
|
-
projectRoot,
|
|
45
|
-
runNpm(command) {
|
|
46
|
-
calls.push(command);
|
|
47
|
-
if (command === failedCommand) throw new Error('npm failed');
|
|
48
|
-
},
|
|
49
|
-
runBeforeBuild: () => assert.fail('must not continue'),
|
|
50
|
-
}), /npm failed/);
|
|
51
|
-
assert.equal(calls.at(-1), failedCommand);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
test('unknown versioned files trigger reinstall but stop without deleting app files or looping', t => {
|
|
56
|
-
const projectRoot = fixture(t, ['custom-helper-1.0.js']);
|
|
57
|
-
const calls = [];
|
|
58
|
-
assert.throws(() => ensureCurrentBuild({
|
|
59
|
-
projectRoot,
|
|
60
|
-
runNpm: command => calls.push(command),
|
|
61
|
-
runBeforeBuild: () => assert.fail('must not continue'),
|
|
62
|
-
}), /Legacy buildCodeplay files remain/);
|
|
63
|
-
assert.deepEqual(calls, ['npm uninstall codeplay-common', 'npm install codeplay-common']);
|
|
64
|
-
assert.ok(fs.existsSync(path.join(projectRoot, 'buildCodeplay', 'custom-helper-1.0.js')));
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('failed refreshed preparation propagates to stop the build', t => {
|
|
68
|
-
const projectRoot = fixture(t, ['packageidBaseModification-1.0.js']);
|
|
69
|
-
assert.throws(() => ensureCurrentBuild({
|
|
70
|
-
projectRoot,
|
|
71
|
-
runNpm(command) {
|
|
72
|
-
if (command === 'npm install codeplay-common') removeVersionedBuildScripts(projectRoot);
|
|
73
|
-
},
|
|
74
|
-
runBeforeBuild() { throw Object.assign(new Error('preparation failed'), { status: 7 }); },
|
|
75
|
-
}), { message: 'preparation failed', status: 7 });
|
|
76
|
-
});
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { ensureCurrentBuild } = require('../files/buildCodeplay/ensure-current-build.cjs');
|
|
7
|
+
const { removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
|
|
8
|
+
|
|
9
|
+
function fixture(t, names = []) {
|
|
10
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'codeplay-legacy-build-'));
|
|
11
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
|
|
12
|
+
fs.mkdirSync(path.join(root, 'buildCodeplay'));
|
|
13
|
+
for (const name of ['codeplayBeforeBuild.js', ...names]) fs.writeFileSync(path.join(root, 'buildCodeplay', name), '');
|
|
14
|
+
return root;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test('current structure continues without npm commands', t => {
|
|
18
|
+
const projectRoot = fixture(t, ['versions.json', 'custom-helper.js']);
|
|
19
|
+
assert.equal(ensureCurrentBuild({ projectRoot, runNpm: () => assert.fail('unexpected npm command') }), false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('legacy files force ordered reinstall and fresh preparation before continuing', t => {
|
|
23
|
+
const projectRoot = fixture(t, ['codeplayBeforeBuild-6.7.js', 'setSplashAnimation-1.2.mjs']);
|
|
24
|
+
const calls = [];
|
|
25
|
+
assert.equal(ensureCurrentBuild({
|
|
26
|
+
projectRoot,
|
|
27
|
+
runNpm(command) {
|
|
28
|
+
calls.push(command);
|
|
29
|
+
if (command === 'npm install codeplay-common') removeVersionedBuildScripts(projectRoot);
|
|
30
|
+
},
|
|
31
|
+
runBeforeBuild(script) {
|
|
32
|
+
assert.equal(script, path.join(projectRoot, 'buildCodeplay', 'codeplayBeforeBuild.js'));
|
|
33
|
+
calls.push('fresh preparation');
|
|
34
|
+
},
|
|
35
|
+
}), true);
|
|
36
|
+
assert.deepEqual(calls, ['npm uninstall codeplay-common', 'npm install codeplay-common', 'fresh preparation']);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
for (const failedCommand of ['npm uninstall codeplay-common', 'npm install codeplay-common']) {
|
|
40
|
+
test(`failure of ${failedCommand} stops preparation`, t => {
|
|
41
|
+
const projectRoot = fixture(t, ['add-splash-screen-1.0.js']);
|
|
42
|
+
const calls = [];
|
|
43
|
+
assert.throws(() => ensureCurrentBuild({
|
|
44
|
+
projectRoot,
|
|
45
|
+
runNpm(command) {
|
|
46
|
+
calls.push(command);
|
|
47
|
+
if (command === failedCommand) throw new Error('npm failed');
|
|
48
|
+
},
|
|
49
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
50
|
+
}), /npm failed/);
|
|
51
|
+
assert.equal(calls.at(-1), failedCommand);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
test('unknown versioned files trigger reinstall but stop without deleting app files or looping', t => {
|
|
56
|
+
const projectRoot = fixture(t, ['custom-helper-1.0.js']);
|
|
57
|
+
const calls = [];
|
|
58
|
+
assert.throws(() => ensureCurrentBuild({
|
|
59
|
+
projectRoot,
|
|
60
|
+
runNpm: command => calls.push(command),
|
|
61
|
+
runBeforeBuild: () => assert.fail('must not continue'),
|
|
62
|
+
}), /Legacy buildCodeplay files remain/);
|
|
63
|
+
assert.deepEqual(calls, ['npm uninstall codeplay-common', 'npm install codeplay-common']);
|
|
64
|
+
assert.ok(fs.existsSync(path.join(projectRoot, 'buildCodeplay', 'custom-helper-1.0.js')));
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('failed refreshed preparation propagates to stop the build', t => {
|
|
68
|
+
const projectRoot = fixture(t, ['packageidBaseModification-1.0.js']);
|
|
69
|
+
assert.throws(() => ensureCurrentBuild({
|
|
70
|
+
projectRoot,
|
|
71
|
+
runNpm(command) {
|
|
72
|
+
if (command === 'npm install codeplay-common') removeVersionedBuildScripts(projectRoot);
|
|
73
|
+
},
|
|
74
|
+
runBeforeBuild() { throw Object.assign(new Error('preparation failed'), { status: 7 }); },
|
|
75
|
+
}), { message: 'preparation failed', status: 7 });
|
|
76
|
+
});
|
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
const { test } = require('node:test');
|
|
2
|
-
const assert = require('node:assert/strict');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { execFileSync } = require('child_process');
|
|
6
|
-
const { readSplashOptions, migrateSplashTheme, migrateReadinessSource, syncSplashSetup } = require('../files/buildCodeplay/splash-setup.cjs');
|
|
7
|
-
|
|
8
|
-
function fixture(t) {
|
|
9
|
-
const base = path.resolve(process.env.CODEPLAY_TEST_ROOT || path.join(__dirname, '../agent-temp'));
|
|
10
|
-
fs.mkdirSync(base, { recursive: true });
|
|
11
|
-
const root = fs.mkdtempSync(path.join(base, 'splash-'));
|
|
12
|
-
t.after(() => {
|
|
13
|
-
if (path.dirname(path.resolve(root)) !== base) throw new Error('Unsafe fixture cleanup');
|
|
14
|
-
fs.rmSync(root, { recursive: true, force: true });
|
|
15
|
-
});
|
|
16
|
-
return root;
|
|
17
|
-
}
|
|
18
|
-
const legacy = `var capacitorApp = {
|
|
19
|
-
handleSplashscreen: function () {
|
|
20
|
-
if (!window.Capacitor) return;
|
|
21
|
-
setTimeout(() => { if (window.Capacitor.Plugins?.SplashScreen) window.Capacitor.Plugins.SplashScreen.hide(); }, 2000);
|
|
22
|
-
},
|
|
23
|
-
};`;
|
|
24
|
-
const options = readSplashOptions({ plugins: { CodeplaySplashScreen: { migrateLegacyReadiness: true } } });
|
|
25
|
-
|
|
26
|
-
test('duration defaults to1000 and preserves explicit0;invalid values fail', () => {
|
|
27
|
-
assert.equal(readSplashOptions({}).duration, 1000);
|
|
28
|
-
assert.equal(readSplashOptions({ plugins: { CodeplaySplashScreen: { exitAnimationDuration: 0 } } }).duration, 0);
|
|
29
|
-
for (const duration of [-1, '0', 1.5, 10001]) assert.throws(() => readSplashOptions({ plugins: { CodeplaySplashScreen: { exitAnimationDuration: duration } } }));
|
|
30
|
-
});
|
|
31
|
-
test('repair known legacy theme,idempotently preserve app-specific themes', () => {
|
|
32
|
-
const before = '<item name="postSplashScreenTheme">@style/Theme.AppCompat.NoActionBar</item>';
|
|
33
|
-
const after = migrateSplashTheme(before);
|
|
34
|
-
assert.ok(after.includes('Theme.AppCompat.DayNight.NoActionBar'));
|
|
35
|
-
assert.equal(migrateSplashTheme(after), after);
|
|
36
|
-
assert.equal(migrateSplashTheme(before.replace('Theme.AppCompat.NoActionBar', 'MyCustomTheme')), before.replace('Theme.AppCompat.NoActionBar', 'MyCustomTheme'));
|
|
37
|
-
});
|
|
38
|
-
test('legacy handler migration requires opt-in,is idempotent,and preserves custom handlers', () => {
|
|
39
|
-
assert.equal(migrateReadinessSource(legacy, readSplashOptions({})).source, legacy);
|
|
40
|
-
const migrated = migrateReadinessSource(legacy, options);
|
|
41
|
-
assert.equal(migrated.status, 'managed');
|
|
42
|
-
assert.equal(migrateReadinessSource(migrated.source, options).source, migrated.source);
|
|
43
|
-
const custom = migrated.source.replace(' if (!window.Capacitor)', ' customStartup();\n if (!window.Capacitor)');
|
|
44
|
-
assert.equal(migrateReadinessSource(custom, options).source, custom);
|
|
45
|
-
const customAfter = migrated.source.replace(' });', ' });\n customStartup();');
|
|
46
|
-
assert.equal(migrateReadinessSource(customAfter, options).source, customAfter);
|
|
47
|
-
});
|
|
48
|
-
test('migration keeps legacy native-disabled config and custom theme intact', t => {
|
|
49
|
-
const root = fixture(t);
|
|
50
|
-
fs.mkdirSync(path.join(root, 'src/js'), { recursive: true });
|
|
51
|
-
fs.mkdirSync(path.join(root, 'buildCodeplay/splashxml'), { recursive: true });
|
|
52
|
-
fs.writeFileSync(path.join(root, 'src/js/capacitor-app.js'), legacy);
|
|
53
|
-
fs.writeFileSync(path.join(root, 'buildCodeplay/splashxml/codeplay_splashScreen.xml'), '<item name="postSplashScreenTheme">@style/Custom</item>');
|
|
54
|
-
fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify({ plugins: { SplashScreen: { launchShowDuration: 0 }, CodeplaySplashScreen: { migrateLegacyReadiness: true } } }));
|
|
55
|
-
const log = [];
|
|
56
|
-
syncSplashSetup(root, { log: value => log.push(value) });
|
|
57
|
-
assert.equal(fs.readFileSync(path.join(root, 'src/js/capacitor-app.js'), 'utf8'), legacy);
|
|
58
|
-
assert.ok(log.some(value => value.includes('native fallback')));
|
|
59
|
-
});
|
|
60
|
-
test('generator emits0ms without changing launchShowDuration', t => {
|
|
61
|
-
const root = fixture(t);
|
|
62
|
-
const java = path.join(root, 'android/app/src/main/java/example/app/MainActivity.java');
|
|
63
|
-
fs.mkdirSync(path.dirname(java), { recursive: true });
|
|
64
|
-
fs.writeFileSync(java, 'package example.app;');
|
|
65
|
-
const config = { appId: 'example.app', plugins: { SplashScreen: { launchShowDuration: 8000 }, CodeplaySplashScreen: { exitAnimationDuration: 0 } } };
|
|
66
|
-
fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify(config));
|
|
67
|
-
execFileSync(process.execPath, [path.resolve(__dirname, '../files/buildCodeplay/setSplashAnimation.js')], { cwd: root, stdio: 'pipe' });
|
|
68
|
-
assert.ok(fs.readFileSync(java, 'utf8').includes('.setDuration(0)'));
|
|
69
|
-
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(root, 'capacitor.config.json'))), config);
|
|
70
|
-
});
|
|
71
|
-
test('complete migration requires fallback and plugin dependency;repeat preparation is stable', t => {
|
|
72
|
-
const root = fixture(t);
|
|
73
|
-
fs.mkdirSync(path.join(root, 'src/js'), { recursive: true });
|
|
74
|
-
const app = path.join(root, 'src/js/capacitor-app.js');
|
|
75
|
-
fs.writeFileSync(app, legacy);
|
|
76
|
-
const config = { plugins: { SplashScreen: { launchShowDuration: 8000, launchAutoHide: true }, CodeplaySplashScreen: { migrateLegacyReadiness: true } } };
|
|
77
|
-
fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify(config));
|
|
78
|
-
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ dependencies: {} }));
|
|
79
|
-
syncSplashSetup(root, { log() {} });
|
|
80
|
-
assert.equal(fs.readFileSync(app, 'utf8'), legacy);
|
|
81
|
-
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ dependencies: { '@capacitor/splash-screen': '^8.0.0' } }));
|
|
82
|
-
syncSplashSetup(root, { log() {} });
|
|
83
|
-
const result = fs.readFileSync(app, 'utf8');
|
|
84
|
-
assert.ok(result.includes('return hideSplashWhenReady('));
|
|
85
|
-
syncSplashSetup(root, { log() {} });
|
|
86
|
-
assert.equal(fs.readFileSync(app, 'utf8'), result);
|
|
87
|
-
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(root, 'capacitor.config.json'))), config);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
function framework(image, cached = false) {
|
|
91
|
-
const handlers = new Map();
|
|
92
|
-
const page = { closest: () => true, querySelector: () => image };
|
|
93
|
-
return { page, handlers, f7: { on: (name, fn) => handlers.set(name, fn), off: name => handlers.delete(name), views: { main: { router: { currentPageEl: cached ? page : null } } } } };
|
|
94
|
-
}
|
|
95
|
-
test('wait for main-page image decode,hide once,and detach listeners', async () => {
|
|
96
|
-
const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
|
|
97
|
-
let decoded, count = 0;
|
|
98
|
-
const listeners = new Map();
|
|
99
|
-
const image = { complete: false, naturalWidth: 100, decode: () => new Promise(resolve => { decoded = resolve; }), addEventListener: (name, fn) => listeners.set(name, fn), removeEventListener: name => listeners.delete(name) };
|
|
100
|
-
const { f7, handlers, page } = framework(image);
|
|
101
|
-
const finish = hideSplashWhenReady({ f7, hide: () => { count++; } });
|
|
102
|
-
handlers.get('pageAfterIn')({ el: { closest: () => false } });
|
|
103
|
-
assert.equal(count, 0);
|
|
104
|
-
handlers.get('pageAfterIn')({ el: page });
|
|
105
|
-
listeners.get('load')();
|
|
106
|
-
await Promise.resolve();
|
|
107
|
-
assert.equal(count, 0);
|
|
108
|
-
decoded();
|
|
109
|
-
await new Promise(resolve => setImmediate(resolve));
|
|
110
|
-
finish();
|
|
111
|
-
assert.equal(count, 1);
|
|
112
|
-
assert.equal(handlers.size, 0);
|
|
113
|
-
assert.equal(listeners.size, 0);
|
|
114
|
-
});
|
|
115
|
-
test('cached page without hero hides immediately and repeated setup is safe', async () => {
|
|
116
|
-
const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
|
|
117
|
-
const { f7 } = framework(null, true);
|
|
118
|
-
let count = 0;
|
|
119
|
-
hideSplashWhenReady({ f7, hide: () => { count++; } });
|
|
120
|
-
hideSplashWhenReady({ f7, hide: () => { count++; } });
|
|
121
|
-
assert.equal(count, 1);
|
|
122
|
-
});
|
|
123
|
-
test('broken image and failed decode release splash', async () => {
|
|
124
|
-
const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
|
|
125
|
-
for (const naturalWidth of [0, 100]) {
|
|
126
|
-
let count = 0;
|
|
127
|
-
const image = { complete: true, naturalWidth, decode: () => Promise.reject(new Error('decode failed')), removeEventListener() {} };
|
|
128
|
-
const { f7 } = framework(image, true);
|
|
129
|
-
hideSplashWhenReady({ f7, hide: () => { count++; } });
|
|
130
|
-
await new Promise(resolve => setImmediate(resolve));
|
|
131
|
-
assert.equal(count, 1);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
test('timeout releases stuck page and consumes native plugin rejection', async () => {
|
|
135
|
-
const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
|
|
136
|
-
const { f7, handlers } = framework(null);
|
|
137
|
-
let count = 0;
|
|
138
|
-
hideSplashWhenReady({ f7, timeout: 10, hide: () => { count++; return Promise.reject(new Error('native unavailable')); } });
|
|
139
|
-
await new Promise(resolve => setTimeout(resolve, 30));
|
|
140
|
-
assert.equal(count, 1);
|
|
141
|
-
assert.equal(handlers.size, 0);
|
|
142
|
-
});
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { execFileSync } = require('child_process');
|
|
6
|
+
const { readSplashOptions, migrateSplashTheme, migrateReadinessSource, syncSplashSetup } = require('../files/buildCodeplay/splash-setup.cjs');
|
|
7
|
+
|
|
8
|
+
function fixture(t) {
|
|
9
|
+
const base = path.resolve(process.env.CODEPLAY_TEST_ROOT || path.join(__dirname, '../agent-temp'));
|
|
10
|
+
fs.mkdirSync(base, { recursive: true });
|
|
11
|
+
const root = fs.mkdtempSync(path.join(base, 'splash-'));
|
|
12
|
+
t.after(() => {
|
|
13
|
+
if (path.dirname(path.resolve(root)) !== base) throw new Error('Unsafe fixture cleanup');
|
|
14
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
15
|
+
});
|
|
16
|
+
return root;
|
|
17
|
+
}
|
|
18
|
+
const legacy = `var capacitorApp = {
|
|
19
|
+
handleSplashscreen: function () {
|
|
20
|
+
if (!window.Capacitor) return;
|
|
21
|
+
setTimeout(() => { if (window.Capacitor.Plugins?.SplashScreen) window.Capacitor.Plugins.SplashScreen.hide(); }, 2000);
|
|
22
|
+
},
|
|
23
|
+
};`;
|
|
24
|
+
const options = readSplashOptions({ plugins: { CodeplaySplashScreen: { migrateLegacyReadiness: true } } });
|
|
25
|
+
|
|
26
|
+
test('duration defaults to1000 and preserves explicit0;invalid values fail', () => {
|
|
27
|
+
assert.equal(readSplashOptions({}).duration, 1000);
|
|
28
|
+
assert.equal(readSplashOptions({ plugins: { CodeplaySplashScreen: { exitAnimationDuration: 0 } } }).duration, 0);
|
|
29
|
+
for (const duration of [-1, '0', 1.5, 10001]) assert.throws(() => readSplashOptions({ plugins: { CodeplaySplashScreen: { exitAnimationDuration: duration } } }));
|
|
30
|
+
});
|
|
31
|
+
test('repair known legacy theme,idempotently preserve app-specific themes', () => {
|
|
32
|
+
const before = '<item name="postSplashScreenTheme">@style/Theme.AppCompat.NoActionBar</item>';
|
|
33
|
+
const after = migrateSplashTheme(before);
|
|
34
|
+
assert.ok(after.includes('Theme.AppCompat.DayNight.NoActionBar'));
|
|
35
|
+
assert.equal(migrateSplashTheme(after), after);
|
|
36
|
+
assert.equal(migrateSplashTheme(before.replace('Theme.AppCompat.NoActionBar', 'MyCustomTheme')), before.replace('Theme.AppCompat.NoActionBar', 'MyCustomTheme'));
|
|
37
|
+
});
|
|
38
|
+
test('legacy handler migration requires opt-in,is idempotent,and preserves custom handlers', () => {
|
|
39
|
+
assert.equal(migrateReadinessSource(legacy, readSplashOptions({})).source, legacy);
|
|
40
|
+
const migrated = migrateReadinessSource(legacy, options);
|
|
41
|
+
assert.equal(migrated.status, 'managed');
|
|
42
|
+
assert.equal(migrateReadinessSource(migrated.source, options).source, migrated.source);
|
|
43
|
+
const custom = migrated.source.replace(' if (!window.Capacitor)', ' customStartup();\n if (!window.Capacitor)');
|
|
44
|
+
assert.equal(migrateReadinessSource(custom, options).source, custom);
|
|
45
|
+
const customAfter = migrated.source.replace(' });', ' });\n customStartup();');
|
|
46
|
+
assert.equal(migrateReadinessSource(customAfter, options).source, customAfter);
|
|
47
|
+
});
|
|
48
|
+
test('migration keeps legacy native-disabled config and custom theme intact', t => {
|
|
49
|
+
const root = fixture(t);
|
|
50
|
+
fs.mkdirSync(path.join(root, 'src/js'), { recursive: true });
|
|
51
|
+
fs.mkdirSync(path.join(root, 'buildCodeplay/splashxml'), { recursive: true });
|
|
52
|
+
fs.writeFileSync(path.join(root, 'src/js/capacitor-app.js'), legacy);
|
|
53
|
+
fs.writeFileSync(path.join(root, 'buildCodeplay/splashxml/codeplay_splashScreen.xml'), '<item name="postSplashScreenTheme">@style/Custom</item>');
|
|
54
|
+
fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify({ plugins: { SplashScreen: { launchShowDuration: 0 }, CodeplaySplashScreen: { migrateLegacyReadiness: true } } }));
|
|
55
|
+
const log = [];
|
|
56
|
+
syncSplashSetup(root, { log: value => log.push(value) });
|
|
57
|
+
assert.equal(fs.readFileSync(path.join(root, 'src/js/capacitor-app.js'), 'utf8'), legacy);
|
|
58
|
+
assert.ok(log.some(value => value.includes('native fallback')));
|
|
59
|
+
});
|
|
60
|
+
test('generator emits0ms without changing launchShowDuration', t => {
|
|
61
|
+
const root = fixture(t);
|
|
62
|
+
const java = path.join(root, 'android/app/src/main/java/example/app/MainActivity.java');
|
|
63
|
+
fs.mkdirSync(path.dirname(java), { recursive: true });
|
|
64
|
+
fs.writeFileSync(java, 'package example.app;');
|
|
65
|
+
const config = { appId: 'example.app', plugins: { SplashScreen: { launchShowDuration: 8000 }, CodeplaySplashScreen: { exitAnimationDuration: 0 } } };
|
|
66
|
+
fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify(config));
|
|
67
|
+
execFileSync(process.execPath, [path.resolve(__dirname, '../files/buildCodeplay/setSplashAnimation.js')], { cwd: root, stdio: 'pipe' });
|
|
68
|
+
assert.ok(fs.readFileSync(java, 'utf8').includes('.setDuration(0)'));
|
|
69
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(root, 'capacitor.config.json'))), config);
|
|
70
|
+
});
|
|
71
|
+
test('complete migration requires fallback and plugin dependency;repeat preparation is stable', t => {
|
|
72
|
+
const root = fixture(t);
|
|
73
|
+
fs.mkdirSync(path.join(root, 'src/js'), { recursive: true });
|
|
74
|
+
const app = path.join(root, 'src/js/capacitor-app.js');
|
|
75
|
+
fs.writeFileSync(app, legacy);
|
|
76
|
+
const config = { plugins: { SplashScreen: { launchShowDuration: 8000, launchAutoHide: true }, CodeplaySplashScreen: { migrateLegacyReadiness: true } } };
|
|
77
|
+
fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify(config));
|
|
78
|
+
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ dependencies: {} }));
|
|
79
|
+
syncSplashSetup(root, { log() {} });
|
|
80
|
+
assert.equal(fs.readFileSync(app, 'utf8'), legacy);
|
|
81
|
+
fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ dependencies: { '@capacitor/splash-screen': '^8.0.0' } }));
|
|
82
|
+
syncSplashSetup(root, { log() {} });
|
|
83
|
+
const result = fs.readFileSync(app, 'utf8');
|
|
84
|
+
assert.ok(result.includes('return hideSplashWhenReady('));
|
|
85
|
+
syncSplashSetup(root, { log() {} });
|
|
86
|
+
assert.equal(fs.readFileSync(app, 'utf8'), result);
|
|
87
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(root, 'capacitor.config.json'))), config);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
function framework(image, cached = false) {
|
|
91
|
+
const handlers = new Map();
|
|
92
|
+
const page = { closest: () => true, querySelector: () => image };
|
|
93
|
+
return { page, handlers, f7: { on: (name, fn) => handlers.set(name, fn), off: name => handlers.delete(name), views: { main: { router: { currentPageEl: cached ? page : null } } } } };
|
|
94
|
+
}
|
|
95
|
+
test('wait for main-page image decode,hide once,and detach listeners', async () => {
|
|
96
|
+
const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
|
|
97
|
+
let decoded, count = 0;
|
|
98
|
+
const listeners = new Map();
|
|
99
|
+
const image = { complete: false, naturalWidth: 100, decode: () => new Promise(resolve => { decoded = resolve; }), addEventListener: (name, fn) => listeners.set(name, fn), removeEventListener: name => listeners.delete(name) };
|
|
100
|
+
const { f7, handlers, page } = framework(image);
|
|
101
|
+
const finish = hideSplashWhenReady({ f7, hide: () => { count++; } });
|
|
102
|
+
handlers.get('pageAfterIn')({ el: { closest: () => false } });
|
|
103
|
+
assert.equal(count, 0);
|
|
104
|
+
handlers.get('pageAfterIn')({ el: page });
|
|
105
|
+
listeners.get('load')();
|
|
106
|
+
await Promise.resolve();
|
|
107
|
+
assert.equal(count, 0);
|
|
108
|
+
decoded();
|
|
109
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
110
|
+
finish();
|
|
111
|
+
assert.equal(count, 1);
|
|
112
|
+
assert.equal(handlers.size, 0);
|
|
113
|
+
assert.equal(listeners.size, 0);
|
|
114
|
+
});
|
|
115
|
+
test('cached page without hero hides immediately and repeated setup is safe', async () => {
|
|
116
|
+
const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
|
|
117
|
+
const { f7 } = framework(null, true);
|
|
118
|
+
let count = 0;
|
|
119
|
+
hideSplashWhenReady({ f7, hide: () => { count++; } });
|
|
120
|
+
hideSplashWhenReady({ f7, hide: () => { count++; } });
|
|
121
|
+
assert.equal(count, 1);
|
|
122
|
+
});
|
|
123
|
+
test('broken image and failed decode release splash', async () => {
|
|
124
|
+
const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
|
|
125
|
+
for (const naturalWidth of [0, 100]) {
|
|
126
|
+
let count = 0;
|
|
127
|
+
const image = { complete: true, naturalWidth, decode: () => Promise.reject(new Error('decode failed')), removeEventListener() {} };
|
|
128
|
+
const { f7 } = framework(image, true);
|
|
129
|
+
hideSplashWhenReady({ f7, hide: () => { count++; } });
|
|
130
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
131
|
+
assert.equal(count, 1);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
test('timeout releases stuck page and consumes native plugin rejection', async () => {
|
|
135
|
+
const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
|
|
136
|
+
const { f7, handlers } = framework(null);
|
|
137
|
+
let count = 0;
|
|
138
|
+
hideSplashWhenReady({ f7, timeout: 10, hide: () => { count++; return Promise.reject(new Error('native unavailable')); } });
|
|
139
|
+
await new Promise(resolve => setTimeout(resolve, 30));
|
|
140
|
+
assert.equal(count, 1);
|
|
141
|
+
assert.equal(handlers.size, 0);
|
|
142
|
+
});
|
package/scripts/sync-files.js
CHANGED
|
@@ -97,7 +97,7 @@ function install(options = {}) {
|
|
|
97
97
|
fs.cpSync(path.join(commonFiles, name), path.join(projectRoot, name), { recursive: true });
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
require('../files/buildCodeplay/splash-setup.cjs').syncSplashSetup(projectRoot);
|
|
100
|
+
require('../files/buildCodeplay/splash-setup.cjs').syncSplashSetup(projectRoot);
|
|
101
101
|
migrateAppConfigurator(projectRoot);
|
|
102
102
|
syncAndroidR8Rules(projectRoot, { installGradleHook: true });
|
|
103
103
|
pkg.scripts = scripts;
|