Skip to content

Commit d4e6e46

Browse files
chasemakesclaude
andcommitted
fix(clients): show the right app name and thread context
The window title flashed "T3 Code (Alpha)" on every channel before the real name landed, and never said what you were working on, so window switchers, browser tabs, and time trackers only ever saw the app name. index.html now ships a neutral title. A Vite plugin stamps the web build's channel into it from the same stage-label logic branding.ts uses, and desktop swaps in its preload-injected branding before first paint. ChatView publishes the open project and thread to a small store that DocumentTitleSync renders: `project / thread` on desktop, with ` — <app name>` added in browser tabs, and the app name with no thread open. The desktop window now keeps the renderer's title instead of resetting it to the app name, falling back only for blank titles. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 83fbbc1 commit d4e6e46

9 files changed

Lines changed: 167 additions & 14 deletions

File tree

‎apps/desktop/src/window/DesktopWindow.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,10 @@ export const make = Effect.gen(function* () {
695695
if (input.type === "gestureScrollEnd") window.webContents.send(TRACKPAD_SCROLL_END_CHANNEL);
696696
});
697697

698-
window.on("page-title-updated", (event) => {
698+
// The renderer titles the window after the open thread; only a blank title
699+
// falls back to the app name.
700+
window.on("page-title-updated", (event, title) => {
701+
if (title.trim() !== "") return;
699702
event.preventDefault();
700703
window.setTitle(environment.displayName);
701704
});
@@ -772,7 +775,6 @@ export const make = Effect.gen(function* () {
772775
}
773776
clearDevelopmentLoadRetry();
774777
developmentLoadRetryIndex = 0;
775-
window.setTitle(environment.displayName);
776778
if (environment.platform === "darwin") syncMacosWindowButtons(window);
777779
});
778780
window.webContents.on(

‎apps/web/index.html‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,12 @@
477477
cursor: pointer;
478478
}
479479
</style>
480-
<title>T3 Code (Alpha)</title>
480+
<!-- vite.config.ts stamps the web build's channel into this title. -->
481+
<title>T3 Code</title>
482+
<script>
483+
// Desktop's preload injects branding before page scripts, so the window starts on its channel.
484+
document.title = window.desktopBridge?.getAppBranding?.()?.displayName ?? document.title;
485+
</script>
481486
</head>
482487
<body>
483488
<div id="root">

‎apps/web/src/branding.logic.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ export function formatAppDisplayName(input: {
1111
return `${input.baseName} (${input.stageLabel})`;
1212
}
1313

14+
export function resolveHostedAppChannelLabel(channel: string | null | undefined): string | null {
15+
const normalized = channel?.trim().toLowerCase();
16+
return normalized === "nightly" ? "Nightly" : normalized === "latest" ? "Latest" : null;
17+
}
18+
19+
/** Stage label of a web build. vite.config.ts stamps it into index.html's title too. */
20+
export function resolveWebAppStageLabel(input: {
21+
readonly hostedAppChannel: string | null | undefined;
22+
readonly development: boolean;
23+
}): string {
24+
return (
25+
resolveHostedAppChannelLabel(input.hostedAppChannel) ?? (input.development ? "Dev" : "Alpha")
26+
);
27+
}
28+
1429
export function resolveServerBackedAppStageLabel(input: {
1530
readonly primaryServerVersion: string | null | undefined;
1631
readonly fallbackStageLabel: string;
@@ -36,3 +51,23 @@ export function resolveServerBackedAppDisplayName(input: {
3651
? input.fallbackDisplayName
3752
: formatAppDisplayName({ baseName: input.baseName, stageLabel });
3853
}
54+
55+
/**
56+
* Names the open thread: `project / thread` on desktop, where the OS already
57+
* shows the app, with the app name appended in browser tabs.
58+
*/
59+
export function resolveWindowTitle(input: {
60+
readonly appDisplayName: string;
61+
readonly projectTitle: string | null;
62+
readonly threadTitle: string | null;
63+
readonly desktop: boolean;
64+
}): string {
65+
const threadTitle = input.threadTitle?.trim() ?? "";
66+
if (threadTitle === "") {
67+
return input.appDisplayName;
68+
}
69+
70+
const projectTitle = input.projectTitle?.trim() ?? "";
71+
const context = projectTitle === "" ? threadTitle : `${projectTitle} / ${threadTitle}`;
72+
return input.desktop ? context : `${context} — ${input.appDisplayName}`;
73+
}

‎apps/web/src/branding.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { afterEach, describe, expect, it, vi } from "vite-plus/test";
22
import {
33
resolveServerBackedAppDisplayName,
44
resolveServerBackedAppStageLabel,
5+
resolveWebAppStageLabel,
6+
resolveWindowTitle,
57
} from "./branding.logic";
68

79
const originalWindow = globalThis.window;
@@ -113,4 +115,52 @@ describe("branding logic", () => {
113115
}),
114116
).toBe("T3 Code (Alpha)");
115117
});
118+
119+
it("labels web builds by hosted channel before dev or production", () => {
120+
expect(resolveWebAppStageLabel({ hostedAppChannel: " Nightly", development: true })).toBe(
121+
"Nightly",
122+
);
123+
expect(resolveWebAppStageLabel({ hostedAppChannel: "latest", development: false })).toBe(
124+
"Latest",
125+
);
126+
expect(resolveWebAppStageLabel({ hostedAppChannel: "preview", development: true })).toBe("Dev");
127+
expect(resolveWebAppStageLabel({ hostedAppChannel: "", development: false })).toBe("Alpha");
128+
});
129+
});
130+
131+
describe("resolveWindowTitle", () => {
132+
const appDisplayName = "T3 Code (Nightly)";
133+
134+
it("is the app name without a thread", () => {
135+
expect(
136+
resolveWindowTitle({ appDisplayName, projectTitle: null, threadTitle: null, desktop: true }),
137+
).toBe(appDisplayName);
138+
expect(
139+
resolveWindowTitle({
140+
appDisplayName,
141+
projectTitle: "acme",
142+
threadTitle: " ",
143+
desktop: true,
144+
}),
145+
).toBe(appDisplayName);
146+
});
147+
148+
it("names the project and thread, adding the app name only in browser tabs", () => {
149+
const input = { appDisplayName, projectTitle: "acme-web", threadTitle: "Fix login bug" };
150+
expect(resolveWindowTitle({ ...input, desktop: true })).toBe("acme-web / Fix login bug");
151+
expect(resolveWindowTitle({ ...input, desktop: false })).toBe(
152+
"acme-web / Fix login bug — T3 Code (Nightly)",
153+
);
154+
});
155+
156+
it("drops the separator without a project title", () => {
157+
expect(
158+
resolveWindowTitle({
159+
appDisplayName,
160+
projectTitle: " ",
161+
threadTitle: "Fix login bug",
162+
desktop: true,
163+
}),
164+
).toBe("Fix login bug");
165+
});
116166
});

‎apps/web/src/branding.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { DesktopAppBranding } from "@t3tools/contracts";
2-
import { formatAppDisplayName } from "./branding.logic";
2+
import {
3+
formatAppDisplayName,
4+
resolveHostedAppChannelLabel,
5+
resolveWebAppStageLabel,
6+
} from "./branding.logic";
37

48
function readInjectedDesktopAppBranding(): DesktopAppBranding | null {
59
if (typeof window === "undefined") {
@@ -14,13 +18,14 @@ const hostedAppChannel = import.meta.env.VITE_HOSTED_APP_CHANNEL?.trim().toLower
1418

1519
export const HOSTED_APP_CHANNEL =
1620
hostedAppChannel === "latest" || hostedAppChannel === "nightly" ? hostedAppChannel : null;
17-
export const HOSTED_APP_CHANNEL_LABEL =
18-
HOSTED_APP_CHANNEL === "nightly" ? "Nightly" : HOSTED_APP_CHANNEL === "latest" ? "Latest" : null;
21+
export const HOSTED_APP_CHANNEL_LABEL = resolveHostedAppChannelLabel(HOSTED_APP_CHANNEL);
1922
export const APP_BASE_NAME = injectedDesktopAppBranding?.baseName ?? "T3 Code";
2023
export const APP_STAGE_LABEL =
2124
injectedDesktopAppBranding?.stageLabel ??
22-
HOSTED_APP_CHANNEL_LABEL ??
23-
(import.meta.env.DEV ? "Dev" : "Alpha");
25+
resolveWebAppStageLabel({
26+
hostedAppChannel: HOSTED_APP_CHANNEL,
27+
development: import.meta.env.DEV,
28+
});
2429
export const APP_DISPLAY_NAME =
2530
injectedDesktopAppBranding?.displayName ??
2631
formatAppDisplayName({ baseName: APP_BASE_NAME, stageLabel: APP_STAGE_LABEL });

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ import {
179179
import * as Cause from "effect/Cause";
180180
import { AsyncResult } from "effect/reactivity";
181181
import { isElectron } from "../env";
182+
import { useWindowTitleThread } from "../windowTitleStore";
182183
import { readLocalApi } from "../localApi";
183184
import { useDiffPanelStore } from "../diffPanelStore";
184185
import { useActiveThreadRef } from "../hooks/useActiveThreadRef";
@@ -2479,6 +2480,7 @@ export default function ChatView(props: ChatViewProps) {
24792480
[activeThread?.environmentId, activeThread?.projectId],
24802481
);
24812482
const activeProject = useProject(activeProjectRef);
2483+
useWindowTitleThread(activeProject?.title ?? null, activeThread?.title ?? null);
24822484
// Environment settings with the active project's overrides applied.
24832485
const activeProjectSettings = useMemo(
24842486
() => resolveProjectSettings(settings, activeProject?.id ?? null, activeProject ?? undefined),

‎apps/web/src/routes/__root.tsx‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { Check, Copy } from "lucide";
1515
import { useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
1616

1717
import { APP_BASE_NAME, APP_DISPLAY_NAME, APP_STAGE_LABEL, APP_VERSION } from "../branding";
18-
import { resolveServerBackedAppDisplayName } from "../branding.logic";
18+
import { resolveServerBackedAppDisplayName, resolveWindowTitle } from "../branding.logic";
1919
import { AppSidebarLayout } from "../components/AppSidebarLayout";
2020
import { CommandPalette } from "../components/CommandPalette";
2121
import { CustomSnoozeDialogHost } from "../components/CustomSnoozeDialog";
@@ -63,6 +63,7 @@ import {
6363
selectProjectGroupingSettings,
6464
} from "../logicalProject";
6565
import { useUiStateStore } from "../uiStateStore";
66+
import { useWindowTitleStore } from "../windowTitleStore";
6667
import { syncBrowserChromeTheme } from "../hooks/useTheme";
6768
import { configureClientTracing } from "../observability/clientTracing";
6869
import { resolveInitialServerAuthGateState } from "../environments/primary";
@@ -342,11 +343,18 @@ function FontAppearanceSync() {
342343
function DocumentTitleSync() {
343344
const primaryServerVersion =
344345
useAtomValue(primaryServerConfigAtom)?.environment.serverVersion ?? null;
345-
const title = resolveServerBackedAppDisplayName({
346-
baseName: APP_BASE_NAME,
347-
fallbackDisplayName: APP_DISPLAY_NAME,
348-
fallbackStageLabel: APP_STAGE_LABEL,
349-
primaryServerVersion,
346+
const projectTitle = useWindowTitleStore((store) => store.projectTitle);
347+
const threadTitle = useWindowTitleStore((store) => store.threadTitle);
348+
const title = resolveWindowTitle({
349+
appDisplayName: resolveServerBackedAppDisplayName({
350+
baseName: APP_BASE_NAME,
351+
fallbackDisplayName: APP_DISPLAY_NAME,
352+
fallbackStageLabel: APP_STAGE_LABEL,
353+
primaryServerVersion,
354+
}),
355+
projectTitle,
356+
threadTitle,
357+
desktop: isElectron,
350358
});
351359

352360
useEffect(() => {
@@ -393,6 +401,7 @@ function RootRouteErrorView({ error }: ErrorComponentProps) {
393401

394402
return (
395403
<StandalonePage tone="error">
404+
<DocumentTitleSync />
396405
<StandalonePageHeader
397406
eyebrow={APP_DISPLAY_NAME}
398407
title="Something went wrong."

‎apps/web/src/windowTitleStore.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useEffect } from "react";
2+
import { create } from "zustand";
3+
4+
interface WindowTitleContext {
5+
readonly projectTitle: string | null;
6+
readonly threadTitle: string | null;
7+
}
8+
9+
/** The open thread's context, which the root layout's DocumentTitleSync renders. */
10+
export const useWindowTitleStore = create<WindowTitleContext>()(() => ({
11+
projectTitle: null,
12+
threadTitle: null,
13+
}));
14+
15+
/** Puts a thread in the window title while the calling view is mounted. */
16+
export function useWindowTitleThread(projectTitle: string | null, threadTitle: string | null) {
17+
useEffect(() => {
18+
useWindowTitleStore.setState({ projectTitle, threadTitle });
19+
return () => useWindowTitleStore.setState({ projectTitle: null, threadTitle: null });
20+
}, [projectTitle, threadTitle]);
21+
}

‎apps/web/vite.config.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import { loadRepoEnv } from "../../scripts/lib/public-config";
1818
import { thirdPartyLicensesPlugin } from "../../scripts/lib/third-party-licenses";
1919
import { tailwindPlugins } from "./vite/tailwind";
20+
import { formatAppDisplayName, resolveWebAppStageLabel } from "./src/branding.logic";
2021

2122
const repoEnv = loadRepoEnv();
2223
Object.assign(process.env, repoEnv);
@@ -146,6 +147,28 @@ function devCompressionPlugin(): Plugin {
146147
};
147148
}
148149

150+
// Stamps index.html's title with the name branding.ts resolves once the app
151+
// loads, so a tab opens on the right channel instead of flashing another's.
152+
// Desktop swaps in its injected branding from an inline script in index.html.
153+
function bootstrapTitlePlugin(): Plugin {
154+
let development = false;
155+
return {
156+
name: "t3code:bootstrap-title",
157+
configResolved(config) {
158+
// The same flag Vite exposes to the app as import.meta.env.DEV.
159+
development = !config.isProduction;
160+
},
161+
transformIndexHtml(html) {
162+
const stageLabel = resolveWebAppStageLabel({
163+
hostedAppChannel: configuredHostedAppChannel,
164+
development,
165+
});
166+
const title = formatAppDisplayName({ baseName: "T3 Code", stageLabel });
167+
return html.replace(/<title>[^<]*<\/title>/, `<title>${title}</title>`);
168+
},
169+
};
170+
}
171+
149172
// Vite rejects requests whose Host header isn't localhost, which blocks sharing
150173
// a dev server over Tailscale/LAN. Tailnet names are safe to allow wholesale:
151174
// the DNS is controlled by tailscale, so they can't be rebound by an attacker.
@@ -160,6 +183,7 @@ export default defineConfig(() => {
160183
return {
161184
assetsInclude: ["**/*.wasm"],
162185
plugins: [
186+
bootstrapTitlePlugin(),
163187
devCompressionPlugin(),
164188
thirdPartyLicensesPlugin({
165189
bundleName: "web",

0 commit comments

Comments
 (0)