返回 DeepSeek-Reasonix
useSessionBannerCommands.ts
根目录 / desktop / frontend / src / app-runtime / useSessionBannerCommands.ts
1 import { app, openExternal } from "../lib/bridge";
2 import { useCommittedCommand } from "../lib/useCommittedCommand";
3 import { useOverlayStore } from "../store/overlays";
4 export type ConfigWarningsReload = (warnings: string[], revision: number) => void;
5
6 /**
7 * Owns the startup/session banner commands: session reclaim or takeover, the
8 * takeover dialog, config-file open/reload, provider setup navigation and the
9 * release-notes link. Banner state (busy tab, dialog, provider gate) lives on
10 * the overlay store.
11 */
12 export function useSessionBannerCommands(options: { remote: boolean; reloadConfigWarnings: ConfigWarningsReload }) {
13 const reclaimBusyTab = useOverlayStore((state) => state.reclaimBusyTab);
14 const setReclaimBusyTab = useOverlayStore((state) => state.setReclaimBusyTab);
15 const setTakeoverDialogTab = useOverlayStore((state) => state.setTakeoverDialogTab);
16
17 const reclaimSession = useCommittedCommand((tabId: string) => {
18 if (reclaimBusyTab) return;
19 setReclaimBusyTab(tabId);
20 (options.remote ? app.ReclaimRemoteTabSession(tabId) : app.TakeoverSession(tabId, "wait"))
21 .catch((error) => console.warn("[takeover] reclaim failed", error))
22 .finally(() => setReclaimBusyTab(null));
23 });
24
25 const openTakeoverDialog = useCommittedCommand((tabId: string) => setTakeoverDialogTab(tabId));
26 const closeTakeoverDialog = useCommittedCommand(() => setTakeoverDialogTab(null));
27
28 const openConfigFile = useCommittedCommand(() => {
29 void app.OpenUserConfigPath?.().catch(() => {});
30 });
31
32 const reloadConfigFile = useCommittedCommand(() => {
33 void (async () => {
34 try {
35 const view = await app.ReloadUserConfig?.();
36 options.reloadConfigWarnings(view?.configWarnings ?? [], view?.configWarningsRevision ?? 0);
37 } catch {
38 /* keep banner */
39 }
40 })();
41 });
42
43 const showReleaseNotes = useCommittedCommand((latest: string) => {
44 const version = latest.replace(/^(?:desktop-)?v/, "");
45 void openExternal(`https://reasonix.io/changelog/v${version}/`);
46 });
47
48 return { reclaimSession, openTakeoverDialog, closeTakeoverDialog, openConfigFile, reloadConfigFile, showReleaseNotes };
49 }
50
50 lines TYPESCRIPT