Build out the glanceboard settings app and widgets
<details> <summary>Prompts Used</summary> User: Thanks, looks pretty good. I notice that during the transition from the glanceboard back to off, the glasses display a flash of the main UI. Let's address that. AI: > Fixed and built. The cause was the hide order in the glance host: it hid the glance surface first, which made the compositor recomposite and transmit the sleeping UI's retained window frames, and only afterwards did the screen-off path blank the display. That one transmitted frame was the flash. > > The hide path in `app/g2/glance-host.ts` now blanks the compositor first and hides the surface second. Blanked, the surface change composites to the same black frame, so nothing extra goes to the glasses. The controller's screen-off path still runs afterwards to drop the wakelock and re-arm the 5-second suspend. Its own blank call is now redundant but harmless. > > The double-tap path is unchanged on purpose: there the surface hides while the shell is waking, so the retained UI appearing is the intended result. > > Typecheck and the full Android build both pass. I recorded the finding in `notes/glanceboard.md` with a new checklist item for the timeout and release transitions. Worth re-checking on hardware: both the 3-second timeout and the long-press release should now go straight to dark. <hr> User: Thanks. Next up, let's make a firmware mod so that we can capture tap and tab-and-hold from deep sleep. AI: > Done. Firmware revision 2 forwards tap, long-press, and long-press release from deep sleep, and the phone side consumes them. Everything builds and the tests pass, but nothing is flashed or hardware-tested yet. > > **How the firmware does it** > > Decompiling the display thread showed that with no app on screen, its touch branch launches the dashboard on double-tap or head-up, launches the stock Menu on tap-then-hold, and frees every other gesture unhandled. The call right after that idle gate at `0x45f01a` has the input record in r4 (raw source at +2, gesture subtype at +4). The new hook in `g2flash/patches/settings_ext.c` wraps that call. When Faceclaw holds the wake lease and the firmware is in the mode where a double-tap would have woken the dashboard, it reports subtype 0 (tap), 3 (long press) and 0xe (release) as settings-sid field-102 events 2, 3 and 4, carrying the raw source. The stock result is returned unchanged, so stock behavior is untouched. Unlike the double-tap wake, nothing stock is deferred, so there is no claim or fallback handshake. I verified in the patched image that the site is a branch into the blob, that the shim hands r4 to the C function, and that the function preserves r4. > > **Phone side** > > - Java parses the new events into ordinary sys-events with the protobuf source while the page is suspended, so TypeScript sees exactly the soft-sleep gestures and the Glanceboard logic needs no change. > - The firmware string is now `Faceclaw/2`, the app requires revision 2, and the embedded patch set was regenerated. Onboarding will offer the reflash. > - A Java test covers the event and source mapping, the wake event staying distinct, and malformed payloads. > > **Verification** > > | Check | Result | > |---|---| > | g2flash `build_cfw.sh` | verified, new output hash pinned | > | Faceclaw `build.sh` | success | > | `npm test` | new tests pass; only the pre-existing pinball and compass-style failures remain | > > **Two caveats** > > - I read "tap-and-hold" as press-and-hold, which is the long-press the Glanceboard uses. The firmware's distinct tap-then-hold gesture still opens the stock Menu app from sleep and is not forwarded. Say so if you wanted that one instead. > - Only the right lens notifies the phone. A double-tap on either temple wakes both lenses, so left-temple taps very likely reach the right lens's display thread while idle, but that is unverified until it runs on hardware. The checklist in `notes/glanceboard.md` has the new deep-sleep steps and the logcat line to look for. > > Nothing is committed in either repository. <hr> User: Thanks, that worked. Next up, there's also a screen-on trigger from the accelerometer detecting that you've tilted your head up 45deg. Let's make that trigger go to the glanceboard rather than the main app. (If this requires another firmware extension, go ahead and make it; otherwise use what's already there.) AI: > Done. It did need a firmware extension, so this is firmware revision 3 plus matching phone changes. Everything builds and tests pass; nothing is flashed or hardware-tested yet. > > **Why firmware was needed.** In deep sleep the head-up already reached the phone, but through the same deferred-wake event as a double-tap, so the phone could not tell them apart. In soft sleep, the first five seconds after the screen goes dark, the head-up never reached the phone at all: the display thread's idle gate drops it while an EvenHub page is on screen. > > **Firmware, revision 3** > > - **Deep sleep.** The idle policy's head-up display-start site now goes through its own wrapper. It runs the identical deferred-wake claim-and-ready handshake but reports field-102 event code 5 instead of 1. One deliberate difference: a head-up while a wake is already pending is ignored, instead of the double-tap's emergency stock-dashboard launch, so lifting your head right after a tap cannot flash the stock dashboard. > - **Soft sleep.** The idle-gate call is wrapped, ported from the old head-tilt branch with two extra guards mirroring the stock idle path: the glasses' head-up switch must be on and the stock busy check must be clear. It forwards the head-up as EvenHub sys-event 12 under the framebuffer lease. > - Both hooks and the two wrappers were verified by disassembling the patched image. The output hash is pinned and the embedded patch set in Faceclaw is regenerated. > > **Phone side** > > - Java decodes wake code 5 as a display-wake carrying the head-up event type, and rewrites the soft-sleep sys-event 12 into the same thing. The Glanceboard logic from earlier already treats that as a press, so a head-tilt now shows the board for the timeout instead of waking the main UI. With the Glanceboard toggle off, a head-tilt still wakes the regular UI as before. > - The app now requires firmware revision 3, so onboarding will offer the reflash. > - The Java test covers the new wake code alongside the tap, long-press, and release events. > > **One thing left as is.** Faceclaw does not push the head-up switch or angle to the glasses. The trigger uses whatever the Even app configured, which is what you have today. The old branch's setting for that is not merged. > > The hardware checklist in `notes/glanceboard.md` has the four head-tilt cases: deep sleep, soft sleep, screen on, and head-tilt right after a double-tap. <hr> User: Thanks. Next up, let's make a glanceboard widget for the Calendar. AI: > Waiting on the Android build; the widget, its registration, and the notes are done. <hr> User: Thanks. Next up, let's make a glanceboard widget for the Terminal app. This will show the same terminals (including, especially, activity indicators) as the terminal list window and reuse some code from it. If the window title is too long to fit, we truncate rather than wrap. Also, if a terminal has a window open, that window's number will be shown in a left column in the terminals list (both the terminal-list window version and the glanceboard version). This will replace the "[open]" tag currently at the end of the line. <hr> User: Continue AI: > The Terminal widget is in, the hub list has the new number column, and the build passes. Not yet tried on hardware. > > **Getting the list to the main thread.** The Terminal app lives in a worker, so the widget cannot read its state directly. I added a small generic channel: a worker can post a `publish-state` reply with a key and a JSON value, and the host stores it in a main-thread registry with change notifications. The Terminal worker publishes a session snapshot under `terminal:sessions` whenever the hub would repaint, deduplicated by content. Each row carries its label, the open view window's sidebar glyph, and an activity deadline in the phone's clock, so the widget can blink and expire indicators on its own 800 ms timer without further messages. > > **Shared row painter.** `app/apps/terminal/session-list.ts` now holds one `drawSessionRow` used by both the hub and the widget: activity square in the gutter, the window number column, then the label truncated to fit, never wrapped. The hub used to draw labels untruncated, so it gains that too. > > **The number column.** A session with an open view window now shows that window's sidebar glyph, "1", "2" and so on, in a column left of the label, in both the hub and the widget. The "[open]" suffix is gone from the list. The assistant's list-sessions tool text says "[open in window 2]" instead. > > **Widget layout** at 288x144: "Terminal" label, then host headings only when more than one host is connected, then session rows, as many as fit. Empty states cover no connections, connecting, and no live sessions. > > **One limitation to know about.** The snapshot exists only once the Terminal app has been opened in this app session, because that is when the worker and its g2mirror control clients start. Before that the widget says to open the Terminal app. Since the shell restores open apps at boot, a hub left open carries across restarts. Making the worker start its control clients at boot without a window is a possible follow-up if you want the widget live from launch. > > Checklist entry 7c in the design note covers the blink sync, the number column in both views, and truncation. Nothing is committed. <hr> User: Thanks. Next up, let's make it so that selecting a widget for a slot that's already used in another slot clears that slot, _except_ that certain widgets that support it can occupy both left slots or both right slots, in which case they render at double height and the line between the slots is removed. We'll implement double-height for the Terminal and Calendar widgets. AI: > Done. Slot uniqueness and double-height regions are in, with a node test for the pure part, and the build passes. > > **The rule** lives in two places that share one adjacency helper in the layout module: > > - **When a picker changes**, the config app clears every other slot holding the same widget, unless the widget is marked tall and that slot is vertically adjacent to the one just chosen. So picking Terminal for Bottom left while it is in Top left keeps both, and then picking it for Top right clears both left slots. This runs from the picker's change hook and goes through the settings broadcast, so the board and the other rows follow on their own. > - **When the board paints**, it resolves the slot choices into regions. A tall widget in two vertically adjacent slots becomes one 288x288 region and its widget gets the taller canvas. Dividers are drawn per region, so the line between the merged slots disappears. > > **Tall widgets.** Terminal and Calendar are marked tall. Both already lay out rows until they run out of height, so at double height they simply show more sessions or more events with no widget code changes. The other widgets stay single-slot. > > **Region diffing.** The board keys live regions by widget plus slots and restarts only what changed on a settings change. Switching a widget from single to tall restarts just that widget; unrelated widgets keep their subscriptions and hardware holds. > > **Verification.** `tests/glanceboard-layout.test.cjs` covers adjacency, left and right merges, non-spanning and diagonal duplicates staying separate, and empty boards. Typecheck and the Android build pass. The design note has a checklist step for the three picker cases. Nothing is committed. <hr> User: Thanks. Let's organize the Glanceboard configuration app into several screens. The entry page will have a title, a paragraph of text describing how the glanceboard works, and a menu with an "Enable Glanceboard" toggle, Preview, Select Contents, and Settings. Settings will contain: * "Show on tap", which instead of a toggle will be a duration (from a list of options 3s, 5s, 7s, 10s, default 5s) * "Show on long press", which will be a toggle * "Show on head tilt", which will be a toggle * "Show lines", which will toggle visibility of the quadrant-separator lines Fable 5.1: > The Glanceboard app is now three screens, the four settings are wired through, and the build and tests pass. > > **Entry page.** Title, a short paragraph on how the board works, and a menu drawn on the same page below it: Enable Glanceboard (toggle, the existing setting relabeled), Preview, Select Contents, Settings. Double-tap on the entry page yields to the sidebar as before; on the sub-screens it goes back. > > **Select Contents** is the slot pickers page from before, including the one-widget-per-board rule and double-height merging. > > **Settings** holds: > > - **Show on tap**: a duration picker, 3, 5, 7 or 10 seconds, default 5. The head-tilt uses the same duration since it behaves as a tap. > - **Show on long press**: toggle. Off means a hold while asleep does nothing. A release still passes through so a hold already in progress can end. > - **Show on head tilt**: toggle. Off sends the head-tilt wake to the regular UI, the pre-Glanceboard behavior. > - **Show lines**: toggle for the slot dividers. > > **Wiring.** The gesture policy moved out of the controller into the glance host, which asks the board provider for the four values. The timeout is handed to the state reducer per event, so the pure module stays testable; a new test covers the supplied timeout. The master toggle off still makes every sleep gesture a no-op. > > The design note's checklist has a step per setting. Nothing is committed. <hr> User: Thanks. Let's maket the menu half width, and use the space on the right for a preview with the quadrant-separator lines and the title of what's in each slot. Instead of "Select Contents" opening a separate page, it will move the focus to that view, so you can pick one of the quadrants there and tap to open a menu of what goes in that quadrant. The four-quadrants preview will show the lines between them; if the show-lines setting is disabled, they'll be reduced to min brightness and dotted (every other pixel). The preview will omit the line between quadrants as appropriate for double-height views. Fable 5.1: > The entry page now has the half-width menu on the left and the slot preview on the right, with Select Contents working inside the preview. Build and tests pass. > > **Preview.** The right half shows the board scaled down with its slot dividers and the name of the widget in each region, or "Empty". A double-height region shows one name and no line across it. With "Show lines" off, the dividers drop to the dimmest visible shade and light only every other pixel, so the layout still reads but signals off. > > **Select Contents.** Choosing it moves focus into the preview instead of opening a page. Scroll moves a highlight between the four quadrants, a tap opens a modal picker for that slot with the current choice marked, and picking applies the same one-widget-per-board rule as before. The preview updates as soon as a choice lands. Double-tap returns focus to the menu. While the preview has focus the menu's selection shows as outline only, following the shell's convention that a filled selection means it has input. > > **Shared geometry.** The divider layout moved out of the board into a pure helper in the layout module, so the live board and the preview draw the same lines, including the merged-region rule. A new test pins the four-slot and tall-Terminal cases. > > The design note's checklist has a step for the preview interactions. Nothing is committed. <hr> User: Thanks. One fix: while the quadrants-preview is selecte, double-tap back currently goes to the app-switcher, but should go to the glanceboard menu. We can also remove the gesture-help below the preview. Fable 5.1: > Fixed and built. The cause was the root wrapper that turns any double-tap at the app's root into a yield to the sidebar, which ran before the page could see the gesture. > > The home page is now the window's root without that wrapper and routes double-tap itself: with the preview focused it returns focus to the menu, with the menu focused it yields to the sidebar as before. The gesture hint under the preview is gone. > > Typecheck and the Android build pass. Nothing is committed. <hr> User: Thanks, looks good. Let's make the lines in the glanceboard (on the real glanceboard, not the configuration widget) dimmer. In the Terminal glanceboard widget, with my configured font size (Roboto Light 12), there is room for one more row. It does seem to be responsive (when I increased the font size to 18 the row count dropped accordingly) but the bottom boundary might be above where it could be. Let's add IOB to the Nightscout glanceboard widget. Also include any of cannula age, cartridge volume, battery voltage, and time since last loop that breach the limits configured in Nightscout settings (if they aren't already included), and double check that the glucose value is crossed out if it's too old. Fable 5.1: > All three done, typechecked and built. > > **Dimmer lines.** The live board's dividers dropped from shade 40 to 20, the dimmest level that survives the 4-bit quantization. The configuration preview keeps its own brighter lines. > > **Terminal rows.** The bottom bound was stricter than it needed to be: it required a full line step, which includes inter-line spacing, to fit above an 8 px bottom pad. Rows are still placed a step apart, but the last one now only needs its glyph line height to clear a 2 px margin, and the gap under the "Terminal" label lost two pixels. With a 12 px font that admits one more row. The Calendar widget got the same rule for consistency. > > **Nightscout widget.** IOB now follows the age line. Below that, only fields breaching the limits from Nightscout settings appear, inverted the way the app marks them: cannula age, reservoir volume, pump battery voltage, and loop age, one per line while room remains. Nothing shown means nothing is out of range. The strikethrough was already correct: the value is crossed at mid-height once the reading is older than the app's 15-minute limit, using the app's own helper. I added a comment saying so. > > Nothing is committed. </details>
This commit is contained in:
1 parent
8a340fc4ad
commit
70d782a4f1
29 files changed
+1375
-134
No files matched your search
@@ -1686,17 +1686,44 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
);
|
||||
faceclawWakeNotification = true;
|
||||
lastConnectionOrInputAtMs = lastIncomingAtMs;
|
||||
// The event type says which gesture woke the glasses: TS
|
||||
// gives a head-up the Glanceboard and a double tap the
|
||||
// regular UI. The claim handshake is the same for both.
|
||||
boolean headUp = BleProtocol.parseFaceclawWakeEventCode(frame.pb)
|
||||
== BleProtocol.FACECLAW_WAKE_EVENT_HEAD_UP;
|
||||
event = new G2Event(
|
||||
"display-wake",
|
||||
"",
|
||||
BleProtocol.EVENT_DOUBLE_CLICK,
|
||||
headUp ? BleProtocol.EVENT_HEAD_UP : BleProtocol.EVENT_DOUBLE_CLICK,
|
||||
0,
|
||||
0
|
||||
);
|
||||
logLine("claimed deferred dashboard wake nonce=" + wakeNonce);
|
||||
logLine("claimed deferred dashboard wake nonce=" + wakeNonce
|
||||
+ (headUp ? " (head-up)" : ""));
|
||||
}
|
||||
}
|
||||
if (!faceclawWakeNotification
|
||||
&& shutdownRequested
|
||||
&& frame.ok
|
||||
&& frame.sid == BleProtocol.SID_UI_SETTING
|
||||
&& address.equalsIgnoreCase(rightAddress)) {
|
||||
// CFW idle-gesture forwarding (firmware revision 2+): with no
|
||||
// EvenHub page the stock display thread drops taps, long
|
||||
// presses and releases; the CFW reports them on the settings
|
||||
// sid while our wake lease is held. Deliver them as the
|
||||
// sys-events a live page would have produced, so TS treats a
|
||||
// sleep-time tap or hold exactly like one during soft sleep
|
||||
// (the Glanceboard).
|
||||
BleProtocol.FaceclawGestureEvent gesture = BleProtocol.parseFaceclawGestureEvent(frame.pb);
|
||||
if (gesture != null) {
|
||||
lastConnectionOrInputAtMs = lastIncomingAtMs;
|
||||
event = new G2Event("sys-event", "", gesture.eventType, gesture.eventSource, 0);
|
||||
logLine("idle gesture forwarded by CFW: type=" + gesture.eventType
|
||||
+ " source=" + gesture.eventSource);
|
||||
}
|
||||
}
|
||||
if (!faceclawWakeNotification
|
||||
&& event == null
|
||||
&& shutdownRequested
|
||||
&& address.equalsIgnoreCase(rightAddress)
|
||||
&& BleProtocol.isDisplayWakeStateChange(frame)) {
|
||||
@@ -1770,6 +1797,15 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
&& address.equalsIgnoreCase(rightAddress)
|
||||
&& (frame.flag == BleProtocol.FLAG_NOTIFY || frame.flag == BleProtocol.FLAG_NOTIFY_ALT)) {
|
||||
event = G2Event.decode(frame);
|
||||
if (event != null
|
||||
&& "sys-event".equals(event.kind)
|
||||
&& event.eventType == BleProtocol.EVENT_HEAD_UP) {
|
||||
// CFW forwards the IMU head-up while our page is on screen
|
||||
// (soft sleep). Surface it as the same wake-only input the
|
||||
// deferred head-up wake produces from a dark display.
|
||||
event = new G2Event("display-wake", "", BleProtocol.EVENT_HEAD_UP, event.eventSource, 0);
|
||||
logLine("head-up forwarded by CFW while page on screen");
|
||||
}
|
||||
if (event != null) {
|
||||
// Pure IMU samples arrive continuously; don't let them count
|
||||
// as user input (which would starve battery polling).
|
||||
|
||||
@@ -71,6 +71,19 @@ public class BleProtocol {
|
||||
public static final int FACECLAW_WEAR_OP_QUERY = 7;
|
||||
public static final int CFW_IMAGE_MODE_CLEANUP = 11;
|
||||
private static final int FACECLAW_WAKE_EVENT = 1;
|
||||
// Field-102 deferred wake from the IMU head-up (Faceclaw firmware revision
|
||||
// 3+); same nonce handshake as the double-tap wake event 1.
|
||||
public static final int FACECLAW_WAKE_EVENT_HEAD_UP = 5;
|
||||
// Field-102 idle-gesture events (Faceclaw firmware revision 2+): gestures the
|
||||
// stock display thread drops while no app is on screen, forwarded while the
|
||||
// wake lease is held. Their last two bytes are the raw touch source and 0.
|
||||
public static final int FACECLAW_GESTURE_EVENT_TAP = 2;
|
||||
public static final int FACECLAW_GESTURE_EVENT_LONG_PRESS = 3;
|
||||
public static final int FACECLAW_GESTURE_EVENT_LONG_PRESS_RELEASE = 4;
|
||||
// The display thread's raw touch sources, as the firmware reports them.
|
||||
private static final int FACECLAW_RAW_SOURCE_LEFT_TEMPLE = 0;
|
||||
private static final int FACECLAW_RAW_SOURCE_RIGHT_TEMPLE = 1;
|
||||
private static final int FACECLAW_RAW_SOURCE_RING = 4;
|
||||
private static final int FACECLAW_WAKE_PROTOCOL_VERSION = 1;
|
||||
// UI_FOREGROUND_EVEN_AI_ID: the stock "Even AI" assistant app. It is a
|
||||
// FOREGROUND app, whereas EvenHub (and therefore faceclaw) is the
|
||||
@@ -111,6 +124,9 @@ public class BleProtocol {
|
||||
public static final int EVENT_RING_LONG_PRESS_RELEASE = 10;
|
||||
// CFW extension: G2 2.2.9 tap-then-hold gesture forwarded to the phone.
|
||||
public static final int EVENT_SHORT_THEN_LONG_PRESS = 11;
|
||||
// CFW extension (firmware revision 3+): the IMU head-up, forwarded as a
|
||||
// sys-event while an EvenHub page is on screen (soft sleep).
|
||||
public static final int EVENT_HEAD_UP = 12;
|
||||
|
||||
public static final int EVENT_SOURCE_GLASSES_R = 1;
|
||||
public static final int EVENT_SOURCE_RING = 2;
|
||||
@@ -501,23 +517,100 @@ public class BleProtocol {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the uint16 wake nonce from a CFW field-102 notification, or -1
|
||||
* when this is an ordinary settings frame.
|
||||
* Return the uint16 wake nonce from a CFW field-102 deferred-wake
|
||||
* notification (double tap or head-up), or -1 when this is an ordinary
|
||||
* settings frame (idle-gesture events included).
|
||||
*/
|
||||
public static int parseFaceclawWakeEvent(byte[] pb) {
|
||||
byte[] event = faceclawWakeEventBytes(pb);
|
||||
return event == null ? -1 : (event[4] & 0xff) | ((event[5] & 0xff) << 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Which gesture a CFW deferred-wake notification reports: 1 (double tap)
|
||||
* or FACECLAW_WAKE_EVENT_HEAD_UP; -1 when the frame is not a wake event.
|
||||
*/
|
||||
public static int parseFaceclawWakeEventCode(byte[] pb) {
|
||||
byte[] event = faceclawWakeEventBytes(pb);
|
||||
return event == null ? -1 : (event[3] & 0xff);
|
||||
}
|
||||
|
||||
private static byte[] faceclawWakeEventBytes(byte[] pb) {
|
||||
if (pb == null) {
|
||||
return -1;
|
||||
return null;
|
||||
}
|
||||
byte[] event = readFieldBytes(stripTrailingCrc(pb), FACECLAW_WAKE_EVENT_FIELD);
|
||||
if (event == null
|
||||
|| event.length != 6
|
||||
|| event[0] != 'F'
|
||||
|| event[1] != 'C'
|
||||
|| (event[2] & 0xff) != FACECLAW_WAKE_PROTOCOL_VERSION
|
||||
|| (event[3] & 0xff) != FACECLAW_WAKE_EVENT) {
|
||||
return -1;
|
||||
|| (event[2] & 0xff) != FACECLAW_WAKE_PROTOCOL_VERSION) {
|
||||
return null;
|
||||
}
|
||||
return (event[4] & 0xff) | ((event[5] & 0xff) << 8);
|
||||
int code = event[3] & 0xff;
|
||||
return code == FACECLAW_WAKE_EVENT || code == FACECLAW_WAKE_EVENT_HEAD_UP ? event : null;
|
||||
}
|
||||
|
||||
/** An idle gesture from a CFW field-102 notification, in EvenHub sys-event terms. */
|
||||
public static final class FaceclawGestureEvent {
|
||||
public final int eventType;
|
||||
public final int eventSource;
|
||||
|
||||
FaceclawGestureEvent(int eventType, int eventSource) {
|
||||
this.eventType = eventType;
|
||||
this.eventSource = eventSource;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a CFW field-102 idle-gesture event (tap, long press, release
|
||||
* while no app is on screen) into the EvenHub sys-event type and source
|
||||
* the same gesture would carry from a live page, or null when the frame
|
||||
* is not one (ordinary settings frames and the double-tap wake event
|
||||
* included).
|
||||
*/
|
||||
public static FaceclawGestureEvent parseFaceclawGestureEvent(byte[] pb) {
|
||||
if (pb == null) {
|
||||
return null;
|
||||
}
|
||||
byte[] event = readFieldBytes(stripTrailingCrc(pb), FACECLAW_WAKE_EVENT_FIELD);
|
||||
if (event == null
|
||||
|| event.length != 6
|
||||
|| event[0] != 'F'
|
||||
|| event[1] != 'C'
|
||||
|| (event[2] & 0xff) != FACECLAW_WAKE_PROTOCOL_VERSION) {
|
||||
return null;
|
||||
}
|
||||
int eventType;
|
||||
switch (event[3] & 0xff) {
|
||||
case FACECLAW_GESTURE_EVENT_TAP:
|
||||
eventType = EVENT_CLICK;
|
||||
break;
|
||||
case FACECLAW_GESTURE_EVENT_LONG_PRESS:
|
||||
eventType = EVENT_RING_LONG_PRESS;
|
||||
break;
|
||||
case FACECLAW_GESTURE_EVENT_LONG_PRESS_RELEASE:
|
||||
eventType = EVENT_RING_LONG_PRESS_RELEASE;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
int eventSource;
|
||||
switch (event[4] & 0xff) {
|
||||
case FACECLAW_RAW_SOURCE_LEFT_TEMPLE:
|
||||
eventSource = EVENT_SOURCE_GLASSES_L;
|
||||
break;
|
||||
case FACECLAW_RAW_SOURCE_RIGHT_TEMPLE:
|
||||
eventSource = EVENT_SOURCE_GLASSES_R;
|
||||
break;
|
||||
case FACECLAW_RAW_SOURCE_RING:
|
||||
eventSource = EVENT_SOURCE_RING;
|
||||
break;
|
||||
default:
|
||||
eventSource = 0;
|
||||
break;
|
||||
}
|
||||
return new FaceclawGestureEvent(eventType, eventSource);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,6 +46,12 @@ export type GlanceboardProvider = {
|
||||
size: { width: number; height: number };
|
||||
/** Whether sleep-time gestures should show the board at all (user setting). */
|
||||
isEnabled: () => boolean;
|
||||
/** How long a tap or head-tilt keeps the board up. */
|
||||
tapTimeoutMs: () => number;
|
||||
/** Whether a long-press holds the board up until released. */
|
||||
showOnLongPress: () => boolean;
|
||||
/** Whether the head-tilt wake goes to the board rather than the regular UI. */
|
||||
showOnHeadTilt: () => boolean;
|
||||
/** A fresh board; requestRender asks the host to repaint it. */
|
||||
createBoard: (requestRender: () => void) => GlanceBoardInstance;
|
||||
};
|
||||
|
||||
@@ -178,7 +178,7 @@ function dayKeyOf(timestampMs: number): string {
|
||||
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;
|
||||
}
|
||||
|
||||
function dayHeaderLabel(timestampMs: number): string {
|
||||
export function dayHeaderLabel(timestampMs: number): string {
|
||||
const date = new Date(timestampMs);
|
||||
const now = new Date();
|
||||
const midnight = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
||||
@@ -189,7 +189,7 @@ function dayHeaderLabel(timestampMs: number): string {
|
||||
return base;
|
||||
}
|
||||
|
||||
function formatEventTime(timestampMs: number): string {
|
||||
export function formatEventTime(timestampMs: number): string {
|
||||
const date = new Date(timestampMs);
|
||||
const minutes = String(date.getMinutes()).padStart(2, "0");
|
||||
const hour24 = date.getHours();
|
||||
|
||||
@@ -1,23 +1,30 @@
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { onAnySettingChanged } from "../../ui/dashboard-settings";
|
||||
import { glanceSlotSettings, type GlanceSlotChoice } from "./glanceboard-settings";
|
||||
import { QUADRANT_LAYOUT, type GlanceLayout } from "./layout";
|
||||
import { glanceShowLinesSetting, glanceSlotSettings } from "./glanceboard-settings";
|
||||
import { QUADRANT_LAYOUT, resolveGlanceRegions, slotDividers, type GlanceLayout, type GlanceRegion } from "./layout";
|
||||
import { type GlanceWidget } from "./widget";
|
||||
import { findGlanceWidget } from "./widgets";
|
||||
import { findGlanceWidget, glanceWidgetSpans } from "./widgets";
|
||||
|
||||
/** Brightness of the hairlines between slots. */
|
||||
const DIVIDER_VALUE = 40;
|
||||
/** Brightness of the hairlines between regions: the dimmest shade that survives 4bpp quantization. */
|
||||
const DIVIDER_VALUE = 20;
|
||||
|
||||
type Slot = { choice: GlanceSlotChoice; widget: GlanceWidget | null };
|
||||
type LiveRegion = { region: GlanceRegion; key: string; widget: GlanceWidget | null };
|
||||
|
||||
/** Identity of a region for diffing: which widget, in which slots. */
|
||||
function regionKey(region: GlanceRegion): string {
|
||||
return `${region.choice}@${region.slots.join(",")}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* A board: the layout's slots filled with the widgets the settings choose,
|
||||
* painted as one image. Widgets are created and started when the board
|
||||
* starts and stopped when it stops; a slot setting changed meanwhile swaps
|
||||
* just that slot's widget.
|
||||
* painted as one image. A widget chosen for two vertically adjacent slots
|
||||
* (when it supports that) gets one double-height region with no divider
|
||||
* between the slots. Widgets are created and started when the board starts
|
||||
* and stopped when it stops; a settings change meanwhile restarts only the
|
||||
* regions that changed.
|
||||
*/
|
||||
export class GlanceBoard {
|
||||
private slots: Slot[] = [];
|
||||
private regions: LiveRegion[] = [];
|
||||
private started = false;
|
||||
private unsubscribeSettings: (() => void) | null = null;
|
||||
|
||||
@@ -37,7 +44,7 @@ export class GlanceBoard {
|
||||
start(): void {
|
||||
if (this.started) return;
|
||||
this.started = true;
|
||||
this.slots = glanceSlotSettings(this.layout).map((setting) => this.createSlot(setting.get()));
|
||||
this.applySlotSettings();
|
||||
this.unsubscribeSettings = onAnySettingChanged(() => this.applySlotSettings());
|
||||
}
|
||||
|
||||
@@ -46,53 +53,65 @@ export class GlanceBoard {
|
||||
this.started = false;
|
||||
this.unsubscribeSettings?.();
|
||||
this.unsubscribeSettings = null;
|
||||
for (const slot of this.slots) slot.widget?.stop();
|
||||
this.slots = [];
|
||||
for (const live of this.regions) live.widget?.stop();
|
||||
this.regions = [];
|
||||
}
|
||||
|
||||
private createSlot(choice: GlanceSlotChoice): Slot {
|
||||
const widget = choice === "none" ? null : (findGlanceWidget(choice)?.create() ?? null);
|
||||
widget?.start(this.requestRender);
|
||||
return { choice, widget };
|
||||
private currentRegions(): GlanceRegion[] {
|
||||
const choices = glanceSlotSettings(this.layout).map((setting) => setting.get());
|
||||
return resolveGlanceRegions(this.layout, choices, glanceWidgetSpans);
|
||||
}
|
||||
|
||||
/** Rebuild the live regions from the settings, keeping widgets whose region is unchanged. */
|
||||
private applySlotSettings(): void {
|
||||
if (!this.started) return;
|
||||
const previous = new Map(this.regions.map((live) => [live.key, live]));
|
||||
const next: LiveRegion[] = [];
|
||||
let changed = false;
|
||||
glanceSlotSettings(this.layout).forEach((setting, index) => {
|
||||
const choice = setting.get();
|
||||
const slot = this.slots[index];
|
||||
if (!slot || slot.choice === choice) return;
|
||||
slot.widget?.stop();
|
||||
this.slots[index] = this.createSlot(choice);
|
||||
for (const region of this.currentRegions()) {
|
||||
const key = regionKey(region);
|
||||
const kept = previous.get(key);
|
||||
if (kept) {
|
||||
previous.delete(key);
|
||||
next.push(kept);
|
||||
continue;
|
||||
}
|
||||
const widget = findGlanceWidget(region.choice)?.create() ?? null;
|
||||
widget?.start(this.requestRender);
|
||||
next.push({ region, key, widget });
|
||||
changed = true;
|
||||
});
|
||||
}
|
||||
for (const removed of previous.values()) {
|
||||
removed.widget?.stop();
|
||||
changed = true;
|
||||
}
|
||||
this.regions = next;
|
||||
if (changed) this.requestRender();
|
||||
}
|
||||
|
||||
/** Paint the whole board (layout-sized). Widgets each get a fresh slot canvas. */
|
||||
/** Paint the whole board (layout-sized). Widgets each get a fresh canvas of their region's size. */
|
||||
paint(): GrayImage {
|
||||
const image = new GrayImage(this.layout.width, this.layout.height, 0);
|
||||
this.layout.slots.forEach((slot, index) => {
|
||||
const widget = this.slots[index]?.widget;
|
||||
if (!widget) return;
|
||||
const canvas = new GrayImage(slot.rect.width, slot.rect.height, 0);
|
||||
for (const live of this.regions) {
|
||||
if (!live.widget) continue;
|
||||
const { rect } = live.region;
|
||||
const canvas = new GrayImage(rect.width, rect.height, 0);
|
||||
try {
|
||||
widget.paint(canvas);
|
||||
live.widget.paint(canvas);
|
||||
} catch (error) {
|
||||
console.warn(`glanceboard widget ${this.slots[index]?.choice} paint failed`, error);
|
||||
console.warn(`glanceboard widget ${live.region.choice} paint failed`, error);
|
||||
}
|
||||
canvas.composeInto(image, slot.rect.x, slot.rect.y);
|
||||
});
|
||||
drawDividers(image, this.layout);
|
||||
canvas.composeInto(image, rect.x, rect.y);
|
||||
}
|
||||
if (glanceShowLinesSetting.get()) {
|
||||
drawDividers(image, this.layout, this.regions.map((live) => live.region));
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
||||
/** Hairlines along every slot edge that is not the board's own edge. */
|
||||
function drawDividers(image: GrayImage, layout: GlanceLayout): void {
|
||||
for (const { rect } of layout.slots) {
|
||||
if (rect.x > 0) image.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height - 1, DIVIDER_VALUE);
|
||||
if (rect.y > 0) image.drawLine(rect.x, rect.y, rect.x + rect.width - 1, rect.y, DIVIDER_VALUE);
|
||||
function drawDividers(image: GrayImage, layout: GlanceLayout, regions: readonly GlanceRegion[]): void {
|
||||
for (const line of slotDividers(layout, regions)) {
|
||||
image.drawLine(line.x0, line.y0, line.x1, line.y1, DIVIDER_VALUE);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +1,268 @@
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { enumSettingMenuItem, toggleSettingMenuItem } from "../../ui/dashboard-settings";
|
||||
import { type InputEvent } from "../../ui/gestures";
|
||||
import { type Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||
import { MenuLayer, type MenuItem } from "../../ui/menu";
|
||||
import { createInProcessWindow, YieldAtRootLayer, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window";
|
||||
import { drawSelectionHighlight, MenuLayer, openModalMenu, type MenuItem } from "../../ui/menu";
|
||||
import { LIST_ROW_TEXT_INSET, lineStep } from "../../ui/metrics";
|
||||
import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window";
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import { GlanceBoard } from "./board";
|
||||
import { glanceboardEnabledSetting, glanceSlotSettings } from "./glanceboard-settings";
|
||||
import { QUADRANT_LAYOUT } from "./layout";
|
||||
import {
|
||||
clearConflictingSlots,
|
||||
glanceboardEnabledSetting,
|
||||
glanceShowLinesSetting,
|
||||
glanceShowOnHeadTiltSetting,
|
||||
glanceShowOnLongPressSetting,
|
||||
glanceSlotChoiceLabel,
|
||||
glanceSlotSettings,
|
||||
glanceTapDurationSetting,
|
||||
type GlanceSlotChoice,
|
||||
} from "./glanceboard-settings";
|
||||
import { QUADRANT_LAYOUT, resolveGlanceRegions, slotDividers } from "./layout";
|
||||
import { glanceWidgetSpans } from "./widgets";
|
||||
|
||||
export const GLANCEBOARD_WINDOW_ID = "glanceboard";
|
||||
export const GLANCEBOARD_SURFACE_ID = "window:glanceboard";
|
||||
|
||||
const TITLE_X = 18;
|
||||
const TITLE_Y = 10;
|
||||
const PARAGRAPH_X = 24;
|
||||
/** The entry page splits at the middle: menu left, slot preview right. */
|
||||
const PREVIEW_MARGIN = 8;
|
||||
const PREVIEW_MIN_LINE_VALUE = 20;
|
||||
const PREVIEW_LINE_VALUE = 100;
|
||||
|
||||
const INTRO =
|
||||
"Small widgets shown while the display is asleep, without waking the regular UI. " +
|
||||
"A tap or a head-tilt shows the board for a few seconds and a long-press holds it " +
|
||||
"up until released; a double-tap wakes the regular UI instead.";
|
||||
|
||||
/** Full-page list layout shared by the sub-screens. */
|
||||
function pageMenuLayout(width: number) {
|
||||
return { x: 8, y: 8, width: width - 16, opaque: true, showBorder: false } as const;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Glanceboard app window: where the board is configured. A list of the
|
||||
* layout's slots (each a widget picker), the sleep-gesture toggle, and a
|
||||
* live preview of the board as it will look when glanced at.
|
||||
* The Glanceboard app's entry page. Left half: title, a short description
|
||||
* and the menu (enable toggle, live preview, slot contents, settings). Right
|
||||
* half: a scaled preview of the board's slots with their dividers and the
|
||||
* name of the widget in each. "Select Contents" moves focus into that
|
||||
* preview, where scroll picks a quadrant and a tap opens the picker for it;
|
||||
* a double-tap returns focus to the menu.
|
||||
*/
|
||||
class GlanceboardConfigLayer implements Layer {
|
||||
class GlanceboardHomeLayer implements Layer {
|
||||
private menu: MenuLayer | null = null;
|
||||
private menuTop = 0;
|
||||
private focus: "menu" | "preview" = "menu";
|
||||
private selectedSlot = 0;
|
||||
|
||||
private currentMenu(ctx: LayerContext, menuTop: number): MenuLayer {
|
||||
if (!this.menu || this.menuTop !== menuTop) {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const half = (width / 2) | 0;
|
||||
const items: MenuItem[] = [
|
||||
toggleSettingMenuItem(glanceboardEnabledSetting),
|
||||
{
|
||||
label: "Preview",
|
||||
onSelect: (menuCtx) => menuCtx.stack.push(new GlancePreviewLayer(() => menuCtx.actions.requestRender())),
|
||||
},
|
||||
{
|
||||
label: "Select Contents",
|
||||
onSelect: () => {
|
||||
this.focus = "preview";
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Settings",
|
||||
onSelect: (menuCtx) => menuCtx.stack.push(new GlanceSettingsLayer()),
|
||||
},
|
||||
];
|
||||
this.menuTop = menuTop;
|
||||
this.menu = new MenuLayer(null, items, {
|
||||
x: 8, y: menuTop, width: half - 16,
|
||||
showBorder: false, minHeight: 0, maxHeight: height - menuTop,
|
||||
});
|
||||
}
|
||||
return this.menu;
|
||||
}
|
||||
|
||||
/** Where the scaled board sits: the right half, board aspect, vertically centred. */
|
||||
private previewRect(width: number, height: number): { x: number; y: number; width: number; height: number } {
|
||||
const half = (width / 2) | 0;
|
||||
const availableWidth = width - half - 2 * PREVIEW_MARGIN;
|
||||
const scale = Math.min(availableWidth / QUADRANT_LAYOUT.width, (height - 2 * PREVIEW_MARGIN) / QUADRANT_LAYOUT.height);
|
||||
const previewWidth = Math.round(QUADRANT_LAYOUT.width * scale);
|
||||
const previewHeight = Math.round(QUADRANT_LAYOUT.height * scale);
|
||||
return {
|
||||
x: half + PREVIEW_MARGIN + (((availableWidth - previewWidth) / 2) | 0),
|
||||
y: ((height - previewHeight) / 2) | 0,
|
||||
width: previewWidth,
|
||||
height: previewHeight,
|
||||
};
|
||||
}
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const half = (width / 2) | 0;
|
||||
image.drawText(font, TITLE_X, TITLE_Y, "Glanceboard", 220);
|
||||
const step = lineStep(font);
|
||||
let y = TITLE_Y + step + 6;
|
||||
for (const line of wrapText(font, INTRO, half - PARAGRAPH_X - 12)) {
|
||||
image.drawText(font, PARAGRAPH_X, y, line, 160);
|
||||
y += step;
|
||||
}
|
||||
// The menu paints onto this page below the paragraph (its fill is raster,
|
||||
// so the deferred paragraph glyphs above stay untouched either way).
|
||||
// While the preview has focus the menu keeps its outline-only selection.
|
||||
const menu = this.currentMenu(ctx, y + 4);
|
||||
const menuFocused = ctx.stack.isFocused() && this.focus === "menu";
|
||||
const menuCtx: LayerContext = { ...ctx, stack: Object.assign(Object.create(ctx.stack), { isFocused: () => menuFocused }) };
|
||||
menu.paint(menuCtx, () => image);
|
||||
|
||||
const preview = this.previewRect(width, height);
|
||||
drawSlotPreview(image, preview, {
|
||||
selectedSlot: this.selectedSlot,
|
||||
selectionFocused: ctx.stack.isFocused() && this.focus === "preview",
|
||||
});
|
||||
return image;
|
||||
}
|
||||
|
||||
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||
if (this.focus === "preview") {
|
||||
const slotCount = QUADRANT_LAYOUT.slots.length;
|
||||
switch (event.type) {
|
||||
case "scroll-up":
|
||||
this.selectedSlot = (this.selectedSlot + slotCount - 1) % slotCount;
|
||||
return;
|
||||
case "scroll-down":
|
||||
this.selectedSlot = (this.selectedSlot + 1) % slotCount;
|
||||
return;
|
||||
case "click":
|
||||
openSlotPicker(ctx, this.selectedSlot);
|
||||
return;
|
||||
case "double-click":
|
||||
// Back from the preview is back to the menu, not out of the app;
|
||||
// this layer is the window's root and handles the yield itself
|
||||
// (see createGlanceboardAppWindow), so the gesture arrives here.
|
||||
this.focus = "menu";
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (event.type === "double-click") {
|
||||
shell.yieldFocusToSidebar();
|
||||
return;
|
||||
}
|
||||
await this.currentMenu(ctx, this.menuTop).handleInput(event, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The board's slots scaled into `rect`: dividers (full brightness, or the
|
||||
* dimmest dotted line when "Show lines" is off), the widget name centred in
|
||||
* each region (a merged double-height region has one name and no line
|
||||
* across it), and the selected quadrant highlighted.
|
||||
*/
|
||||
function drawSlotPreview(
|
||||
image: GrayImage,
|
||||
rect: { x: number; y: number; width: number; height: number },
|
||||
options: { selectedSlot: number; selectionFocused: boolean },
|
||||
): void {
|
||||
const font = getDefaultSmallFont();
|
||||
const layout = QUADRANT_LAYOUT;
|
||||
const settings = glanceSlotSettings(layout);
|
||||
const choices = settings.map((setting) => setting.get());
|
||||
const regions = resolveGlanceRegions(layout, choices, glanceWidgetSpans);
|
||||
const sx = rect.width / layout.width;
|
||||
const sy = rect.height / layout.height;
|
||||
const scaled = (r: { x: number; y: number; width: number; height: number }) => ({
|
||||
x: rect.x + Math.round(r.x * sx),
|
||||
y: rect.y + Math.round(r.y * sy),
|
||||
width: Math.round(r.width * sx),
|
||||
height: Math.round(r.height * sy),
|
||||
});
|
||||
|
||||
image.drawRect(rect.x - 1, rect.y - 1, rect.width + 2, rect.height + 2, 72);
|
||||
const selected = scaled(layout.slots[options.selectedSlot]!.rect);
|
||||
drawSelectionHighlight(image, selected.x + 1, selected.y + 1, selected.width - 2, selected.height - 2, options.selectionFocused, 4);
|
||||
|
||||
const showLines = glanceShowLinesSetting.get();
|
||||
for (const line of slotDividers(layout, regions)) {
|
||||
const x0 = rect.x + Math.round(line.x0 * sx);
|
||||
const y0 = rect.y + Math.round(line.y0 * sy);
|
||||
const x1 = rect.x + Math.round(line.x1 * sx);
|
||||
const y1 = rect.y + Math.round(line.y1 * sy);
|
||||
if (showLines) {
|
||||
image.drawLine(x0, y0, x1, y1, PREVIEW_LINE_VALUE);
|
||||
} else {
|
||||
// Every other pixel at the dimmest visible shade: the line is there to
|
||||
// read the layout by, but says "off".
|
||||
drawDottedLine(image, x0, y0, x1, y1, PREVIEW_MIN_LINE_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
// Names: one per region, "Empty" in slots no region covers.
|
||||
const covered = new Set<number>();
|
||||
const label = (r: { x: number; y: number; width: number; height: number }, text: string, value: number) => {
|
||||
const clipped = truncateText(font, text, Math.max(0, r.width - 8));
|
||||
image.drawText(font, r.x + (((r.width - font.measureText(clipped)) / 2) | 0), r.y + (((r.height - font.lineHeight) / 2) | 0), clipped, value);
|
||||
};
|
||||
for (const region of regions) {
|
||||
for (const index of region.slots) covered.add(index);
|
||||
label(scaled(region.rect), glanceSlotChoiceLabel(region.choice as GlanceSlotChoice), 210);
|
||||
}
|
||||
layout.slots.forEach((slot, index) => {
|
||||
if (!covered.has(index)) label(scaled(slot.rect), "Empty", 90);
|
||||
});
|
||||
}
|
||||
|
||||
/** A horizontal or vertical line lit on every other pixel. */
|
||||
function drawDottedLine(image: GrayImage, x0: number, y0: number, x1: number, y1: number, value: number): void {
|
||||
if (y0 === y1) {
|
||||
for (let x = Math.min(x0, x1); x <= Math.max(x0, x1); x += 2) image.setPixel(x, y0, value);
|
||||
} else {
|
||||
for (let y = Math.min(y0, y1); y <= Math.max(y0, y1); y += 2) image.setPixel(x0, y, value);
|
||||
}
|
||||
}
|
||||
|
||||
/** The picker for one slot: every widget, the current one marked; choosing applies the one-per-board rule. */
|
||||
function openSlotPicker(ctx: LayerContext, slotIndex: number): void {
|
||||
const setting = glanceSlotSettings(QUADRANT_LAYOUT)[slotIndex];
|
||||
if (!setting) return;
|
||||
const current = setting.get();
|
||||
const items: MenuItem[] = setting.values.map((value) => ({
|
||||
label: setting.displayValue(value),
|
||||
onSelect: (menuCtx) => {
|
||||
setting.set(value);
|
||||
clearConflictingSlots(QUADRANT_LAYOUT, slotIndex, value);
|
||||
menuCtx.stack.pop();
|
||||
},
|
||||
render: ({ image, x, y }) => {
|
||||
image.drawText(getDefaultSmallFont(), x, y + LIST_ROW_TEXT_INSET, `${setting.displayValue(value)}${setting.get() === value ? " *" : ""}`, 200);
|
||||
},
|
||||
}));
|
||||
openModalMenu(ctx, setting.label, items, Math.max(0, setting.values.indexOf(current)));
|
||||
}
|
||||
|
||||
/** Settings: which sleep gestures show the board, for how long, and the slot lines. */
|
||||
class GlanceSettingsLayer implements Layer {
|
||||
private menu: MenuLayer | null = null;
|
||||
|
||||
private currentMenu(ctx: LayerContext): MenuLayer {
|
||||
if (!this.menu) {
|
||||
const { width } = ctx.stack.getBaseSize();
|
||||
const items: MenuItem[] = [
|
||||
{
|
||||
label: "Preview",
|
||||
description: "Show the board as it appears when the display is asleep and tapped.",
|
||||
onSelect: (menuCtx) => menuCtx.stack.push(new GlancePreviewLayer(() => menuCtx.actions.requestRender())),
|
||||
},
|
||||
...glanceSlotSettings(QUADRANT_LAYOUT).map((setting) => enumSettingMenuItem(setting)),
|
||||
toggleSettingMenuItem(glanceboardEnabledSetting),
|
||||
enumSettingMenuItem(glanceTapDurationSetting),
|
||||
toggleSettingMenuItem(glanceShowOnLongPressSetting),
|
||||
toggleSettingMenuItem(glanceShowOnHeadTiltSetting),
|
||||
toggleSettingMenuItem(glanceShowLinesSetting),
|
||||
];
|
||||
this.menu = new MenuLayer("Glanceboard", items, {
|
||||
x: 8, y: 8, width: width - 16,
|
||||
opaque: true, showBorder: false,
|
||||
footer: "Asleep: tap shows, hold keeps, double-tap wakes",
|
||||
});
|
||||
this.menu = new MenuLayer("Glanceboard settings", items, pageMenuLayout(width));
|
||||
}
|
||||
return this.menu;
|
||||
}
|
||||
@@ -89,7 +316,9 @@ export function createGlanceboardAppWindow(options: InProcessAppOptions): InProc
|
||||
// 576x288: the board's own size, so the preview is pixel-exact.
|
||||
heightMode: "medium",
|
||||
actions: options.actions,
|
||||
baseLayer: new YieldAtRootLayer(new GlanceboardConfigLayer()),
|
||||
// Not wrapped in YieldAtRootLayer: the home page routes double-click
|
||||
// itself (preview focus -> menu focus, menu focus -> sidebar).
|
||||
baseLayer: new GlanceboardHomeLayer(),
|
||||
submitFrame: options.submitFrame,
|
||||
setSurfaceVisible: options.setSurfaceVisible,
|
||||
removeSurface: options.removeSurface,
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import { ConfigSettingBoolean, ConfigSettingEnum } from "../../ui/dashboard-settings";
|
||||
import { QUADRANT_LAYOUT, type GlanceLayout } from "./layout";
|
||||
import { QUADRANT_LAYOUT, slotsVerticallyAdjacent, type GlanceLayout } from "./layout";
|
||||
import { type GlanceWidgetId } from "./widget";
|
||||
import { glanceWidgetSpans } from "./widgets";
|
||||
|
||||
export type GlanceSlotChoice = GlanceWidgetId | "none";
|
||||
|
||||
const SLOT_CHOICES: readonly GlanceSlotChoice[] = ["none", "system-card", "nightscout", "compass", "music"];
|
||||
const SLOT_CHOICES: readonly GlanceSlotChoice[] = ["none", "system-card", "calendar", "terminal", "nightscout", "compass", "music"];
|
||||
|
||||
const SLOT_CHOICE_LABELS: Record<GlanceSlotChoice, string> = {
|
||||
none: "Empty",
|
||||
"system-card": "System card",
|
||||
calendar: "Calendar",
|
||||
terminal: "Terminal",
|
||||
nightscout: "Nightscout",
|
||||
compass: "Compass",
|
||||
music: "Music",
|
||||
@@ -22,15 +25,60 @@ const DEFAULT_QUADRANT_CHOICES: readonly GlanceSlotChoice[] = ["system-card", "m
|
||||
|
||||
/**
|
||||
* Whether sleep-time gestures show the board at all. Off restores the plain
|
||||
* behaviour: a tap or hold while asleep does nothing, double-tap wakes.
|
||||
* behaviour: a tap, hold or head-tilt while asleep does nothing (a head-tilt
|
||||
* wakes the regular UI), double-tap wakes.
|
||||
*/
|
||||
export const glanceboardEnabledSetting = new ConfigSettingBoolean({
|
||||
id: "glanceboard-enabled",
|
||||
label: "Show on tap while asleep",
|
||||
label: "Enable Glanceboard",
|
||||
storageKey: "glanceboard.enabled",
|
||||
defaultValue: true,
|
||||
description:
|
||||
"While the display is asleep, a single tap shows the Glanceboard for a few seconds and a long-press holds it up until released. Double-tap still wakes the regular UI.",
|
||||
"While the display is asleep, a tap, a long-press or a head-tilt shows the Glanceboard instead of the regular UI. Double-tap still wakes the regular UI.",
|
||||
});
|
||||
|
||||
export type GlanceTapDuration = "3s" | "5s" | "7s" | "10s";
|
||||
|
||||
/** How long a tap (or head-tilt) keeps the board up; each further tap restarts it. */
|
||||
export const glanceTapDurationSetting = new ConfigSettingEnum<GlanceTapDuration>({
|
||||
id: "glanceboard-tap-duration",
|
||||
label: "Show on tap",
|
||||
storageKey: "glanceboard.tapDuration",
|
||||
defaultValue: "5s",
|
||||
values: ["3s", "5s", "7s", "10s"],
|
||||
formatValue: (value) => value.replace("s", " s"),
|
||||
description: "How long a single tap (or a head-tilt) keeps the Glanceboard on screen.",
|
||||
});
|
||||
|
||||
export function glanceTapTimeoutMs(): number {
|
||||
return Number.parseInt(glanceTapDurationSetting.get(), 10) * 1000;
|
||||
}
|
||||
|
||||
/** A long-press holds the board up until the press is released. */
|
||||
export const glanceShowOnLongPressSetting = new ConfigSettingBoolean({
|
||||
id: "glanceboard-show-on-long-press",
|
||||
label: "Show on long press",
|
||||
storageKey: "glanceboard.showOnLongPress",
|
||||
defaultValue: true,
|
||||
description: "Holding a long-press while asleep shows the Glanceboard until the press is released.",
|
||||
});
|
||||
|
||||
/** The head-tilt wake shows the board (for the tap duration) instead of the regular UI. */
|
||||
export const glanceShowOnHeadTiltSetting = new ConfigSettingBoolean({
|
||||
id: "glanceboard-show-on-head-tilt",
|
||||
label: "Show on head tilt",
|
||||
storageKey: "glanceboard.showOnHeadTilt",
|
||||
defaultValue: true,
|
||||
description: "Tilting your head up while asleep shows the Glanceboard instead of waking the regular UI.",
|
||||
});
|
||||
|
||||
/** Hairlines between the board's slots. */
|
||||
export const glanceShowLinesSetting = new ConfigSettingBoolean({
|
||||
id: "glanceboard-show-lines",
|
||||
label: "Show lines",
|
||||
storageKey: "glanceboard.showLines",
|
||||
defaultValue: true,
|
||||
description: "Draw the separator lines between the Glanceboard's slots.",
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -51,3 +99,23 @@ export function glanceSlotSettings(layout: GlanceLayout = QUADRANT_LAYOUT): Conf
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A slot was just set to `choice`: each widget appears on the board once, so
|
||||
* clear every other slot holding the same choice, except a vertically
|
||||
* adjacent one when the widget can span two slots (it then renders at
|
||||
* double height). Returns the indices cleared.
|
||||
*/
|
||||
export function clearConflictingSlots(layout: GlanceLayout, changedIndex: number, choice: GlanceSlotChoice): number[] {
|
||||
if (choice === "none") return [];
|
||||
const settings = glanceSlotSettings(layout);
|
||||
const spans = glanceWidgetSpans(choice);
|
||||
const cleared: number[] = [];
|
||||
settings.forEach((setting, index) => {
|
||||
if (index === changedIndex || setting.get() !== choice) return;
|
||||
if (spans && slotsVerticallyAdjacent(layout, changedIndex, index)) return;
|
||||
setting.set("none");
|
||||
cleared.push(index);
|
||||
});
|
||||
return cleared;
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
import { type AppDefinition } from "../app-definition";
|
||||
import { GlanceBoard } from "./board";
|
||||
import { createGlanceboardAppWindow, GLANCEBOARD_SURFACE_ID, GLANCEBOARD_WINDOW_ID } from "./glanceboard-app";
|
||||
import { glanceboardEnabledSetting } from "./glanceboard-settings";
|
||||
import {
|
||||
glanceboardEnabledSetting,
|
||||
glanceShowOnHeadTiltSetting,
|
||||
glanceShowOnLongPressSetting,
|
||||
glanceTapTimeoutMs,
|
||||
} from "./glanceboard-settings";
|
||||
import { QUADRANT_LAYOUT } from "./layout";
|
||||
|
||||
const glanceboardApp: AppDefinition = {
|
||||
@@ -12,6 +17,9 @@ const glanceboardApp: AppDefinition = {
|
||||
glanceboard: {
|
||||
size: { width: QUADRANT_LAYOUT.width, height: QUADRANT_LAYOUT.height },
|
||||
isEnabled: () => glanceboardEnabledSetting.get(),
|
||||
tapTimeoutMs: glanceTapTimeoutMs,
|
||||
showOnLongPress: () => glanceShowOnLongPressSetting.get(),
|
||||
showOnHeadTilt: () => glanceShowOnHeadTiltSetting.get(),
|
||||
createBoard: (requestRender) => new GlanceBoard(requestRender, QUADRANT_LAYOUT),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -28,3 +28,81 @@ export const QUADRANT_LAYOUT: GlanceLayout = {
|
||||
{ label: "Bottom right", rect: { x: 288, y: 144, width: 288, height: 144 } },
|
||||
],
|
||||
};
|
||||
|
||||
/** Whether two slots stack vertically with matching width (one region if merged). */
|
||||
export function slotsVerticallyAdjacent(layout: GlanceLayout, a: number, b: number): boolean {
|
||||
const first = layout.slots[a]?.rect;
|
||||
const second = layout.slots[b]?.rect;
|
||||
if (!first || !second || a === b) return false;
|
||||
if (first.x !== second.x || first.width !== second.width) return false;
|
||||
return first.y + first.height === second.y || second.y + second.height === first.y;
|
||||
}
|
||||
|
||||
/** A painted area of the board: one slot, or two vertically adjacent slots merged. */
|
||||
export type GlanceRegion = {
|
||||
/** The slot choice (widget id) filling the region. */
|
||||
choice: string;
|
||||
rect: GlanceSlotRect;
|
||||
/** Indices into layout.slots, ascending. */
|
||||
slots: number[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn per-slot choices into regions. A widget chosen for two vertically
|
||||
* adjacent slots, when `canSpan` says it supports it, becomes one
|
||||
* double-height region; every other non-empty slot is a region of its own
|
||||
* (a duplicate that cannot merge simply paints twice). Regions come out in
|
||||
* slot order.
|
||||
*/
|
||||
export function resolveGlanceRegions(
|
||||
layout: GlanceLayout,
|
||||
choices: readonly string[],
|
||||
canSpan: (choice: string) => boolean,
|
||||
): GlanceRegion[] {
|
||||
const regions: GlanceRegion[] = [];
|
||||
const consumed = new Set<number>();
|
||||
layout.slots.forEach((slot, index) => {
|
||||
if (consumed.has(index)) return;
|
||||
const choice = choices[index] ?? "none";
|
||||
if (choice === "none") return;
|
||||
consumed.add(index);
|
||||
let rect = { ...slot.rect };
|
||||
const slots = [index];
|
||||
if (canSpan(choice)) {
|
||||
const partner = layout.slots.findIndex(
|
||||
(_, other) => !consumed.has(other) && choices[other] === choice && slotsVerticallyAdjacent(layout, index, other),
|
||||
);
|
||||
if (partner >= 0) {
|
||||
consumed.add(partner);
|
||||
slots.push(partner);
|
||||
const other = layout.slots[partner]!.rect;
|
||||
const top = Math.min(rect.y, other.y);
|
||||
rect = { x: rect.x, y: top, width: rect.width, height: Math.max(rect.y + rect.height, other.y + other.height) - top };
|
||||
}
|
||||
}
|
||||
regions.push({ choice, rect, slots });
|
||||
});
|
||||
return regions;
|
||||
}
|
||||
|
||||
/** A divider line between slots, in board coordinates (inclusive endpoints). */
|
||||
export type GlanceDivider = { x0: number; y0: number; x1: number; y1: number };
|
||||
|
||||
/**
|
||||
* The hairlines between slots: every slot's left edge (when not at the
|
||||
* board's left) and top edge (when not at the top), except the top edge of
|
||||
* the lower slot of a merged double-height region, which is that region's
|
||||
* interior. Shared by the board painter and the config app's preview.
|
||||
*/
|
||||
export function slotDividers(layout: GlanceLayout, regions: readonly GlanceRegion[]): GlanceDivider[] {
|
||||
const dividers: GlanceDivider[] = [];
|
||||
layout.slots.forEach(({ rect }, index) => {
|
||||
if (rect.x > 0) dividers.push({ x0: rect.x, y0: rect.y, x1: rect.x, y1: rect.y + rect.height - 1 });
|
||||
if (rect.y === 0) return;
|
||||
const interior = regions.some(
|
||||
(region) => region.slots.length > 1 && region.slots.includes(index) && region.rect.y < rect.y,
|
||||
);
|
||||
if (!interior) dividers.push({ x0: rect.x, y0: rect.y, x1: rect.x + rect.width - 1, y1: rect.y });
|
||||
});
|
||||
return dividers;
|
||||
}
|
||||
@@ -27,11 +27,17 @@ export interface GlanceWidget {
|
||||
paint(image: GrayImage): void;
|
||||
}
|
||||
|
||||
export type GlanceWidgetId = "system-card" | "nightscout" | "compass" | "music";
|
||||
export type GlanceWidgetId = "system-card" | "nightscout" | "compass" | "music" | "calendar" | "terminal";
|
||||
|
||||
export type GlanceWidgetDefinition = {
|
||||
id: GlanceWidgetId;
|
||||
/** Picker label in the Glanceboard app. */
|
||||
label: string;
|
||||
/**
|
||||
* The widget can fill two vertically adjacent slots as one double-height
|
||||
* region (chosen for both left or both right quadrants). Its paint then
|
||||
* gets the taller canvas; the divider between the slots is not drawn.
|
||||
*/
|
||||
tall?: boolean;
|
||||
create: () => GlanceWidget;
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
import { type GrayImage, type UiFont } from "../../../graphics/image";
|
||||
import { truncateText } from "../../../graphics/textwrap";
|
||||
import { getDefaultMediumFont, getDefaultSmallFont } from "../../../graphics/ui-fonts";
|
||||
import { hasCalendarPermission } from "../../../g2/android-permissions";
|
||||
import { readUpcomingEvents, type CalendarEvent } from "../../../native/calendar";
|
||||
import { lineStep } from "../../../ui/metrics";
|
||||
import { dayHeaderLabel, formatEventTime } from "../../calendar/calendar";
|
||||
import { type GlanceWidget } from "../widget";
|
||||
|
||||
const PAD = 8;
|
||||
/** A row fits while its glyph line clears this margin above the bottom edge. */
|
||||
const BOTTOM_MARGIN = 2;
|
||||
const MINUTE_MS = 60_000;
|
||||
const HOUR_MS = 60 * MINUTE_MS;
|
||||
|
||||
/**
|
||||
* What is next on the calendar: the current or next event large, with how
|
||||
* far off it is (or when it ends), then the following events grouped under
|
||||
* day headers, as many as fit. Reads the same cached provider query as the
|
||||
* Calendar app; a minute tick keeps the countdown honest and lets the
|
||||
* 30-second cache refresh on its own.
|
||||
*/
|
||||
export class CalendarWidget implements GlanceWidget {
|
||||
private tick: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
start(requestRender: () => void): void {
|
||||
this.tick = setInterval(requestRender, MINUTE_MS);
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
if (this.tick !== null) clearInterval(this.tick);
|
||||
this.tick = null;
|
||||
}
|
||||
|
||||
paint(image: GrayImage): void {
|
||||
const small = getDefaultSmallFont();
|
||||
const medium = getDefaultMediumFont();
|
||||
const step = lineStep(small);
|
||||
const textWidth = image.width - 2 * PAD;
|
||||
|
||||
if (!hasCalendarPermission()) {
|
||||
image.drawText(small, PAD, PAD, "Calendar", 150);
|
||||
image.drawText(small, PAD, PAD + step + 4, "Calendar permission needed", 140);
|
||||
image.drawText(small, PAD, PAD + 2 * step + 4, "Open the Calendar app to grant it", 100);
|
||||
return;
|
||||
}
|
||||
const nowMs = Date.now();
|
||||
// Events still in progress count; the provider's window starts at "now",
|
||||
// so the list can include an event that began earlier and is still on.
|
||||
const events = readUpcomingEvents().filter((event) => event.endMs > nowMs);
|
||||
if (!events.length) {
|
||||
image.drawText(small, PAD, PAD, "Calendar", 150);
|
||||
image.drawText(small, PAD, PAD + step + 4, "No upcoming events", 140);
|
||||
return;
|
||||
}
|
||||
|
||||
// Headline: the current or next event, with its day when it is not today.
|
||||
const next = events[0]!;
|
||||
let y = PAD;
|
||||
const headline = truncateText(medium, next.title || "(untitled)", textWidth);
|
||||
image.drawText(medium, PAD, y, headline, 230);
|
||||
y += medium.lineHeight + 2;
|
||||
image.drawText(small, PAD, y, truncateText(small, headlineDetail(next, nowMs), textWidth), 170);
|
||||
y += step + 6;
|
||||
|
||||
// The rest, grouped by day. A day header only where the day changes from
|
||||
// the previous listed event (the headline's day included).
|
||||
let previousDayKey = dayKeyOf(next.startMs);
|
||||
for (let index = 1; index < events.length; index++) {
|
||||
const event = events[index]!;
|
||||
const dayKey = dayKeyOf(event.startMs);
|
||||
const needsHeader = dayKey !== previousDayKey;
|
||||
// The header and its row are placed a step apart; the row only needs
|
||||
// its line height to fit above the bottom margin.
|
||||
if (y + (needsHeader ? step : 0) + small.lineHeight > image.height - BOTTOM_MARGIN) break;
|
||||
if (needsHeader) {
|
||||
image.drawText(small, PAD, y, truncateText(small, dayHeaderLabel(event.startMs), textWidth), 120);
|
||||
y += step;
|
||||
previousDayKey = dayKey;
|
||||
}
|
||||
drawEventLine(image, small, PAD, y, textWidth, event, 190);
|
||||
y += step;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** "Now, ends 14:30", "In 25 min", "Tomorrow 09:00", "All day"... for the headline. */
|
||||
function headlineDetail(event: CalendarEvent, nowMs: number): string {
|
||||
const dayDelta = dayDeltaFromToday(event.startMs);
|
||||
const when = event.allDay
|
||||
? "All day"
|
||||
: `${formatEventTime(event.startMs)} - ${formatEventTime(event.endMs)}`;
|
||||
if (event.startMs <= nowMs) {
|
||||
if (event.allDay) return dayDelta === 0 ? "All day today" : `All day, ${dayHeaderLabel(event.startMs)}`;
|
||||
return `Now, ends ${formatEventTime(event.endMs)}`;
|
||||
}
|
||||
const untilMs = event.startMs - nowMs;
|
||||
if (dayDelta === 0 && untilMs < 12 * HOUR_MS) {
|
||||
return `In ${formatDuration(untilMs)}, ${when}`;
|
||||
}
|
||||
const day = dayDelta === 0 ? "Today" : dayDelta === 1 ? "Tomorrow" : dayHeaderLabel(event.startMs);
|
||||
return `${day}, ${when}`;
|
||||
}
|
||||
|
||||
function drawEventLine(
|
||||
image: GrayImage,
|
||||
font: UiFont,
|
||||
x: number,
|
||||
y: number,
|
||||
width: number,
|
||||
event: CalendarEvent,
|
||||
value: number,
|
||||
): void {
|
||||
const time = event.allDay ? "All day" : formatEventTime(event.startMs);
|
||||
const timeWidth = font.measureText(time);
|
||||
image.drawText(font, x, y, time, value - 50);
|
||||
const titleX = x + timeWidth + 8;
|
||||
image.drawText(font, titleX, y, truncateText(font, event.title || "(untitled)", Math.max(0, x + width - titleX)), value);
|
||||
}
|
||||
|
||||
function formatDuration(ms: number): string {
|
||||
const minutes = Math.max(1, Math.round(ms / MINUTE_MS));
|
||||
if (minutes < 60) return `${minutes} min`;
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const rest = minutes % 60;
|
||||
return rest ? `${hours} h ${rest} min` : `${hours} h`;
|
||||
}
|
||||
|
||||
function dayKeyOf(timestampMs: number): string {
|
||||
const date = new Date(timestampMs);
|
||||
return `${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;
|
||||
}
|
||||
|
||||
function dayDeltaFromToday(timestampMs: number): number {
|
||||
const midnight = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
||||
return Math.round((midnight(new Date(timestampMs)) - midnight(new Date())) / (24 * HOUR_MS));
|
||||
}
|
||||
@@ -1,12 +1,16 @@
|
||||
import { type GlanceWidgetDefinition, type GlanceWidgetId } from "../widget";
|
||||
import { CalendarWidget } from "./calendar-widget";
|
||||
import { CompassWidget } from "./compass-widget";
|
||||
import { MusicWidget } from "./music-widget";
|
||||
import { NightscoutWidget } from "./nightscout-widget";
|
||||
import { SystemCardWidget } from "./system-card";
|
||||
import { TerminalWidget } from "./terminal-widget";
|
||||
|
||||
/** Every widget a board slot can hold. */
|
||||
export const GLANCE_WIDGETS: readonly GlanceWidgetDefinition[] = [
|
||||
{ id: "system-card", label: "System card", create: () => new SystemCardWidget() },
|
||||
{ id: "calendar", label: "Calendar", tall: true, create: () => new CalendarWidget() },
|
||||
{ id: "terminal", label: "Terminal", tall: true, create: () => new TerminalWidget() },
|
||||
{ id: "nightscout", label: "Nightscout", create: () => new NightscoutWidget() },
|
||||
{ id: "compass", label: "Compass", create: () => new CompassWidget() },
|
||||
{ id: "music", label: "Music", create: () => new MusicWidget() },
|
||||
@@ -15,3 +19,8 @@ export const GLANCE_WIDGETS: readonly GlanceWidgetDefinition[] = [
|
||||
export function findGlanceWidget(id: GlanceWidgetId | string): GlanceWidgetDefinition | null {
|
||||
return GLANCE_WIDGETS.find((widget) => widget.id === id) ?? null;
|
||||
}
|
||||
|
||||
/** Whether a slot choice may span two vertically adjacent slots (see GlanceWidgetDefinition.tall). */
|
||||
export function glanceWidgetSpans(choice: string): boolean {
|
||||
return Boolean(findGlanceWidget(choice)?.tall);
|
||||
}
|
||||
@@ -2,9 +2,10 @@ import { type GrayImage } from "../../../graphics/image";
|
||||
import { getDefaultLargeFont, getDefaultSmallFont } from "../../../graphics/ui-fonts";
|
||||
import { truncateText } from "../../../graphics/textwrap";
|
||||
import { nightscoutBridge, type NightscoutState } from "../../../native/nightscout-bridge";
|
||||
import { isNightscoutSettingsConfigured } from "../../../ui/dashboard-settings";
|
||||
import { isNightscoutSettingsConfigured, loadNightscoutThresholds } from "../../../ui/dashboard-settings";
|
||||
import { lineStep } from "../../../ui/metrics";
|
||||
import { formatAgeShortFromTimestamp } from "~/util/date-util";
|
||||
import { evaluateNightscoutAlerts } from "../../nightscout/nightscout-alerts";
|
||||
import {
|
||||
drawDirectionIndicator,
|
||||
drawNightscoutGraph,
|
||||
@@ -19,8 +20,10 @@ const PAD = 8;
|
||||
const READOUT_WIDTH = 96;
|
||||
|
||||
/**
|
||||
* Current glucose with delta, trend and age beside the Nightscout app's
|
||||
* 2-hour graph. The bridge polls on its own for the whole session, so the
|
||||
* Current glucose (struck through once older than the app's staleness
|
||||
* limit) with delta, trend, age and IOB beside the Nightscout app's 2-hour
|
||||
* graph, plus any of cannula age, reservoir, pump battery and loop age that
|
||||
* breach the limits in Nightscout settings, inverted as the app shows them. The bridge polls on its own for the whole session, so the
|
||||
* widget only subscribes; a minute tick keeps the age and staleness moving
|
||||
* during a stalled fetch.
|
||||
*/
|
||||
@@ -64,12 +67,14 @@ export class NightscoutWidget implements GlanceWidget {
|
||||
return;
|
||||
}
|
||||
|
||||
// Readout column: big value, units, then delta + trend and the age.
|
||||
// Readout column: big value, units, then delta + trend, age and IOB.
|
||||
const glucoseText = `${latest.sgv}`;
|
||||
const glucoseY = PAD + step;
|
||||
const glucoseWidth = large.measureText(glucoseText);
|
||||
image.drawText(large, PAD, glucoseY, glucoseText, 230);
|
||||
if (isNightscoutPointStale(latest, nowMs)) {
|
||||
// Same rule as the app: older than NIGHTSCOUT_STALE_MS (15 min) gets a
|
||||
// line through the digits at mid-height.
|
||||
drawNightscoutValueStrikeThrough(image, PAD, glucoseY + (large.lineHeight >> 1), glucoseWidth);
|
||||
}
|
||||
const unitsX = PAD + glucoseWidth + 4;
|
||||
@@ -82,6 +87,25 @@ export class NightscoutWidget implements GlanceWidget {
|
||||
drawDirectionIndicator(image, small, PAD + small.measureText(deltaText), y, state.direction, 180);
|
||||
y += step;
|
||||
image.drawText(small, PAD, y, `${formatAgeShortFromTimestamp(latest.timestampMs, nowMs)} ago`, 130);
|
||||
y += step;
|
||||
image.drawText(small, PAD, y, `IOB ${state.iob === null ? "--" : state.iob.toFixed(2)}`, 160);
|
||||
y += step;
|
||||
|
||||
// Breached limits only, one per line while they fit, inverted like the
|
||||
// app's warning fields. Nothing here means nothing is out of range.
|
||||
const alerts = evaluateNightscoutAlerts(state, loadNightscoutThresholds(), nowMs);
|
||||
const warnings: string[] = [];
|
||||
if (alerts.cannula) warnings.push(`CAGE ${formatAgeShortFromTimestamp(state.cageTimestampMs, nowMs)}`);
|
||||
if (alerts.cartridge) warnings.push(`Reservoir ${state.reservoirUnits === null ? "--" : Math.round(state.reservoirUnits)}U`);
|
||||
if (alerts.battery) warnings.push(`Battery ${state.batteryVoltage === null ? "--" : state.batteryVoltage.toFixed(2)}V`);
|
||||
if (alerts.loop) warnings.push(`Loop ${formatAgeShortFromTimestamp(state.loopTimestampMs, nowMs)}`);
|
||||
for (const warning of warnings) {
|
||||
if (y + small.lineHeight > image.height - 2) break;
|
||||
const text = truncateText(small, warning, READOUT_WIDTH - 4);
|
||||
image.fillRect(PAD - 2, y - 1, small.measureText(text) + 4, small.lineHeight + 2, 230);
|
||||
image.drawText(small, PAD, y, text, 1);
|
||||
y += step;
|
||||
}
|
||||
|
||||
const graphX = PAD + READOUT_WIDTH + PAD;
|
||||
drawNightscoutGraph(
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
import { type GrayImage } from "../../../graphics/image";
|
||||
import { truncateText } from "../../../graphics/textwrap";
|
||||
import { getDefaultSmallFont } from "../../../graphics/ui-fonts";
|
||||
import { lineStep } from "../../../ui/metrics";
|
||||
import { onWorkerStateChanged, readWorkerState } from "../../../ui/shell/worker-state";
|
||||
import {
|
||||
drawSessionRow,
|
||||
isSessionRowActive,
|
||||
SESSION_ACTIVITY_STEP_MS,
|
||||
TERMINAL_SESSIONS_STATE_KEY,
|
||||
type TerminalSessionsSnapshot,
|
||||
} from "../../terminal/session-list";
|
||||
import { type GlanceWidget } from "../widget";
|
||||
|
||||
const PAD = 8;
|
||||
const GUTTER_X = PAD;
|
||||
/** A row fits while its glyph line clears this margin above the bottom edge. */
|
||||
const BOTTOM_MARGIN = 2;
|
||||
|
||||
/**
|
||||
* The Terminal app's session list at card size: the same hosts, sessions,
|
||||
* activity indicators and open-window numbers as the hub window, painted
|
||||
* with the same row painter from the snapshot the Terminal worker publishes.
|
||||
* The indicator animates on the hub's cadence while any session is active;
|
||||
* each row carries its own activity deadline, so nothing needs the worker
|
||||
* once the snapshot is in.
|
||||
*/
|
||||
export class TerminalWidget implements GlanceWidget {
|
||||
private snapshot: TerminalSessionsSnapshot | undefined = readWorkerState(TERMINAL_SESSIONS_STATE_KEY);
|
||||
private unsubscribe: (() => void) | null = null;
|
||||
private requestRender: (() => void) | null = null;
|
||||
private phase = 0;
|
||||
private animationTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
start(requestRender: () => void): void {
|
||||
this.requestRender = requestRender;
|
||||
this.snapshot = readWorkerState(TERMINAL_SESSIONS_STATE_KEY);
|
||||
this.unsubscribe = onWorkerStateChanged<TerminalSessionsSnapshot>(TERMINAL_SESSIONS_STATE_KEY, (snapshot) => {
|
||||
this.snapshot = snapshot;
|
||||
this.syncAnimation();
|
||||
requestRender();
|
||||
});
|
||||
this.syncAnimation();
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
this.requestRender = null;
|
||||
this.unsubscribe?.();
|
||||
this.unsubscribe = null;
|
||||
if (this.animationTimer !== null) clearInterval(this.animationTimer);
|
||||
this.animationTimer = null;
|
||||
}
|
||||
|
||||
private anyActive(nowMs = Date.now()): boolean {
|
||||
return Boolean(this.snapshot?.hosts.some((host) => host.sessions.some((row) => isSessionRowActive(row, nowMs))));
|
||||
}
|
||||
|
||||
/** Run the indicator clock only while something is active; the last tick clears expired ones. */
|
||||
private syncAnimation(): void {
|
||||
const shouldRun = this.anyActive();
|
||||
if (shouldRun && this.animationTimer === null) {
|
||||
this.phase = 0;
|
||||
this.animationTimer = setInterval(() => {
|
||||
this.phase = (this.phase + 1) % 2;
|
||||
this.requestRender?.();
|
||||
if (!this.anyActive()) this.syncAnimation();
|
||||
}, SESSION_ACTIVITY_STEP_MS);
|
||||
} else if (!shouldRun && this.animationTimer !== null) {
|
||||
clearInterval(this.animationTimer);
|
||||
this.animationTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
paint(image: GrayImage): void {
|
||||
const font = getDefaultSmallFont();
|
||||
const step = lineStep(font);
|
||||
const textWidth = image.width - 2 * PAD;
|
||||
const snapshot = this.snapshot;
|
||||
const nowMs = Date.now();
|
||||
let y = PAD;
|
||||
image.drawText(font, PAD, y, "Terminal", 150);
|
||||
y += step;
|
||||
|
||||
if (!snapshot) {
|
||||
image.drawText(font, PAD, y, "Open the Terminal app to connect", 120);
|
||||
return;
|
||||
}
|
||||
const hosts = snapshot.hosts;
|
||||
const sessionCount = hosts.reduce((sum, host) => sum + host.sessions.length, 0);
|
||||
if (!hosts.length || !sessionCount) {
|
||||
const text = !snapshot.configured
|
||||
? "No connections configured"
|
||||
: !hosts.length
|
||||
? snapshot.status
|
||||
: "No live sessions";
|
||||
image.drawText(font, PAD, y, truncateText(font, text, textWidth), 120);
|
||||
return;
|
||||
}
|
||||
|
||||
// Rows are placed a line step apart but only need their line height to
|
||||
// fit, so the last one may sit right against the bottom margin.
|
||||
const fits = (top: number) => top + font.lineHeight <= image.height - BOTTOM_MARGIN;
|
||||
const multiHost = hosts.length > 1;
|
||||
for (const host of hosts) {
|
||||
if (multiHost) {
|
||||
if (!fits(y)) return;
|
||||
image.drawText(font, PAD, y, truncateText(font, host.name, textWidth), 110);
|
||||
y += step;
|
||||
}
|
||||
for (const row of host.sessions) {
|
||||
if (!fits(y)) return;
|
||||
drawSessionRow(image, font, {
|
||||
x: GUTTER_X,
|
||||
y,
|
||||
width: image.width - GUTTER_X - PAD,
|
||||
label: row.label,
|
||||
openGlyph: row.openGlyph,
|
||||
active: isSessionRowActive(row, nowMs),
|
||||
phase: this.phase,
|
||||
value: 200,
|
||||
});
|
||||
y += step;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* The terminal session list as it is drawn in two places: the Terminal app's
|
||||
* hub window (in the worker) and the Glanceboard's Terminal widget (on the
|
||||
* main thread). The worker publishes a snapshot of the list through the
|
||||
* host's worker-state channel; both painters use drawSessionRow so a row
|
||||
* looks the same in each.
|
||||
*
|
||||
* No NativeScript imports: this module is bundled into the worker as well.
|
||||
*/
|
||||
import { type GrayImage, type UiFont } from "../../graphics/image";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
|
||||
/** Worker-state key the Terminal worker publishes its snapshot under. */
|
||||
export const TERMINAL_SESSIONS_STATE_KEY = "terminal:sessions";
|
||||
|
||||
/** Alternation period of the activity indicator, shared by hub rows, the widget and sidebar cursors. */
|
||||
export const SESSION_ACTIVITY_STEP_MS = 800;
|
||||
|
||||
export type TerminalSessionRow = {
|
||||
/** Connection-scoped identity (connection id + socket). */
|
||||
key: string;
|
||||
label: string;
|
||||
/** Local-clock time (Date.now() domain) until which the session counts as active; 0 = idle. */
|
||||
activeUntilMs: number;
|
||||
/** Sidebar glyph ("1", "2", ...) of the view window showing this session, or null when none is open. */
|
||||
openGlyph: string | null;
|
||||
};
|
||||
|
||||
export type TerminalHostGroup = {
|
||||
/** Host name, shown as a heading when more than one host is connected. */
|
||||
name: string;
|
||||
sessions: TerminalSessionRow[];
|
||||
};
|
||||
|
||||
export type TerminalSessionsSnapshot = {
|
||||
/** Connected hosts, each with its live sessions most-recently-updated first. */
|
||||
hosts: TerminalHostGroup[];
|
||||
/** The hub's status line ("Connecting...", "No connections configured.", ...). */
|
||||
status: string;
|
||||
/** Whether any g2mirror connection is configured at all. */
|
||||
configured: boolean;
|
||||
};
|
||||
|
||||
/** Whether a row's activity indicator should show right now. */
|
||||
export function isSessionRowActive(row: TerminalSessionRow, nowMs = Date.now()): boolean {
|
||||
return row.activeUntilMs > nowMs;
|
||||
}
|
||||
|
||||
/** Width of the window-number column (one glyph plus breathing room). */
|
||||
export function sessionGlyphColumnWidth(font: UiFont): number {
|
||||
return font.measureText("W") + 6;
|
||||
}
|
||||
|
||||
/** Left edge of the label in a row whose activity gutter starts at `x`. */
|
||||
export function sessionLabelX(font: UiFont, x: number): number {
|
||||
return x + SESSION_INDICATOR_SIZE + 4 + sessionGlyphColumnWidth(font);
|
||||
}
|
||||
|
||||
const SESSION_INDICATOR_SIZE = 6;
|
||||
|
||||
/**
|
||||
* One session row: the activity indicator in the gutter at `x` (a small
|
||||
* square, filled on even animation phases and outlined on odd ones, drawn as
|
||||
* shapes rather than a font glyph so both states read in every UI font),
|
||||
* then the open view window's glyph in its own column, then the label,
|
||||
* truncated (never wrapped) to fit `width`.
|
||||
*/
|
||||
export function drawSessionRow(
|
||||
image: GrayImage,
|
||||
font: UiFont,
|
||||
options: {
|
||||
x: number;
|
||||
/** Top of the text line. */
|
||||
y: number;
|
||||
/** Horizontal room from `x`, label included. */
|
||||
width: number;
|
||||
label: string;
|
||||
openGlyph: string | null;
|
||||
active: boolean;
|
||||
/** Animation phase (0 = filled indicator). */
|
||||
phase: number;
|
||||
/** Text brightness for the label (the glyph draws a little dimmer). */
|
||||
value: number;
|
||||
},
|
||||
): void {
|
||||
const { x, y, width, label, openGlyph, active, phase, value } = options;
|
||||
if (active) {
|
||||
const iy = y + Math.max(0, ((font.lineHeight - SESSION_INDICATOR_SIZE) / 2) | 0);
|
||||
if (phase % 2 === 0) {
|
||||
image.fillRect(x, iy, SESSION_INDICATOR_SIZE, SESSION_INDICATOR_SIZE, value);
|
||||
} else {
|
||||
image.drawRect(x, iy, SESSION_INDICATOR_SIZE, SESSION_INDICATOR_SIZE, value);
|
||||
}
|
||||
}
|
||||
if (openGlyph) {
|
||||
image.drawText(font, x + SESSION_INDICATOR_SIZE + 4, y, openGlyph, Math.max(0, value - 60));
|
||||
}
|
||||
const labelX = sessionLabelX(font, x);
|
||||
image.drawText(font, labelX, y, truncateText(font, label, Math.max(0, x + width - labelX)), value);
|
||||
}
|
||||
@@ -37,6 +37,11 @@ import { prepareFrameDraws } from "../../graphics/glyph-wire";
|
||||
import { getDefaultSmallFont, getTerminalFontConfig } from "../../graphics/ui-fonts";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import { TERMINAL_ICON_GLYPHS, type IconActivity } from "../../graphics/icons";
|
||||
import {
|
||||
drawSessionRow,
|
||||
TERMINAL_SESSIONS_STATE_KEY,
|
||||
type TerminalSessionsSnapshot,
|
||||
} from "./session-list";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import { getActiveDisplay } from "../../native/active-display";
|
||||
import { GESTURE_DOUBLE_CLICK, type InputEvent } from "../../ui/gestures";
|
||||
@@ -722,6 +727,48 @@ function renderHubWindows(): void {
|
||||
for (const window of windows.values()) {
|
||||
if (window.kind === "hub") scheduleRender(window);
|
||||
}
|
||||
// Every change the hub repaints for is one the published list may reflect.
|
||||
publishSessionsSnapshot();
|
||||
}
|
||||
|
||||
let lastPublishedSnapshot = "";
|
||||
|
||||
/**
|
||||
* Publish the session list for main-thread consumers (the Glanceboard's
|
||||
* Terminal widget): connected hosts with their sessions most-recently-updated
|
||||
* first, each with its activity deadline (local clock, so the consumer can
|
||||
* expire and animate it itself) and the glyph of its open view window. Posted
|
||||
* only when the JSON actually changed.
|
||||
*/
|
||||
function publishSessionsSnapshot(): void {
|
||||
const connected = connectedControls();
|
||||
const snapshot: TerminalSessionsSnapshot = {
|
||||
hosts: connected.map((control) => {
|
||||
const connectionId = control.config.id;
|
||||
const sessions = (control.state?.sessions ?? [])
|
||||
.slice()
|
||||
.sort(
|
||||
(a, b) =>
|
||||
(sessionRecency.get(recencyKey(connectionId, b.socket)) ?? 0) -
|
||||
(sessionRecency.get(recencyKey(connectionId, a.socket)) ?? 0),
|
||||
);
|
||||
return {
|
||||
name: connectionDisplayName(control.config),
|
||||
sessions: sessions.map((session) => ({
|
||||
key: recencyKey(connectionId, session.socket),
|
||||
label: sessionLabel(session),
|
||||
activeUntilMs: (sessionActivity.get(recencyKey(connectionId, session.socket)) ?? -ACTIVITY_ACTIVE_MS) + ACTIVITY_ACTIVE_MS,
|
||||
openGlyph: viewGlyphForSocket(connectionId, session.socket),
|
||||
})),
|
||||
};
|
||||
}),
|
||||
status: sessionsStatusLine(),
|
||||
configured: controls.size > 0,
|
||||
};
|
||||
const encoded = JSON.stringify(snapshot);
|
||||
if (encoded === lastPublishedSnapshot) return;
|
||||
lastPublishedSnapshot = encoded;
|
||||
post({ type: "publish-state", key: TERMINAL_SESSIONS_STATE_KEY, state: snapshot });
|
||||
}
|
||||
|
||||
// One animation clock for foreground hub rows and every terminal sidebar icon.
|
||||
@@ -1117,6 +1164,8 @@ type HubItem = {
|
||||
heading?: boolean;
|
||||
/** Session with recent output: an animated indicator marks the row. */
|
||||
active?: boolean;
|
||||
/** Glyph of the view window showing this session (the number column). */
|
||||
openGlyph?: string | null;
|
||||
onSelect?: () => void;
|
||||
};
|
||||
|
||||
@@ -1182,10 +1231,10 @@ function hubSessionItems(window: HubWindow): HubItem[] {
|
||||
}
|
||||
const sessions = orderedSessions(window, control);
|
||||
for (const session of sessions) {
|
||||
const openWindowId = viewWindowIdForSocket(control.config.id, session.socket);
|
||||
items.push({
|
||||
label: openWindowId ? `${sessionLabel(session)} [open]` : sessionLabel(session),
|
||||
label: sessionLabel(session),
|
||||
active: isSessionActive(control.config.id, session.socket),
|
||||
openGlyph: viewGlyphForSocket(control.config.id, session.socket),
|
||||
onSelect: () => {
|
||||
const windowId = viewWindowIdForSocket(control.config.id, session.socket);
|
||||
if (windowId) {
|
||||
@@ -1420,6 +1469,19 @@ function handleHubInput(window: HubWindow, event: InputEvent, frameId: number):
|
||||
* Includes views that were requested but whose surface hasn't opened yet, so
|
||||
* a quick double-select can't spawn two windows for one session.
|
||||
*/
|
||||
/** Sidebar glyph of the (open or opening) view window on a session, or null. */
|
||||
function viewGlyphForSocket(connectionId: string, socket: string): string | null {
|
||||
for (const window of windows.values()) {
|
||||
if (window.kind === "view" && window.connectionId === connectionId && window.socket === socket) {
|
||||
return window.glyph || null;
|
||||
}
|
||||
}
|
||||
for (const pending of pendingViews.values()) {
|
||||
if (pending.connectionId === connectionId && pending.socket === socket) return pending.glyph || null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function viewWindowIdForSocket(connectionId: string, socket: string): string | null {
|
||||
for (const window of windows.values()) {
|
||||
if (window.kind === "view" && window.connectionId === connectionId && window.socket === socket) {
|
||||
@@ -1538,20 +1600,18 @@ function paintHub(window: HubWindow): GrayImage {
|
||||
// an outline-only selection signals the sidebar owns input.
|
||||
drawSelectionHighlight(image, 20, y - 2, window.viewportWidth - 40, hubRowH - 1, window.focused, 8);
|
||||
}
|
||||
image.drawText(chromeFont(), 32, y + 2, item.label, selected ? 255 : 200);
|
||||
if (item.active) {
|
||||
// Activity indicator in the gutter left of the label, alternating
|
||||
// filled/outline each animation step (drawn shapes, not a font glyph,
|
||||
// so the two states render distinctly in every UI font).
|
||||
const size = 6;
|
||||
const iy = y + 2 + Math.max(0, ((font.lineHeight - size) / 2) | 0);
|
||||
const value = selected ? 255 : 200;
|
||||
if (hubAnimationPhase === 0) {
|
||||
image.fillRect(22, iy, size, size, value);
|
||||
} else {
|
||||
image.drawRect(22, iy, size, size, value);
|
||||
}
|
||||
}
|
||||
// Activity gutter, open-window number column, then the label, truncated
|
||||
// to the row (shared with the Glanceboard's Terminal widget).
|
||||
drawSessionRow(image, chromeFont(), {
|
||||
x: 22,
|
||||
y: y + 2,
|
||||
width: window.viewportWidth - 22 - 26,
|
||||
label: item.label,
|
||||
openGlyph: item.openGlyph ?? null,
|
||||
active: Boolean(item.active),
|
||||
phase: hubAnimationPhase,
|
||||
value: selected ? 255 : 200,
|
||||
});
|
||||
}
|
||||
if (items.length > visibleRowCount) {
|
||||
drawListScrollbar(
|
||||
@@ -1594,6 +1654,11 @@ function hubStatusLine(window: HubWindow): string {
|
||||
if (window.mode === "connections") {
|
||||
return "Select a connection to connect, disconnect, or remove.";
|
||||
}
|
||||
return sessionsStatusLine();
|
||||
}
|
||||
|
||||
/** The sessions view's status line (also published with the session snapshot). */
|
||||
function sessionsStatusLine(): string {
|
||||
if (controls.size === 0) {
|
||||
return "No connections configured.";
|
||||
}
|
||||
@@ -1829,7 +1894,8 @@ function toolListSessions(): ToolResult {
|
||||
lines.push(`${connectionDisplayName(control.config)}:`);
|
||||
}
|
||||
for (const session of sessions) {
|
||||
const open = viewWindowIdForSocket(control.config.id, session.socket) ? " [open]" : "";
|
||||
const glyph = viewGlyphForSocket(control.config.id, session.socket);
|
||||
const open = glyph ? ` [open in window ${glyph}]` : viewWindowIdForSocket(control.config.id, session.socket) ? " [open]" : "";
|
||||
lines.push(`- ${sessionLabel(session)}${open}`);
|
||||
}
|
||||
if (!sessions.length && multiHost) {
|
||||
|
||||
@@ -44,7 +44,7 @@ const MIRROR_TOUCH_GESTURES: Record<Exclude<MirrorTouchKind, "tap">, WearRemoteI
|
||||
};
|
||||
import { findSoundEffect, playSoundEffect } from "../ui/sound-effects";
|
||||
import { GlanceHost } from "./glance-host";
|
||||
import { glanceEventForGesture, type GlanceEvent } from "./glance-state";
|
||||
import { type GlanceEvent } from "./glance-state";
|
||||
import { isWelcomeSoundPending, setWelcomeSoundPending } from "../phone-ui/onboarding-state";
|
||||
import { beginRenderPass, endRenderPass } from "../util/render-freshness";
|
||||
import { voiceControlBridge } from "../native/voice-control";
|
||||
@@ -2188,11 +2188,10 @@ class DashboardController {
|
||||
* regular UI's wake.
|
||||
*/
|
||||
private glanceEventFor(inputEvent: InputEvent, event: RawInputEvent): GlanceEvent | null {
|
||||
if (!this.glance.isEnabled()) return null;
|
||||
if (inputEvent.type === "display-wake") {
|
||||
return event.eventType === OsEventTypeList.HEAD_UP_EVENT ? { type: "press" } : null;
|
||||
return event.eventType === OsEventTypeList.HEAD_UP_EVENT ? this.glance.eventForGesture("head-tilt") : null;
|
||||
}
|
||||
return glanceEventForGesture(inputEvent.type, this.glance.isVisible());
|
||||
return this.glance.eventForGesture(inputEvent.type);
|
||||
}
|
||||
|
||||
/** Launch or focus an in-process singleton app (notifications, debug tests). */
|
||||
|
||||
@@ -26,7 +26,7 @@ export type FirmwareInfo = {
|
||||
};
|
||||
|
||||
/** The Faceclaw firmware revision this build of the app needs. */
|
||||
export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 1;
|
||||
export const REQUIRED_FACECLAW_FIRMWARE_VERSION = 3;
|
||||
|
||||
const FACECLAW_PREFIX = "Faceclaw/";
|
||||
const LEGACY_PREFIX = "EVENCFW";
|
||||
|
||||
@@ -19,7 +19,7 @@ export type FirmwarePatchSet = {
|
||||
export const CFW_PATCH_SET: FirmwarePatchSet = {
|
||||
"base": "g2_2.2.9.22.bin",
|
||||
"baseSha256": "a03fbea9f68a9de6bc271daabb9f3a41c59053d1086622c76a4e990f829cc561",
|
||||
"outputSha256": "d65a2930519e82a5ff72e7c6c852a25f2ed7651133fa95ccba5fbecdf76ef950",
|
||||
"outputSha256": "55fdfb81d4d6432ffd01d340b21286c121d6bd14af0012acf2c92ca80dbce277",
|
||||
"patches": [
|
||||
{
|
||||
"offset": 1363762,
|
||||
@@ -66,7 +66,7 @@ export const CFW_PATCH_SET: FirmwarePatchSet = {
|
||||
{
|
||||
"offset": 1516784,
|
||||
"old": "70f775ff",
|
||||
"new": "d6f2fffa",
|
||||
"new": "d6f22dfa",
|
||||
"desc": "bl snapshot_side @ 0x4ec0ee (shared image-complete helper)"
|
||||
},
|
||||
{
|
||||
@@ -78,55 +78,67 @@ export const CFW_PATCH_SET: FirmwarePatchSet = {
|
||||
{
|
||||
"offset": 1222660,
|
||||
"old": "49f0daff",
|
||||
"new": "1ef379f9",
|
||||
"new": "1ef3a7f8",
|
||||
"desc": "bl image_deferred (deferred consumer -> FIFO restore + worker, both lenses)"
|
||||
},
|
||||
{
|
||||
"offset": 1242342,
|
||||
"old": "d4f790fb",
|
||||
"new": "1af320fd",
|
||||
"new": "1af3e2fb",
|
||||
"desc": "bl settings_send_wrapper (append caps field 100)"
|
||||
},
|
||||
{
|
||||
"offset": 1240038,
|
||||
"old": "f5f710f9",
|
||||
"new": "1af3b6fe",
|
||||
"new": "1af3b8fd",
|
||||
"desc": "bl settings_decode_wrapper (Faceclaw lease field 101)"
|
||||
},
|
||||
{
|
||||
"offset": 939336,
|
||||
"old": "0bf02af9",
|
||||
"new": "64f321f9",
|
||||
"desc": "bl faceclaw_display_start @ 0x45f146 (fail-open double-tap takeover)"
|
||||
"new": "64f32ff8",
|
||||
"desc": "bl faceclaw_display_start @ 0x45f146 (fail-open wake takeover)"
|
||||
},
|
||||
{
|
||||
"offset": 939528,
|
||||
"old": "0bf0caf8",
|
||||
"new": "64f3c1f8",
|
||||
"desc": "bl faceclaw_display_start @ 0x45f206 (fail-open double-tap takeover)"
|
||||
"new": "64f39df8",
|
||||
"desc": "bl faceclaw_display_start_headup @ 0x45f206 (fail-open wake takeover)"
|
||||
},
|
||||
{
|
||||
"offset": 939016,
|
||||
"old": "10f096f8",
|
||||
"new": "65f3affd",
|
||||
"desc": "bl headup_gate (head-up sensor event -> EvenHub sys event 12 under lease)"
|
||||
},
|
||||
{
|
||||
"offset": 939036,
|
||||
"old": "fff765fb",
|
||||
"new": "63f3f3ff",
|
||||
"desc": "bl faceclaw_idle_input_gate (idle tap/long/release -> field-102 events 2/3/4)"
|
||||
},
|
||||
{
|
||||
"offset": 831036,
|
||||
"old": "1df057fc",
|
||||
"new": "80f333f9",
|
||||
"new": "7ff38bff",
|
||||
"desc": "bl gesture_press (Faceclaw lease gates event 9 vs stock UI event 8)"
|
||||
},
|
||||
{
|
||||
"offset": 831042,
|
||||
"old": "24f023f9",
|
||||
"new": "80f3d4f9",
|
||||
"new": "80f32cf8",
|
||||
"desc": "bl gesture_short_long (Faceclaw lease gates event 11 vs stock Menu path)"
|
||||
},
|
||||
{
|
||||
"offset": 831800,
|
||||
"old": "1df0d9fa",
|
||||
"new": "7ff3b9ff",
|
||||
"new": "7ff311fe",
|
||||
"desc": "bl gesture_release (source-qualified event 10 vs stock UI event 0x4a)"
|
||||
},
|
||||
{
|
||||
"offset": 1553752,
|
||||
"old": "7fb50600",
|
||||
"new": "cef2d5bc",
|
||||
"new": "cef297bb",
|
||||
"desc": "even_ai_display_ctrl entry -> conditional Faceclaw lease trampoline"
|
||||
},
|
||||
{
|
||||
@@ -144,67 +156,67 @@ export const CFW_PATCH_SET: FirmwarePatchSet = {
|
||||
{
|
||||
"offset": 1255404,
|
||||
"old": "d9f758ff",
|
||||
"new": "16f3cdfe",
|
||||
"new": "16f30ffe",
|
||||
"desc": "bl faceclaw_send_wear_event @ 0x4ac3ea (outside onboarding)"
|
||||
},
|
||||
{
|
||||
"offset": 1255504,
|
||||
"old": "d9f726ff",
|
||||
"new": "16f39bfe",
|
||||
"new": "16f3ddfd",
|
||||
"desc": "bl faceclaw_send_wear_event @ 0x4ac44e (outside onboarding)"
|
||||
},
|
||||
{
|
||||
"offset": 1297700,
|
||||
"old": "65f0affd",
|
||||
"new": "0cf3a1f9",
|
||||
"new": "0cf367f8",
|
||||
"desc": "bl compass_decode_capture (sample-matched GAF diagnostics)"
|
||||
},
|
||||
{
|
||||
"offset": 1296176,
|
||||
"old": "fff759fc",
|
||||
"new": "0cf315fd",
|
||||
"new": "0cf3dbfb",
|
||||
"desc": "bl compass_report_event (stock UI + heading with diagnostics over BLE)"
|
||||
},
|
||||
{
|
||||
"offset": 4476518,
|
||||
"old": "",
|
||||
"new": "02fb01f000e000bfb0b54ff2ac44c2f229040146206846f23f52c5f28802b2eb500f40f258304cf2e9124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304cf20732c2f20000c0f24802104770b500284ed001684ef66a62ccf2ff02914218bf70bd90f8081190f8095146f6756c8d42c0f2510c2ad205eb8501014491f80d2191f80e4191f80ae191f80b3191f80c1142ea0424012c4ff0010298bf14466e1c054680f80961b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f80811bde870406047e047d5f8040138b142f64d42c0f244022146bde87040104770bd00bf2de9f04f9db04ff2a84ac2f2290adaf800b058466ff39600b0f1005f40f07d81dbf800004ef66a67ccf2ff07b84240f074819bf82802002800f05d81dbf82442002c00f0588140f6b400c2f20000d0f8008004a802f0d4ffb8f1000f00f02382032045f24075cff68070a4f1600108f160026ff0bf03c0f2020500bf0e6ed41826664e6ec03366668e6eab42a666ce6ee6660e6f26674e6f66678e6fa667ce6fe667d1f88060c4f88060d1f88460c4f88460d1f88860c4f88860d1f88c60c4f88c60d1f89060c4f89060d1f89460c4f89460d1f89860c4f89860d1f89c60c4f89c60d1f8a060c4f8a060d1f8a460c4f8a460d1f8a860c4f8a860d1f8ac60c4f8ac60d1f8b060c4f8b060d1f8b460c4f8b460d1f8b860c4f8b860d1f8bc60c4f8bc6051f8c06fc4f8c0604e68c4f8c4608e68c4f8c860ce68c4f8cc600e69c4f8d0604e69c4f8d4608e69c4f8d860ce69c4f8dc600e6ac4f8e0604e6ac4f8e4608e6ac4f8e860ce6ac4f8ec600e6bc4f8f0604e6bc4f8f4608e6bc4f8f860ce6bc4f8fc600e6cc4f800614e6cc4f804618e6cc4f80861ce6cc4f80c610e6dc4f810614e6dc4f814618e6dc4f81861ce6dc4f81c617ff462afdaf800603040b0f1005f40f0b2803068b84240f0ae8096f8ce00002840f07a8196f8dc10002000298df8140000f0f28105a90a5c002a00f0c5810a185378002b00f083819378002b00f08181d378002b00f07f811379002b00f07d815379002b00f07b819379002b00f07981d379002b00f07781137a002b00f07581537a002b00f07381937a002b00f07181d37a002b00f06f81137b002b00f06d81537b002b00f06b81937b002b00f06981d37b002b00f06781137c002b00f06581537c002b00f06381937c002b00f06181d37c002b00f05f81137d002b00f05d81537d002b00f05b81937d002b00f05981d37d002b00f05781137e002b00f05581537e002b00f05381937e002b00f05181d37e002b00f04f81137f002b00f04d81537f002b00f04b81937f002b00f04981d27f002a00f04781203060287ff47baf66e19bf82a0270b1dbf82c0240b146f68051c2f207010968401a002800f3f48000208bf82a0240f6d100c0f247001db0bde8f04f00474ff4497005f0dbf8002800f0c7804ff6dc41cff6ff71002200bf4318433183f8242383f8252383f8262383f8272383f8282383f8292383f82a2383f82b2383f82c2383f82d2383f82e2383f82f2383f8302383f8312383f8322383f8332383f8342383f8352383f8362383f8372383f8382383f8392383f83a2383f83b2383f83c2383f83d2383f83e2383f83f2383f8402383f8412383f8422383f8432383f8442383f8452383f8462383f8472383f8482383f8492383f84a2383f84b2383f84c2383f84d2383f84e2383f84f2383f8502383f8512383f8522383f8532383f8542383f8552383f8562383f8572383f8582383f8592383f85a2383f85b2383f85c2383f85d2383f85e2383f85f2383f8602383f8612383f8622383f8632383f8642383f8652383f866237ff476af012180f8ce104ff0ff310760a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe1010e000208bf82802cbf824028bf82a0201208bf8290240f6d100c0f24700804715e00020caf8000000208bf82802cbf824024ff416304cf60361069005a8c0f24701cdf81480884701208bf82a0204a802f0b4fecbf8d4001db0bde8f08f01303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f2821d84ff052020a541dd0014445225e284a7018d04f225d288a7014d052225c28ca7010d044225b280a710cd045225a284a7108d0522259288a7104d020225828ca7142f0168500208df87300012096f8dd10002900f0c280002105aa535c002b00f0a08057187b78002b5ed0bb78002b5dd0fb78002b5cd03b79002b5bd07b79002b5ad0bb79002b59d0fb79002b58d03b7a002b57d07b7a002b56d0bb7a002b55d0fb7a002b54d03b7b002b53d07b7b002b52d0bb7b002b51d0fb7b002b50d03b7c002b4fd07b7c002b4ed0bb7c002b4dd0fb7c002b4cd03b7d002b4bd07b7d002b4ad0bb7d002b49d0fb7d002b48d03b7e002b47d07b7e002b46d0bb7e002b45d0fb7e002b44d03b7f002b43d07b7f002b42d0bb7f002b41d0fb7f002b40d0203160297ff49aaf54e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2915d84ff05303535411d00a444b235e2953700cd049235d29937008d050235c29d37004d020235b29137140f0c28200218df87310013096f8de10002900f0be80002105aa535c002b00f0a08057187b78002b5ed0bb78002b5dd0fb78002b5cd03b79002b5bd07b79002b5ad0bb79002b59d0fb79002b58d03b7a002b57d07b7a002b56d0bb7a002b55d0fb7a002b54d03b7b002b53d07b7b002b52d0bb7b002b51d0fb7b002b50d03b7c002b4fd07b7c002b4ed0bb7c002b4dd0fb7c002b4cd03b7d002b4bd07b7d002b4ad0bb7d002b49d0fb7d002b48d03b7e002b47d07b7e002b46d0bb7e002b45d0fb7e002b44d03b7f002b43d07b7f002b42d0bb7f002b41d0fb7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315Line truncated
|
||||
"new": "02fb01f000e000bfb0b54ff2ac44c2f229040146206846f23f52c5f28802b2eb500f40f258304cf2e9124cf67e25c2f20000c0f24802caf2101518bf25609047002804bf691c2160b0bd00bf0846ffe7014640f258304cf20732c2f20000c0f24802104770b500284ed001684ef66a62ccf2ff02914218bf70bd90f8081190f8095146f6756c8d42c0f2510c2ad205eb8501014491f80d2191f80e4191f80ae191f80b3191f80c1142ea0424012c4ff0010298bf14466e1c054680f80961b9b164294eea032028bf6421012888bf024644f62060824228bf02460cf5e2731046984706e0002180f80811bde870406047e047d5f8040138b142f64d42c0f244022146bde87040104770bd00bf2de9f04f9db04ff2a84ac2f2290adaf800b058466ff39600b0f1005f40f07d81dbf800004ef66a67ccf2ff07b84240f074819bf82802002800f05d81dbf82442002c00f0588140f6b400c2f20000d0f8008004a802f0a0ffb8f1000f00f0ee81032045f24075cff68070a4f1600108f160026ff0bf03c0f2020500bf0e6ed41826664e6ec03366668e6eab42a666ce6ee6660e6f26674e6f66678e6fa667ce6fe667d1f88060c4f88060d1f88460c4f88460d1f88860c4f88860d1f88c60c4f88c60d1f89060c4f89060d1f89460c4f89460d1f89860c4f89860d1f89c60c4f89c60d1f8a060c4f8a060d1f8a460c4f8a460d1f8a860c4f8a860d1f8ac60c4f8ac60d1f8b060c4f8b060d1f8b460c4f8b460d1f8b860c4f8b860d1f8bc60c4f8bc6051f8c06fc4f8c0604e68c4f8c4608e68c4f8c860ce68c4f8cc600e69c4f8d0604e69c4f8d4608e69c4f8d860ce69c4f8dc600e6ac4f8e0604e6ac4f8e4608e6ac4f8e860ce6ac4f8ec600e6bc4f8f0604e6bc4f8f4608e6bc4f8f860ce6bc4f8fc600e6cc4f800614e6cc4f804618e6cc4f80861ce6cc4f80c610e6dc4f810614e6dc4f814618e6dc4f81861ce6dc4f81c617ff462afdaf800603040b0f1005f40f0b2803068b84240f0ae8096f8ce00002840f0458196f8dc10002000298df8140000f0bd8105a90a5c002a00f090810a185378002b00f04e819378002b00f04c81d378002b00f04a811379002b00f048815379002b00f046819379002b00f04481d379002b00f04281137a002b00f04081537a002b00f03e81937a002b00f03c81d37a002b00f03a81137b002b00f03881537b002b00f03681937b002b00f03481d37b002b00f03281137c002b00f03081537c002b00f02e81937c002b00f02c81d37c002b00f02a81137d002b00f02881537d002b00f02681937d002b00f02481d37d002b00f02281137e002b00f02081537e002b00f01e81937e002b00f01c81d37e002b00f01a81137f002b00f01881537f002b00f01681937f002b00f01481d27f002a00f01281203060287ff47baf31e19bf82a0270b1dbf82c0240b146f68051c2f207010968401a002800f3bf8000208bf82a0240f6d100c0f247001db0bde8f04f00474ff44d7004f09dff002800f092804ff6cc41cff6ff71002200bf4318293183f8342383f8352383f8362383f8372383f8382383f8392383f83a2383f83b2383f83c2383f83d2383f83e2383f83f2383f8402383f8412383f8422383f8432383f8442383f8452383f8462383f8472383f8482383f8492383f84a2383f84b2383f84c2383f84d2383f84e2383f84f2383f8502383f8512383f8522383f8532383f8542383f8552383f8562383f8572383f8582383f8592383f85a2383f85b2383f85c23aad1012180f8ce104ff0ff310760a0f8e010a0f8e210a0f8e410a0f8e610a0f8e810a0f8ea10a0f8ec10a0f8ee10a0f8f010a0f8f210a0f8f410a0f8f610a0f8f810a0f8fa10a0f8fc10a0f8fe1010e000208bf82802cbf824028bf82a0201208bf8290240f6d100c0f24700804715e00020caf8000000208bf82802cbf824024ff416304cf60361069005a8c0f24701cdf81480884701208bf82a0204a802f081fecbf8d4001db0bde8f08f01303ae0023038e0033036e0043034e0053032e0063030e007302ee008302ce009302ae00a3028e00b3026e00c3024e00d3022e00e3020e00f301ee010301ce011301ae0123018e0133016e0143014e0153012e0163010e017300ee018300ce019300ae01a3008e01b3006e01c3004e01d3002e01e3000e01f305f2821d84ff052020a541dd0014445225e284a7018d04f225d288a7014d052225c28ca7010d044225b280a710cd045225a284a7108d0522259288a7104d020225828ca7142f0178500208df87300012096f8dd10002900f0c280002105aa535c002b00f0a08057187b78002b5ed0bb78002b5dd0fb78002b5cd03b79002b5bd07b79002b5ad0bb79002b59d0fb79002b58d03b7a002b57d07b7a002b56d0bb7a002b55d0fb7a002b54d03b7b002b53d07b7b002b52d0bb7b002b51d0fb7b002b50d03b7c002b4fd07b7c002b4ed0bb7c002b4dd0fb7c002b4cd03b7d002b4bd07b7d002b4ad0bb7d002b49d0fb7d002b48d03b7e002b47d07b7e002b46d0bb7e002b45d0fb7e002b44d03b7f002b43d07b7f002b42d0bb7f002b41d0fb7f002b40d0203160297ff49aaf54e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2915d84ff05303535411d00a444b235e2953700cd049235d29937008d050235c29d37004d020235b29137140f0c28200218df87310013096f8de10002900f0be80002105aa535c002b00f0a08057187b78002b5ed0bb78002b5dd0fb78002b5cd03b79002b5bd07b79002b5ad0bb79002b59d0fb79002b58d03b7a002b57d07b7a002b56d0bb7a002b55d0fb7a002b54d03b7b002b53d07b7b002b52d0bb7b002b51d0fb7b002b50d03b7c002b4fd07b7c002b4ed0bb7c002b4dd0fb7c002b4cd03b7d002b4bd07b7d002b4ad0bb7d002b49d0fb7d002b48d03b7e002b47d07b7e002b46d0bb7e002b45d0fb7e002b44d03b7f002b43d07b7f002b42d0bb7f002b41d0fb7f002b40d0203160297ff49aaf50e001313ae0023138e0033136e0043134e0053132e0063130e007312ee008312ce009312ae00a3128e00b3126e00c3124e00d3122e00e3120e00f311ee010311ce011311ae0123118e0133116e0143114e0153112e0163110e017310ee018310ce019310ae01a3108e01b3106e01c3104e01d3102e01e3100e01f315f2911d84ff0440353540dd00a4455235e29537008d050235d29937004d020235c29d37040f08e8000218df87310013096f8df10002900f0cd80002005a90a5c002a00f0a3800a185378002b5ed09378002b5dd0d378002b5cd01379002b5bd05379002b5ad09379002b5Line truncated
|
||||
"desc": "append injected blobs to main-app payload"
|
||||
},
|
||||
{
|
||||
"offset": 779114,
|
||||
"old": "846a3800",
|
||||
"new": "e8103900",
|
||||
"new": "680b3900",
|
||||
"desc": "main-app subheader payload size (ps)"
|
||||
},
|
||||
{
|
||||
"offset": 152,
|
||||
"old": "046b3800",
|
||||
"new": "68113900",
|
||||
"new": "e80b3900",
|
||||
"desc": "main-app TOC entry size (ps + 128)"
|
||||
},
|
||||
{
|
||||
"offset": 779234,
|
||||
"old": "846a3804",
|
||||
"new": "e8103904",
|
||||
"new": "680b3904",
|
||||
"desc": "main-app preamble length (low 24 bits)"
|
||||
},
|
||||
{
|
||||
"offset": 779238,
|
||||
"old": "85c355a2",
|
||||
"new": "642d8359",
|
||||
"new": "d0ef3d77",
|
||||
"desc": "[5] ota/s200_firmware_ota.bin preamble crc32"
|
||||
},
|
||||
{
|
||||
"offset": 156,
|
||||
"old": "ed292ee4",
|
||||
"new": "2ecbc5ac",
|
||||
"new": "dc9ffb3b",
|
||||
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (TOC)"
|
||||
},
|
||||
{
|
||||
"offset": 779118,
|
||||
"old": "ed292ee4",
|
||||
"new": "2ecbc5ac",
|
||||
"new": "dc9ffb3b",
|
||||
"desc": "[5] ota/s200_firmware_ota.bin component crc32c (subheader)"
|
||||
}
|
||||
]
|
||||
|
||||
+18
-2
@@ -15,7 +15,7 @@ import { type DisplayTarget } from "../native/preview-display";
|
||||
import { minWindowTop } from "../ui/shell/geometry";
|
||||
import { beginRenderPass, endRenderPass } from "../util/render-freshness";
|
||||
import { type GlanceBoardInstance, type GlanceboardProvider } from "../apps/app-definition";
|
||||
import { GLANCE_HIDDEN, reduceGlance, type GlanceEvent, type GlanceState } from "./glance-state";
|
||||
import { GLANCE_HIDDEN, glanceEventForGesture, reduceGlance, type GlanceEvent, type GlanceState } from "./glance-state";
|
||||
|
||||
export const GLANCE_SURFACE_ID = "glance";
|
||||
/** Above the shell (1) and every window (0); below the lock screen (1000). */
|
||||
@@ -65,13 +65,29 @@ export class GlanceHost {
|
||||
return this.options.getProvider()?.isEnabled() ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The glance event a sleep-time gesture means under the board's settings,
|
||||
* or null when the shell should see the input as usual: nothing while the
|
||||
* board is disabled, no hold when "Show on long press" is off, no press
|
||||
* from a head-tilt when "Show on head tilt" is off (it then wakes the
|
||||
* regular UI). A release always passes so a hold in progress can end.
|
||||
*/
|
||||
eventForGesture(gesture: "head-tilt" | string): GlanceEvent | null {
|
||||
const provider = this.options.getProvider();
|
||||
if (!provider?.isEnabled()) return null;
|
||||
if (gesture === "long-press" && !provider.showOnLongPress()) return null;
|
||||
if (gesture === "head-tilt" && !provider.showOnHeadTilt()) return null;
|
||||
return glanceEventForGesture(gesture, this.isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a glance event from sleep-time input. The frame is owned from here:
|
||||
* a show submits it with the board's first frame, anything else finishes it.
|
||||
*/
|
||||
async handleEvent(event: GlanceEvent, frameId: number): Promise<void> {
|
||||
const before = this.state;
|
||||
this.state = reduceGlance(before, event, Date.now());
|
||||
const timeoutMs = this.options.getProvider()?.tapTimeoutMs();
|
||||
this.state = reduceGlance(before, event, Date.now(), timeoutMs);
|
||||
this.armHideTimer();
|
||||
if (this.state.visible === before.visible) {
|
||||
frameTimings.finishFrame(frameId, this.state.visible ? "glanceboard stays up" : "glance event while hidden");
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* by tests/glance-state.test.cjs.
|
||||
*/
|
||||
|
||||
/** How long a press keeps the board up; each further press restarts it. */
|
||||
/** Fallback press timeout when the host supplies none; each further press restarts it. */
|
||||
export const GLANCE_TIMEOUT_MS = 3000;
|
||||
|
||||
export type GlanceState = {
|
||||
@@ -35,12 +35,17 @@ export type GlanceEvent =
|
||||
|
||||
export const GLANCE_HIDDEN: GlanceState = Object.freeze({ visible: false, holding: false, hideAtMs: null });
|
||||
|
||||
export function reduceGlance(state: GlanceState, event: GlanceEvent, nowMs: number): GlanceState {
|
||||
export function reduceGlance(
|
||||
state: GlanceState,
|
||||
event: GlanceEvent,
|
||||
nowMs: number,
|
||||
timeoutMs: number = GLANCE_TIMEOUT_MS,
|
||||
): GlanceState {
|
||||
switch (event.type) {
|
||||
case "press":
|
||||
// A tap during a hold changes nothing: the hold decides when it ends.
|
||||
if (state.holding) return state;
|
||||
return { visible: true, holding: false, hideAtMs: nowMs + GLANCE_TIMEOUT_MS };
|
||||
return { visible: true, holding: false, hideAtMs: nowMs + timeoutMs };
|
||||
case "hold":
|
||||
return { visible: true, holding: true, hideAtMs: null };
|
||||
case "release":
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Main-thread mirror of small state that worker apps publish (the
|
||||
* "publish-state" worker reply): the latest value per key, with change
|
||||
* notifications, so main-thread consumers that are not the app's own windows
|
||||
* (a Glanceboard widget, say) can show what a worker knows without a second
|
||||
* data connection. Values cross postMessage, so they are plain JSON.
|
||||
*/
|
||||
const values = new Map<string, unknown>();
|
||||
const listeners = new Map<string, Set<(value: unknown) => void>>();
|
||||
|
||||
export function publishWorkerState(key: string, value: unknown): void {
|
||||
values.set(key, value);
|
||||
for (const listener of Array.from(listeners.get(key) ?? [])) {
|
||||
try {
|
||||
listener(value);
|
||||
} catch (error) {
|
||||
console.warn(`worker-state listener for ${key} failed`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The latest published value for `key`, or undefined when nothing was published yet. */
|
||||
export function readWorkerState<T>(key: string): T | undefined {
|
||||
return values.get(key) as T | undefined;
|
||||
}
|
||||
|
||||
/** Subscribe to later publications of `key`; returns the unsubscribe. */
|
||||
export function onWorkerStateChanged<T>(key: string, listener: (value: T) => void): () => void {
|
||||
let set = listeners.get(key);
|
||||
if (!set) {
|
||||
set = new Set();
|
||||
listeners.set(key, set);
|
||||
}
|
||||
set.add(listener as (value: unknown) => void);
|
||||
return () => {
|
||||
set!.delete(listener as (value: unknown) => void);
|
||||
};
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { toolRegistry, type ToolResult, type ToolSpec } from "../../assistant/to
|
||||
import { appViewportSize, type WindowHeightMode } from "./geometry";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import { shell, type ShellWindow } from "./shell";
|
||||
import { publishWorkerState } from "./worker-state";
|
||||
|
||||
/**
|
||||
* Messages between the shell (main thread) and an app worker. One worker
|
||||
@@ -134,6 +135,15 @@ export type WorkerAppReply =
|
||||
type: "tool-result";
|
||||
callId: string;
|
||||
result: ToolResult;
|
||||
}
|
||||
| {
|
||||
/**
|
||||
* Publish a small piece of app state for main-thread consumers outside
|
||||
* the app's windows (see app/ui/shell/worker-state.ts). JSON only.
|
||||
*/
|
||||
type: "publish-state";
|
||||
key: string;
|
||||
state: unknown;
|
||||
};
|
||||
|
||||
export type WorkerWindowSpec = {
|
||||
@@ -306,6 +316,9 @@ export class WorkerAppHost {
|
||||
case "set-title":
|
||||
// Titles are informational for now (sidebar shows icons only).
|
||||
break;
|
||||
case "publish-state":
|
||||
publishWorkerState(message.key, message.state);
|
||||
break;
|
||||
case "set-tools":
|
||||
// Only a window we actually have open may contribute tools.
|
||||
if (this.openWindows.has(message.windowId)) {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
const test = require('node:test');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { execFileSync } = require('node:child_process');
|
||||
|
||||
test('CFW idle-gesture events decode to sys-event types and sources; wake and junk do not', () => {
|
||||
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'faceclaw-gesture-java-'));
|
||||
const javaBin = (name) => process.env.JAVA_HOME ? path.join(process.env.JAVA_HOME, 'bin', name) : name;
|
||||
try {
|
||||
execFileSync(javaBin('javac'), ['-d', directory,
|
||||
path.join(__dirname, '../App_Resources/Android/src/main/java/com/faceclaw/app/g2protocol/BleProtocol.java'),
|
||||
path.join(__dirname, '../App_Resources/Android/src/main/java/com/faceclaw/app/util/CollectionUtils.java'),
|
||||
path.join(__dirname, 'fixtures/FaceclawGestureEventTest.java')], { stdio: 'pipe' });
|
||||
execFileSync(javaBin('java'), ['-ea', '-cp', directory, 'com.faceclaw.app.FaceclawGestureEventTest'], { stdio: 'pipe' });
|
||||
} finally {
|
||||
fs.rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
@@ -34,7 +34,7 @@ test("the required revision and newer revisions are compatible", () => {
|
||||
test("older Faceclaw revisions and legacy EVENCFW builds need a reflash", () => {
|
||||
const older = info(`Faceclaw/${REQUIRED - 1}`);
|
||||
assert.equal(compat.hasCompatibleFirmware(older), false);
|
||||
assert.match(compat.firmwareIncompatibilityMessage(older), /revision 0/);
|
||||
assert.match(compat.firmwareIncompatibilityMessage(older), new RegExp(`revision ${REQUIRED - 1}`));
|
||||
assert.match(compat.firmwareIncompatibilityMessage(older), new RegExp(`requires revision ${REQUIRED}`));
|
||||
assert.equal(compat.classifyOnboardingFirmware(older).kind, "older-faceclaw");
|
||||
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package com.faceclaw.app;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class FaceclawGestureEventTest {
|
||||
private static byte[] hex(String value) {
|
||||
byte[] result = new byte[value.length() / 2];
|
||||
for (int i = 0; i < result.length; ++i)
|
||||
result[i] = (byte)Integer.parseInt(value.substring(i * 2, i * 2 + 2), 16);
|
||||
return result;
|
||||
}
|
||||
private static byte[] pb(byte[] payload) {
|
||||
byte[] frame = BleProtocol.framePb(payload, 9, BleProtocol.FLAG_NOTIFY, 15).get(0);
|
||||
return BleProtocol.parseFrame(frame).pb;
|
||||
}
|
||||
/** G2SettingPackage{commandId=3, magic=0, field102=['F','C',1,event,source,0]}: the CFW's wire shape. */
|
||||
private static byte[] packet(int event, int source) {
|
||||
byte[] p = hex("08031000b20606464301000000");
|
||||
p[10] = (byte)event; p[11] = (byte)source;
|
||||
return p;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
// Event codes map to the sys-events a live page would produce.
|
||||
int[][] events = {
|
||||
{2, BleProtocol.EVENT_CLICK},
|
||||
{3, BleProtocol.EVENT_RING_LONG_PRESS},
|
||||
{4, BleProtocol.EVENT_RING_LONG_PRESS_RELEASE},
|
||||
};
|
||||
int[][] sources = {
|
||||
{0, BleProtocol.EVENT_SOURCE_GLASSES_L},
|
||||
{1, BleProtocol.EVENT_SOURCE_GLASSES_R},
|
||||
{4, BleProtocol.EVENT_SOURCE_RING},
|
||||
{7, 0},
|
||||
};
|
||||
for (int[] e : events) for (int[] s : sources) {
|
||||
BleProtocol.FaceclawGestureEvent g = BleProtocol.parseFaceclawGestureEvent(pb(packet(e[0], s[0])));
|
||||
assert g != null && g.eventType == e[1] && g.eventSource == s[1] : e[0] + "/" + s[0];
|
||||
}
|
||||
// The double-tap wake event (1) and unknown codes are not gestures, and the
|
||||
// wake parser does not mistake a gesture for a wake.
|
||||
byte[] wake = packet(1, 0x34); wake[12] = 0x12;
|
||||
assert BleProtocol.parseFaceclawGestureEvent(pb(wake)) == null;
|
||||
assert BleProtocol.parseFaceclawWakeEvent(pb(wake)) == 0x1234;
|
||||
assert BleProtocol.parseFaceclawWakeEventCode(pb(wake)) == 1;
|
||||
// The head-up wake (5) shares the nonce handshake but keeps its own code.
|
||||
byte[] headUp = packet(5, 0x34); headUp[12] = 0x12;
|
||||
assert BleProtocol.parseFaceclawGestureEvent(pb(headUp)) == null;
|
||||
assert BleProtocol.parseFaceclawWakeEvent(pb(headUp)) == 0x1234;
|
||||
assert BleProtocol.parseFaceclawWakeEventCode(pb(headUp)) == BleProtocol.FACECLAW_WAKE_EVENT_HEAD_UP;
|
||||
for (int code : new int[] {2, 3, 4, 6}) {
|
||||
assert BleProtocol.parseFaceclawWakeEvent(pb(packet(code, 1))) == -1;
|
||||
assert BleProtocol.parseFaceclawWakeEventCode(pb(packet(code, 1))) == -1;
|
||||
}
|
||||
for (int code : new int[] {0, 5, 6, 255})
|
||||
assert BleProtocol.parseFaceclawGestureEvent(pb(packet(code, 1))) == null;
|
||||
// Wrong protocol version, wrong magic letters, truncated payloads, plain settings.
|
||||
byte[] bad = packet(2, 1); bad[9] = 2;
|
||||
assert BleProtocol.parseFaceclawGestureEvent(pb(bad)) == null;
|
||||
bad = packet(2, 1); bad[7] = 'X';
|
||||
assert BleProtocol.parseFaceclawGestureEvent(pb(bad)) == null;
|
||||
byte[] full = packet(2, 1);
|
||||
for (int n = 0; n < full.length; ++n)
|
||||
assert BleProtocol.parseFaceclawGestureEvent(pb(Arrays.copyOf(full, n))) == null : n;
|
||||
assert BleProtocol.parseFaceclawGestureEvent(pb(hex("08031000"))) == null;
|
||||
assert BleProtocol.parseFaceclawGestureEvent(null) == null;
|
||||
System.out.println("FaceclawGestureEventTest ok");
|
||||
}
|
||||
}
|
||||
@@ -57,3 +57,10 @@ test("gesture mapping: taps and head-tilt press, long-press holds, double-tap di
|
||||
assert.equal(glanceEventForGesture("scroll-up", true), null);
|
||||
assert.equal(glanceEventForGesture("short-then-long-press", 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);
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const { QUADRANT_LAYOUT, resolveGlanceRegions, slotsVerticallyAdjacent } = require("../.test-build/app/apps/glanceboard/layout.js");
|
||||
|
||||
const spans = (choice) => choice === "terminal" || choice === "calendar";
|
||||
|
||||
test("quadrant adjacency: left pair and right pair stack, nothing else", () => {
|
||||
assert.equal(slotsVerticallyAdjacent(QUADRANT_LAYOUT, 0, 2), true);
|
||||
assert.equal(slotsVerticallyAdjacent(QUADRANT_LAYOUT, 3, 1), true);
|
||||
assert.equal(slotsVerticallyAdjacent(QUADRANT_LAYOUT, 0, 1), false);
|
||||
assert.equal(slotsVerticallyAdjacent(QUADRANT_LAYOUT, 0, 3), false);
|
||||
assert.equal(slotsVerticallyAdjacent(QUADRANT_LAYOUT, 1, 1), false);
|
||||
});
|
||||
|
||||
test("a spanning widget in both left slots becomes one double-height region", () => {
|
||||
const regions = resolveGlanceRegions(QUADRANT_LAYOUT, ["terminal", "music", "terminal", "none"], spans);
|
||||
assert.deepEqual(regions, [
|
||||
{ choice: "terminal", rect: { x: 0, y: 0, width: 288, height: 288 }, slots: [0, 2] },
|
||||
{ choice: "music", rect: { x: 288, y: 0, width: 288, height: 144 }, slots: [1] },
|
||||
]);
|
||||
});
|
||||
|
||||
test("a spanning widget in both right slots merges too, in slot order", () => {
|
||||
const regions = resolveGlanceRegions(QUADRANT_LAYOUT, ["none", "calendar", "compass", "calendar"], spans);
|
||||
assert.deepEqual(regions.map((region) => [region.choice, region.slots, region.rect.height]), [
|
||||
["calendar", [1, 3], 288],
|
||||
["compass", [2], 144],
|
||||
]);
|
||||
});
|
||||
|
||||
test("a non-spanning duplicate and a diagonal duplicate stay separate regions", () => {
|
||||
const music = resolveGlanceRegions(QUADRANT_LAYOUT, ["music", "none", "music", "none"], spans);
|
||||
assert.deepEqual(music.map((region) => region.slots), [[0], [2]]);
|
||||
const diagonal = resolveGlanceRegions(QUADRANT_LAYOUT, ["terminal", "none", "none", "terminal"], spans);
|
||||
assert.deepEqual(diagonal.map((region) => region.slots), [[0], [3]]);
|
||||
});
|
||||
|
||||
test("empty slots produce no region", () => {
|
||||
assert.deepEqual(resolveGlanceRegions(QUADRANT_LAYOUT, ["none", "none", "none", "none"], spans), []);
|
||||
});
|
||||
|
||||
test("dividers: left edges of the right column, top edges of the bottom row, minus merged interiors", () => {
|
||||
const { slotDividers } = require("../.test-build/app/apps/glanceboard/layout.js");
|
||||
const single = resolveGlanceRegions(QUADRANT_LAYOUT, ["music", "compass", "none", "none"], spans);
|
||||
assert.deepEqual(slotDividers(QUADRANT_LAYOUT, single), [
|
||||
{ x0: 288, y0: 0, x1: 288, y1: 143 },
|
||||
{ x0: 0, y0: 144, x1: 287, y1: 144 },
|
||||
{ x0: 288, y0: 144, x1: 288, y1: 287 },
|
||||
{ x0: 288, y0: 144, x1: 575, y1: 144 },
|
||||
]);
|
||||
// A tall Terminal on the left drops the line across the left column only.
|
||||
const tall = resolveGlanceRegions(QUADRANT_LAYOUT, ["terminal", "music", "terminal", "none"], spans);
|
||||
assert.deepEqual(slotDividers(QUADRANT_LAYOUT, tall), [
|
||||
{ x0: 288, y0: 0, x1: 288, y1: 143 },
|
||||
{ x0: 288, y0: 144, x1: 288, y1: 287 },
|
||||
{ x0: 288, y0: 144, x1: 575, y1: 144 },
|
||||
]);
|
||||
});
|
||||
@@ -18,6 +18,7 @@
|
||||
"../app/g2/glasses-artwork.ts",
|
||||
"../app/g2/glasses-display-state.ts",
|
||||
"../app/g2/glance-state.ts",
|
||||
"../app/apps/glanceboard/layout.ts",
|
||||
"../app/g2/pairing-candidates.ts",
|
||||
"../app/apps/calculator/math/*.ts",
|
||||
"../app/apps/microphones/mic-protocol.ts",
|
||||
|
||||
Reference in new issue
Block a user