Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

app.config.ts

526 lines19.1 KB

1import type { ExpoConfig } from "expo/config";
2​
3import { BRAND_ASSET_PATHS } from "../../scripts/lib/brand-assets.ts";
4import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
5​
6type AppVariant = "development" | "preview" | "production";
7​
8const repoEnv = loadRepoEnv();
9Object.assign(process.env, repoEnv);
10// Expo's TypeScript setup otherwise installs `typescript` on every start; we typecheck with tsrs.
11process.env.EXPO_NO_TYPESCRIPT_SETUP = "1";
12​
13const APP_VARIANT = resolveAppVariant(repoEnv.APP_VARIANT);
14const isIosPersonalTeamBuild = repoEnv.T3CODE_IOS_PERSONAL_TEAM === "1";
15const runtimeVersionPolicy =
16 process.env.MOBILE_VERSION_POLICY ??
17 (APP_VARIANT === "development" ? "appVersion" : "fingerprint");
18​
19const personalTeamBundleIdentifier = repoEnv.T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID?.trim();
20const IOS_BUNDLE_IDENTIFIER_PATTERN = /^[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+$/;
21​
22// Compiled into the native project. Without a relay, Observe's native side could dispatch to
23// Expo's own ingest before observe.ts turns it off; `.invalid` never resolves (RFC 6761).
24const observeEndpointUrl = repoEnv.T3CODE_RELAY_URL?.trim()
25 ? new URL("/v1/mobile/observe", repoEnv.T3CODE_RELAY_URL.trim()).toString()
26 : "https://observe.invalid";
27​
28const fromRepoRoot = (relativePath: string) => `../../${relativePath}`;
29const androidAdaptiveForeground = "./assets/android-icon-foreground.png";
30​
31if (
32 isIosPersonalTeamBuild &&
33 (!personalTeamBundleIdentifier ||
34 !IOS_BUNDLE_IDENTIFIER_PATTERN.test(personalTeamBundleIdentifier))
35) {
36 throw new Error(
37 "T3CODE_IOS_PERSONAL_TEAM_BUNDLE_ID must be a reverse-DNS identifier such as com.example.t3code when T3CODE_IOS_PERSONAL_TEAM=1.",
38 );
40​
41const DEVELOPMENT_ASSETS = {
42 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIosIconPng),
43 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIconComposerProject),
44 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.developmentIosIconPng),
45 androidAdaptiveForeground,
46 androidAdaptiveBackgroundColor: "#347FF8",
47 androidAdaptiveBackgroundImage: "./assets/android-icon-background-dev.png",
48 androidSplashIcon: "./assets/android-splash-icon-dev.png",
49 androidMonochromeIcon: "./assets/android-icon-mark.png",
50 androidNotificationIcon: "./assets/android-notification-icon.png",
51 androidNotificationColor: "#00639B",
52} as const;
53​
54const PREVIEW_ASSETS = {
55 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIosIconPng),
56 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIconComposerProject),
57 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.nightlyIosIconPng),
58 androidAdaptiveForeground,
59 androidAdaptiveBackgroundColor: "#111533",
60 androidAdaptiveBackgroundImage: "./assets/android-icon-background-nightly.png",
61 androidSplashIcon: "./assets/android-splash-icon-nightly.png",
62 androidMonochromeIcon: "./assets/android-icon-mark.png",
63 androidNotificationIcon: "./assets/android-notification-icon.png",
64 androidNotificationColor: "#7565C7",
65} as const;
66​
67const RELEASE_ASSETS = {
68 appIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIosIconPng),
69 iosIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIconComposerProject),
70 splashIcon: fromRepoRoot(BRAND_ASSET_PATHS.productionIosIconPng),
71 androidAdaptiveForeground,
72 androidAdaptiveBackgroundColor: "#000000",
73 androidAdaptiveBackgroundImage: undefined,
74 androidSplashIcon: "./assets/android-splash-icon-prod.png",
75 androidMonochromeIcon: "./assets/android-icon-mark.png",
76 androidNotificationIcon: "./assets/android-notification-icon.png",
77 androidNotificationColor: "#FFFFFF",
78} as const;
79​
80const VARIANT_CONFIG = {
81 development: {
82 appName: "T3 Code Dev",
83 scheme: "t3code-dev",
84 iosBundleIdentifier: "com.t3tools.t3code.dev",
85 androidPackage: "com.t3tools.t3code.dev",
86 relyingParty: "clerk.t3.codes",
87 assets: DEVELOPMENT_ASSETS,
88 },
89 preview: {
90 appName: "T3 Code Preview",
91 scheme: "t3code-preview",
92 iosBundleIdentifier: "com.t3tools.t3code.preview",
93 androidPackage: "com.t3tools.t3code.preview",
94 relyingParty: "clerk.t3.codes",
95 assets: PREVIEW_ASSETS,
96 },
97 production: {
98 appName: "T3 Code",
99 scheme: "t3code",
100 iosBundleIdentifier: "com.t3tools.t3code",
101 androidPackage: "com.t3tools.t3code",
102 relyingParty: "clerk.t3.codes",
103 assets: RELEASE_ASSETS,
104 },
105} as const;
106​
107function resolveAppVariant(value: string | undefined): AppVariant {
108 switch (value) {
109 case "development":
110 case "preview":
111 case "production":
112 return value;
113 case undefined:
114 return "production";
115 default:
116 throw new Error("APP_VARIANT must be development, preview, or production.");
117 }
119​
120const variant = VARIANT_CONFIG[APP_VARIANT];
121// Copied thread links open the app. app.t3.codes/.well-known lists every variant's identifiers.
122const HOSTED_APP_HOST = "app.t3.codes";
123const iosBundleIdentifier = isIosPersonalTeamBuild
124 ? personalTeamBundleIdentifier!
125 : variant.iosBundleIdentifier;
126​
127const dmSansFonts = {
128 regular: "@expo-google-fonts/dm-sans/400Regular/DMSans_400Regular.ttf",
129 medium: "@expo-google-fonts/dm-sans/500Medium/DMSans_500Medium.ttf",
130 bold: "@expo-google-fonts/dm-sans/700Bold/DMSans_700Bold.ttf",
131} as const;
132​
133const mesloFonts = {
134 regular: "./assets/fonts/MesloLGS-NF-Regular.ttf",
135 bold: "./assets/fonts/MesloLGS-NF-Bold.ttf",
136} as const;
137​
138const widgetsPlugin: NonNullable<ExpoConfig["plugins"]>[number] = [
139 "expo-widgets",
140 {
141 bundleIdentifier: `${iosBundleIdentifier}.widgets`,
142 groupIdentifier: `group.${iosBundleIdentifier}`,
143 enablePushNotifications: true,
144 // Frequent updates need the iOS entitlement to avoid early throttling.
145 frequentUpdates: true,
146 enableAndroid: true,
147 widgets: [
148 {
149 name: "SubscriptionUsage",
150 displayName: "Subscription usage",
151 description: "Subscription quotas from your connected T3 Code environments.",
152 ios: {
153 configuration: {
154 title: "Subscription usage",
155 description:
156 "Both shows Session and Weekly when available. The Lock Screen shows the tightest selected limit.",
157 parameters: {
158 codexPeriod: {
159 title: "Codex limits",
160 type: "enum",
161 default: "auto",
162 values: [
163 { name: "Both", value: "auto" },
164 { name: "Session", value: "session" },
165 { name: "Weekly", value: "weekly" },
166 ],
167 },
168 claudePeriod: {
169 title: "Claude limits",
170 type: "enum",
171 default: "auto",
172 values: [
173 { name: "Both", value: "auto" },
174 { name: "Session", value: "session" },
175 { name: "Weekly", value: "weekly" },
176 ],
177 },
178 },
179 },
180 supportedFamilies: [
181 "systemSmall",
182 "systemMedium",
183 "systemLarge",
184 "systemExtraLarge",
185 "accessoryRectangular",
186 ],
187 },
188 android: {
189 minWidth: 250,
190 minHeight: 180,
191 minResizeWidth: 180,
192 minResizeHeight: 130,
193 targetCellWidth: 4,
194 targetCellHeight: 3,
195 resizeMode: "both",
196 // The embedded layout renders before first launch; publishing replaces it with stored props.
197 initialLayout: "./src/widgets/SubscriptionUsage.android.tsx",
198 },
199 },
200 {
201 name: "AgentActivity",
202 displayName: "Agent Activity",
203 description: "Shows the current state of active T3 Code agents.",
204 android: null,
205 ios: {
206 supportedFamilies: ["systemSmall", "systemMedium", "accessoryRectangular"],
207 // Embeds the layout so the gallery preview and a new widget render
208 // before the app has run once; the app replaces it on publish.
209 initialLayout: "./src/widgets/AgentActivityWidget.tsx",
210 },
211 },
212 ],
213 },
214];
215​
216const sharingPlugin: NonNullable<ExpoConfig["plugins"]>[number] = [
217 "expo-sharing",
218 {
219 ios: {
220 // Personal Teams cannot sign App Groups or extension targets; keep local builds usable.
221 enabled: !isIosPersonalTeamBuild,
222 extensionBundleIdentifier: `${iosBundleIdentifier}.sharing`,
223 appGroupId: `group.${iosBundleIdentifier}`,
224 activationRule: {
225 supportsText: true,
226 supportsWebUrlWithMaxCount: 1,
227 supportsImageWithMaxCount: 8,
228 supportsMovieWithMaxCount: 8,
229 supportsFileWithMaxCount: 8,
230 },
231 },
232 android: {
233 enabled: true,
234 singleShareMimeTypes: ["*/*"],
235 multipleShareMimeTypes: ["*/*"],
236 },
237 },
238];
239​
240// Match iOS PostScript names on Android so RN and the native composer share fonts before runtime loading.
241​
242const config: ExpoConfig = {
243 name: variant.appName,
244 slug: "t3-code",
245 platforms: ["ios", "android"],
246 scheme: variant.scheme,
247 version: repoEnv.T3CODE_MOBILE_VERSION ?? "2.4.1",
248 runtimeVersion: {
249 // Skip costly fingerprinting on dev launches; preview and production OTAs require matching native projects.
250 policy: runtimeVersionPolicy,
251 },
252 orientation: "portrait",
253 icon: variant.assets.appIcon,
254 userInterfaceStyle: "automatic",
255 updates: {
256 enabled: repoEnv.T3CODE_MOBILE_UPDATES_ENABLED !== "0",
257 url: "https://u.expo.dev/d763fcb8-d37c-41ea-a773-b54a0ab4a454",
258 checkAutomatically: "ON_LOAD",
259 fallbackToCacheTimeout: 0,
260 },
261 ios: {
262 icon: variant.assets.iosIcon,
263 supportsTablet: true,
264 requireFullScreen: process.env.T3_SHOWCASE_CAPTURE_BUILD === "1",
265 bundleIdentifier: iosBundleIdentifier,
266 // Avoid Personal Team fallback: it cannot sign App Groups, Apple sign-in or push entitlements.
267 appleTeamId: "ARK85ZXQ4Z",
268 associatedDomains: [
269 `applinks:${variant.relyingParty}`,
270 `webcredentials:${variant.relyingParty}`,
271 `applinks:${HOSTED_APP_HOST}`,
272 ],
273 entitlements: {
274 "keychain-access-groups": [`$(AppIdentifierPrefix)${variant.iosBundleIdentifier}`],
275 },
276 infoPlist: {
277 UISupportedInterfaceOrientations: [
278 "UIInterfaceOrientationPortrait",
279 "UIInterfaceOrientationLandscapeLeft",
280 "UIInterfaceOrientationLandscapeRight",
281 ],
282 NSAppTransportSecurity: {
283 NSAllowsArbitraryLoads: true,
284 },
285 NSLocalNetworkUsageDescription:
286 "Allow T3 Code to connect to T3 Code servers on your local network or tailnet.",
287 // Built with the iOS 27 SDK, only view controllers can hide or style the status bar.
288 UIViewControllerBasedStatusBarAppearance: true,
289 NSPhotoLibraryAddUsageDescription:
290 "Allow T3 Code to save images and videos to your photo library.",
291 // System picture in picture needs background audio to start and survive outside the app.
292 UIBackgroundModes: ["audio"],
293 ITSAppUsesNonExemptEncryption: false,
294 // Capture builds disable multitasking because iPadOS otherwise ignores orientation requests.
295 ...(process.env.T3_SHOWCASE_CAPTURE_BUILD === "1"
296 ? {
297 "UISupportedInterfaceOrientations~ipad": [
298 "UIInterfaceOrientationPortrait",
299 "UIInterfaceOrientationPortraitUpsideDown",
300 "UIInterfaceOrientationLandscapeLeft",
301 "UIInterfaceOrientationLandscapeRight",
302 ],
303 }
304 : {}),
305 },
306 },
307 android: {
308 icon: variant.assets.appIcon,
309 package: variant.androidPackage,
310 ...(repoEnv.T3CODE_ANDROID_GOOGLE_SERVICES_FILE
311 ? { googleServicesFile: repoEnv.T3CODE_ANDROID_GOOGLE_SERVICES_FILE }
312 : {}),
313 adaptiveIcon: {
314 backgroundColor: variant.assets.androidAdaptiveBackgroundColor,
315 ...(variant.assets.androidAdaptiveBackgroundImage
316 ? { backgroundImage: variant.assets.androidAdaptiveBackgroundImage }
317 : {}),
318 foregroundImage: variant.assets.androidAdaptiveForeground,
319 monochromeImage: variant.assets.androidMonochromeIcon,
320 },
321 // JS back dispatch needs RN's Android 16 shim and withAndroidPredictiveBackCompat on Android 13-15.
322 predictiveBackGestureEnabled: true,
323 // expo-sensors declares this for its pedometer, which the app does not use.
324 blockedPermissions: ["android.permission.ACTIVITY_RECOGNITION"],
325 intentFilters: [
326 {
327 action: "VIEW",
328 autoVerify: true,
329 data: [{ scheme: "https", host: HOSTED_APP_HOST, pathPrefix: "/threads/" }],
330 category: ["BROWSABLE", "DEFAULT"],
331 },
332 ],
333 },
334 web: {
335 favicon: variant.assets.appIcon,
336 },
337 plugins: [
338 "expo-asset",
339 [
340 "expo-font",
341 {
342 ios: {
343 fonts: [
344 dmSansFonts.regular,
345 dmSansFonts.medium,
346 dmSansFonts.bold,
347 mesloFonts.regular,
348 mesloFonts.bold,
349 ],
350 },
351 android: {
352 fonts: [
353 {
354 fontFamily: "DMSans-Regular",
355 fontDefinitions: [{ path: dmSansFonts.regular, weight: 400 }],
356 },
357 {
358 fontFamily: "DMSans-Medium",
359 fontDefinitions: [{ path: dmSansFonts.medium, weight: 500 }],
360 },
361 {
362 fontFamily: "DMSans-Bold",
363 // Android picks fallback glyphs (such as Vietnamese) at the requested weight, so bold text
364 // asks for 700; the 400 entry lets a relative bold step (Typeface.BOLD) land on 700 too.
365 fontDefinitions: [
366 { path: dmSansFonts.bold, weight: 400 },
367 { path: dmSansFonts.bold, weight: 700 },
368 ],
369 },
370 {
371 // One family for both weights, as on iOS, so fontWeight picks the bold file.
372 fontFamily: "MesloLGS-NF-Regular",
373 fontDefinitions: [
374 { path: mesloFonts.regular, weight: 400 },
375 { path: mesloFonts.bold, weight: 700 },
376 ],
377 },
378 ],
379 },
380 },
381 ],
382 "expo-secure-store",
383 "expo-sqlite",
384 ...(isIosPersonalTeamBuild
385 ? [sharingPlugin]
386 : ["./plugins/withShareExtensionDisplayName.cjs", sharingPlugin]),
387 [
388 "expo-notifications",
389 {
390 icon: variant.assets.androidNotificationIcon,
391 color: variant.assets.androidNotificationColor,
392 mode: APP_VARIANT === "development" ? "development" : "production",
393 },
394 ],
395 // Gate Clerk here: withoutIosPersonalTeamCapabilities runs too early to strip its entitlement.
396 ["@clerk/expo", { theme: "./clerk-theme.json", appleSignIn: !isIosPersonalTeamBuild }],
397 "expo-web-browser",
398 [
399 "expo-quick-actions",
400 {
401 androidIcons: {
402 shortcut_icon: {
403 foregroundImage: variant.assets.androidAdaptiveForeground,
404 backgroundColor: variant.assets.androidAdaptiveBackgroundColor,
405 ...(variant.assets.androidAdaptiveBackgroundImage
406 ? { backgroundImage: variant.assets.androidAdaptiveBackgroundImage }
407 : {}),
408 },
409 },
410 },
411 ],
412 [
413 "expo-audio",
414 {
415 microphonePermission: "Allow T3 Code to use your microphone for voice input.",
416 recordAudioAndroid: true,
417 enableBackgroundPlayback: false,
418 enableBackgroundRecording: false,
419 },
420 ],
421 [
422 "expo-camera",
423 {
424 cameraPermission: "Allow T3 Code to access your camera so you can scan pairing QR codes.",
425 microphonePermission: false,
426 barcodeScannerEnabled: true,
427 recordAudioAndroid: false,
428 },
429 ],
430 [
431 "expo-image-picker",
432 {
433 photosPermission: false,
434 // `false` makes this plugin add RECORD_AUDIO to blockedPermissions, breaking Android dictation.
435 microphonePermission: "Allow T3 Code to use your microphone for voice input.",
436 },
437 ],
438 [
439 "expo-splash-screen",
440 {
441 image: variant.assets.splashIcon,
442 resizeMode: "contain",
443 backgroundColor: "#ffffff",
444 imageWidth: 220,
445 dark: {
446 image: variant.assets.splashIcon,
447 backgroundColor: "#0a0a0a",
448 },
449 android: {
450 // Android 12+ masks the central two thirds of the 288dp canvas; adaptive layers avoid clipped corners.
451 image: variant.assets.androidSplashIcon,
452 imageWidth: 288,
453 dark: { image: variant.assets.androidSplashIcon },
454 },
455 },
456 ],
457 [
458 "expo-build-properties",
459 {
460 android: {
461 minSdkVersion: 24,
462 // SDK 58 lacks Kotlin 2.3's runtime-inert annotation. R8 needs explicit InputMerger constructors for widgets.
463 extraProguardRules: [
464 "-dontwarn kotlin.MustUseReturnValues",
465 "-keep class * extends androidx.work.InputMerger { <init>(); }",
466 ].join("\n"),
467 },
468 ios: {
469 deploymentTarget: "18.0",
470 // AppCheckCore 11.3+ includes Swift and needs module maps for these Objective-C dependencies.
471 extraPods: [
472 { name: "GoogleUtilities", modular_headers: true },
473 { name: "RecaptchaInterop", modular_headers: true },
474 ],
475 },
476 },
477 ],
478 "./plugins/withIosCocoaPodsUuidCache.cjs",
479 // Compile out the unused pedometer to avoid an iOS motion purpose string.
480 ["expo-sensors", { motionPermission: false }],
481 // Mods run in reverse order; expo-widgets must create and wipe the target before assets are added.
482 ...(!isIosPersonalTeamBuild ? ["./plugins/withWidgetLogoAsset.cjs", widgetsPlugin] : []),
483 "./plugins/withAndroidNetworkSecurityConfig.cjs",
484 "./plugins/withAndroidGradleHeap.cjs",
485 "./plugins/withAndroidInputBackground.cjs",
486 "./plugins/withAndroidModernPopupMenu.cjs",
487 "./plugins/withAndroidModernAlertDialog.cjs",
488 "./plugins/withAndroidPredictiveBackCompat.cjs",
489 // MainActivity mods run in reverse order; extend the tablet-orientation override.
490 "./plugins/withAndroidWindowDisplayMetrics.cjs",
491 "./plugins/withAndroidTabletOrientation.cjs",
492 ...(isIosPersonalTeamBuild ? ["./plugins/withoutIosPersonalTeamCapabilities.cjs"] : []),
493 ],
494 extra: {
495 appVariant: APP_VARIANT,
496 iosPersonalTeamBuild: isIosPersonalTeamBuild,
497 relay: {
498 url: repoEnv.T3CODE_RELAY_URL ?? null,
499 },
500 clerk: {
501 publishableKey: repoEnv.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY ?? null,
502 jwtTemplate: repoEnv.EXPO_PUBLIC_CLERK_JWT_TEMPLATE ?? null,
503 },
504 // Clerk reads these exact names at prebuild. Omit unset values: manifest null becomes truthy {}.
505 EXPO_PUBLIC_CLERK_GOOGLE_WEB_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_WEB_CLIENT_ID,
506 EXPO_PUBLIC_CLERK_GOOGLE_IOS_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_IOS_CLIENT_ID,
507 EXPO_PUBLIC_CLERK_GOOGLE_ANDROID_CLIENT_ID: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_ANDROID_CLIENT_ID,
508 EXPO_PUBLIC_CLERK_GOOGLE_IOS_URL_SCHEME: repoEnv.EXPO_PUBLIC_CLERK_GOOGLE_IOS_URL_SCHEME,
509 observability: {
510 tracesUrl: repoEnv.EXPO_PUBLIC_OTLP_TRACES_URL ?? "https://api.axiom.co/v1/traces",
511 tracesDataset: repoEnv.EXPO_PUBLIC_OTLP_TRACES_DATASET ?? null,
512 tracesToken: repoEnv.EXPO_PUBLIC_OTLP_TRACES_TOKEN ?? null,
513 },
514 eas: {
515 projectId: "d763fcb8-d37c-41ea-a773-b54a0ab4a454",
516 observe: { endpointUrl: observeEndpointUrl },
517 },
518 },
519 owner: "pingdotgg",
520 experiments: {
521 // Metro only runs babel-plugin-react-compiler when this is set; see src/reactCompilerCoverage.test.ts.
522 reactCompiler: true,
523 },
524};
525​
526export default config;