返回 DeepSeek-Reasonix
useAppEffectHosts.ts
根目录 / desktop / frontend / src / app-runtime / useAppEffectHosts.ts
1 import { useEffect } from "react";
2 import { onRecoverableError, type RecoverableErrorDetail } from "../lib/globalCrashHandlers";
3 import { useCommittedCommand } from "../lib/useCommittedCommand";
4 import type { useToast } from "../lib/toast";
5 import { recordFrontendDiagnostic } from "../lib/frontendDiagnosticBridge";
6
7 export function useAppDiagnostics(input: {
8 activeTabId?: string | null;
9 tabCount: number;
10 ready: boolean;
11 running: boolean;
12 hydrating: boolean;
13 runtimeTransitioning: boolean;
14 contentRevision?: number;
15 }) {
16 useEffect(() => {
17 recordFrontendDiagnostic("app", "app.surface", { hasActiveTab: Boolean(input.activeTabId), tabCount: input.tabCount });
18 }, [input.activeTabId, input.tabCount]);
19 useEffect(() => {
20 recordFrontendDiagnostic("app", "app.runtime-state", {
21 ready: input.ready, running: input.running, hydrating: input.hydrating,
22 runtimeTransitioning: input.runtimeTransitioning, contentRevision: input.contentRevision,
23 });
24 }, [input.contentRevision, input.hydrating, input.ready, input.running, input.runtimeTransitioning]);
25 }
26
27 export function useSidebarConnectionValidity<T extends { id: string }>(input: {
28 connections: readonly T[];
29 setConnectionId: (update: (current: string) => string) => void;
30 }) {
31 const { connections, setConnectionId } = input;
32 useEffect(() => {
33 setConnectionId((current) => !current || connections.some((connection) => connection.id === current) ? current : "");
34 }, [connections, setConnectionId]);
35 }
36
37 export function useRecoverableErrorToasts(showToast: ReturnType<typeof useToast>["showToast"]) {
38 const report = useCommittedCommand(({ message }: RecoverableErrorDetail) => {
39 showToast(message, "warn", { durationMs: 6000 });
40 });
41 useEffect(() => onRecoverableError(report), [report]);
42 }
43
43 lines TYPESCRIPT