Skip to content

Commit b183048

Browse files
feat(mobile,web): copied thread links open the mobile app (#29815)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 251369d commit b183048

9 files changed

Lines changed: 97 additions & 8 deletions

File tree

‎apps/mobile/app.config.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import { DEFAULT_HOSTED_APP_URL } from "@t3tools/shared/connectAuth";
12
import { afterEach, expect, it, vi } from "vite-plus/test";
23

4+
import appleAppSiteAssociation from "../web/public/.well-known/apple-app-site-association.json";
5+
import assetLinks from "../web/public/.well-known/assetlinks.json";
6+
37
// Keep config parsing independent of local env files and build credentials.
48
vi.mock("../../scripts/lib/public-config.ts", () => ({
59
loadRepoEnv: () => ({ APP_VARIANT: process.env.APP_VARIANT }),
@@ -30,4 +34,14 @@ it.each([
3034
const config = await loadConfig(value);
3135
expect(config.ios?.bundleIdentifier).toBe(identifier);
3236
expect(config.android?.package).toBe(identifier);
37+
// Copied thread links open this app only while app.t3.codes lists it.
38+
const host = new URL(DEFAULT_HOSTED_APP_URL).host;
39+
expect(config.ios?.associatedDomains).toContain(`applinks:${host}`);
40+
expect(appleAppSiteAssociation.applinks.details[0]?.appIDs).toContain(
41+
`${config.ios?.appleTeamId}.${identifier}`,
42+
);
43+
expect(config.android?.intentFilters?.[0]?.data).toEqual([
44+
{ scheme: "https", host, pathPrefix: "/threads/" },
45+
]);
46+
expect(assetLinks.map((link) => link.target.package_name)).toContain(identifier);
3347
});

‎apps/mobile/app.config.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ function resolveAppVariant(value: string | undefined): AppVariant {
116116
}
117117

118118
const variant = VARIANT_CONFIG[APP_VARIANT];
119+
// Copied thread links open the app. app.t3.codes/.well-known lists every variant's identifiers.
120+
const HOSTED_APP_HOST = "app.t3.codes";
119121
const iosBundleIdentifier = isIosPersonalTeamBuild
120122
? personalTeamBundleIdentifier!
121123
: variant.iosBundleIdentifier;
@@ -252,6 +254,7 @@ const config: ExpoConfig = {
252254
associatedDomains: [
253255
`applinks:${variant.relyingParty}`,
254256
`webcredentials:${variant.relyingParty}`,
257+
`applinks:${HOSTED_APP_HOST}`,
255258
],
256259
entitlements: {
257260
"keychain-access-groups": [`$(AppIdentifierPrefix)${variant.iosBundleIdentifier}`],
@@ -302,6 +305,14 @@ const config: ExpoConfig = {
302305
predictiveBackGestureEnabled: true,
303306
// expo-sensors declares this for its pedometer, which the app does not use.
304307
blockedPermissions: ["android.permission.ACTIVITY_RECOGNITION"],
308+
intentFilters: [
309+
{
310+
action: "VIEW",
311+
autoVerify: true,
312+
data: [{ scheme: "https", host: HOSTED_APP_HOST, pathPrefix: "/threads/" }],
313+
category: ["BROWSABLE", "DEFAULT"],
314+
},
315+
],
305316
},
306317
web: {
307318
favicon: variant.assets.appIcon,

‎apps/mobile/src/App.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
type NavigationState,
1919
} from "@react-navigation/native";
2020
import { pipe } from "effect/Function";
21+
import { DEFAULT_HOSTED_APP_URL } from "@t3tools/shared/connectAuth";
2122

2223
import { RegistryContext } from "@effect/atom-react";
2324
import { ProjectChipIconRasterizer } from "./native/ProjectChipIconImages";
@@ -122,7 +123,13 @@ function getAppStateFromPath(path: string, options: Parameters<typeof getStateFr
122123
}
123124

124125
const appLinking = {
125-
prefixes: [Linking.createURL("/"), "t3code://", "t3code-dev://", "t3code-preview://"],
126+
prefixes: [
127+
Linking.createURL("/"),
128+
"t3code://",
129+
"t3code-dev://",
130+
"t3code-preview://",
131+
DEFAULT_HOSTED_APP_URL,
132+
],
126133
config: { initialRouteName: "Home" },
127134
filter: (url: string) => shouldHandleAppLink(url, hasCloudPublicConfig()),
128135
getInitialURL: async () => (await Linking.getInitialURL()) ?? (await launchWorkspaceURL()),

‎apps/mobile/src/lib/appLinking.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe("shouldHandleAppLink", () => {
2121
"t3code://threads/env-1/thread-1",
2222
"t3code://pair?pairingUrl=x",
2323
"t3code-dev://settings/usage?tab=limits",
24+
"https://app.t3.codes/threads/env/thread?prompt=Fix%20expo-development-client%20and%20t3code://expo-sharing",
2425
])("handles path-bearing URL %s", (url) => {
2526
expect(shouldHandleAppLink(url, true)).toBe(true);
2627
});

‎apps/mobile/src/lib/appLinking.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import type { NavigationState, PartialState } from "@react-navigation/native";
77
* to the NotFound wildcard route on every dev launch.
88
*/
99
export function shouldHandleAppLink(url: string, cloudConfigured: boolean): boolean {
10+
// Only the route: a thread link's ?prompt= may mention either lifecycle URL.
11+
const route = url.split(/[?#]/)[0] ?? "";
1012
return (
11-
!url.includes("expo-development-client") &&
12-
!url.includes("://expo-sharing") &&
13+
!route.includes("expo-development-client") &&
14+
!route.includes("://expo-sharing") &&
1315
!/^t3code(-dev|-preview)?:\/*$/.test(url) &&
14-
(cloudConfigured || !CLOUD_ONLY_LINK_PATH.test(url.split(/[?#]/)[0] ?? ""))
16+
(cloudConfigured || !CLOUD_ONLY_LINK_PATH.test(route))
1517
);
1618
}
1719

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"applinks": {
3+
"details": [
4+
{
5+
"appIDs": [
6+
"ARK85ZXQ4Z.com.t3tools.t3code",
7+
"ARK85ZXQ4Z.com.t3tools.t3code.preview",
8+
"ARK85ZXQ4Z.com.t3tools.t3code.dev"
9+
],
10+
"components": [{ "/": "/threads/*" }]
11+
}
12+
]
13+
}
14+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"relation": ["delegate_permission/common.handle_all_urls"],
4+
"target": {
5+
"namespace": "android_app",
6+
"package_name": "com.t3tools.t3code",
7+
"sha256_cert_fingerprints": [
8+
"B9:F5:1E:D5:A7:6C:D1:86:C9:51:08:F2:19:91:B7:D5:3A:58:FD:A9:83:12:A9:E3:53:E2:1A:59:B2:42:03:B6"
9+
]
10+
}
11+
},
12+
{
13+
"relation": ["delegate_permission/common.handle_all_urls"],
14+
"target": {
15+
"namespace": "android_app",
16+
"package_name": "com.t3tools.t3code.preview",
17+
"sha256_cert_fingerprints": [
18+
"BE:B8:BD:67:53:2F:12:95:0A:30:62:88:91:C1:2F:D0:CF:20:28:C3:81:5D:6D:31:45:E7:5A:AF:24:A2:8F:18"
19+
]
20+
}
21+
},
22+
{
23+
"relation": ["delegate_permission/common.handle_all_urls"],
24+
"target": {
25+
"namespace": "android_app",
26+
"package_name": "com.t3tools.t3code.dev",
27+
"sha256_cert_fingerprints": [
28+
"FA:C6:17:45:DC:09:03:78:6F:B9:ED:E6:2A:96:2B:39:9F:73:48:F0:BB:6F:89:9B:83:32:66:75:91:03:3B:9C"
29+
]
30+
}
31+
}
32+
]

‎apps/web/vercel.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,12 @@ export const config: VercelConfig = {
6262
dest: `${LATEST_ORIGIN}/$1`,
6363
},
6464
],
65-
rewrites: [routes.rewrite("/(.*)", "/index.html")],
65+
rewrites: [
66+
// Apple fetches it without an extension; the .json file is served as application/json.
67+
routes.rewrite(
68+
"/.well-known/apple-app-site-association",
69+
"/.well-known/apple-app-site-association.json",
70+
),
71+
routes.rewrite("/(.*)", "/index.html"),
72+
],
6673
};

‎docs/user/prompt-links.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ malicious.
5858
## Share a thread
5959

6060
**Copy thread** copies a link such as `https://app.t3.codes/threads/<environment>/<thread>`. Paste
61-
it anywhere, such as Slack, a GitHub comment, or your notes. Opening it asks where to open it, like
62-
a prompt link, then opens the thread. Only someone connected to the machine that runs the thread
63-
can see it. In T3 Code, a thread link in a message opens the thread in the app.
61+
it anywhere, such as Slack, a GitHub comment, or your notes. On a phone with T3 Code installed, it
62+
opens the thread in the app. Elsewhere, opening it asks where to open it, like a prompt link, then
63+
opens the thread. Only someone connected to the machine that runs the thread can see it. In T3 Code,
64+
a thread link in a message opens the thread in the app.

0 commit comments

Comments
 (0)