MCPcopy Index your code
hub / github.com/QLHazyCoder/FlowPilot / handleMessage

Function handleMessage

background/message-router.js:196–555  ·  view source on GitHub ↗
(message, sender)

Source from the content-addressed store, hash-verified

194 }
195
196 async function handleMessage(message, sender) {
197 switch (message.type) {
198 case 'CONTENT_SCRIPT_READY': {
199 const tabId = sender.tab?.id;
200 if (tabId && message.source) {
201 await registerTab(message.source, tabId);
202 flushCommand(message.source, tabId);
203 await addLog(`内容脚本已就绪:${getSourceLabel(message.source)}(标签页 ${tabId})`);
204 }
205 return { ok: true };
206 }
207
208 case 'LOG': {
209 const { message: msg, level } = message.payload;
210 await addLog(`[${getSourceLabel(message.source)}] ${msg}`, level);
211 return { ok: true };
212 }
213
214 case 'STEP_COMPLETE': {
215 if (getStopRequested()) {
216 await setStepStatus(message.step, 'stopped');
217 await appendManualAccountRunRecordIfNeeded(`step${message.step}_stopped`, null, '流程已被用户停止。');
218 notifyStepError(message.step, '流程已被用户停止。');
219 return { ok: true };
220 }
221 const completionState = message.step === 9 ? await getState() : null;
222 await setStepStatus(message.step, 'completed');
223 await addLog(`步骤 ${message.step} 已完成`, 'ok');
224 await handleStepData(message.step, message.payload);
225 if (message.step === 9 && typeof appendAccountRunRecord === 'function') {
226 await appendAccountRunRecord('success', completionState);
227 }
228 notifyStepComplete(message.step, message.payload);
229 return { ok: true };
230 }
231
232 case 'STEP_ERROR': {
233 if (isStopError(message.error)) {
234 await setStepStatus(message.step, 'stopped');
235 await addLog(`步骤 ${message.step} 已被用户停止`, 'warn');
236 await appendManualAccountRunRecordIfNeeded(`step${message.step}_stopped`, null, message.error);
237 notifyStepError(message.step, message.error);
238 } else {
239 await setStepStatus(message.step, 'failed');
240 await addLog(`步骤 ${message.step} 失败:${message.error}`, 'error');
241 await appendManualAccountRunRecordIfNeeded(`step${message.step}_failed`, null, message.error);
242 notifyStepError(message.step, message.error);
243 }
244 return { ok: true };
245 }
246
247 case 'GET_STATE': {
248 return await getState();
249 }
250
251 case 'RESET': {
252 clearStopRequest();
253 await clearAutoRunTimerAlarm();

Callers

nothing calls this directly

Calls 15

notifyStepErrorFunction · 0.85
getStateFunction · 0.85
appendAccountRunRecordFunction · 0.85
notifyStepCompleteFunction · 0.85
clearStopRequestFunction · 0.85
clearAutoRunTimerAlarmFunction · 0.85
resetStateFunction · 0.85
setEmailStateFunction · 0.85
setPersistentSettingsFunction · 0.85
setStateFunction · 0.85

Tested by

no test coverage detected