UNPKG

app-walk

Version:

An intuitive guided walkthrough library with UI highlighting and voice narration for web apps.

34 lines (33 loc) 1.23 kB
import { handleUiAction, handleUrlAction } from "./handleAction"; import { speakTextAsync } from "./speech"; import { wait } from "./utils"; import { isUrlAction } from "./dataTypes"; export async function runActionSteps(steps, navigate) { var _a; console.log("Starting runActionSteps:", steps); for (const step of steps) { const success = await runActionStep(step, navigate); if (!success) { console.error("Step failed, terminating walkthrough:", step); speakTextAsync("Element not found. The process failed."); break; // terminate on first failure } const waitSeconds = (_a = step.waitSeconds) !== null && _a !== void 0 ? _a : 1; await wait(waitSeconds * 1000); } console.log("runActionSteps completed (terminated early if failure occurred)."); } export async function runActionStep(step, navigate) { try { if (isUrlAction(step)) { await handleUrlAction(step, navigate); return true; } const result = await handleUiAction(step); return result !== false; } catch (error) { console.error("runActionStep failed", error, step); return false; } }