ReviewOS

also looking at this

craft-native/craft

Android: Bluetooth heart-rate straps, and offline media on WorkManager

#370
Merged chris wants to merge feat/android-heart-rate into main
21 files +2307 -56

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

packages/typescript/src/__tests__/bridge-request-id.test.tsmodified+23-2
Changes to packages/typescript/src/__tests__/bridge-request-id.test.ts
@@ -1,4 +1,4 @@
1import { describe, expect, it } from 'bun:test'
1import { afterEach, describe, expect, it } from 'bun:test'
22
33/**
44 * The reply-correlation contract, exercised against the real
@@ -37,6 +37,27 @@ interface Harness {
3737 * they can simply be passed in as parameters — no DOM, no jsdom, and nothing
3838 * shared between tests.
3939 */
40/**
41 * The bridge's timers. A test that sends without answering (an id check, a
42 * fire-and-forget) leaves its call's timeout running; left alone it rejects
43 * during whatever test runs then, as an unhandled error that fails that one.
44 * Each test's bridge stops when the test does.
45 */
46const timers = new Set<ReturnType<typeof setTimeout>>()
47const bridgeSetTimeout = (run: (...args: unknown[]) => void, ms?: number, ...args: unknown[]) => {
48 const timer = setTimeout(() => { timers.delete(timer); run(...args) }, ms)
49 timers.add(timer)
50 return timer
51}
52const bridgeClearTimeout = (timer: ReturnType<typeof setTimeout>) => {
53 timers.delete(timer)
54 clearTimeout(timer)
55}
56afterEach(() => {
57 for (const timer of timers) clearTimeout(timer)
58 timers.clear()
59})
60
4061function loadBridge(platform: 'webkit' | 'webview2' = 'webkit'): Harness {
4162 const sent: Envelope[] = []
4263 const errors: unknown[][] = []
@@ -57,7 +78,7 @@ function loadBridge(platform: 'webkit' | 'webview2' = 'webkit'): Harness {
5778
5879 // eslint-disable-next-line no-new-func
5980 const run = new Function('window', 'document', 'console', 'setTimeout', 'clearTimeout', 'setInterval', BRIDGE_SRC)
60 run(win, doc, console_, setTimeout, clearTimeout, () => 0)
81 run(win, doc, console_, bridgeSetTimeout, bridgeClearTimeout, () => 0)
6182
6283 return {
6384 craft: win.craft,