Skip to content

armgit / bygga

Public Imported from GitHub
0

IKEA assembly, step by step: animated, manual-style 3D guides. Scan any paper manual with Together AI.

TypeScript

Say "tap anywhere" when Safari won't restart listening on its own

Youssefd1b378a32734
diff --git a/src/components/guide/GuideApp.tsx b/src/components/guide/GuideApp.tsx
index 82d80e1..8c4973f 100644
--- a/src/components/guide/GuideApp.tsx
+++ b/src/components/guide/GuideApp.tsx
@@ -793,19 +793,21 @@ function Guide({ plan, slug, via, ai, startStep }: { plan: Plan; slug: string; v
? `Heard “${heard}”`
: mic === "on"
? "Say “next” when you're ready"
- : mic === "asking"
- ? "Allow the microphone, then say “next”"
- : mic === "denied"
- ? "Mic is blocked. Tap done to move on"
- : mic === "busy"
- ? "Another app has the mic. Tap done to move on"
- : mic === "nomic"
- ? "No microphone found. Tap done to move on"
- : mic === "offline"
- ? "Can't listen right now. Tap done to move on"
- : mic === "unsupported" || !canListen
- ? "Reading aloud. Tap done to move on"
- : "Turning on the mic"}
+ : mic === "paused"
+ ? "Tap anywhere to keep listening"
+ : mic === "asking"
+ ? "Allow the microphone, then say “next”"
+ : mic === "denied"
+ ? "Mic is blocked. Tap done to move on"
+ : mic === "busy"
+ ? "Another app has the mic. Tap done to move on"
+ : mic === "nomic"
+ ? "No microphone found. Tap done to move on"
+ : mic === "offline"
+ ? "Can't listen right now. Tap done to move on"
+ : mic === "unsupported" || !canListen
+ ? "Reading aloud. Tap done to move on"
+ : "Turning on the mic"}
</span>
</div>
)}
diff --git a/src/components/guide/hooks.ts b/src/components/guide/hooks.ts
index 3888fe7..ac2be0c 100644
--- a/src/components/guide/hooks.ts
+++ b/src/components/guide/hooks.ts
@@ -31,7 +31,7 @@ export function useWakeLock(active: boolean) {
}, [active]);
}
-export type Mic = "off" | "asking" | "on" | "denied" | "busy" | "nomic" | "unsupported" | "offline";
+export type Mic = "off" | "asking" | "on" | "paused" | "denied" | "busy" | "nomic" | "unsupported" | "offline";
type Ctx = typeof AudioContext;
const AudioCtx = () => (typeof window === "undefined" ? undefined : (window.AudioContext ?? (window as unknown as { webkitAudioContext?: Ctx }).webkitAudioContext));
@@ -123,8 +123,16 @@ export function useListener(enabled: boolean, onHeard: (text: string, seg: Segme
if (seg) send(seg);
};
+ // Safari won't start audio again after the screen locks until there's a tap
+ let wake: (() => void) | null = null;
+ const unwake = () => {
+ if (wake) document.removeEventListener("pointerdown", wake);
+ wake = null;
+ };
+
const release = () => {
clearTimeout(asking);
+ unwake();
for (const n of nodes) {
try {
n.disconnect();
@@ -197,7 +205,16 @@ export function useListener(enabled: boolean, onHeard: (text: string, seg: Segme
tap.connect(sink);
nodes = [src, tap, sink];
cut = segmenter();
- setMic("on");
+ if (ctx.state === "running") setMic("on");
+ else {
+ setMic("paused");
+ unwake();
+ wake = () => {
+ unwake();
+ ctx.resume().then(() => !stop && stream === s && setMic(ctx.state === "running" ? "on" : "paused"), () => {});
+ };
+ document.addEventListener("pointerdown", wake);
+ }
// a mic unplugged, or taken by a call, ends the track: open it again
s.getAudioTracks()[0]?.addEventListener("ended", () => {
if (stream !== s) return;