@protobase/cli 0.96.6 → 0.96.8
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/dist/cli/package.js +1 -1
- package/dist/mobile/android-splash-image.js +63 -0
- package/dist/mobile/android-splash.js +19 -7
- package/dist/mobile/generate.js +6 -5
- package/dist/mobile/icon-source.js +16 -10
- package/dist/mobile/ios-splash-image.js +61 -0
- package/dist/mobile/ios-splash.js +22 -5
- package/dist/mobile/mobile-config.js +4 -2
- package/dist/mobile/native-splash.js +10 -2
- package/dist/mobile/run.js +12 -2
- package/dist/mobile/splash-backgrounds.js +21 -0
- package/dist/mobile/splash-config.js +31 -0
- package/dist/mobile/splash-image.js +23 -0
- package/package.json +8 -8
- package/skills/protobase/references/features/build-and-run.md +1 -1
- package/skills/protobase/references/guides/mobile-app.md +19 -1
- package/skills/protobase/references/reference/blocks.md +1 -1
- package/skills/protobase/references/reference/config/app.md +2 -1
- package/skills/protobase/references/reference/layouts.md +1 -1
package/dist/cli/package.js
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { densityScales } from "./android-app-icon.js";
|
|
2
|
+
//#region src/mobile/android-splash-image.ts
|
|
3
|
+
const res = "app/src/main/res";
|
|
4
|
+
const side = 288;
|
|
5
|
+
const shown = 192;
|
|
6
|
+
/** The splash image's drawable, which the launch theme names. */
|
|
7
|
+
const androidSplashImageName = "protobase_splash_image";
|
|
8
|
+
/**
|
|
9
|
+
* The splash for the splash screen plugin to show while the app reloads into a live update, as Android 12 and the
|
|
10
|
+
* core-splashscreen library draw the launch: the image at 288dp, masked to its middle 192dp circle by a ring in the
|
|
11
|
+
* background's colour, on that background.
|
|
12
|
+
*/
|
|
13
|
+
const androidSplashImageDrawable = `<?xml version="1.0" encoding="utf-8"?>
|
|
14
|
+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
|
15
|
+
<item android:gravity="fill">
|
|
16
|
+
<color android:color="@color/protobase_splash_background" />
|
|
17
|
+
</item>
|
|
18
|
+
<item
|
|
19
|
+
android:width="${side}dp"
|
|
20
|
+
android:height="${side}dp"
|
|
21
|
+
android:drawable="@drawable/${androidSplashImageName}"
|
|
22
|
+
android:gravity="center" />
|
|
23
|
+
<item
|
|
24
|
+
android:width="408dp"
|
|
25
|
+
android:height="408dp"
|
|
26
|
+
android:gravity="center">
|
|
27
|
+
<shape android:shape="oval">
|
|
28
|
+
<solid android:color="@android:color/transparent" />
|
|
29
|
+
<stroke
|
|
30
|
+
android:width="108dp"
|
|
31
|
+
android:color="@color/protobase_splash_background" />
|
|
32
|
+
</shape>
|
|
33
|
+
</item>
|
|
34
|
+
</layer-list>
|
|
35
|
+
`;
|
|
36
|
+
/**
|
|
37
|
+
* The app's own Android splash image at each density, 288dp, its dark one under `night` beside it when there is one,
|
|
38
|
+
* and the drawable the splash screen plugin shows.
|
|
39
|
+
*/
|
|
40
|
+
const androidSplashImage = async (sharp, light, dark) => {
|
|
41
|
+
const files = [{
|
|
42
|
+
file: `${res}/drawable/protobase_splash.xml`,
|
|
43
|
+
content: androidSplashImageDrawable
|
|
44
|
+
}];
|
|
45
|
+
for (const [density, scale] of Object.entries(densityScales)) {
|
|
46
|
+
const px = side * scale;
|
|
47
|
+
files.push({
|
|
48
|
+
file: `${res}/drawable-${density}/${androidSplashImageName}.png`,
|
|
49
|
+
content: await sharp(light).resize(px, px).png().toBuffer()
|
|
50
|
+
});
|
|
51
|
+
if (dark) files.push({
|
|
52
|
+
file: `${res}/drawable-night-${density}/${androidSplashImageName}.png`,
|
|
53
|
+
content: await sharp(dark).resize(px, px).png().toBuffer()
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return files;
|
|
57
|
+
};
|
|
58
|
+
/** The side of the splash image, in pixels, it is drawn from: 288dp at Android's largest density. */
|
|
59
|
+
const splashSourceSize = side * densityScales.xxxhdpi;
|
|
60
|
+
/** The share of the splash image's side Android shows, in its middle. */
|
|
61
|
+
const shownShare = shown / side;
|
|
62
|
+
//#endregion
|
|
63
|
+
export { androidSplashImage, androidSplashImageDrawable, androidSplashImageName, shownShare, splashSourceSize };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { androidSplashImageName } from "./android-splash-image.js";
|
|
2
|
+
import { copySplashFile, removeTemplateSplash, writeSplashFiles } from "./native-splash.js";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
5
|
//#region src/mobile/android-splash.ts
|
|
@@ -28,10 +29,17 @@ const launchTheme = ` <style name="AppTheme.NoActionBarLaunch" parent="Theme.
|
|
|
28
29
|
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>
|
|
29
30
|
<item name="windowSplashScreenIconBackgroundColor">@color/ic_launcher_background</item>
|
|
30
31
|
</style>`;
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
const imageLaunchTheme = ` <style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">
|
|
33
|
+
<item name="windowSplashScreenBackground">@color/protobase_splash_background</item>
|
|
34
|
+
<item name="windowSplashScreenAnimatedIcon">@drawable/${androidSplashImageName}</item>
|
|
35
|
+
</style>`;
|
|
36
|
+
/**
|
|
37
|
+
* The template's styles.xml with Protobase's launch theme, showing the app's own splash image with `ownImage`; it fails
|
|
38
|
+
* on any other, which may set its own splash.
|
|
39
|
+
*/
|
|
40
|
+
const withLaunchTheme = (styles, ownImage = false) => {
|
|
33
41
|
if (!styles.includes(templateLaunchTheme)) throw new Error("The generated android project's styles.xml is not Capacitor's template: its launch theme is not the one Protobase replaces");
|
|
34
|
-
return styles.replace(templateLaunchTheme, launchTheme);
|
|
42
|
+
return styles.replace(templateLaunchTheme, ownImage ? imageLaunchTheme : launchTheme);
|
|
35
43
|
};
|
|
36
44
|
/** The `protobase_splash_background` colour resource, in values for light mode and values-night for dark. */
|
|
37
45
|
const splashBackgroundResource = (color) => `<?xml version="1.0" encoding="utf-8"?>
|
|
@@ -39,10 +47,13 @@ const splashBackgroundResource = (color) => `<?xml version="1.0" encoding="utf-8
|
|
|
39
47
|
<color name="protobase_splash_background">${color}</color>
|
|
40
48
|
</resources>
|
|
41
49
|
`;
|
|
42
|
-
/**
|
|
43
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Gives the Android project in the workspace Protobase's splash screen on its background, `colors`, in place of
|
|
52
|
+
* Capacitor's: the launcher icon, or the app's own splash image, its `image` files, with them.
|
|
53
|
+
*/
|
|
54
|
+
const withAndroidSplash = async (ws, { light, dark }, image) => {
|
|
44
55
|
const styles = path.join(ws, "android", stylesPath);
|
|
45
|
-
await writeFile(styles, withLaunchTheme(await readFile(styles, "utf8")));
|
|
56
|
+
await writeFile(styles, withLaunchTheme(await readFile(styles, "utf8"), image !== void 0));
|
|
46
57
|
for (const [values, color] of [["values", light], ["values-night", dark]]) {
|
|
47
58
|
const dir = path.join(ws, "android", res, values);
|
|
48
59
|
await mkdir(dir, { recursive: true });
|
|
@@ -50,6 +61,7 @@ const withAndroidSplash = async (ws, { light, dark }) => {
|
|
|
50
61
|
}
|
|
51
62
|
for (const image of templateSplashImages) await removeTemplateSplash(ws, "android", image);
|
|
52
63
|
for (const file of androidSplashFiles) await copySplashFile(ws, "android", file);
|
|
64
|
+
if (image) await writeSplashFiles(ws, "android", image);
|
|
53
65
|
};
|
|
54
66
|
//#endregion
|
|
55
67
|
export { androidSplashFiles, androidSplashLayout, splashBackgroundResource, templateSplashImages, withAndroidSplash, withLaunchTheme };
|
package/dist/mobile/generate.js
CHANGED
|
@@ -16,13 +16,14 @@ const androidManifest = (ws) => path.join(ws, "android", "app", "src", "main", "
|
|
|
16
16
|
/**
|
|
17
17
|
* Generates the platform's native project in the workspace from its capacitor.config.json and app files, replacing
|
|
18
18
|
* the last one: it is never edited by hand. Its home-screen icon is the app's own in `icon`, or Protobase's without
|
|
19
|
-
* one, and its splash screen
|
|
19
|
+
* one, and its splash screen the app's own splash image in `splashImage`, or without one that icon, on the background
|
|
20
|
+
* in `splash`, light and dark, in place of Capacitor's logo. An Android app with push gets the
|
|
20
21
|
* project's google-services.json from `googleServicesFrom`, an iOS app with push its entitlement in `apnsEnvironment` and
|
|
21
22
|
* the token forwarding, and an iOS app calling the API over plain http may reach local addresses. Android apps opt out
|
|
22
23
|
* of backup and device transfer, and iOS apps start as a fresh install after a restore or a move, so nothing carries
|
|
23
24
|
* over to another phone.
|
|
24
25
|
*/
|
|
25
|
-
const generatePlatform = async (ws, platform, { cleartext, splash, icon, googleServicesFrom, apnsEnvironment }, cap) => {
|
|
26
|
+
const generatePlatform = async (ws, platform, { cleartext, splash, splashImage, icon, googleServicesFrom, apnsEnvironment }, cap) => {
|
|
26
27
|
await rm(path.join(ws, platform), {
|
|
27
28
|
recursive: true,
|
|
28
29
|
force: true
|
|
@@ -31,7 +32,7 @@ const generatePlatform = async (ws, platform, { cleartext, splash, icon, googleS
|
|
|
31
32
|
if (icon) await withAppIcon(ws, platform, icon.icon);
|
|
32
33
|
else await withProtobaseIcon(ws, platform);
|
|
33
34
|
if (platform === "android") {
|
|
34
|
-
await withAndroidSplash(ws, splash);
|
|
35
|
+
await withAndroidSplash(ws, splash, splashImage);
|
|
35
36
|
if (googleServicesFrom !== void 0) await copyGoogleServices(googleServicesFrom, ws);
|
|
36
37
|
await writeFile(androidManifest(ws), withoutBackup(await readFile(androidManifest(ws), "utf8")));
|
|
37
38
|
const rules = path.join(ws, "android", ...dataExtractionRulesPath);
|
|
@@ -39,8 +40,8 @@ const generatePlatform = async (ws, platform, { cleartext, splash, icon, googleS
|
|
|
39
40
|
await writeFile(rules, dataExtractionRules);
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
|
-
await withIosSplash(ws, splash);
|
|
43
|
-
if (icon) await writeNativeFiles(ws, "ios", icon.splash, iosSplashImages.map(([file]) => file));
|
|
43
|
+
await withIosSplash(ws, splash, splashImage);
|
|
44
|
+
if (icon && !splashImage) await writeNativeFiles(ws, "ios", icon.splash, iosSplashImages.map(([file]) => file));
|
|
44
45
|
await writeFile(appDelegate(ws), withFreshInstall(await readFile(appDelegate(ws), "utf8")));
|
|
45
46
|
if (apnsEnvironment !== void 0) await setUpIosPush(ws, apnsEnvironment);
|
|
46
47
|
if (!cleartext) return;
|
|
@@ -4,22 +4,28 @@ import path from "node:path";
|
|
|
4
4
|
/** The size every icon is drawn from: the App Store icon's, the largest one. */
|
|
5
5
|
const sourceSize = 1024;
|
|
6
6
|
/**
|
|
7
|
-
* Reads the
|
|
8
|
-
*
|
|
9
|
-
* the
|
|
7
|
+
* Reads the image `file` the setting names from the project's folder `projectDir`: a square PNG of at least `size`
|
|
8
|
+
* pixels, or a square SVG, drawn at that size. Any other file stops the build, naming the setting and the rule, since
|
|
9
|
+
* the platforms would take a wrong one quietly.
|
|
10
10
|
*/
|
|
11
|
-
const
|
|
11
|
+
const readSquareImage = async (sharp, projectDir, file, { setting, noun, size }) => {
|
|
12
12
|
const at = path.resolve(projectDir, file);
|
|
13
|
-
if (!existsSync(at)) throw new Error(
|
|
13
|
+
if (!existsSync(at)) throw new Error(`${setting} names ${file}, which does not exist: ${at}`);
|
|
14
14
|
const { format, width = 0, height = 0 } = await sharp(at).metadata();
|
|
15
|
-
if (format !== "png" && format !== "svg") throw new Error(
|
|
16
|
-
if (width === 0 || width !== height) throw new Error(
|
|
17
|
-
if (format === "png" && width <
|
|
18
|
-
const image = await (format === "svg" ? sharp(at, { density: 72 *
|
|
15
|
+
if (format !== "png" && format !== "svg") throw new Error(`${setting} names ${file}, which is no PNG or SVG: the ${noun} must be a PNG or an SVG`);
|
|
16
|
+
if (width === 0 || width !== height) throw new Error(`${setting} names ${file}, which is ${width}x${height} pixels: the ${noun} must be square`);
|
|
17
|
+
if (format === "png" && width < size) throw new Error(`${setting} names ${file}, which is ${width}x${height} pixels: a PNG ${noun} must be at least ${size}x${size}`);
|
|
18
|
+
const image = await (format === "svg" ? sharp(at, { density: 72 * size / width }) : sharp(at)).resize(size, size).ensureAlpha().png().toBuffer();
|
|
19
19
|
return {
|
|
20
20
|
image,
|
|
21
21
|
opaque: (await sharp(image).stats()).isOpaque
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
|
+
/** Reads the app's icon `file`, `mobile.icon`: a square PNG of at least `sourceSize` pixels, or a square SVG. */
|
|
25
|
+
const readIconSource = (sharp, projectDir, file) => readSquareImage(sharp, projectDir, file, {
|
|
26
|
+
setting: "mobile.icon",
|
|
27
|
+
noun: "icon",
|
|
28
|
+
size: sourceSize
|
|
29
|
+
});
|
|
24
30
|
//#endregion
|
|
25
|
-
export { readIconSource, sourceSize };
|
|
31
|
+
export { readIconSource, readSquareImage, sourceSize };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { shownShare } from "./android-splash-image.js";
|
|
2
|
+
//#region src/mobile/ios-splash-image.ts
|
|
3
|
+
const imageSet = "App/App/Assets.xcassets/Splash.imageset";
|
|
4
|
+
const scales = [
|
|
5
|
+
1,
|
|
6
|
+
2,
|
|
7
|
+
3
|
|
8
|
+
];
|
|
9
|
+
const name = (scale, dark) => `splash${dark ? "-dark" : ""}${scale === 1 ? "" : `@${scale}x`}.png`;
|
|
10
|
+
const entry = (scale, dark) => ({
|
|
11
|
+
...dark && { appearances: [{
|
|
12
|
+
appearance: "luminosity",
|
|
13
|
+
value: "dark"
|
|
14
|
+
}] },
|
|
15
|
+
filename: name(scale, dark),
|
|
16
|
+
idiom: "universal",
|
|
17
|
+
scale: `${scale}x`
|
|
18
|
+
});
|
|
19
|
+
/** The `Splash` image set's Contents.json, with the dark appearance when the app has a dark image. */
|
|
20
|
+
const splashImageContents = (dark) => `${JSON.stringify({
|
|
21
|
+
images: [...scales.map((scale) => entry(scale, false)), ...dark ? scales.map((scale) => entry(scale, true)) : []],
|
|
22
|
+
info: {
|
|
23
|
+
author: "xcode",
|
|
24
|
+
version: 1
|
|
25
|
+
}
|
|
26
|
+
}, null, 2)}\n`;
|
|
27
|
+
const circleMask = (size) => Buffer.from(`<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}"><circle cx="${size / 2}" cy="${size / 2}" r="${size / 2}" fill="#fff"/></svg>`);
|
|
28
|
+
const shownCircle = async (sharp, image, size) => {
|
|
29
|
+
const { width = 0 } = await sharp(image).metadata();
|
|
30
|
+
const kept = Math.round(width * shownShare);
|
|
31
|
+
const left = Math.floor((width - kept) / 2);
|
|
32
|
+
return sharp(image).extract({
|
|
33
|
+
left,
|
|
34
|
+
top: left,
|
|
35
|
+
width: kept,
|
|
36
|
+
height: kept
|
|
37
|
+
}).resize(size, size).ensureAlpha().composite([{
|
|
38
|
+
input: circleMask(size),
|
|
39
|
+
blend: "dest-in"
|
|
40
|
+
}]).png().toBuffer();
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* The app's own iOS splash image, the `Splash` image set: the middle circle of the image Android shows, at 1x, 2x and
|
|
44
|
+
* 3x of `iosSplashImagePoints`, and the dark image's beside it when there is one, so both platforms show the same.
|
|
45
|
+
*/
|
|
46
|
+
const iosSplashImage = async (sharp, light, dark) => {
|
|
47
|
+
const drawn = (image, isDark) => Promise.all(scales.map(async (scale) => ({
|
|
48
|
+
file: `${imageSet}/${name(scale, isDark)}`,
|
|
49
|
+
content: await shownCircle(sharp, image, 192 * scale)
|
|
50
|
+
})));
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
file: `${imageSet}/Contents.json`,
|
|
54
|
+
content: splashImageContents(dark !== void 0)
|
|
55
|
+
},
|
|
56
|
+
...await drawn(light, false),
|
|
57
|
+
...dark ? await drawn(dark, true) : []
|
|
58
|
+
];
|
|
59
|
+
};
|
|
60
|
+
//#endregion
|
|
61
|
+
export { iosSplashImage, splashImageContents };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { copySplashFile, removeTemplateSplash } from "./native-splash.js";
|
|
1
|
+
import { copySplashFile, removeTemplateSplash, writeSplashFiles } from "./native-splash.js";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
//#region src/mobile/ios-splash.ts
|
|
5
5
|
const assets = "App/App/Assets.xcassets";
|
|
6
6
|
/**
|
|
@@ -39,8 +39,21 @@ const splashBackgroundContents = ({ light, dark }) => `${JSON.stringify({
|
|
|
39
39
|
version: 1
|
|
40
40
|
}
|
|
41
41
|
}, null, 2)}\n`;
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const iconSize = ["constant=\"128\"", "width=\"128\" height=\"128\""];
|
|
43
|
+
/** Protobase's launch storyboard with the `Splash` image drawn at `points`; it fails on any other storyboard. */
|
|
44
|
+
const withSplashImageSize = (storyboard, points) => {
|
|
45
|
+
let sized = storyboard;
|
|
46
|
+
for (const size of iconSize) {
|
|
47
|
+
if (sized.split(size).length !== 3) throw new Error("@protobase/mobile's LaunchScreen.storyboard does not draw the Splash image at 128 points, the size Protobase replaces");
|
|
48
|
+
sized = sized.replaceAll(size, size.replaceAll("128", String(points)));
|
|
49
|
+
}
|
|
50
|
+
return sized;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Gives the iOS project in the workspace Protobase's launch screen on its background, `colors`, in place of
|
|
54
|
+
* Capacitor's: the app's icon, or the app's own splash image, its `image` files, with them.
|
|
55
|
+
*/
|
|
56
|
+
const withIosSplash = async (ws, colors, image) => {
|
|
44
57
|
for (const file of iosSplashFiles) {
|
|
45
58
|
await removeTemplateSplash(ws, "ios", file);
|
|
46
59
|
await copySplashFile(ws, "ios", file);
|
|
@@ -48,6 +61,10 @@ const withIosSplash = async (ws, colors) => {
|
|
|
48
61
|
const set = path.join(ws, "ios", splashBackgroundSet);
|
|
49
62
|
await mkdir(set, { recursive: true });
|
|
50
63
|
await writeFile(path.join(set, "Contents.json"), splashBackgroundContents(colors));
|
|
64
|
+
if (!image) return;
|
|
65
|
+
await writeSplashFiles(ws, "ios", image);
|
|
66
|
+
const storyboard = path.join(ws, "ios", iosSplashFiles[0]);
|
|
67
|
+
await writeFile(storyboard, withSplashImageSize(await readFile(storyboard, "utf8"), 192));
|
|
51
68
|
};
|
|
52
69
|
//#endregion
|
|
53
|
-
export { iosSplashFiles, splashBackgroundContents, splashBackgroundSet, withIosSplash };
|
|
70
|
+
export { iosSplashFiles, splashBackgroundContents, splashBackgroundSet, withIosSplash, withSplashImageSize };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { appIdProblem, isAppId } from "./app-id.js";
|
|
2
2
|
import { packageNameProblem } from "./package-name.js";
|
|
3
3
|
import { pinnedProblem } from "./pinned-packages.js";
|
|
4
|
+
import { checkSplashConfig } from "./splash-config.js";
|
|
4
5
|
import { updaterPublicKey } from "./public-key.js";
|
|
5
6
|
//#region src/mobile/mobile-config.ts
|
|
6
7
|
const noMobileSection = "This project has no mobile section: add `mobile: { appId: 'com.example.app' }` to the default export of protobase.config.ts";
|
|
@@ -10,13 +11,14 @@ const isRecord = (value) => typeof value === "object" && value !== null && !Arra
|
|
|
10
11
|
const checkMobileConfig = (value) => {
|
|
11
12
|
if (value === void 0) throw new Error(noMobileSection);
|
|
12
13
|
if (!isRecord(value)) throw new Error("mobile in protobase.config.ts must be an object such as { appId: 'com.example.app' }");
|
|
13
|
-
const { appId, plugins, publicKey, icon } = value;
|
|
14
|
+
const { appId, plugins, publicKey, icon, splash } = value;
|
|
14
15
|
if (!isAppId(appId)) throw new Error(appIdProblem(appId));
|
|
15
16
|
if (publicKey !== void 0) updaterPublicKey(publicKey);
|
|
16
17
|
if (icon !== void 0 && (typeof icon !== "string" || icon === "")) throw new Error("mobile.icon must be the path of the app's icon from the project's folder, such as 'icon.png'");
|
|
17
18
|
const key = {
|
|
18
19
|
...publicKey !== void 0 && { publicKey },
|
|
19
|
-
...icon !== void 0 && { icon }
|
|
20
|
+
...icon !== void 0 && { icon },
|
|
21
|
+
...splash !== void 0 && { splash: checkSplashConfig(splash) }
|
|
20
22
|
};
|
|
21
23
|
if (plugins === void 0) return {
|
|
22
24
|
appId,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { cp, rm } from "node:fs/promises";
|
|
3
|
+
import { cp, mkdir, rm, writeFile } from "node:fs/promises";
|
|
4
4
|
//#region src/mobile/native-splash.ts
|
|
5
5
|
/** Where @protobase/mobile, installed in the workspace `ws`, has the platform's splash files, by their native project paths. */
|
|
6
6
|
const protobaseSplashDir = (ws, platform) => path.join(ws, "node_modules", "@protobase", "mobile", "splash", platform);
|
|
@@ -19,5 +19,13 @@ const removeTemplateSplash = async (ws, platform, file) => {
|
|
|
19
19
|
if (!existsSync(at)) throw new Error(`The generated ${platform} project has no ${file}, the splash screen Protobase's replaces`);
|
|
20
20
|
await rm(at, { recursive: true });
|
|
21
21
|
};
|
|
22
|
+
/** Writes the app's own splash `files` into the platform's native project in the workspace, over Protobase's. */
|
|
23
|
+
const writeSplashFiles = async (ws, platform, files) => {
|
|
24
|
+
for (const { file, content } of files) {
|
|
25
|
+
const to = path.join(ws, platform, file);
|
|
26
|
+
await mkdir(path.dirname(to), { recursive: true });
|
|
27
|
+
await writeFile(to, content);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
22
30
|
//#endregion
|
|
23
|
-
export { copySplashFile, protobaseSplashDir, removeTemplateSplash };
|
|
31
|
+
export { copySplashFile, protobaseSplashDir, removeTemplateSplash, writeSplashFiles };
|
package/dist/mobile/run.js
CHANGED
|
@@ -19,6 +19,8 @@ import { liveUpdateSettings } from "./live-update-settings.js";
|
|
|
19
19
|
import { loadMobileProject } from "./load-project.js";
|
|
20
20
|
import { signForDevelopment } from "./development-signing.js";
|
|
21
21
|
import { checkIosPlugins, checkProtobasePlugin, guardIosLiveUpdate, guardLiveUpdate } from "./protobase-plugin.js";
|
|
22
|
+
import { splashBackgrounds } from "./splash-backgrounds.js";
|
|
23
|
+
import { splashImage } from "./splash-image.js";
|
|
22
24
|
import { mobileSpec, prepareWorkspace, workspaceDir, workspacePackageJson } from "./workspace.js";
|
|
23
25
|
import path from "node:path";
|
|
24
26
|
import { nativeFingerprint } from "@protobase/server/mobile-release";
|
|
@@ -28,10 +30,11 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
|
|
|
28
30
|
if (live !== void 0 && api !== void 0) throw new Error("--live opens protobase dev, which serves the API itself: leave out --api");
|
|
29
31
|
const project = await loadMobileProject(projectDir, extensions);
|
|
30
32
|
const mobile = checkMobileConfig(project.mobile);
|
|
31
|
-
const
|
|
33
|
+
const theme = await splashColors(projectDir);
|
|
34
|
+
const splash = splashBackgrounds(mobile.splash, theme);
|
|
32
35
|
const ownIcon = mobile.icon === void 0 ? void 0 : {
|
|
33
36
|
file: mobile.icon,
|
|
34
|
-
background: iconBackground(project.backgroundColor,
|
|
37
|
+
background: iconBackground(project.backgroundColor, theme)
|
|
35
38
|
};
|
|
36
39
|
const url = live === void 0 ? apiUrl(api, project.auth?.issuer, platform) : new URL(`http://localhost:${live}`);
|
|
37
40
|
if (release) checkReleaseUrl(url);
|
|
@@ -62,6 +65,12 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
|
|
|
62
65
|
platform,
|
|
63
66
|
...ownIcon
|
|
64
67
|
});
|
|
68
|
+
const ownSplash = await splashImage({
|
|
69
|
+
ws,
|
|
70
|
+
projectDir,
|
|
71
|
+
splash: mobile.splash,
|
|
72
|
+
platform
|
|
73
|
+
});
|
|
65
74
|
const { builtInOrder } = live === void 0 ? await buildWebPart({
|
|
66
75
|
projectDir,
|
|
67
76
|
ws,
|
|
@@ -102,6 +111,7 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
|
|
|
102
111
|
await generatePlatform(ws, platform, {
|
|
103
112
|
...allowances,
|
|
104
113
|
splash,
|
|
114
|
+
...ownSplash && { splashImage: ownSplash },
|
|
105
115
|
...icon && { icon },
|
|
106
116
|
...push && platform === "android" && { googleServicesFrom: projectDir },
|
|
107
117
|
...apnsEnvironment && { apnsEnvironment }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { cssColor, opaqueHex } from "./splash-colors.js";
|
|
2
|
+
//#region src/mobile/splash-backgrounds.ts
|
|
3
|
+
const nativeColor = (text, setting) => {
|
|
4
|
+
const color = opaqueHex(cssColor(text));
|
|
5
|
+
if (!color) throw new Error(`${setting} is ${text}: the splash screen needs an opaque sRGB colour, such as #0d9488, rgb() or hsl()`);
|
|
6
|
+
return color;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The splash screen's background in light and dark mode: `mobile.splash.background` and `mobile.splash.dark.background`,
|
|
10
|
+
* a dark one left out taking the light one, and without either the theme's, `theme`.
|
|
11
|
+
*/
|
|
12
|
+
const splashBackgrounds = (splash, theme) => {
|
|
13
|
+
const light = splash?.background === void 0 ? void 0 : nativeColor(splash.background, "mobile.splash.background");
|
|
14
|
+
const dark = splash?.dark?.background === void 0 ? void 0 : nativeColor(splash.dark.background, "mobile.splash.dark.background");
|
|
15
|
+
return {
|
|
16
|
+
light: light ?? theme.light,
|
|
17
|
+
dark: dark ?? light ?? theme.dark
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { splashBackgrounds };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/mobile/splash-config.ts
|
|
2
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3
|
+
const shape = "such as { image: 'splash.png', background: '#0d9488', dark: { background: '#042f2e' } }";
|
|
4
|
+
const checkLook = (value, setting) => {
|
|
5
|
+
const { image, background } = value;
|
|
6
|
+
if (image !== void 0 && (typeof image !== "string" || image === "")) throw new Error(`${setting}.image must be the path of the splash image from the project's folder, such as 'splash.png'`);
|
|
7
|
+
if (background !== void 0 && (typeof background !== "string" || background === "")) throw new Error(`${setting}.background must be a colour, such as '#0d9488'`);
|
|
8
|
+
return {
|
|
9
|
+
...image !== void 0 && { image },
|
|
10
|
+
...background !== void 0 && { background }
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The `mobile.splash` section, checked for its shape; its colours and image are checked when they are drawn. A dark
|
|
15
|
+
* image needs a light one, since the light launch shows the icon in a layout of its own.
|
|
16
|
+
*/
|
|
17
|
+
const checkSplashConfig = (value) => {
|
|
18
|
+
if (!isRecord(value)) throw new Error(`mobile.splash must be an object, ${shape}`);
|
|
19
|
+
const { dark } = value;
|
|
20
|
+
if (dark !== void 0 && !isRecord(dark)) throw new Error(`mobile.splash.dark must be an object, ${shape}`);
|
|
21
|
+
const light = checkLook(value, "mobile.splash");
|
|
22
|
+
if (dark === void 0) return light;
|
|
23
|
+
const darkLook = checkLook(dark, "mobile.splash.dark");
|
|
24
|
+
if (darkLook.image !== void 0 && light.image === void 0) throw new Error("mobile.splash.dark.image needs mobile.splash.image: set the light image too");
|
|
25
|
+
return {
|
|
26
|
+
...light,
|
|
27
|
+
dark: darkLook
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { checkSplashConfig };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { androidSplashImage, splashSourceSize } from "./android-splash-image.js";
|
|
2
|
+
import { loadSharp } from "./icon-sharp.js";
|
|
3
|
+
import { readSquareImage } from "./icon-source.js";
|
|
4
|
+
import { iosSplashImage } from "./ios-splash-image.js";
|
|
5
|
+
//#region src/mobile/splash-image.ts
|
|
6
|
+
/**
|
|
7
|
+
* The files of the app's own splash image for the platform, `mobile.splash.image` and its dark one, drawn with the
|
|
8
|
+
* sharp installed in the workspace `ws`; none without an image, when the splash shows the app's icon.
|
|
9
|
+
*/
|
|
10
|
+
const splashImage = async ({ ws, projectDir, splash, platform }) => {
|
|
11
|
+
if (splash?.image === void 0) return;
|
|
12
|
+
const sharp = loadSharp(ws);
|
|
13
|
+
const read = (file, setting) => readSquareImage(sharp, projectDir, file, {
|
|
14
|
+
setting,
|
|
15
|
+
noun: "splash image",
|
|
16
|
+
size: splashSourceSize
|
|
17
|
+
});
|
|
18
|
+
const light = await read(splash.image, "mobile.splash.image");
|
|
19
|
+
const dark = splash.dark?.image === void 0 ? void 0 : await read(splash.dark.image, "mobile.splash.dark.image");
|
|
20
|
+
return (platform === "android" ? androidSplashImage : iosSplashImage)(sharp, light.image, dark?.image);
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { splashImage };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.96.
|
|
3
|
+
"version": "0.96.8",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.96.
|
|
47
|
-
"@protobase/layout": "0.96.
|
|
48
|
-
"@protobase/query": "0.96.
|
|
49
|
-
"@protobase/schema": "0.96.
|
|
50
|
-
"@protobase/server": "0.96.
|
|
51
|
-
"@protobase/ui": "0.96.
|
|
52
|
-
"@protobase/workflows": "0.96.
|
|
46
|
+
"@protobase/config": "0.96.8",
|
|
47
|
+
"@protobase/layout": "0.96.8",
|
|
48
|
+
"@protobase/query": "0.96.8",
|
|
49
|
+
"@protobase/schema": "0.96.8",
|
|
50
|
+
"@protobase/server": "0.96.8",
|
|
51
|
+
"@protobase/ui": "0.96.8",
|
|
52
|
+
"@protobase/workflows": "0.96.8",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -26,7 +26,7 @@ Develop, build and run an app, on servers, in containers and on phones.
|
|
|
26
26
|
- [Container images](../guides/deploy.md#images): A runtime image for each release, for amd64 and arm64.
|
|
27
27
|
- [Self-hosted image](../guides/deploy.md#a-self-hosted-image): One image with the app inside that serves, migrates and creates the first admin.
|
|
28
28
|
- [Protobase Cloud deploys](../guides/deploy.md#protobase-cloud): A push to the app's GitHub branch builds it, migrates and checks its database in one transaction, and switches to the new version once it answers its health check.
|
|
29
|
-
- [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, also on your own iPhone, with sign-in, and builds signed store releases from a section in its config. Your app shows its own home-screen icon on iOS and Android, generated from one image you name in your config.
|
|
29
|
+
- [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, also on your own iPhone, with sign-in, and builds signed store releases from a section in its config. Your app shows its own home-screen icon on iOS and Android, generated from one image you name in your config. It can open on a splash screen of its own, an image on a colour, in light and dark mode.
|
|
30
30
|
- [Files from the phone](../guides/mobile-app.md#files-from-the-phone) (beta): In the iOS and Android app, Import and file fields open the phone's file picker, offering Excel, CSV and JSON files from the device and its cloud drives.
|
|
31
31
|
- [Mobile releases](../reference/cli.md#mobile-releases) (in development): The server offers the mobile app a newer copy of its files, signed, and any host that serves bundles can offer the same from the bundle's files without running its config.
|
|
32
32
|
- [Live updates](../reference/cli.md#the-live-updater) (in development): The Android and iOS app update themselves in the background to the server's release, downloading only the files that changed, switch to it when they come back after 5 minutes or more away, on the same page, and go back to the files they were built with when a release fails to start.
|
|
@@ -37,7 +37,7 @@ export default defineConfig({
|
|
|
37
37
|
|
|
38
38
|
The app is installed under the name it shows in its upper left, on iOS and Android alike: `protobase mobile` reads it from the server the app calls (its web manifest), so a `PROTOBASE_APP_NAME` the server runs with names the app on the phone too. When that server cannot be reached, `run` and `open` warn and take the project's own name, the config's `name` or `PROTOBASE_APP_NAME` in its environment, and `build` stops.
|
|
39
39
|
|
|
40
|
-
On the home screen the app shows [its own icon](#the-icon), or Protobase's without one, on iOS and Android alike. While it starts, its splash screen shows that icon in the middle of the app's background: the `--background` [token](../reference/theme.md) of its `protobase.theme.css`, or the default without one, light or dark as the phone is. `protobase mobile` takes it as a colour such as `#f4f3ee`, `rgb()`, `hsl()` or `white`, and stops on one a phone's splash screen cannot show, such as `oklch()` or `var()`.
|
|
40
|
+
On the home screen the app shows [its own icon](#the-icon), or Protobase's without one, on iOS and Android alike. While it starts, its [splash screen](#the-splash-screen) shows that icon in the middle of the app's background, unless you set one of its own: the `--background` [token](../reference/theme.md) of its `protobase.theme.css`, or the default without one, light or dark as the phone is. `protobase mobile` takes it as a colour such as `#f4f3ee`, `rgb()`, `hsl()` or `white`, and stops on one a phone's splash screen cannot show, such as `oklch()` or `var()`.
|
|
41
41
|
|
|
42
42
|
With a mobile section, the API answers the app's origins, `capacitor://localhost` on iOS and `https://localhost` on Android, through [CORS](../reference/api.md#cors). Apps without one get no new dependency, and `protobase build` and `protobase dev` work as before.
|
|
43
43
|
|
|
@@ -66,6 +66,24 @@ mobile: { appId: 'com.example.shop', icon: 'icon.png' },
|
|
|
66
66
|
|
|
67
67
|
Changing the icon takes a new store release: a [live update](#7-live-updates) does not change it.
|
|
68
68
|
|
|
69
|
+
### The splash screen
|
|
70
|
+
|
|
71
|
+
Set a splash image and background colour in the mobile section, with dark-mode values if you like, and the app opens on that image in the middle of that colour, on iOS and Android alike. Without them it opens on its icon over its theme background.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
mobile: {
|
|
75
|
+
appId: 'com.example.shop',
|
|
76
|
+
splash: { image: 'splash.png', background: '#0d9488', dark: { image: 'splash-dark.png', background: '#042f2e' } },
|
|
77
|
+
},
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- `image` is a path from the project's folder to a square PNG of at least 1152 × 1152 pixels, or a square SVG. Android shows it at 288 dp and only its middle circle, two thirds of its side across, so keep everything you want seen within that circle; iOS shows the same circle. `protobase mobile` stops on a missing file, any other format, an image that is not square or a smaller PNG, naming the setting.
|
|
81
|
+
- `background` is an opaque colour such as `#0d9488`, `rgb()` or `hsl()`; `protobase mobile` stops on any other, naming the setting.
|
|
82
|
+
- `dark` holds the image and background for dark mode. One left out there takes the light one, so a single image and colour serve both. A dark image needs a light one.
|
|
83
|
+
- Each is optional: an image without a background sits on the theme background, and a background without an image shows the icon on it.
|
|
84
|
+
|
|
85
|
+
The splash image is a centred image, not full-screen artwork, as that is all Android's splash screen shows. Changing it takes a new store release: a [live update](#7-live-updates) does not change it.
|
|
86
|
+
|
|
69
87
|
## 3. Run it
|
|
70
88
|
|
|
71
89
|
```sh
|
|
@@ -543,7 +543,7 @@ A thread with an assistant in it can show what the assistant did between its mes
|
|
|
543
543
|
|
|
544
544
|
Each call is a line under the messages before it, closed at first; a call with an input, result or error opens and closes with a click on its line. The thread reads the latest calls as it reads the latest messages, `limit` at a time, newest first by `time`, so that read needs an index on the filter's field and `time`, which [`protobase doctor`](cli.md#doctor) checks, and **Load earlier messages** loads the earlier calls with the earlier messages, keeping them in time order. A user who cannot read the calls' `name`, `time` or `status` gets the thread without its calls, and one who cannot read `input`, `result` or `error` gets the calls without that part.
|
|
545
545
|
|
|
546
|
-
Clients that cannot draw the calls get their simpler forms from `@protobase/layout`: `threadLines(items)` gives one short line per item, a message as its sender and first line and a call as its name and status, and `threadMarkdown(items, words)` gives the thread as Markdown, for clients that read text, such as an MCP client or a language model: each message under its sender in bold, each call as its name and status with its input and result as JSON and its error in fenced code blocks. <gap>A watch cannot show a thread's tool calls as lines because drawing a thread on a watch is not implemented.</gap> <gap>An MCP client cannot read a thread as Markdown because serving a page's blocks as text is not implemented.</gap>
|
|
546
|
+
Clients that cannot draw the calls get their simpler forms from `@protobase/layout`: `threadLines(items)` gives one short line per item, a message as its sender and first line and a call as its name and status, and `threadMarkdown(items, words)` gives the thread as Markdown, for clients that read text, such as an MCP client or a language model: each message under its sender in bold, each call as its name and status with its input and result as JSON and its error in fenced code blocks. A message's text is escaped so it reads as written, unless its item sets `markdown: true`. The Markdown comes from [`renderText`](layouts.md#text-form), the text form every block renders through: `threadItemNodes(items, words)` gives the items as elements, and a `Thread` element holding them as its children reads as its heading with its items under it, so a page's text can include its thread. <gap>A watch cannot show a thread's tool calls as lines because drawing a thread on a watch is not implemented.</gap> <gap>An MCP client cannot read a thread as Markdown because serving a page's blocks as text is not implemented.</gap>
|
|
547
547
|
|
|
548
548
|
### Composer
|
|
549
549
|
|
|
@@ -98,7 +98,7 @@ export default defineConfig({ backgroundColor: '#ffffff' })
|
|
|
98
98
|
|
|
99
99
|
## mobile
|
|
100
100
|
|
|
101
|
-
- **Type:** `{ appId: string; plugins?: Record<string, string>; publicKey?: string; icon?: string }`
|
|
101
|
+
- **Type:** `{ appId: string; plugins?: Record<string, string>; publicKey?: string; icon?: string; splash?: { image?: string; background?: string; dark?: { image?: string; background?: string } } }`
|
|
102
102
|
|
|
103
103
|
The app's iOS and Android build: with it, `protobase mobile` builds the app with Capacitor, and the API also allows the app's Capacitor origins (`capacitor://localhost`, `https://localhost`) for [CORS](api.md#cors). See [A mobile app](../../guides/mobile-app.md).
|
|
104
104
|
|
|
@@ -106,6 +106,7 @@ The app's iOS and Android build: with it, `protobase mobile` builds the app with
|
|
|
106
106
|
- `plugins`: extra native Capacitor plugins, by npm name and version range. A range fetched over plain `http:` or `git:` is refused.
|
|
107
107
|
- `publicKey`: the public key, PEM, of the RSA key the server signs the app's [releases](../cli.md#the-live-updater) with, from [`protobase mobile keys`](../cli.md#mobile): with it the Android and iOS app update themselves. Anything but an RSA public key of at least 2048 bits stops the build.
|
|
108
108
|
- `icon`: the app's [home-screen icon](../../guides/mobile-app.md#the-icon), a path from the project's folder to a square PNG of at least 1024 × 1024 pixels or a square SVG, from which `protobase mobile` makes every iOS and Android icon. Without it the app shows Protobase's icon.
|
|
109
|
+
- `splash`: the app's own [splash screen](../../guides/mobile-app.md#the-splash-screen), an `image` centred on a `background` colour, with `dark` values for dark mode, each optional. Without it the app opens on its icon over its theme background.
|
|
109
110
|
|
|
110
111
|
```ts
|
|
111
112
|
export default defineConfig({
|
|
@@ -92,7 +92,7 @@ renderText(tree, { forms: { Grid: ruled, Card: noted, SeatChart: childrenText }
|
|
|
92
92
|
|
|
93
93
|
A custom component reads as its [fallback](custom-components.md#fallbacks) when it declares one, and otherwise as what it holds, unless `forms` names it.
|
|
94
94
|
|
|
95
|
-
<gap>A data block's text form cannot read its records itself, such as a table's rows, because reading records for the text form is not implemented.</gap> <gap>A data block other than a `Table` cannot list records you pass because its text form for records is not implemented.</gap> <gap>A field's text form cannot apply its `format`, such as a relative time, because formatting in the text form is not implemented.</gap> <gap>MCP clients cannot read a page's text form because a tool that serves it is not implemented.</gap>
|
|
95
|
+
<gap>A data block's text form cannot read its records itself, such as a table's rows, because reading records for the text form is not implemented.</gap> A `Thread` holding the elements of [`threadItemNodes`](blocks.md#tool-calls) reads as its messages and calls. <gap>A data block other than a `Table` or a `Thread` cannot list records you pass because its text form for records is not implemented.</gap> <gap>A field's text form cannot apply its `format`, such as a relative time, because formatting in the text form is not implemented.</gap> <gap>MCP clients cannot read a page's text form because a tool that serves it is not implemented.</gap>
|
|
96
96
|
|
|
97
97
|
## What a layout may hold
|
|
98
98
|
|