返回 DeepSeek-Reasonix
useComposerCommandCatalog.ts
根目录 / desktop / frontend / src / lib / useComposerCommandCatalog.ts
1 import { useEffect, useState } from "react";
2 import { asArray } from "./array";
3 import { app } from "./bridge";
4 import type { CommandInfo } from "./types";
5
6 export function useComposerCommandCatalog(
7 supplied: readonly CommandInfo[] | undefined,
8 ready: boolean,
9 cwd: string | undefined,
10 running: boolean,
11 workspaceScopeKey: string,
12 ): CommandInfo[] {
13 const [commands, setCommands] = useState<CommandInfo[]>([]);
14 useEffect(() => {
15 if (supplied) {
16 setCommands([...supplied]);
17 return;
18 }
19 let live = true;
20 app.Commands()
21 .then((next) => { if (live) setCommands(asArray(next)); })
22 .catch(() => {});
23 return () => { live = false; };
24 }, [cwd, ready, running, supplied, workspaceScopeKey]);
25 return commands;
26 }
27
27 lines TYPESCRIPT