forked from Blendman974/faceclaw
Voice assistant can set/check/cancel timers without the timer app being already open
This commit is contained in:
1 parent
2562761038
commit
b4728f4f15
5 files changed
+124
-49
No files matched your search
@@ -6,10 +6,9 @@
|
||||
*/
|
||||
import { ensureFineLocationPermission } from "../g2/android-permissions";
|
||||
import { toolRegistry, type ToolRegistry, type ToolResult } from "./tool-registry";
|
||||
import { callAppToolWithLaunch } from "./launch-on-call";
|
||||
|
||||
const APP_TOOL_PREFIX = "app.navigate.";
|
||||
const TOOL_APPEAR_TIMEOUT_MS = 5_000;
|
||||
const TOOL_APPEAR_POLL_MS = 150;
|
||||
|
||||
let registered = false;
|
||||
|
||||
@@ -47,7 +46,7 @@ export function registerNavigateTools(
|
||||
if (!destination) return err("nav.start_navigation requires a destination");
|
||||
// Fire the permission prompt early; the phone shows it while we work.
|
||||
void ensureFineLocationPermission().catch(() => {});
|
||||
const forwarded = await callAppTool(launchApp, registry, "start_route", {
|
||||
const forwarded = await callAppToolWithLaunch(registry, launchApp, "navigate", "start_route", {
|
||||
query: destination,
|
||||
profile: args?.profile,
|
||||
});
|
||||
@@ -86,31 +85,6 @@ export function registerNavigateTools(
|
||||
);
|
||||
}
|
||||
|
||||
/** Launch the Navigate app if needed, wait for its tool, and forward the call. */
|
||||
async function callAppTool(
|
||||
launchApp: (appId: string) => Promise<void>,
|
||||
registry: ToolRegistry,
|
||||
unprefixedName: string,
|
||||
args: unknown,
|
||||
): Promise<ToolResult> {
|
||||
const fullName = `${APP_TOOL_PREFIX}${unprefixedName}`;
|
||||
if (!registry.listTools().some((tool) => tool.name === fullName)) {
|
||||
await launchApp("navigate");
|
||||
const deadline = Date.now() + TOOL_APPEAR_TIMEOUT_MS;
|
||||
while (!registry.listTools().some((tool) => tool.name === fullName)) {
|
||||
if (Date.now() > deadline) {
|
||||
return err("The Navigate app did not start in time.");
|
||||
}
|
||||
await sleep(TOOL_APPEAR_POLL_MS);
|
||||
}
|
||||
}
|
||||
return registry.callTool(fullName, args);
|
||||
}
|
||||
|
||||
function sleep(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
function ok(content: string): ToolResult {
|
||||
return { ok: true, content };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user