@devries-cameron20 / t3code Mirror · read-only / commits / c80cf02fb7
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 23:15 UTC

fix(mobile): match subscription widgets to app theme (#15941)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: SAPHID <saphid@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Alex Southwell committed Oct 20, 2026 at 05:05 UTC c80cf02fb78154537d267cf0860c498506dad058
6 files changed +181 -38
apps/mobile/src/widgets/SubscriptionUsage.android.tsx
+18 -3
@@ -21,9 +21,24 @@ export function SubscriptionUsage(props: SubscriptionUsageProps, environment: Wi
21 // The widget runtime evaluates this function without the app's module scope.
22 const now = Date.now();
23 const limit = 2;
24 - const colors = getMaterialColors({
25 - scheme: environment.colorScheme === "dark" ? "dark" : "light",
26 - });
24 + const mode = props.theme?.mode;
25 + const appearance =
26 + mode === "light" || mode === "dark"
27 + ? mode
28 + : environment.colorScheme === "dark"
29 + ? "dark"
30 + : "light";
31 + const palette = props.theme?.[appearance];
32 + const colors = palette
33 + ? {
34 + surface: palette.background,
35 + onSurface: palette.foreground,
36 + onSurfaceVariant: palette.secondary,
37 + surfaceVariant: palette.track,
38 + primary: palette.accent,
39 + error: palette.danger,
40 + }
41 + : getMaterialColors({ scheme: appearance });
42 const muted = colors.onSurfaceVariant;
43 const providers = props.providers ?? [
44 { name: "Codex", detail: "Open T3 to connect", windows: [], expiresAt: 0, totalWindows: 0 },
apps/mobile/src/widgets/SubscriptionUsage.tsx
+48 -30
@@ -2,6 +2,8 @@ import { HStack, ProgressView, Spacer, Text, VStack } from "@expo/ui/swift-ui";
2 import {
3 accessibilityElement,
4 accessibilityLabel,
5 + containerBackground,
6 + environment,
7 fixedSize,
8 font,
9 foregroundStyle,
@@ -23,20 +25,36 @@ type UsageConfiguration = {
25
26 function SubscriptionUsage(
27 props: SubscriptionUsageProps,
26 - environment: WidgetEnvironment<UsageConfiguration>,
28 + widgetEnvironment: WidgetEnvironment<UsageConfiguration> & {
29 + showsContainerBackground?: boolean;
30 + },
31 ) {
32 "widget";
33 // The extension evaluates this function without the app's module scope.
30 - const family = environment.widgetFamily;
34 + const family = widgetEnvironment.widgetFamily;
35 // Gallery snapshots can render an old timeline entry after it has expired.
32 - const now = Math.max(environment.date?.getTime() ?? 0, Date.now());
36 + const now = Math.max(widgetEnvironment.date?.getTime() ?? 0, Date.now());
37 const accessory = family === "accessoryRectangular";
38 const compact =
35 - family === "systemSmall" || accessory || environment.levelOfDetail === "simplified";
39 + family === "systemSmall" || accessory || widgetEnvironment.levelOfDetail === "simplified";
40 const dense = family === "systemSmall" || family === "systemMedium";
41 const limit = family === "systemExtraLarge" ? 6 : family === "systemLarge" ? 4 : 2;
42 const monochrome =
39 - environment.widgetRenderingMode !== "fullColor" || environment.isLuminanceReduced;
43 + widgetEnvironment.widgetRenderingMode !== "fullColor" || widgetEnvironment.isLuminanceReduced;
44 + const mode = props.theme?.mode;
45 + const appearance =
46 + mode === "light" || mode === "dark"
47 + ? mode
48 + : widgetEnvironment.colorScheme === "dark"
49 + ? "dark"
50 + : "light";
51 + // StandBy can remove the card even in full color; text must then follow the host.
52 + const palette =
53 + !accessory && !monochrome && widgetEnvironment.showsContainerBackground !== false
54 + ? props.theme?.[appearance]
55 + : undefined;
56 + const primary = palette?.foreground ?? "primary";
57 + const secondary = palette?.secondary ?? "secondary";
58 const providers = props.providers ?? [
59 { name: "Codex", detail: "Open T3 to connect", windows: [], expiresAt: 0 },
60 { name: "Claude", detail: "Open T3 to connect", windows: [], expiresAt: 0 },
@@ -44,8 +62,9 @@ function SubscriptionUsage(
62 const columns = providers.map((provider) => {
63 const stale = provider.windows.length > 0 && now >= provider.expiresAt;
64 const period =
47 - environment.configuration?.[provider.name === "Claude" ? "claudePeriod" : "codexPeriod"] ??
48 - "auto";
65 + widgetEnvironment.configuration?.[
66 + provider.name === "Claude" ? "claudePeriod" : "codexPeriod"
67 + ] ?? "auto";
68 const windows = stale
69 ? []
70 : provider.windows.filter((window) => period === "auto" || window.kind === period);
@@ -58,7 +77,7 @@ function SubscriptionUsage(
77 windows.find((window) => window.kind === "weekly"),
78 ].filter((window) => window !== undefined);
79 const shown =
61 - accessory || environment.levelOfDetail === "simplified"
80 + accessory || widgetEnvironment.levelOfDetail === "simplified"
81 ? tightest
82 ? [tightest]
83 : []
@@ -100,7 +119,7 @@ function SubscriptionUsage(
119 modifiers={[
120 font({ textStyle: "caption", weight: "semibold" }),
121 lineLimit(1),
103 - foregroundStyle("primary"),
122 + foregroundStyle(primary),
123 ]}
124 >
125 {provider.name}
@@ -112,7 +131,7 @@ function SubscriptionUsage(
131 font({ textStyle: "caption", weight: "semibold" }),
132 lineLimit(1),
133 layoutPriority(1),
115 - foregroundStyle("primary"),
134 + foregroundStyle(primary),
135 ]}
136 >
137 {tightest
@@ -142,18 +161,14 @@ function SubscriptionUsage(
161 modifiers={[
162 font({ textStyle: compact ? "caption" : "headline", weight: "bold" }),
163 lineLimit(1),
145 - foregroundStyle("primary"),
164 + foregroundStyle(primary),
165 ]}
166 >
167 {provider.name}
168 </Text>
169 {!compact || shown.length === 0 ? (
170 <Text
152 - modifiers={[
153 - font({ textStyle: "caption2" }),
154 - foregroundStyle("secondary"),
155 - lineLimit(1),
156 - ]}
171 + modifiers={[font({ textStyle: "caption2" }), foregroundStyle(secondary), lineLimit(1)]}
172 >
173 {detail === "Subscription remaining" ? " " : detail}
174 </Text>
@@ -174,7 +189,7 @@ function SubscriptionUsage(
189 <Text
190 modifiers={[
191 font({ textStyle: compact || dense ? "caption2" : "caption" }),
177 - foregroundStyle("secondary"),
192 + foregroundStyle(secondary),
193 lineLimit(1),
194 ]}
195 >
@@ -191,10 +206,9 @@ function SubscriptionUsage(
206 layoutPriority(1),
207 foregroundStyle(
208 window.remaining <= 10 && !monochrome
194 - ? environment.colorScheme === "light"
195 - ? "#dc2626"
196 - : "#fca5a5"
197 - : "primary",
209 + ? (palette?.danger ??
210 + (widgetEnvironment.colorScheme === "light" ? "#dc2626" : "#fca5a5"))
211 + : primary,
212 ),
213 ]}
214 >
@@ -203,7 +217,7 @@ function SubscriptionUsage(
217 </HStack>
218 <ProgressView value={window.remaining / 100} modifiers={barModifiers} />
219 {!compact ? (
206 - <Text modifiers={[font({ size: 10 }), foregroundStyle("secondary"), lineLimit(1)]}>
220 + <Text modifiers={[font({ size: 10 }), foregroundStyle(secondary), lineLimit(1)]}>
221 {window.reset}
222 </Text>
223 ) : null}
@@ -213,11 +227,7 @@ function SubscriptionUsage(
227 !stale &&
228 (period === "auto" ? (provider.totalWindows ?? windows.length) : windows.length) > limit ? (
229 <Text
216 - modifiers={[
217 - font({ textStyle: "caption2" }),
218 - foregroundStyle("secondary"),
219 - lineLimit(1),
220 - ]}
230 + modifiers={[font({ textStyle: "caption2" }), foregroundStyle(secondary), lineLimit(1)]}
231 >
232 {(period === "auto" ? (provider.totalWindows ?? windows.length) : windows.length) -
233 limit}{" "}
@@ -231,10 +241,18 @@ function SubscriptionUsage(
241 <VStack
242 alignment="leading"
243 spacing={accessory || dense ? 2 : 6}
234 - modifiers={props.url ? [widgetURL(props.url)] : []}
244 + modifiers={[
245 + ...(props.url ? [widgetURL(props.url)] : []),
246 + ...(palette
247 + ? [
248 + containerBackground(palette.background, "widget"),
249 + environment("colorScheme", appearance),
250 + ]
251 + : []),
252 + ]}
253 >
254 {providers.length === 0 ? (
237 - <Text modifiers={[font({ textStyle: "caption" }), foregroundStyle("secondary")]}>
255 + <Text modifiers={[font({ textStyle: "caption" }), foregroundStyle(secondary)]}>
256 No subscription limits available.
257 </Text>
258 ) : compact ? (
@@ -249,7 +267,7 @@ function SubscriptionUsage(
267 {!accessory ? <Spacer /> : null}
268 {!accessory ? (
269 <Text
252 - modifiers={[font({ textStyle: "caption2" }), foregroundStyle("secondary"), lineLimit(1)]}
270 + modifiers={[font({ textStyle: "caption2" }), foregroundStyle(secondary), lineLimit(1)]}
271 >
272 {props.checkedAt
273 ? `As of ${new Date(props.checkedAt).toLocaleString(undefined, { hour: "numeric", minute: "2-digit", month: "short", day: "numeric" })}`
apps/mobile/src/widgets/SubscriptionUsageCoordinator.tsx
+25 -3
@@ -3,11 +3,13 @@ import { Atom } from "effect/reactivity";
3 import * as Linking from "expo-linking";
4 import { useEffect } from "react";
5 import { Platform } from "react-native";
6 +import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
7 import { environmentCatalog } from "../connection/catalog";
8 import { environmentPresentations } from "../state/presentation";
9 import { publishSubscriptionUsage } from "./publishSubscriptionUsage";
10 import { useSubscriptionUsage } from "./useSubscriptionUsage";
11 import { buildSubscriptionUsageSnapshot } from "./subscriptionUsageSnapshot";
12 +import { createWidgetTheme } from "./widgetTheme";
13
14 // Isolate quota changes from the much busier thread/config presentation stream.
15 const snapshotAtom = Atom.make((get) =>
@@ -19,16 +21,36 @@ const snapshotAtom = Atom.make((get) =>
21 ).pipe(Atom.withEquality((a, b) => JSON.stringify(a) === JSON.stringify(b)));
22
23 export function SubscriptionUsageCoordinator() {
24 + const {
25 + themeMode,
26 + themeAppearance,
27 + themeVariablesByAppearance,
28 + isReady: appearanceReady,
29 + } = useAppearancePreferences();
30 const catalog = useAtomValue(environmentCatalog.catalogValueAtom);
31 const snapshot = useAtomValue(snapshotAtom);
32 useSubscriptionUsage(catalog.isReady);
33 + const androidAppearance = Platform.OS === "android" ? themeAppearance : null;
34 useEffect(() => {
26 - if (!catalog.isReady) return;
35 + if (!catalog.isReady || !appearanceReady) return;
36 void Promise.resolve()
28 - .then(() => publishSubscriptionUsage(snapshot))
37 + .then(() =>
38 + publishSubscriptionUsage({
39 + ...snapshot,
40 + theme: createWidgetTheme(themeMode, themeVariablesByAppearance),
41 + }),
42 + )
43 .catch((error: unknown) => {
44 console.warn("Could not update subscription usage widget", error);
45 });
32 - }, [catalog.isReady, snapshot]);
46 + }, [
47 + catalog.isReady,
48 + appearanceReady,
49 + snapshot,
50 + themeMode,
51 + themeVariablesByAppearance,
52 + // oxlint-disable-next-line react/exhaustive-effect-dependencies -- Android stores resolved colors; System appearance changes must republish them.
53 + androidAppearance,
54 + ]);
55 return null;
56 }
apps/mobile/src/widgets/subscriptionUsageSnapshot.test.ts
+47 -2
@@ -6,13 +6,30 @@ import {
6 type ServerProvider,
7 } from "@t3tools/contracts";
8 import { describe, expect, it, vi } from "vite-plus/test";
9 +import { getMobileThemeRuntimeVariables } from "../lib/mobileThemeVariables";
10 +import { createWidgetTheme } from "./widgetTheme";
11 import {
12 + type SubscriptionUsageSnapshot,
13 buildSubscriptionUsageSnapshot,
14 createWidgetRefresher,
15 WIDGET_REFRESH_INTERVAL,
16 subscriptionUsageTimeline,
17 } from "./subscriptionUsageSnapshot";
18
19 +function contrastRatio(first: string, second: string) {
20 + const luminance = (color: string) => {
21 + if (!/^#[0-9a-f]{6}(?:ff)?$/i.test(color)) throw new Error(`Expected opaque hex: ${color}`);
22 + const linear = [1, 3, 5].map((offset) => {
23 + const channel = Number.parseInt(color.slice(offset, offset + 2), 16) / 255;
24 + return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
25 + });
26 + return 0.2126 * linear[0]! + 0.7152 * linear[1]! + 0.0722 * linear[2]!;
27 + };
28 + const a = luminance(first);
29 + const b = luminance(second);
30 + return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
31 +}
32 +
33 const checkedAt = "2026-09-05T12:00:00.000Z";
34 const now = Date.parse(checkedAt);
35 const window = {
@@ -221,12 +238,40 @@ describe("subscription widget snapshots", () => {
238 expect(snapshot.providers[0]?.expiresAt).toBe(now + 15 * 60_000);
239 expect(snapshot.providers[0]?.windows[0]?.reset).toBe("Reset time unavailable");
240 });
224 - it("schedules a reset boundary without inventing a zero quota", () => {
225 - const snapshot = buildSubscriptionUsageSnapshot(presentations(), deepLink);
241 + it("preserves the saved appearance through a reset without inventing a zero quota", () => {
242 + const light = getMobileThemeRuntimeVariables("t3-chat", "light", "ios");
243 + const dark = getMobileThemeRuntimeVariables("t3-code", "dark", "ios");
244 + const snapshot: SubscriptionUsageSnapshot = JSON.parse(
245 + JSON.stringify({
246 + ...buildSubscriptionUsageSnapshot(presentations(), deepLink),
247 + theme: createWidgetTheme("dark", { light, dark }),
248 + }),
249 + );
250 const timeline = subscriptionUsageTimeline(snapshot, now);
251 expect(timeline.map((entry) => entry.date.getTime())).toEqual([now, now + 10 * 60_000]);
252 expect(timeline[1]?.props.providers[0]?.windows).toEqual([]);
253 expect(subscriptionUsageTimeline(snapshot, now + 60 * 60_000)).toHaveLength(1);
254 + for (const entry of timeline) {
255 + expect(JSON.parse(JSON.stringify(entry.props)).theme).toEqual({
256 + mode: "dark",
257 + light: expect.objectContaining({
258 + background: light["--color-card"],
259 + foreground: light["--color-foreground"],
260 + }),
261 + dark: expect.objectContaining({
262 + background: dark["--color-card"],
263 + foreground: dark["--color-foreground"],
264 + }),
265 + });
266 + }
267 + });
268 + it("keeps the default Android unfilled track distinguishable from the card", () => {
269 + const theme = createWidgetTheme("system", {
270 + light: getMobileThemeRuntimeVariables("t3-code", "light", "android"),
271 + dark: getMobileThemeRuntimeVariables("t3-code", "dark", "android"),
272 + });
273 + expect(contrastRatio(theme.dark.track, theme.dark.background)).toBeGreaterThanOrEqual(1.3);
274 + expect(contrastRatio(theme.light.track, theme.light.background)).toBeGreaterThanOrEqual(1.3);
275 });
276 it("expires providers independently without inventing a refill", () => {
277 const snapshot = buildSubscriptionUsageSnapshot(
apps/mobile/src/widgets/subscriptionUsageSnapshot.ts
+3
@@ -5,7 +5,10 @@ import {
5 type LimitPresentations,
6 } from "@t3tools/shared/usageLimits";
7
8 +import type { WidgetTheme } from "./widgetTheme";
9 +
10 export interface SubscriptionUsageSnapshot {
11 + theme?: WidgetTheme;
12 url?: string;
13 checkedAt: number;
14 providers: Array<{
apps/mobile/src/widgets/widgetTheme.ts new
+40
@@ -0,0 +1,40 @@
1 +import {
2 + flattenThemeColor,
3 + themeColorWithAlpha,
4 + type MobileThemeMode,
5 + type MobileThemeVariables,
6 +} from "../lib/mobileTheme";
7 +
8 +export interface WidgetPalette {
9 + background: string;
10 + foreground: string;
11 + secondary: string;
12 + accent: string;
13 + track: string;
14 + danger: string;
15 +}
16 +
17 +export interface WidgetTheme {
18 + mode: MobileThemeMode;
19 + light: WidgetPalette;
20 + dark: WidgetPalette;
21 +}
22 +
23 +export function createWidgetTheme(
24 + mode: MobileThemeMode,
25 + palettes: Readonly<Record<"light" | "dark", MobileThemeVariables>>,
26 +): WidgetTheme {
27 + const palette = (variables: MobileThemeVariables) => ({
28 + background: variables["--color-card"],
29 + foreground: variables["--color-foreground"],
30 + secondary: variables["--color-foreground-secondary"],
31 + accent: variables["--color-primary"],
32 + // Surface tokens can coincide; a foreground blend keeps the unfilled track visible.
33 + track: flattenThemeColor(
34 + themeColorWithAlpha(variables["--color-foreground"], 0.16),
35 + variables["--color-card"],
36 + ),
37 + danger: variables["--color-danger-foreground"],
38 + });
39 + return { mode, light: palette(palettes.light), dark: palette(palettes.dark) };
40 +}