forked from Blendman974/faceclaw
- Head tilt angle setting (Glanceboard): sets the glasses' own head-up trigger through the stock settings message (g2_setting.proto DeviceReceiveInfoFromAPP.deviceReceiveHeadUpSetting), so detection stays on the glasses and nothing streams while the screen is off. The stored calibration is read back and compensated for, and the value is re-applied on every connect. "glasses" (the default) leaves the glasses' setting untouched. - "Set to current head angle" measures the tilt from a ~1.2 s IMU burst and rounds it to the nearest 5 degrees. - Glance down to hide: a head-tilt showing now stays up until the head comes back down (HEAD_DOWN, forwarded by Faceclaw/38) instead of a fixed timeout, with a 60 s safety cap. HEAD_DOWN goes only to the Glanceboard on Android and iOS, so it never counts as shell activity. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
99 lines
5.4 KiB
JavaScript
99 lines
5.4 KiB
JavaScript
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
|
|
const {
|
|
GLANCE_HIDDEN,
|
|
GLANCE_TIMEOUT_MS,
|
|
GLANCE_TILT_MAX_MS,
|
|
glanceEventForGesture,
|
|
reduceGlance,
|
|
} = require("../.test-build/app/g2/glance-state.js");
|
|
|
|
const T0 = 1_000_000;
|
|
|
|
test("a press shows the board and arms the auto-hide timer", () => {
|
|
const shown = reduceGlance(GLANCE_HIDDEN, { type: "press" }, T0);
|
|
assert.deepEqual(shown, { visible: true, holding: false, tilted: false, hideAtMs: T0 + GLANCE_TIMEOUT_MS });
|
|
// A timer firing early is ignored; on time it hides.
|
|
assert.equal(reduceGlance(shown, { type: "timeout" }, T0 + GLANCE_TIMEOUT_MS - 1), shown);
|
|
assert.deepEqual(reduceGlance(shown, { type: "timeout" }, T0 + GLANCE_TIMEOUT_MS), GLANCE_HIDDEN);
|
|
});
|
|
|
|
test("a further press renews the timer from the new press", () => {
|
|
const shown = reduceGlance(GLANCE_HIDDEN, { type: "press" }, T0);
|
|
const renewed = reduceGlance(shown, { type: "press" }, T0 + 2000);
|
|
assert.equal(renewed.hideAtMs, T0 + 2000 + GLANCE_TIMEOUT_MS);
|
|
assert.equal(reduceGlance(renewed, { type: "timeout" }, T0 + GLANCE_TIMEOUT_MS), renewed);
|
|
});
|
|
|
|
test("a hold shows the board without a timer and the release hides it", () => {
|
|
const held = reduceGlance(GLANCE_HIDDEN, { type: "hold" }, T0);
|
|
assert.deepEqual(held, { visible: true, holding: true, tilted: false, hideAtMs: null });
|
|
assert.equal(reduceGlance(held, { type: "timeout" }, T0 + 60_000), held);
|
|
// A tap mid-hold neither hides nor starts a timer.
|
|
assert.equal(reduceGlance(held, { type: "press" }, T0 + 500), held);
|
|
assert.deepEqual(reduceGlance(held, { type: "release" }, T0 + 1000), GLANCE_HIDDEN);
|
|
});
|
|
|
|
test("a release that was not holding the board is ignored", () => {
|
|
assert.equal(reduceGlance(GLANCE_HIDDEN, { type: "release" }, T0), GLANCE_HIDDEN);
|
|
const shown = reduceGlance(GLANCE_HIDDEN, { type: "press" }, T0);
|
|
assert.equal(reduceGlance(shown, { type: "release" }, T0 + 100), shown);
|
|
});
|
|
|
|
test("dismiss hides from any state", () => {
|
|
const held = reduceGlance(GLANCE_HIDDEN, { type: "hold" }, T0);
|
|
assert.deepEqual(reduceGlance(held, { type: "dismiss" }, T0), GLANCE_HIDDEN);
|
|
const shown = reduceGlance(GLANCE_HIDDEN, { type: "press" }, T0);
|
|
assert.deepEqual(reduceGlance(shown, { type: "dismiss" }, T0), GLANCE_HIDDEN);
|
|
});
|
|
|
|
test("gesture mapping: taps press, head-tilt tilts, both long-press gestures hold, double-tap dismisses only a visible board", () => {
|
|
assert.deepEqual(glanceEventForGesture("click", false), { type: "press" });
|
|
assert.deepEqual(glanceEventForGesture("head-tilt", false), { type: "tilt" });
|
|
assert.deepEqual(glanceEventForGesture("head-down", true), { type: "head-down" });
|
|
assert.equal(glanceEventForGesture("head-down", false), null);
|
|
assert.deepEqual(glanceEventForGesture("long-press", false), { type: "hold" });
|
|
assert.deepEqual(glanceEventForGesture("short-then-long-press", false), { type: "hold" });
|
|
assert.deepEqual(glanceEventForGesture("short-then-long-press", true), { type: "hold" });
|
|
assert.deepEqual(glanceEventForGesture("long-press-release", true), { type: "release" });
|
|
assert.equal(glanceEventForGesture("double-click", false), null);
|
|
assert.deepEqual(glanceEventForGesture("double-click", true), { type: "dismiss" });
|
|
assert.equal(glanceEventForGesture("scroll-up", true), null);
|
|
});
|
|
|
|
test("the press timeout is the host's when supplied", () => {
|
|
const shown = reduceGlance(GLANCE_HIDDEN, { type: "press" }, T0, 10_000);
|
|
assert.equal(shown.hideAtMs, T0 + 10_000);
|
|
assert.equal(reduceGlance(shown, { type: "timeout" }, T0 + GLANCE_TIMEOUT_MS), shown);
|
|
assert.deepEqual(reduceGlance(shown, { type: "timeout" }, T0 + 10_000), GLANCE_HIDDEN);
|
|
});
|
|
|
|
test("a head-tilt shows the board until the head comes back down", () => {
|
|
const up = reduceGlance(GLANCE_HIDDEN, { type: "tilt" }, T0);
|
|
assert.deepEqual(up, { visible: true, holding: false, tilted: true, hideAtMs: T0 + GLANCE_TILT_MAX_MS });
|
|
// The tap duration no longer applies, and taps change nothing.
|
|
assert.equal(reduceGlance(up, { type: "timeout" }, T0 + GLANCE_TIMEOUT_MS), up);
|
|
assert.equal(reduceGlance(up, { type: "press" }, T0 + 500), up);
|
|
assert.deepEqual(reduceGlance(up, { type: "head-down" }, T0 + 9000), GLANCE_HIDDEN);
|
|
// The safety cap still hides it if the head-down never arrives.
|
|
assert.deepEqual(reduceGlance(up, { type: "timeout" }, T0 + GLANCE_TILT_MAX_MS), GLANCE_HIDDEN);
|
|
});
|
|
|
|
test("head-down leaves a tap's or a hold's showing alone", () => {
|
|
const shown = reduceGlance(GLANCE_HIDDEN, { type: "press" }, T0);
|
|
assert.equal(reduceGlance(shown, { type: "head-down" }, T0 + 100), shown);
|
|
const held = reduceGlance(GLANCE_HIDDEN, { type: "hold" }, T0);
|
|
assert.equal(reduceGlance(held, { type: "head-down" }, T0 + 100), held);
|
|
});
|
|
|
|
test("a hold and a head-tilt together: the board stays until both end", () => {
|
|
const both = reduceGlance(reduceGlance(GLANCE_HIDDEN, { type: "tilt" }, T0), { type: "hold" }, T0 + 100);
|
|
assert.deepEqual(both, { visible: true, holding: true, tilted: true, hideAtMs: null });
|
|
const released = reduceGlance(both, { type: "release" }, T0 + 200);
|
|
assert.deepEqual(released, { visible: true, holding: false, tilted: true, hideAtMs: T0 + 200 + GLANCE_TILT_MAX_MS });
|
|
const downWhileHeld = reduceGlance(both, { type: "head-down" }, T0 + 200);
|
|
assert.deepEqual(downWhileHeld, { visible: true, holding: true, tilted: false, hideAtMs: null });
|
|
assert.deepEqual(reduceGlance(downWhileHeld, { type: "release" }, T0 + 300), GLANCE_HIDDEN);
|
|
});
|