also looking at this
feat(ios): the speech pair closes the last deferral — ratchet 28 -> 26
#101
10 files
+1287
-573
| @@ -33,6 +33,39 @@ const char craft_slice_page[] = | ||
| 33 | 33 | "window.addEventListener('craftMotionUpdate', function () {\n" |
| 34 | 34 | " if (!sentEvent) { sentEvent = true; bridge.postMessage({t:'mobile', a:'getDeviceInfo', i:16}); }\n" |
| 35 | 35 | "});\n" |
| 36 | "// Speech answers on the event channel and nowhere else: neither action\n" | |
| 37 | "// replies, so these three listeners are the whole page-visible surface.\n" | |
| 38 | "// A start settles as EITHER craftSpeechStart or craftSpeechError, and both\n" | |
| 39 | "// count: the first means the engine is running, the second means the\n" | |
| 40 | "// authorization block fired, hopped to the main queue and named a reason.\n" | |
| 41 | "// What neither can be produced by is a module that was never reached.\n" | |
| 42 | "window.addEventListener('craftSpeechStart', function (e) {\n" | |
| 43 | " if (sentSpeechStart || sentSpeechErr) { return; }\n" | |
| 44 | " // The detail is an object, not a string and not null — a page indexes\n" | |
| 45 | " // into it, so `{}` and `\"\"` are not interchangeable.\n" | |
| 46 | " if (!e.detail || typeof e.detail !== 'object') { return; }\n" | |
| 47 | " sentSpeechStart = true;\n" | |
| 48 | " bridge.postMessage({t:'mobile', a:'getDeviceInfo', i:68});\n" | |
| 49 | " bridge.postMessage({t:'mobile', a:'stopListening', i:109});\n" | |
| 50 | "});\n" | |
| 51 | "window.addEventListener('craftSpeechError', function (e) {\n" | |
| 52 | " if (sentSpeechStart || sentSpeechErr) { return; }\n" | |
| 53 | " // One of the four messages Swift sends, carried under Swift's key.\n" | |
| 54 | " var known = ['Not authorized', 'Audio session failed',\n" | |
| 55 | " 'Speech recognizer unavailable', 'Audio engine failed'];\n" | |
| 56 | " if (!e.detail || known.indexOf(e.detail.error) === -1) { return; }\n" | |
| 57 | " sentSpeechErr = true;\n" | |
| 58 | " bridge.postMessage({t:'mobile', a:'getDeviceInfo', i:74});\n" | |
| 59 | " bridge.postMessage({t:'mobile', a:'stopListening', i:109});\n" | |
| 60 | "});\n" | |
| 61 | "window.addEventListener('craftSpeechEnd', function (e) {\n" | |
| 62 | " if (sentSpeechEnd || !e.detail || typeof e.detail !== 'object') { return; }\n" | |
| 63 | " sentSpeechEnd = true;\n" | |
| 64 | " bridge.postMessage({t:'mobile', a:'getDeviceInfo', i:72});\n" | |
| 65 | " // Genuinely last: this backgrounds the app, and every chain that needs\n" | |
| 66 | " // a foreground process has now closed.\n" | |
| 67 | " bridge.postMessage({t:'mobile', a:'openSettings', i:102});\n" | |
| 68 | "});\n" | |
| 36 | 69 | "var sentEvent = false;\n" |
| 37 | 70 | "var sentRoundTrip = false, sentHandOff = false, sentTierZero = false, sentSecure = false, sentDb = false, sentNotif = false;\n" |
| 38 | 71 | "var bridge = window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.craft;\n" |
| @@ -53,6 +86,7 @@ const char craft_slice_page[] = | ||
| 53 | 86 | "var sentDownload = false, sentWatch = false, sentSettings = false;\n" |
| 54 | 87 | "var sentBtStart = false, sentBtStop = false;\n" |
| 55 | 88 | "var sentRecStart = false, sentRecStop = false, sentHealth = false;\n" |
| 89 | "var sentSpeechStart = false, sentSpeechErr = false, sentSpeechEnd = false;\n" | |
| 56 | 90 | "window.__craftBridgeError = function (ctx) {\n" |
| 57 | 91 | " // The message crossed Zig's escaping with a backslash, quote, and\n" |
| 58 | 92 | " // newline intact; anything mangled and this equality fails, i=7 never\n" |
| @@ -215,6 +249,12 @@ const char craft_slice_page[] = | ||
| 215 | 249 | " if (raw.slice(4, 8) === 'ftyp' && raw.length > 500) {\n" |
| 216 | 250 | " sentRecStop = true;\n" |
| 217 | 251 | " bridge.postMessage({t:'mobile', a:'getDeviceInfo', i:64});\n" |
| 252 | " // Only now. Both features drive the one shared AVAudioSession, and\n" | |
| 253 | " // speech sets category .record while the recorder wants\n" | |
| 254 | " // .playAndRecord — starting speech mid-recording would reconfigure\n" | |
| 255 | " // the session under a live encoder and make i=64 flaky for a reason\n" | |
| 256 | " // that has nothing to do with either module.\n" | |
| 257 | " bridge.postMessage({t:'mobile', a:'startListening', i:108});\n" | |
| 218 | 258 | " }\n" |
| 219 | 259 | " }\n" |
| 220 | 260 | " if (!sentBtStop && action === 'stopBluetoothScan' && payload === true) {\n" |
| @@ -381,9 +421,12 @@ const char craft_slice_page[] = | ||
| 381 | 421 | " bridge.postMessage({t:'mobile', a:'getAppState', i:88});\n" |
| 382 | 422 | " // And one the shim answers by rejecting, to prove the error route.\n" |
| 383 | 423 | " bridge.postMessage({t:'mobile', a:'hostOnlyFail', i:6});\n" |
| 384 | " // Last, deliberately: this navigates to the Settings app, so anything\n" | |
| 385 | " // posted after it would race the webview being backgrounded.\n" | |
| 386 | " bridge.postMessage({t:'mobile', a:'openSettings', i:102});\n" | |
| 424 | " // openSettings is NOT posted here. It navigates to the Settings app,\n" | |
| 425 | " // and everything posted afterwards then runs in a backgrounded\n" | |
| 426 | " // process — which is fine for a call that answers immediately and\n" | |
| 427 | " // fatal for one that needs the system to present a prompt. It goes\n" | |
| 428 | " // out from the craftSpeechEnd listener instead, once the last chain\n" | |
| 429 | " // that needs a foreground app has finished.\n" | |
| 387 | 430 | "} else {\n" |
| 388 | 431 | " document.getElementById('s').textContent = 'NO BRIDGE';\n" |
| 389 | 432 | "}\n" |