Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/mobile/assets/widget/Claude.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions apps/mobile/assets/widget/Codex.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions apps/mobile/assets/widget/Cursor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions apps/mobile/assets/widget/Grok.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions apps/mobile/assets/widget/OpenCode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"config:prod": "APP_VARIANT=production expo config",
"profile:android:hermes": "mkdir -p profiles/review && react-native profile-hermes profiles/review",
"sync:pierre-icons": "node modules/t3-markdown-text/scripts/sync-pierre-file-icons.mjs",
"sync:provider-marks": "node scripts/sync-provider-marks.mjs",
"check:provider-marks": "node scripts/sync-provider-marks.mjs --check",
"test": "vp test run",
"typecheck": "tsc --noEmit"
},
Expand Down
27 changes: 17 additions & 10 deletions apps/mobile/plugins/withWidgetLogoAsset.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

// Ships the branded T3 mark to the Live Activity / widget extension.
// Ships the branded T3 mark and the provider marks to the Live Activity /
// widget extension.
//
// expo-widgets generates ExpoWidgetsTarget without a Resources build phase and
// has no asset support, so this plugin (a) writes an SVG template image set into
Expand All @@ -22,14 +23,16 @@ const { addWidgetAssetCatalog } = require("./lib/addWidgetAssetCatalog.cjs");

const TARGET_NAME = "ExpoWidgetsTarget";
const CATALOG_NAME = "Assets.xcassets";
const IMAGE_SET = "T3Mark.imageset";
const SVG_NAME = "T3Mark.svg";
// Asset names the Live Activity layout resolves with `Image assetName`. The
// provider marks mirror the web app's icons (apps/web/src/components/Icons) so a
// card reads the same on the lock screen as it does in the sidebar.
const MARK_NAMES = ["T3Mark", "Codex", "Claude", "Cursor", "OpenCode", "Grok"];

const CATALOG_CONTENTS = JSON.stringify({ info: { author: "expo", version: 1 } }, null, 2) + "\n";
const IMAGE_SET_CONTENTS =
const imageSetContents = (svgName) =>
JSON.stringify(
{
images: [{ idiom: "universal", filename: SVG_NAME }],
images: [{ idiom: "universal", filename: svgName }],
info: { author: "expo", version: 1 },
properties: {
"preserves-vector-representation": true,
Expand All @@ -44,13 +47,17 @@ function withAssetFiles(config) {
return withDangerousMod(config, [
"ios",
(cfg) => {
const source = path.join(cfg.modRequest.projectRoot, "assets", "widget", SVG_NAME);
const catalogDir = path.join(cfg.modRequest.platformProjectRoot, TARGET_NAME, CATALOG_NAME);
const imageSetDir = path.join(catalogDir, IMAGE_SET);
fs.mkdirSync(imageSetDir, { recursive: true });
fs.mkdirSync(catalogDir, { recursive: true });
fs.writeFileSync(path.join(catalogDir, "Contents.json"), CATALOG_CONTENTS);
fs.writeFileSync(path.join(imageSetDir, "Contents.json"), IMAGE_SET_CONTENTS);
fs.copyFileSync(source, path.join(imageSetDir, SVG_NAME));
for (const name of MARK_NAMES) {
const svgName = `${name}.svg`;
const source = path.join(cfg.modRequest.projectRoot, "assets", "widget", svgName);
const imageSetDir = path.join(catalogDir, `${name}.imageset`);
fs.mkdirSync(imageSetDir, { recursive: true });
fs.writeFileSync(path.join(imageSetDir, "Contents.json"), imageSetContents(svgName));
fs.copyFileSync(source, path.join(imageSetDir, svgName));
}
return cfg;
},
]);
Expand Down
132 changes: 132 additions & 0 deletions apps/mobile/scripts/sync-provider-marks.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#!/usr/bin/env node

// Derives the widget extension's provider marks from the web app's icons.
//
// The Live Activity resolves its marks through an asset catalog (`Image
// assetName`), so it cannot import the React components in
// apps/web/src/components/Icons.tsx. Rather than hand-copy the path data and let
// it drift, generate the SVGs from that file and verify them in CI.
//
// node scripts/sync-provider-marks.mjs # write
// node scripts/sync-provider-marks.mjs --check # verify, exit 1 on drift

import * as NodeFSP from "node:fs/promises";
import * as NodePath from "node:path";
import * as NodeProcess from "node:process";
import * as NodeURL from "node:url";

const MOBILE_ROOT = NodePath.resolve(
NodePath.dirname(NodeURL.fileURLToPath(import.meta.url)),
"..",
);
const REPO_ROOT = NodePath.resolve(MOBILE_ROOT, "../..");
const ICONS_SOURCE = NodePath.join(REPO_ROOT, "apps/web/src/components/Icons.tsx");
const OUTPUT_DIR = NodePath.join(MOBILE_ROOT, "assets/widget");

// Asset name -> the exported icon it comes from. The asset names are what
// withWidgetLogoAsset.cjs ships and what the widget layouts ask for; the
// components mirror PROVIDER_ICON_BY_PROVIDER in providerIconUtils.ts.
const MARKS = [
{ asset: "Codex", component: "OpenAI" },
{ asset: "Claude", component: "ClaudeAI" },
{ asset: "Cursor", component: "CursorIcon" },
{ asset: "Grok", component: "GrokIcon" },
{ asset: "OpenCode", component: "OpenCodeIcon" },
];

// Cursor's mark is one path holding the outer cube and the inner facet. Nonzero
// winding fills both and collapses it to a featureless block, so it needs
// even-odd for the facet to cut through.
const EVEN_ODD = new Set(["Cursor"]);
// OpenCode's mark is a frame plus a dimmer inner block. A template image is a
// single colour, so the inner block is carried at partial opacity instead.
const INNER_BLOCK_OPACITY = "0.45";

function componentBlock(source, name) {
const start = source.indexOf(`export const ${name}: Icon`);
if (start === -1) throw new Error(`Icons.tsx no longer exports ${name}`);
const end = source.indexOf("\nexport const ", start + 10);
return source.slice(start, end === -1 ? undefined : end);
}

function viewBox(block, name) {
const match = /viewBox="([^"]+)"/.exec(block);
if (!match) throw new Error(`${name} has no viewBox`);
return match[1];
}

function pathTags(block) {
return [...block.matchAll(/<path\b([^>]*?)\/>/gs)].map((match) => match[1]);
}

function pathData(attributes, name) {
const match = /(?:^|\s)d="([^"]+)"/s.exec(attributes);
if (!match) throw new Error(`${name} has a <path> without a d attribute`);
return match[1];
}
Comment thread
macroscopeapp[bot] marked this conversation as resolved.
Resolved

function renderSvg({ asset, block }) {
const box = viewBox(block, asset);
const [, , width, height] = box.split(/\s+/);
const fillRule = EVEN_ODD.has(asset) ? ' fill-rule="evenodd"' : "";

let paths;
if (asset === "OpenCode") {
// Icons.tsx carries a light and a dark pair toggled by className; take the
// dark one, whose frame is the light shape on a dark surface.
const dark = pathTags(block).filter((attributes) => attributes.includes("dark:block"));
if (dark.length !== 2) {
throw new Error(`OpenCodeIcon no longer has exactly two dark-mode paths (${dark.length})`);
}
const [inner, frame] = dark;
paths = [
` <path fill="currentColor" fill-opacity="${INNER_BLOCK_OPACITY}" d="${pathData(inner, asset)}"/>`,
` <path fill="currentColor" d="${pathData(frame, asset)}"/>`,
];
} else {
paths = pathTags(block).map(
(attributes) => ` <path fill="currentColor"${fillRule} d="${pathData(attributes, asset)}"/>`,
);
}
if (paths.length === 0) throw new Error(`${asset} produced no paths`);

return (
`<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" ` +
`viewBox="${box}">\n${paths.join("\n")}\n</svg>\n`
);
}

const checkOnly = NodeProcess.argv.includes("--check");
const source = await NodeFSP.readFile(ICONS_SOURCE, "utf8");

const drifted = [];
let written = 0;
for (const mark of MARKS) {
const svg = renderSvg({ asset: mark.asset, block: componentBlock(source, mark.component) });
const target = NodePath.join(OUTPUT_DIR, `${mark.asset}.svg`);
const current = await NodeFSP.readFile(target, "utf8").catch(() => null);
if (current === svg) continue;
if (checkOnly) {
drifted.push(mark.asset);
continue;
}
await NodeFSP.mkdir(OUTPUT_DIR, { recursive: true });
await NodeFSP.writeFile(target, svg);
written += 1;
console.log(`updated ${NodePath.relative(REPO_ROOT, target)}`);
}

if (checkOnly && drifted.length > 0) {
console.error(
`Provider marks are out of date with Icons.tsx: ${drifted.join(", ")}.\n` +
"Run `vp run --filter @t3tools/mobile sync:provider-marks` and commit the result.",
);
NodeProcess.exit(1);
}
console.log(
checkOnly
? `All ${MARKS.length} provider marks are current.`
: written === 0
? `All ${MARKS.length} provider marks were already current.`
: `Updated ${written} of ${MARKS.length} provider marks.`,
);
Loading
Loading