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

main
ts 85 lines 3.21 KB
Raw
1 const NIGHTLY_SERVER_VERSION_PATTERN = /^[^-+]+-(?:nightly|preview)\.\d{8}\.\d+$/;
2
3 export function formatAppDisplayName(input: {
4 readonly baseName: string;
5 readonly stageLabel: string;
6 }): string {
7 if (input.stageLabel.trim().toLowerCase() === "latest") {
8 return input.baseName;
9 }
10
11 return `${input.baseName} (${input.stageLabel})`;
12 }
13
14 export function resolveHostedAppChannelLabel(channel: string | null | undefined): string | null {
15 const normalized = channel?.trim().toLowerCase();
16 // oxlint-disable-next-line t3code/no-untranslated-copy -- release channel name, part of the product name
17 return normalized === "nightly" ? "Nightly" : normalized === "latest" ? "Latest" : null;
18 }
19
20 /** Stage label of a web build. vite.config.ts stamps it into index.html's title too. */
21 export function resolveWebAppStageLabel(input: {
22 readonly hostedAppChannel: string | null | undefined;
23 readonly development: boolean;
24 }): string {
25 return (
26 // oxlint-disable-next-line t3code/no-untranslated-copy -- release channel name, part of the product name
27 resolveHostedAppChannelLabel(input.hostedAppChannel) ?? (input.development ? "Dev" : "Beta")
28 );
29 }
30
31 export function resolveServerBackedAppStageLabel(input: {
32 readonly primaryServerVersion: string | null | undefined;
33 readonly fallbackStageLabel: string;
34 }): string {
35 return input.primaryServerVersion &&
36 NIGHTLY_SERVER_VERSION_PATTERN.test(input.primaryServerVersion)
37 ? // oxlint-disable-next-line t3code/no-untranslated-copy -- release channel name, part of the product name
38 "Nightly"
39 : input.fallbackStageLabel;
40 }
41
42 export function resolveServerBackedAppDisplayName(input: {
43 readonly baseName: string;
44 readonly fallbackDisplayName: string;
45 readonly fallbackStageLabel: string;
46 readonly primaryServerVersion: string | null | undefined;
47 }): string {
48 const stageLabel = resolveServerBackedAppStageLabel({
49 primaryServerVersion: input.primaryServerVersion,
50 fallbackStageLabel: input.fallbackStageLabel,
51 });
52
53 return stageLabel === input.fallbackStageLabel
54 ? input.fallbackDisplayName
55 : formatAppDisplayName({ baseName: input.baseName, stageLabel });
56 }
57
58 /**
59 * Names the open thread: `project / thread` on desktop, where the OS already
60 * shows the app, with the app name appended in browser tabs.
61 */
62 export function resolveWindowTitle(input: {
63 readonly appDisplayName: string;
64 readonly projectTitle: string | null;
65 readonly threadTitle: string | null;
66 /** The screen reader title: status, then thread, then project, since a screen reader reads from the start. */
67 readonly screenReader?: { readonly threadStatus: string | null };
68 readonly desktop: boolean;
69 }): string {
70 const threadTitle = input.threadTitle?.trim() ?? "";
71 const status = input.screenReader?.threadStatus;
72 if (threadTitle === "") {
73 return status ? `${status}: ${input.appDisplayName}` : input.appDisplayName;
74 }
75
76 const projectTitle = input.projectTitle?.trim() ?? "";
77 const context =
78 projectTitle === ""
79 ? threadTitle
80 : input.screenReader
81 ? `${threadTitle} - ${projectTitle}`
82 : `${projectTitle} / ${threadTitle}`;
83 const title = status ? `${status}: ${context}` : context;
84 return input.desktop ? title : `${title} - ${input.appDisplayName}`;
85 }