返回 DeepSeek-Reasonix
DesktopCloseBehaviorHint.tsx
根目录 / desktop / frontend / src / components / DesktopCloseBehaviorHint.tsx
1 import { useEffect, useState } from "react";
2 import { app, type DesktopShellStatusView } from "../lib/bridge";
3 import { desktopHost } from "../lib/desktopHost";
4
5 export function DesktopCloseBehaviorHint({
6 backgroundSelected,
7 hint,
8 unavailableHint,
9 }: {
10 backgroundSelected: boolean;
11 hint: string;
12 unavailableHint: string;
13 }) {
14 const [status, setStatus] = useState<DesktopShellStatusView | null>(null);
15 useEffect(() => {
16 let active = true;
17 const update = (value: unknown) => {
18 if (!active || !value || typeof value !== "object") return;
19 const candidate = value as Partial<DesktopShellStatusView>;
20 setStatus({
21 trayState: candidate.trayState === "ready" || candidate.trayState === "unavailable" ? candidate.trayState : "probing",
22 backgroundCloseAvailable: candidate.backgroundCloseAvailable === true,
23 reason: typeof candidate.reason === "string" ? candidate.reason : undefined,
24 });
25 };
26 const getStatus = app.GetDesktopShellStatus;
27 if (typeof getStatus === "function") void getStatus.call(app).then(update).catch(() => undefined);
28 const host = desktopHost();
29 const off = host.kind === "none" ? undefined : host.events.on("desktop:shell-status", update);
30 return () => {
31 active = false;
32 off?.();
33 };
34 }, []);
35 if (!backgroundSelected || !status || status.backgroundCloseAvailable) return hint;
36 return <>{hint}<br />{unavailableHint}</>;
37 }
38
38 lines Plain Text