@protobase/cli 0.96.2 → 0.96.3

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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.96.2";
2
+ var version = "0.96.3";
3
3
  //#endregion
4
4
  export { version };
@@ -0,0 +1,89 @@
1
+ //#region src/mobile/android-app-icon.ts
2
+ const res = "app/src/main/res";
3
+ /** Android's densities, by their scale of a dp. */
4
+ const densityScales = {
5
+ mdpi: 1,
6
+ hdpi: 1.5,
7
+ xhdpi: 2,
8
+ xxhdpi: 3,
9
+ xxxhdpi: 4
10
+ };
11
+ const legacy = 48;
12
+ const layer = 108;
13
+ const safeZone = 66;
14
+ /** The adaptive icons of the template, which the monochrome layer joins. */
15
+ const adaptiveIconFiles = [`${res}/mipmap-anydpi-v26/ic_launcher.xml`, `${res}/mipmap-anydpi-v26/ic_launcher_round.xml`];
16
+ /** The template's adaptive icon with a monochrome layer, which Android tints for themed icons. */
17
+ const themedAdaptiveIcon = `<?xml version="1.0" encoding="utf-8"?>
18
+ <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
19
+ <background android:drawable="@color/ic_launcher_background"/>
20
+ <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
21
+ <monochrome android:drawable="@mipmap/ic_launcher_monochrome"/>
22
+ </adaptive-icon>
23
+ `;
24
+ /** The adaptive icon's background colour resource. */
25
+ const launcherBackground = (color) => `<?xml version="1.0" encoding="utf-8"?>
26
+ <resources>
27
+ <color name="ic_launcher_background">${color.toUpperCase()}</color>
28
+ </resources>
29
+ `;
30
+ 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>`);
31
+ const transparent = {
32
+ r: 0,
33
+ g: 0,
34
+ b: 0,
35
+ alpha: 0
36
+ };
37
+ /**
38
+ * The app's own Android icon at each density: the legacy icon flattened onto `background` and its round one, and the
39
+ * adaptive icon's foreground, the source scaled into the safe zone, with `background` as its background colour. A source with transparency also
40
+ * gets the monochrome layer, the foreground, whose shape Android tints; an opaque one would be a plain square, so it
41
+ * gets none and Android shows the icon as it is.
42
+ */
43
+ const androidAppIcon = async (sharp, { image, opaque }, background) => {
44
+ const files = [{
45
+ file: `${res}/values/ic_launcher_background.xml`,
46
+ content: launcherBackground(background)
47
+ }];
48
+ for (const [density, scale] of Object.entries(densityScales)) {
49
+ const dir = `${res}/mipmap-${density}`;
50
+ const side = legacy * scale;
51
+ const flat = await sharp(image).resize(side, side).flatten({ background }).png().toBuffer();
52
+ const round = await sharp(flat).ensureAlpha().composite([{
53
+ input: circleMask(side),
54
+ blend: "dest-in"
55
+ }]).png().toBuffer();
56
+ const outer = layer * scale;
57
+ const inner = Math.round(safeZone * scale);
58
+ const before = Math.floor((outer - inner) / 2);
59
+ const after = outer - inner - before;
60
+ const foreground = await sharp(image).resize(inner, inner).extend({
61
+ top: before,
62
+ bottom: after,
63
+ left: before,
64
+ right: after,
65
+ background: transparent
66
+ }).png().toBuffer();
67
+ files.push({
68
+ file: `${dir}/ic_launcher.png`,
69
+ content: flat
70
+ }, {
71
+ file: `${dir}/ic_launcher_round.png`,
72
+ content: round
73
+ }, {
74
+ file: `${dir}/ic_launcher_foreground.png`,
75
+ content: foreground
76
+ });
77
+ if (!opaque) files.push({
78
+ file: `${dir}/ic_launcher_monochrome.png`,
79
+ content: foreground
80
+ });
81
+ }
82
+ if (opaque) return files;
83
+ return [...files, ...adaptiveIconFiles.map((file) => ({
84
+ file,
85
+ content: themedAdaptiveIcon
86
+ }))];
87
+ };
88
+ //#endregion
89
+ export { adaptiveIconFiles, androidAppIcon, densityScales, launcherBackground, themedAdaptiveIcon };
@@ -0,0 +1,23 @@
1
+ import { androidAppIcon } from "./android-app-icon.js";
2
+ import { loadSharp } from "./icon-sharp.js";
3
+ import { readIconSource } from "./icon-source.js";
4
+ import { iosAppIcon, iosAppSplash } from "./ios-app-icon.js";
5
+ //#region src/mobile/app-icon.ts
6
+ /** The files of the app's icon `source` for the platform, on `background`, a `#rrggbb` colour. */
7
+ const appIconFiles = async (sharp, source, background, platform) => {
8
+ if (platform === "android") return {
9
+ icon: await androidAppIcon(sharp, source, background),
10
+ splash: []
11
+ };
12
+ return {
13
+ icon: await iosAppIcon(sharp, source, background),
14
+ splash: await iosAppSplash(sharp, source, background)
15
+ };
16
+ };
17
+ /** The files of the app's icon `file`, `mobile.icon`, for the platform, drawn with the sharp installed in the workspace `ws`. */
18
+ const appIcon = async ({ ws, projectDir, file, background, platform }) => {
19
+ const sharp = loadSharp(ws);
20
+ return appIconFiles(sharp, await readIconSource(sharp, projectDir, file), background, platform);
21
+ };
22
+ //#endregion
23
+ export { appIcon, appIconFiles };
@@ -1,11 +1,12 @@
1
1
  import { withAndroidSplash } from "./android-splash.js";
2
+ import { iosSplashImages } from "./ios-app-icon.js";
2
3
  import { dataExtractionRules, dataExtractionRulesPath, withoutBackup } from "./android-backup.js";
3
4
  import { copyGoogleServices } from "./google-services.js";
4
5
  import { withLocalNetworking } from "./info-plist.js";
5
6
  import { withFreshInstall } from "./ios-fresh-install.js";
6
7
  import { setUpIosPush } from "./ios-push.js";
7
8
  import { withIosSplash } from "./ios-splash.js";
8
- import { withProtobaseIcon } from "./native-icon.js";
9
+ import { withAppIcon, withProtobaseIcon, writeNativeFiles } from "./native-icon.js";
9
10
  import path from "node:path";
10
11
  import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
11
12
  //#region src/mobile/generate.ts
@@ -14,20 +15,21 @@ const appDelegate = (ws) => path.join(ws, "ios", "App", "App", "AppDelegate.swif
14
15
  const androidManifest = (ws) => path.join(ws, "android", "app", "src", "main", "AndroidManifest.xml");
15
16
  /**
16
17
  * Generates the platform's native project in the workspace from its capacitor.config.json and app files, replacing
17
- * the last one: it is never edited by hand. Its home-screen icon is Protobase's, and its splash screen that icon on the
18
- * app's background in `splash`, light and dark, in place of Capacitor's logo. An Android app with push gets the
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 that icon on the app's background in `splash`, light and dark, in place of Capacitor's logo. An Android app with push gets the
19
20
  * project's google-services.json from `googleServicesFrom`, an iOS app with push its entitlement in `apnsEnvironment` and
20
21
  * the token forwarding, and an iOS app calling the API over plain http may reach local addresses. Android apps opt out
21
22
  * of backup and device transfer, and iOS apps start as a fresh install after a restore or a move, so nothing carries
22
23
  * over to another phone.
23
24
  */
24
- const generatePlatform = async (ws, platform, { cleartext, splash, googleServicesFrom, apnsEnvironment }, cap) => {
25
+ const generatePlatform = async (ws, platform, { cleartext, splash, icon, googleServicesFrom, apnsEnvironment }, cap) => {
25
26
  await rm(path.join(ws, platform), {
26
27
  recursive: true,
27
28
  force: true
28
29
  });
29
30
  await cap(["add", platform]);
30
- await withProtobaseIcon(ws, platform);
31
+ if (icon) await withAppIcon(ws, platform, icon.icon);
32
+ else await withProtobaseIcon(ws, platform);
31
33
  if (platform === "android") {
32
34
  await withAndroidSplash(ws, splash);
33
35
  if (googleServicesFrom !== void 0) await copyGoogleServices(googleServicesFrom, ws);
@@ -38,6 +40,7 @@ const generatePlatform = async (ws, platform, { cleartext, splash, googleService
38
40
  return;
39
41
  }
40
42
  await withIosSplash(ws, splash);
43
+ if (icon) await writeNativeFiles(ws, "ios", icon.splash, iosSplashImages.map(([file]) => file));
41
44
  await writeFile(appDelegate(ws), withFreshInstall(await readFile(appDelegate(ws), "utf8")));
42
45
  if (apnsEnvironment !== void 0) await setUpIosPush(ws, apnsEnvironment);
43
46
  if (!cleartext) return;
@@ -0,0 +1,14 @@
1
+ import { cssColor, opaqueHex } from "./splash-colors.js";
2
+ //#region src/mobile/icon-background.ts
3
+ /**
4
+ * The background of the app's own icon, as `#rrggbb`: the config's `backgroundColor`, or without one the light
5
+ * background of the splash screen, so the icon sits on the colour the app starts on.
6
+ */
7
+ const iconBackground = (backgroundColor, splash) => {
8
+ if (backgroundColor === void 0) return splash.light;
9
+ const color = opaqueHex(cssColor(backgroundColor));
10
+ if (!color) throw new Error(`backgroundColor in protobase.config.ts is ${backgroundColor}: mobile.icon needs it as an opaque sRGB colour, such as #ffffff, rgb() or hsl()`);
11
+ return color;
12
+ };
13
+ //#endregion
14
+ export { iconBackground };
@@ -0,0 +1,15 @@
1
+ import { installedPackage } from "./installed-package.js";
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ //#region src/mobile/icon-sharp.ts
5
+ const require = createRequire(import.meta.url);
6
+ /**
7
+ * The sharp @protobase/mobile brings into the workspace `ws`, loaded by path, never by Node's lookup, which would go on
8
+ * into the project's own node_modules: the CLI itself carries no image library.
9
+ */
10
+ const loadSharp = (ws) => {
11
+ installedPackage(ws, "sharp");
12
+ return require(path.join(ws, "node_modules", "sharp"));
13
+ };
14
+ //#endregion
15
+ export { loadSharp };
@@ -0,0 +1,25 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ //#region src/mobile/icon-source.ts
4
+ /** The size every icon is drawn from: the App Store icon's, the largest one. */
5
+ const sourceSize = 1024;
6
+ /**
7
+ * Reads the app's icon `file`, `mobile.icon` from the project's folder `projectDir`: a square PNG of at least
8
+ * `sourceSize` pixels, or a square SVG, drawn at that size. Any other file stops the build, naming the setting and
9
+ * the rule, since the platforms would take a wrong one quietly.
10
+ */
11
+ const readIconSource = async (sharp, projectDir, file) => {
12
+ const at = path.resolve(projectDir, file);
13
+ if (!existsSync(at)) throw new Error(`mobile.icon names ${file}, which does not exist: ${at}`);
14
+ const { format, width = 0, height = 0 } = await sharp(at).metadata();
15
+ if (format !== "png" && format !== "svg") throw new Error(`mobile.icon names ${file}, which is no PNG or SVG: the icon must be a PNG or an SVG`);
16
+ if (width === 0 || width !== height) throw new Error(`mobile.icon names ${file}, which is ${width}x${height} pixels: the icon must be square`);
17
+ if (format === "png" && width < 1024) throw new Error(`mobile.icon names ${file}, which is ${width}x${height} pixels: a PNG icon must be at least ${sourceSize}x${sourceSize}`);
18
+ const image = await (format === "svg" ? sharp(at, { density: 72 * sourceSize / width }) : sharp(at)).resize(sourceSize, sourceSize).ensureAlpha().png().toBuffer();
19
+ return {
20
+ image,
21
+ opaque: (await sharp(image).stats()).isOpaque
22
+ };
23
+ };
24
+ //#endregion
25
+ export { readIconSource, sourceSize };
@@ -0,0 +1,75 @@
1
+ //#region src/mobile/ios-app-icon.ts
2
+ const iconSet = "App/App/Assets.xcassets/AppIcon.appiconset";
3
+ /** The template's App Store icon, the one icon of its asset catalog, and that catalog's Contents.json. */
4
+ const iosIconFile = `${iconSet}/AppIcon-512@2x.png`;
5
+ const iosIconContents = `${iconSet}/Contents.json`;
6
+ const icon = (filename, appearance) => ({
7
+ ...appearance && { appearances: [{
8
+ appearance: "luminosity",
9
+ value: appearance
10
+ }] },
11
+ filename,
12
+ idiom: "universal",
13
+ platform: "ios",
14
+ size: "1024x1024"
15
+ });
16
+ /** The AppIcon set's Contents.json with the dark and tinted appearances beside the template's one icon. */
17
+ const appearancesContents = `${JSON.stringify({
18
+ images: [
19
+ icon("AppIcon-512@2x.png"),
20
+ icon("AppIcon-dark.png", "dark"),
21
+ icon("AppIcon-tinted.png", "tinted")
22
+ ],
23
+ info: {
24
+ author: "xcode",
25
+ version: 1
26
+ }
27
+ }, null, 2)}\n`;
28
+ /** The launch screen's `Splash` image at 1x, 2x and 3x: 128 points, as the storyboard draws it. */
29
+ const iosSplashImages = [
30
+ ["App/App/Assets.xcassets/Splash.imageset/splash.png", 128],
31
+ ["App/App/Assets.xcassets/Splash.imageset/splash@2x.png", 256],
32
+ ["App/App/Assets.xcassets/Splash.imageset/splash@3x.png", 384]
33
+ ];
34
+ const cornerRadius = .2237;
35
+ const roundedMask = (size) => Buffer.from(`<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}"><rect width="${size}" height="${size}" rx="${size * cornerRadius}" fill="#fff"/></svg>`);
36
+ /**
37
+ * The app's own iOS icon: the App Store icon flattened onto `background`, as it takes no alpha channel. A source with
38
+ * transparency also gets the dark appearance, its mark on the transparent background iOS darkens, and the tinted one,
39
+ * its greyscale; an opaque source gets neither, and iOS derives them from the icon.
40
+ */
41
+ const iosAppIcon = async (sharp, { image, opaque }, background) => {
42
+ const files = [{
43
+ file: iosIconFile,
44
+ content: await sharp(image).flatten({ background }).png().toBuffer()
45
+ }];
46
+ if (opaque) return files;
47
+ return [
48
+ ...files,
49
+ {
50
+ file: `${iconSet}/AppIcon-dark.png`,
51
+ content: image
52
+ },
53
+ {
54
+ file: `${iconSet}/AppIcon-tinted.png`,
55
+ content: await sharp(image).greyscale().png().toBuffer()
56
+ },
57
+ {
58
+ file: iosIconContents,
59
+ content: appearancesContents
60
+ }
61
+ ];
62
+ };
63
+ /** The launch screen's `Splash` image of the app's own icon: the App Store icon with its corners rounded. */
64
+ const iosAppSplash = async (sharp, { image }, background) => {
65
+ const flat = await sharp(image).flatten({ background }).png().toBuffer();
66
+ return Promise.all(iosSplashImages.map(async ([file, size]) => ({
67
+ file,
68
+ content: await sharp(flat).resize(size, size).ensureAlpha().composite([{
69
+ input: roundedMask(size),
70
+ blend: "dest-in"
71
+ }]).png().toBuffer()
72
+ })));
73
+ };
74
+ //#endregion
75
+ export { appearancesContents, iosAppIcon, iosAppSplash, iosIconContents, iosIconFile, iosSplashImages };
@@ -5,8 +5,8 @@ import { appNameOver } from "@protobase/server";
5
5
  //#region src/mobile/load-project.ts
6
6
  /**
7
7
  * What a mobile build needs of the project in `dir`, merged as `protobase dev` merges it after the configs of
8
- * `extensions`: its mobile section, unchecked, whether it has `notifications()`, and with sign-in on the app's URL, its
9
- * tokens' issuer, and its name.
8
+ * `extensions`: its mobile section, unchecked, whether it has `notifications()`, its `backgroundColor`, and with sign-in
9
+ * on the app's URL, its tokens' issuer, and its name.
10
10
  * The project's .env is loaded first, as other commands do, and no `PROTOBASE_ANDROID_*` variable is left in the
11
11
  * environment; nothing but the configs runs. A config function is called with `command: 'build'`, as for the deploy bundle
12
12
  * the app's files come from, so the binary's fingerprint and that bundle's manifest name the same `notifications()`.
@@ -14,7 +14,7 @@ import { appNameOver } from "@protobase/server";
14
14
  const loadMobileProject = async (dir, extensions) => {
15
15
  loadNearestEnvFile(dir);
16
16
  dropAndroidSigning(process.env);
17
- const { mobile, auth, url, name, notifications } = await loadSourceConfig(dir, {
17
+ const { mobile, auth, url, name, notifications, backgroundColor } = await loadSourceConfig(dir, {
18
18
  command: "build",
19
19
  extensions
20
20
  });
@@ -25,7 +25,8 @@ const loadMobileProject = async (dir, extensions) => {
25
25
  auth: auth && url ? {
26
26
  issuer: url,
27
27
  ...appName && { appName }
28
- } : void 0
28
+ } : void 0,
29
+ ...backgroundColor && { backgroundColor }
29
30
  };
30
31
  };
31
32
  //#endregion
@@ -10,10 +10,14 @@ const isRecord = (value) => typeof value === "object" && value !== null && !Arra
10
10
  const checkMobileConfig = (value) => {
11
11
  if (value === void 0) throw new Error(noMobileSection);
12
12
  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 } = value;
13
+ const { appId, plugins, publicKey, icon } = value;
14
14
  if (!isAppId(appId)) throw new Error(appIdProblem(appId));
15
15
  if (publicKey !== void 0) updaterPublicKey(publicKey);
16
- const key = publicKey === void 0 ? {} : { publicKey };
16
+ 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
+ const key = {
18
+ ...publicKey !== void 0 && { publicKey },
19
+ ...icon !== void 0 && { icon }
20
+ };
17
21
  if (plugins === void 0) return {
18
22
  appId,
19
23
  ...key
@@ -1,6 +1,8 @@
1
+ import { adaptiveIconFiles } from "./android-app-icon.js";
2
+ import { iosIconContents } from "./ios-app-icon.js";
1
3
  import { existsSync } from "node:fs";
2
4
  import path from "node:path";
3
- import { copyFile } from "node:fs/promises";
5
+ import { copyFile, writeFile } from "node:fs/promises";
4
6
  /**
5
7
  * The template's home-screen icon files, by path in the platform's native project, which Protobase's icon replaces:
6
8
  * iOS's one 1024 pixel icon; Android's legacy, round and adaptive foreground icons at each density, and the adaptive
@@ -35,5 +37,23 @@ const withProtobaseIcon = async (ws, platform) => {
35
37
  await copyFile(from, to);
36
38
  }
37
39
  };
40
+ /** The template's files the app's own icon may replace: Protobase's, the AppIcon set's Contents.json and Android's adaptive icons. */
41
+ const templateIconFiles = {
42
+ ios: [...nativeIconFiles.ios, iosIconContents],
43
+ android: [...nativeIconFiles.android, ...adaptiveIconFiles]
44
+ };
45
+ /**
46
+ * Writes `files` into the platform's native project in the workspace, where each of `replaced` must already be, so a
47
+ * template that moves one fails here rather than leaving an icon of another on the phone.
48
+ */
49
+ const writeNativeFiles = async (ws, platform, files, replaced) => {
50
+ for (const { file, content } of files) {
51
+ const to = path.join(ws, platform, file);
52
+ if (replaced.includes(file) && !existsSync(to)) throw new Error(`The generated ${platform} project has no ${file}, which the app's icon replaces`);
53
+ await writeFile(to, content);
54
+ }
55
+ };
56
+ /** Gives the platform's native project in the workspace the app's own icon, its `files`, in place of Capacitor's. */
57
+ const withAppIcon = (ws, platform, files) => writeNativeFiles(ws, platform, files, templateIconFiles[platform]);
38
58
  //#endregion
39
- export { nativeIconFiles, protobaseIconDir, withProtobaseIcon };
59
+ export { nativeIconFiles, protobaseIconDir, templateIconFiles, withAppIcon, withProtobaseIcon, writeNativeFiles };
@@ -10,7 +10,8 @@ var dependencies = {
10
10
  "@capacitor/keyboard": "8.0.6",
11
11
  "@capacitor/push-notifications": "8.1.3",
12
12
  "@capacitor/splash-screen": "8.0.2",
13
- "@capawesome/capacitor-live-update": "8.7.1"
13
+ "@capawesome/capacitor-live-update": "8.7.1",
14
+ "sharp": "0.35.5"
14
15
  };
15
16
  //#endregion
16
17
  export { dependencies, name, nativeContract };
@@ -7,8 +7,12 @@ import { installedPackage } from "./installed-package.js";
7
7
  * @protobase/mobile of its own version, the one it installs.
8
8
  */
9
9
  const pinnedPackages = /* @__PURE__ */ new Set([name, ...Object.keys(dependencies)]);
10
+ /** The packages @protobase/mobile holds for `protobase mobile` itself, which run on the developer's machine, never in the app. */
11
+ const buildTools = /* @__PURE__ */ new Set(["sharp"]);
12
+ /** Every package @protobase/mobile pins, name → version. */
13
+ const mobileDependencies = dependencies;
10
14
  /** The native packages @protobase/mobile pins, name → version. */
11
- const nativeDependencies = Object.fromEntries(Object.entries(dependencies).filter(([name]) => !name.startsWith("@protobase/")));
15
+ const nativeDependencies = Object.fromEntries(Object.entries(mobileDependencies).filter(([name]) => !name.startsWith("@protobase/") && !buildTools.has(name)));
12
16
  /**
13
17
  * The native code an app's binary carries from @protobase/mobile, name → version, which a native fingerprint names:
14
18
  * the native packages it pins, at their versions, and its own native code by its `nativeContract`, `native-<n>`. Never
@@ -49,4 +53,4 @@ const checkPinnedNative = (dir, pinned = nativeDependencies) => {
49
53
  }
50
54
  };
51
55
  //#endregion
52
- export { checkInstalledPlugins, checkPinnedNative, nativeDependencies, pinnedNative, pinnedPackages, pinnedProblem, pushPlugin };
56
+ export { buildTools, checkInstalledPlugins, checkPinnedNative, mobileDependencies, nativeDependencies, pinnedNative, pinnedPackages, pinnedProblem, pushPlugin };
@@ -10,13 +10,15 @@ import { buildWebPart, placeholderWebPart } from "./web-part.js";
10
10
  import { capacitorConfig, writeCapacitorConfig } from "./capacitor-config.js";
11
11
  import { childEnv, envFileKeys, projectEnvFiles } from "./child-env.js";
12
12
  import { deviceAppName } from "./device-app-name.js";
13
+ import { appIcon } from "./app-icon.js";
13
14
  import { hasGoogleServices, missingGoogleServices } from "./google-services.js";
14
15
  import { generatePlatform } from "./generate.js";
16
+ import { splashColors } from "./splash-colors.js";
17
+ import { iconBackground } from "./icon-background.js";
15
18
  import { liveUpdateSettings } from "./live-update-settings.js";
16
19
  import { loadMobileProject } from "./load-project.js";
17
20
  import { signForDevelopment } from "./development-signing.js";
18
21
  import { checkIosPlugins, checkProtobasePlugin, guardIosLiveUpdate, guardLiveUpdate } from "./protobase-plugin.js";
19
- import { splashColors } from "./splash-colors.js";
20
22
  import { mobileSpec, prepareWorkspace, workspaceDir, workspacePackageJson } from "./workspace.js";
21
23
  import path from "node:path";
22
24
  import { nativeFingerprint } from "@protobase/server/mobile-release";
@@ -27,6 +29,10 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
27
29
  const project = await loadMobileProject(projectDir, extensions);
28
30
  const mobile = checkMobileConfig(project.mobile);
29
31
  const splash = await splashColors(projectDir);
32
+ const ownIcon = mobile.icon === void 0 ? void 0 : {
33
+ file: mobile.icon,
34
+ background: iconBackground(project.backgroundColor, splash)
35
+ };
30
36
  const url = live === void 0 ? apiUrl(api, project.auth?.issuer, platform) : new URL(`http://localhost:${live}`);
31
37
  if (release) checkReleaseUrl(url);
32
38
  const allowances = httpAllowances(url);
@@ -50,6 +56,12 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
50
56
  }));
51
57
  checkInstalledPlugins(ws, plugins);
52
58
  checkPinnedNative(ws);
59
+ const icon = ownIcon && await appIcon({
60
+ ws,
61
+ projectDir,
62
+ platform,
63
+ ...ownIcon
64
+ });
53
65
  const { builtInOrder } = live === void 0 ? await buildWebPart({
54
66
  projectDir,
55
67
  ws,
@@ -90,6 +102,7 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
90
102
  await generatePlatform(ws, platform, {
91
103
  ...allowances,
92
104
  splash,
105
+ ...icon && { icon },
93
106
  ...push && platform === "android" && { googleServicesFrom: projectDir },
94
107
  ...apnsEnvironment && { apnsEnvironment }
95
108
  }, cap);
@@ -34,11 +34,12 @@ const backgrounds = (code, file) => {
34
34
  dark: important.dark ?? normal.dark
35
35
  };
36
36
  };
37
- const namedColor = (name) => {
37
+ /** A CSS colour, such as `white` or `#0d9488`, as the property `color` reads it; `undefined` when it is none. */
38
+ const cssColor = (text) => {
38
39
  let color;
39
40
  transform({
40
41
  filename: "name.css",
41
- code: Buffer.from(`a{color:${name}}`),
42
+ code: Buffer.from(`a{color:${text}}`),
42
43
  visitor: { Declaration: { color: (declaration) => void (declaration.property === "color" && (color = declaration.value)) } }
43
44
  });
44
45
  return color;
@@ -47,15 +48,20 @@ const parsedColor = (value) => {
47
48
  const [only] = value;
48
49
  if (value.length !== 1 || !only) return;
49
50
  if (only.type === "color") return only.value;
50
- if (only.type === "token" && only.value.type === "ident") return namedColor(only.value.value);
51
+ if (only.type === "token" && only.value.type === "ident") return cssColor(only.value.value);
51
52
  };
52
53
  const isRgb = (color) => typeof color === "object" && color.type === "rgb";
53
54
  const hex = (value) => value.toString(16).padStart(2, "0");
54
- const nativeColor = (value, where) => {
55
- const color = parsedColor(value);
56
- if (!isRgb(color) || color.alpha !== 1) throw new Error(`${where}: the native splash screen needs --background as an opaque sRGB colour, such as #f4f3ee, rgb() or hsl()`);
55
+ /** The colour as `#rrggbb`, the way native colours take it; `undefined` for one that is not an opaque sRGB colour. */
56
+ const opaqueHex = (color) => {
57
+ if (!isRgb(color) || color.alpha !== 1) return;
57
58
  return `#${hex(color.r)}${hex(color.g)}${hex(color.b)}`;
58
59
  };
60
+ const nativeColor = (value, where) => {
61
+ const color = opaqueHex(parsedColor(value));
62
+ if (!color) throw new Error(`${where}: the native splash screen needs --background as an opaque sRGB colour, such as #f4f3ee, rgb() or hsl()`);
63
+ return color;
64
+ };
59
65
  /**
60
66
  * The background the app's first screen paints, for the native splash screen: `--background` from the project's
61
67
  * protobase.theme.css, where it sets it, and from the installed @protobase/ui's tokens otherwise. As in the app, a theme
@@ -75,4 +81,4 @@ const splashColors = async (projectDir, tokens = tokensFile) => {
75
81
  };
76
82
  };
77
83
  //#endregion
78
- export { splashColors };
84
+ export { cssColor, opaqueHex, splashColors };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.96.2",
3
+ "version": "0.96.3",
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.2",
47
- "@protobase/layout": "0.96.2",
48
- "@protobase/query": "0.96.2",
49
- "@protobase/schema": "0.96.2",
50
- "@protobase/server": "0.96.2",
51
- "@protobase/ui": "0.96.2",
52
- "@protobase/workflows": "0.96.2",
46
+ "@protobase/config": "0.96.3",
47
+ "@protobase/layout": "0.96.3",
48
+ "@protobase/query": "0.96.3",
49
+ "@protobase/schema": "0.96.3",
50
+ "@protobase/server": "0.96.3",
51
+ "@protobase/ui": "0.96.3",
52
+ "@protobase/workflows": "0.96.3",
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.
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.
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 Protobase's icon, 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()`. <gap>An app cannot show its own icon on the phone, on the home screen or its splash screen, because setting the mobile app's icon is not implemented.</gap>
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()`.
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
 
@@ -50,6 +50,22 @@ Signing in works in the app as on the web, with nothing more to set up:
50
50
  - Page script cannot reach the session cookie, on iOS and Android alike: Capacitor's `CapacitorHttp`, `CapacitorCookies` and `WebView` plugins are refused to it, and so are the app's local file routes. A plugin that reads files for its JavaScript, such as `@capacitor/filesystem`, could still hand the cookie over.
51
51
  - While you develop over plain `http://localhost` with a mobile section, a page served on `https://localhost` in the same browser can send sign-in requests that carry your dev session, as some browsers treat the two as the same site. Do not open untrusted pages on `https://localhost` while you develop.
52
52
 
53
+ ### The icon
54
+
55
+ Name one square image in the mobile section, and every icon size for iOS and Android is made for you: the App Store icon with iOS's dark and tinted icons, and Android's launcher, round, adaptive and themed icons. Without one, the app shows the Protobase icon.
56
+
57
+ ```ts
58
+ mobile: { appId: 'com.example.shop', icon: 'icon.png' },
59
+ ```
60
+
61
+ - `icon` is a path from the project's folder to a square PNG of at least 1024 × 1024 pixels, or a square SVG. `protobase mobile` stops on a missing file, any other format, an image that is not square or a smaller PNG, naming `mobile.icon`.
62
+ - The icon sits on the app's [`backgroundColor`](../reference/app-identity.md#the-colours), or on the splash screen's light background without one: iOS's App Store icon is filled with it, as the App Store takes no transparency, and it is the background of Android's adaptive icon. With an icon, `backgroundColor` must be an opaque colour such as `#ffffff`, `rgb()` or `hsl()`.
63
+ - Android's adaptive icon draws the whole image within the middle 66 of its 108 dp, the safe zone no launcher's mask cuts into.
64
+ - An image on a transparent background also gives iOS's dark icon, its mark on the dark background iOS draws, and its tinted icon, the mark in greyscale, and Android's themed icon, in the mark's shape. An image without transparency gives none of these: iOS makes its dark and tinted icons from the App Store icon, and Android shows the icon as it is. A mark on a transparent background suits every platform best.
65
+ - The splash screen shows the app's icon too, on iOS with its corners rounded.
66
+
67
+ Changing the icon takes a new store release: a [live update](#7-live-updates) does not change it.
68
+
53
69
  ## 3. Run it
54
70
 
55
71
  ```sh
@@ -9,9 +9,9 @@ An app looks like its own everywhere from three things in its project: its name,
9
9
  | What | Where | Used by |
10
10
  | --- | --- | --- |
11
11
  | Name | `name` in `protobase.config.ts` ([config](config.md)), overridden at run time by `PROTOBASE_APP_NAME` | the sidebar's logo, the sign-in page's title ("Sign in to Acme Admin"), the end of every tab title, the title of the [API docs](api.md), the installed app's name, the [mobile app](../guides/mobile-app.md)'s name on the phone, passkey and authenticator prompts, auth mail and its sender's name |
12
- | Icon | `protobase.favicon.svg` at the project's root | the browser tab, `/favicon.ico`, the sidebar's logo, the sign-in page, the installed app's icon, the [MCP endpoint](mcp.md#the-apps-icon)'s icon in AI clients; the [mobile app](../guides/mobile-app.md) shows Protobase's icon instead |
12
+ | Icon | `protobase.favicon.svg` at the project's root | the browser tab, `/favicon.ico`, the sidebar's logo, the sign-in page, the installed app's icon, the [MCP endpoint](mcp.md#the-apps-icon)'s icon in AI clients; the [mobile app](../guides/mobile-app.md#the-icon) shows the image `mobile.icon` names instead, or Protobase's icon |
13
13
  | Raster icons | optional PNGs beside the SVG, below | the iPhone home screen and Android launchers, which take no SVG |
14
- | Colours | `themeColor` and `backgroundColor` in `protobase.config.ts` | the installed app's title bar and its start screen |
14
+ | Colours | `themeColor` and `backgroundColor` in `protobase.config.ts` | the installed app's title bar and its start screen; `backgroundColor` is also the background of the mobile app's own icon |
15
15
 
16
16
  ```ts
17
17
  // protobase.config.ts
@@ -52,7 +52,7 @@ Each is optional, and none is made from the SVG: without the touch icon an iPhon
52
52
  Each takes any CSS colour, and the web manifest carries the ones set:
53
53
 
54
54
  - `themeColor`: the installed app's title bar and the browser's toolbar around it (`theme_color`).
55
- - `backgroundColor`: the screen the installed app shows while it starts (`background_color`).
55
+ - `backgroundColor`: the screen the installed app shows while it starts (`background_color`), and the background of the [mobile app's own icon](../guides/mobile-app.md#the-icon).
56
56
 
57
57
  The app's own colours, its buttons and surfaces, are the [theme](theme.md)'s.
58
58
 
@@ -90,7 +90,7 @@ export default defineConfig({ themeColor: '#0d9488' })
90
90
 
91
91
  - **Type:** `string`, any CSS colour
92
92
 
93
- The colour of the screen the installed app shows while it starts, the web manifest's `background_color`.
93
+ The colour of the screen the installed app shows while it starts, the web manifest's `background_color`, and the background of the mobile app's own [icon](../../guides/mobile-app.md#the-icon).
94
94
 
95
95
  ```ts
96
96
  export default defineConfig({ backgroundColor: '#ffffff' })
@@ -98,13 +98,14 @@ export default defineConfig({ backgroundColor: '#ffffff' })
98
98
 
99
99
  ## mobile
100
100
 
101
- - **Type:** `{ appId: string; plugins?: Record<string, string>; publicKey?: string }`
101
+ - **Type:** `{ appId: string; plugins?: Record<string, string>; publicKey?: string; icon?: 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
 
105
105
  - `appId`: the app's id on both iOS and Android, such as `com.example.shop`: two or more dot-separated parts, each a letter then letters and digits.
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
+ - `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.
108
109
 
109
110
  ```ts
110
111
  export default defineConfig({