Skip to content

Commit 8a4ad94

Browse files
refactor(web): root notification and toast coordinators start with the app (#25233)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 04a21bb commit 8a4ad94

21 files changed

Lines changed: 729 additions & 594 deletions

‎apps/web/src/appInit.tsx‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,29 @@ import { applyAppearanceFontVariables } from "./appearanceFonts";
77
import { retainThreadOverlaysForThread } from "./components/chat/threadOverlayRetention";
88
import { startBackgroundThreadAnnouncements } from "./components/BackgroundThreadAnnouncer";
99
import { startSshPasswordPromptQueue } from "./components/desktop/SshPasswordPromptDialog";
10+
import { startHostFreezeToasts } from "./components/HostFreezeToastCoordinator";
11+
import { startLegacyThreadMigrationToast } from "./components/LegacyThreadMigrationToast";
12+
import { startPermissionUpdateNotices } from "./components/PermissionUpdateNotice";
1013
import { startAgentOpenedPreviews } from "./components/preview/agentOpenedPreviews";
1114
import { startMainAppLocationTracking } from "./components/sidebar/mainAppLocation";
15+
import { startDesktopUpdateLaunchNotice } from "./components/sidebar/updateEverythingRun";
16+
import { startThreadNotifications } from "./components/ThreadNotificationCoordinator";
1217
import { APP_BASE_NAME, APP_DISPLAY_NAME, APP_STAGE_LABEL } from "./branding";
1318
import { resolveServerBackedAppDisplayName } from "./branding.logic";
1419
import { isElectron } from "./env";
1520
import { useComposerDraftStore } from "./composerDraftStore";
16-
import { getClientSettings, subscribeClientSettings } from "./hooks/useSettings";
21+
import { startDefaultThemeAdoption } from "./hooks/useDefaultTheme";
22+
import {
23+
getClientSettings,
24+
startModelPreferencesMigration,
25+
subscribeClientSettings,
26+
} from "./hooks/useSettings";
1727
import { startThreadVisitedMigration } from "./hooks/useThreadVisitedMigration";
1828
import {
1929
syncDocumentElectronPlatformClasses,
2030
syncDocumentWindowControlsOverlayClass,
2131
} from "./lib/windowControlsOverlay";
22-
import { prepareProviderAuthDelivery } from "./providerAuthDelivery";
32+
import { startProviderAuthDelivery } from "./providerAuthDelivery";
2333
import { getRouter, type AppRouter } from "./router";
2434
import { appAtomRegistry } from "./rpc/atomRegistry";
2535
import { primaryServerConfigAtom } from "./state/server";
@@ -116,7 +126,7 @@ function startThreadOverlayRetention(router: AppRouter): void {
116126
*/
117127
export function startAppServices(): AppRouter {
118128
// Ahead of the history: the provider auth code must leave the address before anything reads it.
119-
prepareProviderAuthDelivery();
129+
startProviderAuthDelivery();
120130

121131
// Electron loads the app from a file-backed shell, so hash history avoids path resolution issues.
122132
const router = getRouter(isElectron ? createHashHistory() : createBrowserHistory());
@@ -128,12 +138,20 @@ export function startAppServices(): AppRouter {
128138

129139
startClientAppearance();
130140
startDocumentTitle();
141+
startDefaultThemeAdoption();
142+
startModelPreferencesMigration();
131143
startAgentOpenedPreviews();
132144
startThreadOverlayRetention(router);
133145
startMainAppLocationTracking(router);
134146
startBackgroundThreadAnnouncements(appAtomRegistry, router);
135147
startThreadVisitedMigration(appAtomRegistry);
136148
startSshPasswordPromptQueue();
137149

150+
startHostFreezeToasts();
151+
startLegacyThreadMigrationToast();
152+
startPermissionUpdateNotices(router);
153+
startThreadNotifications(appAtomRegistry, router);
154+
if (isElectron) startDesktopUpdateLaunchNotice();
155+
138156
return router;
139157
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { hostFreezeNotice } from "@t3tools/client-runtime/connection";
2+
3+
import { appAtomRegistry } from "../rpc/atomRegistry";
4+
import { environmentSummaries } from "../state/presentation";
5+
import { environmentServerConfigsAtom } from "../state/server";
6+
import { toastManager } from "./ui/toast";
7+
8+
/** Tells the user why a host dropped, once per stall, when it reports one on reconnect. */
9+
export function startHostFreezeToasts(): () => void {
10+
const shown = new Set<string>();
11+
return appAtomRegistry.subscribe(
12+
environmentServerConfigsAtom,
13+
(configs) => {
14+
for (const [environmentId, config] of configs) {
15+
const stall = config.lastEventLoopStall;
16+
if (stall === undefined) continue;
17+
const key = `${environmentId}:${stall.detectedAt}`;
18+
if (shown.has(key)) continue;
19+
shown.add(key);
20+
const label =
21+
appAtomRegistry
22+
.get(environmentSummaries.identitiesAtom)
23+
.find((identity) => identity.environmentId === environmentId)?.label ??
24+
config.environment.label;
25+
const notice = hostFreezeNotice(label, stall);
26+
if (notice !== null) {
27+
toastManager.add({ type: "warning", ...notice });
28+
}
29+
}
30+
},
31+
{ immediate: true },
32+
);
33+
}

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

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { appAtomRegistry } from "../rpc/atomRegistry";
2+
import { primaryServerLegacyThreadMigrationAtom } from "../state/server";
3+
import { toastManager } from "./ui/toast";
4+
5+
type MigrationToastId = ReturnType<typeof toastManager.add>;
6+
7+
/** A loading toast for as long as the primary server reports a legacy thread migration running. */
8+
export function startLegacyThreadMigrationToast(): () => void {
9+
let toastId: MigrationToastId | null = null;
10+
11+
const unsubscribe = appAtomRegistry.subscribe(
12+
primaryServerLegacyThreadMigrationAtom,
13+
(migration) => {
14+
if (migration?.status === "running") {
15+
if (toastId !== null) return;
16+
toastId = toastManager.add({
17+
type: "loading",
18+
title: "Restoring your threads…",
19+
description: `Migrating ${migration.totalThreadCount.toLocaleString()} ${
20+
migration.totalThreadCount === 1 ? "thread" : "threads"
21+
} from the previous version. You can keep working while this finishes.`,
22+
timeout: 0,
23+
});
24+
return;
25+
}
26+
27+
if (toastId !== null) {
28+
toastManager.close(toastId);
29+
toastId = null;
30+
}
31+
},
32+
{ immediate: true },
33+
);
34+
35+
return () => {
36+
unsubscribe();
37+
if (toastId !== null) toastManager.close(toastId);
38+
};
39+
}

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

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { sessionHasLegacyPermissions, type EnvironmentId } from "@t3tools/contracts";
2+
import type { AnyRouter } from "@tanstack/react-router";
3+
import * as Schema from "effect/Schema";
4+
import { Atom } from "effect/reactivity";
5+
6+
import { getLocalStorageItem, setLocalStorageItem } from "../hooks/useLocalStorage";
7+
import { appAtomRegistry } from "../rpc/atomRegistry";
8+
import { environmentSummaries } from "../state/presentation";
9+
import { environmentSession } from "../state/session";
10+
import { toastManager } from "./ui/toast";
11+
12+
interface LegacyPermissionEnvironment {
13+
readonly environmentId: EnvironmentId;
14+
readonly label: string;
15+
}
16+
17+
/** Environments whose settled session still carries pre-scope permissions. */
18+
const legacyPermissionEnvironmentsAtom = Atom.make((get) =>
19+
get(environmentSummaries.identitiesAtom).filter(({ environmentId }) => {
20+
const session = get(environmentSession.sessionStateAtom(environmentId));
21+
return (
22+
session._tag === "Success" && !session.waiting && sessionHasLegacyPermissions(session.value)
23+
);
24+
}),
25+
).pipe(Atom.withLabel("web-legacy-permission-environments"));
26+
27+
const dismissalKey = (environmentId: EnvironmentId) =>
28+
`t3code:permission-update:v1:${environmentId}`;
29+
30+
function showPermissionNotice(
31+
router: AnyRouter,
32+
{ environmentId, label }: LegacyPermissionEnvironment,
33+
) {
34+
const key = dismissalKey(environmentId);
35+
const persistDismissal = () => {
36+
try {
37+
setLocalStorageItem(key, true, Schema.Boolean);
38+
} catch {}
39+
};
40+
const dismiss = () => {
41+
persistDismissal();
42+
toastManager.close(id);
43+
};
44+
const id = toastManager.add({
45+
title: `Permissions have changed for ${label}`,
46+
description:
47+
"This connection still uses the old permissions, so some actions may no longer be available. Pair again using a new link with the permissions you need.",
48+
timeout: 0,
49+
onClose: persistDismissal,
50+
actionProps: {
51+
children: "Open Connections",
52+
onClick: () => {
53+
dismiss();
54+
void router.navigate({ to: "/settings/connections" });
55+
},
56+
},
57+
data: {
58+
actionLayout: "stacked-end",
59+
secondaryActionProps: { children: "Dismiss", onClick: dismiss },
60+
secondaryActionVariant: "ghost",
61+
},
62+
});
63+
}
64+
65+
/** Asks once per environment, until dismissed, to re-pair a connection that predates scoped permissions. */
66+
export function startPermissionUpdateNotices(router: AnyRouter): () => void {
67+
const shown = new Set<EnvironmentId>();
68+
return appAtomRegistry.subscribe(
69+
legacyPermissionEnvironmentsAtom,
70+
(environments) => {
71+
for (const environment of environments) {
72+
if (shown.has(environment.environmentId)) continue;
73+
try {
74+
if (getLocalStorageItem(dismissalKey(environment.environmentId), Schema.Boolean))
75+
continue;
76+
} catch {}
77+
shown.add(environment.environmentId);
78+
showPermissionNotice(router, environment);
79+
}
80+
},
81+
{ immediate: true },
82+
);
83+
}

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

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)