MCPcopy
hub / github.com/loggerhead/json4u / runCommand

Function runCommand

src/stores/editorStore.ts:131–154  ·  view source on GitHub ↗
(id: MessageKey)

Source from the content-addressed store, hash-verified

129 ],
130
131 async runCommand(id: MessageKey) {
132 const { translations: t, commands, isReady } = get();
133 if (!isReady()) {
134 console.log("editor is not ready!");
135 return;
136 }
137
138 const r = await Promise.resolve(commands.find((item) => item.id === id)?.run());
139 let isSucc = true;
140 const name = t!(id);
141
142 if (r !== undefined) {
143 if (r) {
144 // @ts-ignore
145 toastSucc(t!("cmd_exec_succ", { name }));
146 } else {
147 // @ts-ignore
148 toastErr(t!(r ? r : "cmd_exec_fail", { name }));
149 isSucc = false;
150 }
151 }
152
153 sendGAEvent("event", "cmd_usage", { name, isSucc });
154 },
155
156 setTranslations(translations: ReturnType<typeof useTranslations>) {
157 set({ translations });

Callers 4

CommandSearchFunction · 0.85
onKeyDownFunction · 0.85
SwapButton.tsxFile · 0.85
RightPanelButtonsFunction · 0.85

Calls 3

toastSuccFunction · 0.90
toastErrFunction · 0.90
isReadyFunction · 0.85

Tested by

no test coverage detected