diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 00000000..cffc8d6a --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,40 @@ +name: Deploy website + +# Publishes website/ to GitHub Pages. Requires the repository's +# Settings > Pages > Source to be set to "GitHub Actions". + +on: + push: + branches: [main] + paths: + - 'website/**' + - 'PRIVACY' + - 'scripts/sync-site.mjs' + - '.github/workflows/pages.yml' + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: pages + cancel-in-progress: false + +jobs: + deploy: + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - uses: actions/checkout@v4 + - name: Check generated blocks are up to date + run: node scripts/sync-site.mjs --check + - uses: actions/configure-pages@v5 + - uses: actions/upload-pages-artifact@v3 + with: + path: website + - id: deployment + uses: actions/deploy-pages@v4 diff --git a/.gitignore b/.gitignore index dc56b331..5f98a77a 100644 --- a/.gitignore +++ b/.gitignore @@ -41,5 +41,5 @@ old faceclaw_settings.xml # Developer configs -build.sh -build_and_run.sh +build_paths.sh + diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java index fb1550f9..9d9daf4b 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawBleCommunicator.java @@ -363,6 +363,19 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable { } } + /** + * Whether the glasses mic is enabled right now. The enable lives in the + * current EvenHub session, so it dies with a transport drop, the charging + * case, or a suspend — silently, from the phone's point of view. Callers + * that track a capture across those events must check this rather than + * assume their earlier enable still holds. + */ + public boolean isAudioCaptureActive() { + synchronized (lock) { + return running && sessionReady && !shutdownRequested && audioCaptureActive; + } + } + /** * Acquire/renew or release CFW's volatile wake-takeover lease on both * arms. Delivery (not a protocol ACK) is awaited so a caller can ensure diff --git a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java index 00c55697..1de06ca9 100644 --- a/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java +++ b/App_Resources/Android/src/main/java/com/faceclaw/app/FaceclawVoiceController.java @@ -76,6 +76,9 @@ public class FaceclawVoiceController { private volatile FaceclawBleCommunicator communicator; private Thread workerThread; private volatile boolean started; + // Set once the worker has the glasses mic enabled for this session. + // Read and written under `lock`, so it flips with `started` atomically. + private boolean audioStarted; private VoiceInputMode mode = VoiceInputMode.CLOUD; private OfflineRecognizer recognizer; private FaceclawLc3Decoder lc3Decoder; @@ -219,11 +222,36 @@ public class FaceclawVoiceController { } mode = parseMode(requestedMode); started = true; + audioStarted = false; workerThread = new Thread(this::runLoop, "FaceclawVoiceController"); workerThread.start(); } } + /** + * Whether mic audio is actually flowing. {@link #start} only records + * intent: the enable lives in the glasses' EvenHub session, so a transport + * drop or a session suspend can leave this controller started with a + * worker that will never see another packet. Anything deciding whether to + * (re)start capture must ask this rather than assume its own bookkeeping. + */ + public boolean isCapturing() { + boolean audioUp; + synchronized (lock) { + if (!started) { + return false; + } + audioUp = audioStarted; + } + if (!audioUp) { + // The worker is still bringing the mic up; report it as running so + // a concurrent request shares it instead of restarting it. + return true; + } + FaceclawBleCommunicator currentCommunicator = communicator; + return currentCommunicator != null && currentCommunicator.isAudioCaptureActive(); + } + public void stop() { Thread threadToJoin; synchronized (lock) { @@ -288,6 +316,9 @@ public class FaceclawVoiceController { emitStatus("Could not start G2 microphone input."); return; } + synchronized (lock) { + audioStarted = true; + } emitStatus(currentMode == VoiceInputMode.CLOUD ? "Listening (cloud)..." @@ -312,6 +343,7 @@ public class FaceclawVoiceController { releaseLc3(); synchronized (lock) { started = false; + audioStarted = false; workerThread = null; } } diff --git a/CLAUDE.md b/CLAUDE.md index 6433edb7..3ef2a977 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -8,20 +8,19 @@ Typescript parts are in app/. Java parts are in App_Resources/Android/src/main/j wear/ is a separate Gradle project (Kotlin + Compose for Wear OS): the watch remote that drives Faceclaw over the Wearable Data Layer. Its phone-side counterparts are FaceclawWearBridge.java, app/native/wear-bridge.ts and -app/g2/wear-remote.ts; the message format is in wear/PROTOCOL.md. Build it -with `cd wear && ./gradlew :app:assembleDebug` (needs JAVA_HOME and -ANDROID_HOME); it is not part of `npm run build`. +app/g2/wear-remote.ts; the message format is in wear/PROTOCOL.md. -If build.sh exists, it's a machine-specific wrapper that sets some environment -variables to point to where tools are installed, then runs `npm run build`. -If build_and_run.sh exists, it does everything build.sh does plus - `nativescript run android --device --justlaunch`, -which will launch the app on the developer's phone if it is plugged in and has -adb enabled. If no phone is connected, it will still build but the install step -will fail and the output will contain the string "Cannot find connected -devices." To lint and typecheck, prefer to use build.sh; if the user asks you -to run or test the app, use build_and_run.sh and then use `adb logcat` to view -the results. +`build.sh` and `build_wear.sh` build the Android and Wear OS apps respectively. +`build_and_run.sh` builds the Android app then also installs it on a phone +paired with `adb`. Building may require configuring environment variables +(JAVA_HOME, ANDROID_HOME, PATH, ANDROID_KEYSTORE, ANDROID_KEYSTORE) to point at +relevant tools and an Android device ID to install on; do this in +build_paths.sh, which is created from build_paths.sh.template and not checked +into git. + +To lint and typecheck, prefer to use build.sh; if the user asks you to run or +test the app, use build_and_run.sh and then use `adb logcat` to view the +results. If you are working on low-level communication bits, consider checking out https://github.com/Commute773/g2-kit-unofficial/ and referring to ble/docs/ @@ -30,4 +29,10 @@ well as some communication test scripts and documentation of caveats that come up when communicating with the headset. There may already be an existing local checkout above this workspace at ../g2-kit-unofficial. +This Android app uses a modded firmware for the G2 smart glasses. Source code +to the corresponding firmware modifications lives in +https://github.com/jimrandomh/g2flash; there is a compiled version of the +firmware patch-set in app/g2/firmware/cfw-patches.ts. Strongly prefer making +changes to the Android app over making changes to changes to the firmware, as +firmware development is considerably more fraught. diff --git a/README.md b/README.md index 92f73153..d83b2e48 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,15 @@ glasses. The Android app itself can install and uninstall the custom firmware; it downloads the stock firmware from Even and applies patches generated from https://github.com/jimrandomh/g2flash. +User-facing documentation lives at https://faceclaw.org/. + ## Screenshots -![App launcher](screenshots/launcher.png) -![Music player](screenshots/music-player.png) -![Assistant settings](screenshots/settings-assistant.png) -![Display settings](screenshots/settings-display.png) +![App launcher](website/screenshots/launcher.png) +![Music player](website/screenshots/music-player.png) +![Assistant settings](website/screenshots/settings-assistant.png) +![Display settings](website/screenshots/settings-display.png) ## Installation @@ -23,67 +25,66 @@ To compile, you will need an Android SDK environment with SDK version 35 installed and licenses accepted, and the ANDROID_HOME pointing to the install. You will need Nativescript installed, and a JDK environment (v21), with the JAVA_HOME environment variable pointed at it. You will also need a reasonably -up to date npm and nodejs installed. +up to date npm and nodejs installed. You can put environment variables in +build_paths.sh and they will be used by all build commands. -To install a version that you compiled, you will need `adb` connected. Go to -Settings>About phone and tap the "Build number" field seven times. Then plug -the phone's USB-C port into your computer, authorize access on the phone, then -run `nativescript run android - -The compile, run - 'npm run build' -To install, run - `nativescript run android --juslaunch` +To install a version that you compiled, you will need developer mode enabled on +your phone, and `adb` connected. To enable developer mode, go to Settings>About +phone and tap the "Build number" field seven times. Then plug the phone's USB-C +port into your computer, authorize access on the phone, and run +`./build_and_run.sh` to install. ## Features - * A voice assistant that wakes up when you say "Hey Even", transcribes text - with an on-device model, OpenAI Whisper, ElevenLabs, or Soniox API, and - responds to queries and commands using an onboard model (Qwen3 4B, slow) - or with an Anthropic or OpenAI model (requires an API key), or using your - own long-running OpenClaw agent (see "Connecting an external agent" below). - * Multitasking, with an app-switcher sidebar and app launcher - * Mostly-compatible with EvenHub apps - * A lock screen; glasses lock automatically when you take them off and unlock - when you unlock your phone - * Full-screen apps can use the full 640x480 display area (rather than the - 576x288 that EvenHub apps can use) - * Integration with Android notifications: A top-bar that shows the - same icons your phone does, popups when notifications arrive, and menu - items to dismiss or use Android-app-provided custom actions like mark as - read or quick reply. - * Mirror terminal apps such as Claude Code or Codex CLI with g2mirror - (https://github.com/jimrandomh/g2mirror), view them on the glasses, and - send them inputs with the voice assistant - * Media player controls including playlist and media library navigation, - compatible with most Android media players - * Turn-by-turn directions (requires a Mapbox API token) - * Nightscout, an app for viewing blood-glucose data (requires a cloud server - and API token) - * Power management: the glasses go to sleep properly when the screen is off, - and wake when you double-tap the ring or speak the wakeword, allowing + + + * **A voice assistant** that wakes up when you say "Hey Even", transcribes + text with an on-device model, OpenAI Whisper, ElevenLabs, or Soniox API, + and responds to queries and commands using an onboard model (Qwen3 4B, + slow) or with an Anthropic or OpenAI model (requires an API key), or using + your own long-running OpenClaw agent. + * **Multitasking**, with an app-switcher sidebar and app launcher. + * **Mostly-compatible with EvenHub apps.** + * **A lock screen**; glasses lock automatically when you take them off and + unlock when you unlock your phone. + * **The full display.** Full-screen apps can use the full 640x480 display + area, rather than the 576x288 that EvenHub apps can use. + * **Integration with Android notifications**: a top bar that shows the same + icons your phone does, popups when notifications arrive, and menu items to + dismiss or use Android-app-provided custom actions like mark as read or + quick reply. + * **Terminal mirroring.** Mirror terminal apps such as Claude Code or Codex + CLI with [g2mirror](https://github.com/jimrandomh/g2mirror), view them on + the glasses, and send them inputs with the voice assistant. + * **Media player controls** including playlist and media library navigation, + compatible with most Android media players. + * **Turn-by-turn directions** (requires a Mapbox API token). + * **Nightscout**, an app for viewing blood-glucose data (requires a cloud + server and API token). + * **Power management**: the glasses go to sleep properly when the screen is + off, and wake when you double-tap the ring or speak the wakeword, allowing battery life similar to the stock Even app. - * Connection management with auto-reconnect, and autodetection of conflict - with the official Even Realities app - * A Wear OS watch app that replaces (and outdoes) the R1 ring: tap, swipe, - hold and crown gestures, side buttons, app launching and window switching, - voice or keyboard queries to the assistant with the reply on your wrist, - typing into apps, and glasses status/lock/display control (see "Watch - remote" below) - * On-phone screen mirroring with touch control: tap what you see on the + * **Connection management** with auto-reconnect, and autodetection of + conflict with the official Even Realities app. + * **A Wear OS watch app** that replaces (and outdoes) the R1 ring: tap, + swipe, hold and crown gestures, side buttons, app launching and window + switching, voice or keyboard queries to the assistant with the reply on + your wrist, typing into apps, and glasses status/lock/display control. + * **On-phone screen mirroring with touch control**: tap what you see on the mirror (sidebar icons, launcher cells), or use the phone's own touchpad, - d-pad and Back/Menu buttons — the same spatial scheme as the watch — plus - a compact ring simulator. A display-mode picker (576×288 band, 576×480 - tall, or the full 640×480 panel with an auto-hiding sidebar) and a - brightness slider with an Auto toggle sit beside the mirror. - * Bluetooth pairing that scans for nearby glasses and identifies each pair - before connecting: model, frame shape, and colour decoded from the + d-pad and Back/Menu buttons — the same spatial scheme as the watch — plus a + compact ring simulator. A display-mode picker (576×288 band, 576×480 tall, + or the full 640×480 panel with an auto-hiding sidebar) and a brightness + slider with an Auto toggle sit beside the mirror. + * **Bluetooth pairing** that scans for nearby glasses and identifies each + pair before connecting: model, frame shape, and colour decoded from the advertised serial (with product photos), left and right arms matched to each other by that serial, an estimated distance so the pair in your hand - sorts first, and the optional R1 ring - * Dual-language NativeScript architecture with Java for the multithreaded - Android API and bluetooth stack bits, Typescript for the bits you want to - hack on + sorts first, and the optional R1 ring. + * **Dual-language NativeScript architecture**, with Java for the + multithreaded Android API and bluetooth stack bits, Typescript for the bits + you want to hack on. + ## Watch remote (Wear OS) @@ -157,7 +158,7 @@ https://github.com/jimrandomh/faceclaw. The Typescript and Java code in this repository runs on your phone, not on the glasses themselves, and (with the narrow exception of the firmware-updating tool), can't hurt your hardware. For changes to the glasses firmware, refer to -[g2flash](https://github.com/jimrandomh/faceclaw); changes there require more +[g2flash](https://github.com/jimrandomh/g2flash); changes there require more caution. Faceclaw is Free Software (GPLv3). Please only contribute code that you wrote diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index 61b7b4d1..4b39736e 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -58,7 +58,7 @@ import { type InProcessAppOptions, type InProcessWindow } from "../ui/shell/in-p import { loadPersistedOpenApps, savePersistedOpenApps } from "../ui/shell/open-apps-persistence"; import { appViewportRect, SIDEBAR_WIDTH, sidebarStripVisible, type WindowHeightMode } from "../ui/shell/geometry"; import { type LayerActions } from "../ui/layers"; -import { assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, brightnessSetting, brightnessSettingToLevel, displayModeSetting, watchWakesDisplaySetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings"; +import { assistantAllowProactiveSetting, assistantBackendSetting, assistantBridgeHostSetting, assistantBridgePortSetting, assistantBridgeTokenSetting, brightnessSetting, brightnessSettingToLevel, displayModeSetting, elevenLabsApiKeySetting, getStringSettingById, openAiApiKeySetting, nightscoutApiTokenSetting, firmwareDebugFlagsSetting, lockScreenEnabledSetting, nightscoutSiteUrlSetting, onAnySettingChanged, previewColorSetting, ringConnectionModeSetting, saveVoiceRecordingsSetting, sonioxApiKeySetting, screenTimeoutSetting, screenTimeoutSettingToMs, suspendEvenHubWhenScreenOffSetting, verticalPositionSetting, voiceProviderSetting, wakeWordActionSetting, type ConfigSettingString } from "../ui/dashboard-settings"; import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization"; import { getInstalledEvenHubAppById, @@ -68,6 +68,7 @@ import { import { closeRunningPackage, launchInstalledPackage } from "../apps/evenhub/manager"; import { wearerVerificationOptions } from "../apps/microphones/speakers"; import { micSession } from "../apps/microphones/mic-session"; +import { glassesDisplayLabel } from "./glasses-display-state"; type ConnectionPhase = "disconnected" | "connecting" | "connected" | "charging" | "disconnecting"; @@ -302,12 +303,13 @@ class DashboardController { requestShellRender: () => this.requestShellRender(), onWindowsChanged: () => { this.persistOpenApps(); - this.wearRemote?.schedulePublish(); + // The foreground title is mirrored on both remote-control faces. + this.emit(); }, onScreenStateChanged: (on) => { this.handleScreenStateChanged(on); if (on) this.requestShellRender(); - this.wearRemote?.schedulePublish(); + this.emit(); }, }); // Boot hooks register windows that exist from startup (the launcher, @@ -355,6 +357,8 @@ class DashboardController { status: this.status, glassesLocked: this.glassesLocked, glassesWorn: this.glassesWorn, + silentMode: this.silentMode, + lastHeadsetBattery: this.lastHeadsetBattery, }), appendLog: (line) => this.appendLog(line), }); @@ -700,6 +704,14 @@ class DashboardController { return; } + if (voiceControlBridge.isCaptureHeld()) { + // Ending the plugin task ends the mic with it, so a live capture (the + // Transcribe window, typically) outranks the screen-off power save. + // Check before the lease refresh below, which costs a BLE message. + this.scheduleEvenHubSuspend(); + return; + } + void (async () => { if (this.faceclawWakeLeaseSupported) { // Refresh immediately before teardown so the first suspended wake @@ -725,6 +737,9 @@ class DashboardController { .then((suspended) => { if (suspended === undefined) return; if (suspended) { + // A capture that raced the suspend lost its mic with the plugin + // task; park it for the resume path. + voiceControlBridge.handleSessionEnded(); this.appendLog("EvenHub session suspended while screen is off"); return; } @@ -849,12 +864,15 @@ class DashboardController { /** * Message to show in place of the display preview, or "" to show the preview. * - * Both cases look identical to a dead pair of glasses from the phone side: - * silent mode blanks the display and swallows input while the BLE session - * stays up, and a battery that just ran out simply stops answering. + * These states look identical to a dead pair of glasses from the phone side: + * charging and silent mode both make the display unavailable while BLE stays + * up, and a battery that just ran out simply stops answering. */ private displayPreviewMessage(): string { - if (this.silentMode && (this.phase === "connected" || this.phase === "charging")) { + if (this.phase === "charging") { + return this.glassesDisplayLabel(); + } + if (this.silentMode && this.phase === "connected") { return "Connected (Silent mode enabled)"; } const connectionFailing = this.phase === "disconnected" || this.phase === "connecting"; @@ -868,6 +886,17 @@ class DashboardController { return ""; } + /** What occupies the foreground-title line on the watch-style controls. */ + glassesDisplayLabel(): string { + return glassesDisplayLabel({ + phase: this.phase, + silentMode: this.silentMode, + screenOn: shell.isScreenOn(), + battery: this.lastHeadsetBattery, + foregroundTitle: shell.getForegroundApp()?.title ?? null, + }); + } + /** * Re-check the Doze exemption (cheap system call, but cached so snapshot() * stays trivial). Called on connect, page load, and after the user answers @@ -954,8 +983,13 @@ class DashboardController { this.refreshEvenAppStatus(); this.setPhase("connecting"); this.setStatus("Connecting to the glasses..."); + // "Only via glasses" (the default) means the phone never opens its own + // link to the ring: the glasses relay its gestures to us anyway, and the + // direct link is currently unreliable. An empty address disables every + // direct-ring code path in the communicator. + const ringAddress = ringConnectionModeSetting.get() === "direct" ? addresses.ring : ""; this.appendLog( - `Using configured arms: R=${addresses.right} L=${addresses.left}${addresses.ring ? ` ring=${addresses.ring}` : ""}`, + `Using configured arms: R=${addresses.right} L=${addresses.left}${ringAddress ? ` ring=${ringAddress}` : ""}`, ); let communicator: FaceclawCommunicatorBridge | null = null; @@ -972,7 +1006,7 @@ class DashboardController { communicator = new FaceclawCommunicatorBridge({ right: addresses.right, left: addresses.left, - ring: addresses.ring, + ring: ringAddress, }); this.communicator = communicator; this.offLog = communicator.onLog((line) => { @@ -1020,6 +1054,10 @@ class DashboardController { // the transport comes back, so do not make lock decisions from a // stale pre-disconnect value in the meantime. this.glassesWorn = null; + // The mic enable was session-scoped too: park any live capture so + // the next session restarts it, instead of leaving a holder that + // makes every later request think the mic is already running. + voiceControlBridge.handleSessionEnded(); } this.setPhase(mappedPhase); this.setStatus(state.status); @@ -1049,16 +1087,21 @@ class DashboardController { this.handlePhoneLockState(locked); }); this.offBattery = communicator.onBatteryState((state) => { - this.lastHeadsetBattery = state.battery >= 0 ? state.battery : null; + // An unavailable reading must not erase the useful last-known value, + // especially while the glasses remain reachable in their case. + const hasBatteryLevel = Number.isInteger(state.battery) && state.battery >= 0 && state.battery <= 100; + if (hasBatteryLevel) this.lastHeadsetBattery = state.battery; shell.setBatteryLevels({ - headset: state.battery, + headset: hasBatteryLevel ? state.battery : this.lastHeadsetBattery, headsetCharging: state.chargingStatus > 0, }); if ((this.phase === "connected" || this.phase === "charging") && this.communicator) { // Repaint the top bar (battery indicators live in the shell chrome). this.requestShellRender(); } - this.wearRemote?.schedulePublish(); + // Battery belongs in the charging stand-in on the phone as well as in + // the watch state, so refresh both consumers on every report. + this.emit(); }); this.offEvenAppConflict = communicator.onEvenAppConflict((message) => { this.refreshEvenAppStatus(); @@ -1077,6 +1120,10 @@ class DashboardController { this.schedulePreviewUpdate(); if (this.phase === "connected") { this.setStatus("Connected."); + // A rendered frame also means the display path is warm enough for + // the glasses to accept a mic enable, so this is where a capture + // parked by the previous session (or by an EvenHub suspend) resumes. + this.resumeVoiceCapture(); // A rendered frame means the session is warmed up (fixedLayoutCreated), // so the buzzer won't be dropped. Play the one-time welcome sound now. if (this.welcomeSoundArmed) { @@ -1369,7 +1416,7 @@ class DashboardController { // Faceclaw's final BLE message before the transport closes. await mediaControllerBridge.stop().catch(() => {}); await nightscoutBridge.stop().catch(() => {}); - voiceControlBridge.stop(); + voiceControlBridge.handleSessionEnded(); const cleanupAcked = skipFirmwareCleanup ? false @@ -1411,22 +1458,17 @@ class DashboardController { * finger-down/finger-up (the watch) hold for as long as the user does. */ async injectSyntheticRingInput(kind: WearRemoteInputKind, origin: SyntheticInputOrigin = "ring"): Promise { - // Watch-scheme input (the Wear app, the phone's pad/d-pad, mirror touches) - // wakes a dark display and then lands normally, resuming the previous - // focus. The ring's own scheme keeps its double-tap-only wake. + // Match the ring while the display is dark: only a double-click wakes it, + // and that wake is handled by Shell.receiveInput. This check also protects + // against a watch acting on a stale state snapshot. if ( origin === "watch" && !shell.isScreenOn() && - !this.glassesLocked && - (this.phase === "connected" || this.phase === "charging") && - watchWakesDisplaySetting.get() && kind !== "double-click" && - kind !== "wakeword" && kind !== "long-press-release" ) { - shell.wake(shell.getFocus()); - this.requestShellRender(); - this.appendLog(`${kind} (watch scheme) woke the display`); + this.appendLog(`${kind} (watch scheme) ignored while display is off`); + return; } if (kind === "long-press") { // Hardware delivers a press event and then a release when the finger @@ -1454,15 +1496,8 @@ class DashboardController { return; } if (!shell.isScreenOn()) { - // The same wake policy as the rest of the watch scheme: honour the - // "input wakes display" setting; with it off, only a double-tap (a - // normal double-click) reaches the dark display. - if (!watchWakesDisplaySetting.get()) { - if (kind === "double-tap") await this.injectSyntheticRingInput("double-click", "watch"); - return; - } - shell.wake(shell.getFocus()); - this.requestShellRender(); + if (kind === "double-tap") await this.injectSyntheticRingInput("double-click", "watch"); + return; } if (kind !== "tap") { await this.injectSyntheticRingInput(MIRROR_TOUCH_GESTURES[kind], "watch"); @@ -1549,6 +1584,37 @@ class DashboardController { voiceControlBridge.stopContinuousCapture(); } + /** Provider and key settings for a capture on the given connection. */ + private voiceCaptureOptions(communicator: FaceclawCommunicatorBridge) { + return { + communicator: communicator.getNativeCommunicator(), + provider: voiceProviderSetting.get(), + elevenLabsApiKey: elevenLabsApiKeySetting.get(), + openAiApiKey: openAiApiKeySetting.get(), + sonioxApiKey: sonioxApiKeySetting.get(), + saveRecording: saveVoiceRecordingsSetting.get(), + // "My voice only" (Microphones app): verify command utterances + // against the enrolled wearer voice-print; non-matching speakers' + // finals are suppressed by the bridge. + speakerVerification: wearerVerificationOptions() ?? undefined, + // The Microphones app's processing config applies to every capture: + // spectral noise suppression and the Sonic Radar listening beam. + ...micSession.captureProcessingOptions(), + }; + } + + /** + * Restart the mic for a capture that a previous session left holding. Cheap + * to call per frame: it does nothing unless one is actually parked. + */ + private resumeVoiceCapture(): void { + if (!voiceControlBridge.hasSuspendedCapture()) return; + const communicator = this.communicator; + if (!communicator || this.phase !== "connected") return; + this.appendLog("resuming voice capture on the new glasses session"); + voiceControlBridge.resumeCapture(this.voiceCaptureOptions(communicator)); + } + private beginVoiceCapture(kind: "ptt" | "continuous", endpointing = false): void { if (this.phase !== "connected" || !this.communicator) { return; @@ -1557,22 +1623,7 @@ class DashboardController { void ensureVoicePermissions() .then(() => { if (this.phase !== "connected" || this.communicator !== communicator) return; - const options = { - communicator: communicator.getNativeCommunicator(), - provider: voiceProviderSetting.get(), - elevenLabsApiKey: elevenLabsApiKeySetting.get(), - openAiApiKey: openAiApiKeySetting.get(), - sonioxApiKey: sonioxApiKeySetting.get(), - saveRecording: saveVoiceRecordingsSetting.get(), - endpointing, - // "My voice only" (Microphones app): verify command utterances - // against the enrolled wearer voice-print; non-matching speakers' - // finals are suppressed by the bridge. - speakerVerification: wearerVerificationOptions() ?? undefined, - // The Microphones app's processing config applies to every capture: - // spectral noise suppression and the Sonic Radar listening beam. - ...micSession.captureProcessingOptions(), - }; + const options = { ...this.voiceCaptureOptions(communicator), endpointing }; if (kind === "ptt") { voiceControlBridge.startPushToTalk(options); } else { diff --git a/app/g2/glasses-display-state.ts b/app/g2/glasses-display-state.ts new file mode 100644 index 00000000..88f951ae --- /dev/null +++ b/app/g2/glasses-display-state.ts @@ -0,0 +1,34 @@ +export type GlassesDisplayState = { + phase: string; + silentMode: boolean; + screenOn: boolean; + battery: number | null; + foregroundTitle: string | null; +}; + +/** Compact status shown where the foreground-window title normally lives. */ +export function glassesDisplayLabel(state: GlassesDisplayState): string { + // Charging wins over every session-local state: the glasses are in their + // case, so neither the lock screen nor the foreground window is visible. + if (state.phase === "charging") { + return chargingDisplayLabel(state.battery); + } + if (state.phase !== "connected") { + return "Glasses disconnected"; + } + if (state.silentMode) { + return "Silent mode"; + } + if (!state.screenOn) { + return "Display off"; + } + return state.foregroundTitle || "Launcher"; +} + +export function chargingDisplayLabel(battery: number | null): string { + return validBatteryLevel(battery) ? `Charging · G2 ${battery}%` : "Charging"; +} + +function validBatteryLevel(battery: number | null): battery is number { + return battery !== null && Number.isInteger(battery) && battery >= 0 && battery <= 100; +} diff --git a/app/g2/wear-remote.ts b/app/g2/wear-remote.ts index bfc69543..d2b7f460 100644 --- a/app/g2/wear-remote.ts +++ b/app/g2/wear-remote.ts @@ -25,6 +25,7 @@ import { displayModeSetting, onAnySettingChanged, watchCanUnlockSetting, + watchCrownClockwiseNextSetting, watchMirrorAssistantSetting, watchRemoteEnabledSetting, } from "../ui/dashboard-settings"; @@ -101,6 +102,8 @@ export type WearRemoteHost = { status: string; glassesLocked: boolean; glassesWorn: boolean | null; + silentMode: boolean; + lastHeadsetBattery: number | null; }; appendLog: (line: string) => void; }; @@ -195,8 +198,9 @@ export class WearRemote { locked: state.glassesLocked, worn: state.glassesWorn, listening: voiceActivity.isActive(), - battery: battery.headset, - charging: battery.headsetCharging === true, + battery: state.lastHeadsetBattery, + charging: state.phase === "charging" || battery.headsetCharging === true, + silentMode: state.silentMode, foreground: foreground ? { appId: foreground.appId, title: foreground.title } : null, windows: shell.getWindows().map((window) => ({ windowId: window.windowId, @@ -209,6 +213,7 @@ export class WearRemote { apps: this.listApps(), displayMode: displayModeSetting.get(), remoteEnabled: watchRemoteEnabledSetting.get(), + crownClockwiseNext: watchCrownClockwiseNextSetting.get(), canUnlock: watchCanUnlockSetting.get(), mirrorAssistant: watchMirrorAssistantSetting.get(), assistantAvailable: shell.isAssistantAvailable(), @@ -294,10 +299,8 @@ export class WearRemote { ack(false, "The glasses are not connected."); return; } - // The lock only yields to a double-click, exactly as the ring's does - // (handled inside the controller); a dark display wakes on any watch- - // scheme gesture (injectSyntheticRingInput, shared with the phone's own - // pad and d-pad). + // The lock and a dark display only yield to a double-click, exactly as + // the ring does (handled inside the controller). const repeatable = kind === "scroll-up" || kind === "scroll-down" || kind === "swipe-up" || kind === "swipe-down"; const steps = repeatable ? Math.min(MAX_SCROLL_STEPS, Math.max(1, Math.round(readNumber(payload.steps, 1)))) : 1; for (let i = 0; i < steps; i++) { @@ -339,6 +342,10 @@ export class WearRemote { ack(false, "The glasses are not connected."); return; } + if (payload.source === "gesture" && !shell.isScreenOn()) { + ack(true); + return; + } if (state.glassesLocked && command !== "unlock" && command !== "lock") { ack(false, "The glasses are locked."); return; diff --git a/app/native/voice-control.ts b/app/native/voice-control.ts index afd5c190..205f4316 100644 --- a/app/native/voice-control.ts +++ b/app/native/voice-control.ts @@ -83,6 +83,13 @@ export class FaceclawVoiceControlBridge { // when the last one releases. Transcript events broadcast to every // listener, so push-to-talk and the Transcribe window both receive text. private readonly captureHolders = new Set(); + // Holders whose stream died with the glasses session (transport drop, + // charging case, EvenHub suspend). They still want the mic, so the next + // session restarts it for them; see handleSessionEnded/resumeCapture. + private readonly suspendedHolders = new Set(); + private suspendedRaw = false; + // Endpointing of the live capture, replayed when it is resumed. + private captureEndpointing = false; // Non-null while a cloud provider owns the transcript; Java only decodes PCM. private cloudClient: CloudSttClient | null = null; // Raw-PCM tap (EvenHub mic apps): when active, the controller runs in the @@ -156,8 +163,13 @@ export class FaceclawVoiceControlBridge { */ startRawCapture(options: { communicator: any }): boolean { if (!global.isAndroid) return false; - if (this.rawActive) return true; - if (this.captureHolders.size > 0 || this.started) return false; + if (this.rawActive && this.micIsLive()) return true; + // An STT holder owns the mic even while its stream waits on a new glasses + // session; the tap re-tries when the app's eligibility is re-evaluated. + if (this.captureHolders.size > 0 || this.suspendedHolders.size > 0) return false; + // A tap left over from a dead session is not something to share. + if (this.started || this.rawActive) this.teardownCapture(); + this.suspendedRaw = false; this.ensureController(); this.controller?.setCommunicator(options.communicator); this.controller?.setSaveRecordings(false); @@ -177,6 +189,7 @@ export class FaceclawVoiceControlBridge { } stopRawCapture(): void { + this.suspendedRaw = false; if (!this.rawActive) return; this.rawActive = false; this.started = false; @@ -188,17 +201,26 @@ export class FaceclawVoiceControlBridge { // STT preempts the raw-PCM tap: a live transcription session owns the mic, // and an EvenHub app gets no audio for its duration. if (this.rawActive) this.stopRawCapture(); - const wasIdle = this.captureHolders.size === 0; + // Whether the mic is already running is a question about the stream, not + // about this set: a holder whose capture died with the glasses session + // (or whose mic enable was refused) is still in it. Trusting the set here + // let one stale holder silently swallow every later request for the + // process's lifetime. + const micLive = this.micIsLive(); + this.suspendedHolders.delete(holder); this.captureHolders.add(holder); - if (!wasIdle) { + if (micLive) { // Mic already running; the new holder just shares the existing stream // (transcripts are already broadcast to its listeners). return; } + // Any leftover capture is dead; drop it before starting the new one. + if (this.started) this.teardownCapture(); this.ensureController(); this.controller?.setCommunicator(options.communicator); this.controller?.setSaveRecordings(options.saveRecording); this.controller?.setEndpointing(Boolean(options.endpointing)); + this.captureEndpointing = Boolean(options.endpointing); this.controller?.setNoiseSuppression(Boolean(options.noiseSuppression)); if (options.beamFilter) { this.controller?.setBeamFilter(true, Math.round(options.beamFilter.centerDeg), Math.round(options.beamFilter.halfWidthDeg)); @@ -271,6 +293,9 @@ export class FaceclawVoiceControlBridge { } private releaseCapture(holder: CaptureHolder, commit: boolean): void { + // A holder that gives up while its capture is parked must not be resumed + // by the next session. + this.suspendedHolders.delete(holder); if (!this.captureHolders.delete(holder)) { // Never held; still finish a dangling cloud commit if one is pending. if (commit) this.cloudClient?.finish(); @@ -298,6 +323,75 @@ export class FaceclawVoiceControlBridge { stop(): void { this.captureHolders.clear(); + this.suspendedHolders.clear(); + this.suspendedRaw = false; + this.teardownCapture(); + this.setStatus("Voice control stopped."); + } + + /** + * The glasses session ended under a live capture (transport drop, charging + * case, EvenHub suspend). Its mic enable did not survive, so drop the local + * capture state — leaving it in place would make the holder set claim a + * stream that no longer exists — and remember who was holding so + * resumeCapture() can bring the mic back on the next session. + */ + handleSessionEnded(): void { + if (this.captureHolders.size === 0 && !this.started && !this.rawActive) return; + for (const holder of this.captureHolders) { + this.suspendedHolders.add(holder); + } + this.captureHolders.clear(); + this.suspendedRaw = this.rawActive; + this.teardownCapture(); + if (this.suspendedHolders.size > 0) { + this.setStatus("Waiting for the glasses..."); + } + } + + /** Whether a capture is parked waiting for a session to come back. */ + hasSuspendedCapture(): boolean { + return this.suspendedHolders.size > 0 || this.suspendedRaw; + } + + /** Whether anyone holds the mic, including across a session outage. */ + isCaptureHeld(): boolean { + return this.captureHolders.size > 0 || this.suspendedHolders.size > 0; + } + + /** + * A fresh glasses session is ready (its display path warmed up, so a mic + * enable will be accepted): restart the mic for every holder that was + * capturing when the last session ended. Mic permission was granted for the + * original capture and cannot be revoked without restarting the process, so + * this does not ask again. + */ + resumeCapture(options: Omit): void { + const holders = Array.from(this.suspendedHolders); + const resumeRaw = this.suspendedRaw; + this.suspendedHolders.clear(); + this.suspendedRaw = false; + for (const holder of holders) { + this.acquireCapture(holder, { ...options, endpointing: this.captureEndpointing }); + } + if (resumeRaw && !holders.length) { + this.startRawCapture({ communicator: options.communicator }); + } + } + + /** + * Whether the glasses mic is actually streaming. The holder set and + * `started` are phone-side bookkeeping; the enable itself lives in the + * glasses session, so the controller (via the communicator) is the only + * authority on whether audio is still flowing. + */ + private micIsLive(): boolean { + if (!global.isAndroid || !this.started) return false; + return Boolean(this.controller?.isCapturing()); + } + + /** Stop the native capture and any cloud client; leaves holders alone. */ + private teardownCapture(): void { this.rawActive = false; if (global.isAndroid) { this.controller?.stop(); @@ -305,7 +399,6 @@ export class FaceclawVoiceControlBridge { this.started = false; this.cloudClient?.stop(); this.cloudClient = null; - this.setStatus("Voice control stopped."); } private ensureController(): void { diff --git a/app/phone-ui/main-view-model.ts b/app/phone-ui/main-view-model.ts index e5287504..5394e453 100644 --- a/app/phone-ui/main-view-model.ts +++ b/app/phone-ui/main-view-model.ts @@ -771,10 +771,7 @@ export class MainViewModel extends Observable { /** What the next gesture lands on, as the watch pad shows it. */ get padFocusLine(): string { - if (this.phase !== "connected" && this.phase !== "charging") return "Glasses disconnected"; - if (!shell.isScreenOn()) return "Display off"; - const foreground = shell.getForegroundApp(); - return foreground ? foreground.title : "Launcher"; + return dashboardController.glassesDisplayLabel(); } private refreshPadFocusLine(): void { diff --git a/app/ui/dashboard-settings.ts b/app/ui/dashboard-settings.ts index 55f1094f..d2ae86d4 100644 --- a/app/ui/dashboard-settings.ts +++ b/app/ui/dashboard-settings.ts @@ -328,13 +328,13 @@ export const watchCanUnlockSetting = new ConfigSettingBoolean({ "Let the watch unlock the glasses' lock screen (which otherwise waits for the phone to be unlocked). Your watch is on your wrist; turn this off if you would rather it stay a phone-only unlock.", }); -export const watchWakesDisplaySetting = new ConfigSettingBoolean({ - id: "watch-wakes-display", - label: "Watch input wakes display", - storageKey: "watch.wakesDisplay", - defaultValue: true, +export const watchCrownClockwiseNextSetting = new ConfigSettingBoolean({ + id: "watch-crown-clockwise-next", + label: "Clockwise crown = next", + storageKey: "watch.crownClockwiseNext", + defaultValue: false, description: - "Any gesture from the watch turns the glasses display on (the ring only wakes it with a double-tap). Off: watch input is ignored while the display is off, as ring input is.", + "Choose which crown direction moves to the next item. Off: clockwise moves to the previous item. On: clockwise moves to the next item.", }); export const watchMirrorAssistantSetting = new ConfigSettingBoolean({ @@ -390,6 +390,19 @@ export const suspendEvenHubWhenScreenOffSetting = new ConfigSettingBoolean({ description: "Suspend the EvenHub session while the display is off. This significantly improves battery life, but increases the latency of waking the screen.", }); +export type RingConnectionMode = "glasses" | "direct"; + +export const ringConnectionModeSetting = new ConfigSettingEnum({ + id: "ring-connection-mode", + label: "Ring connection", + storageKey: "developer.ringConnectionMode", + defaultValue: "glasses", + values: ["glasses", "direct"], + formatValue: (value) => (value === "direct" ? "Direct" : "Only via glasses"), + description: + "How R1 ring input reaches the phone. Only via glasses: the ring's own link to the glasses carries its gestures, and the phone never opens a Bluetooth connection to the ring. Direct: also connect to the ring from the phone (currently unreliable). Takes effect on the next connection to the glasses.", +}); + export type VoiceProvider = "onboard" | "elevenlabs" | "whisper" | "soniox"; const voiceProviderLabels: Record = { diff --git a/app/ui/dashboard/settings-menus.ts b/app/ui/dashboard/settings-menus.ts index 59988a2a..a66cf2cf 100644 --- a/app/ui/dashboard/settings-menus.ts +++ b/app/ui/dashboard/settings-menus.ts @@ -41,6 +41,7 @@ import { mirrorTouchSetting, openAiApiKeySetting, previewColorSetting, + ringConnectionModeSetting, roamApiTokenSetting, roamGraphNameSetting, sonioxApiKeySetting, @@ -60,9 +61,9 @@ import { screenTimeoutSetting, wakeWordActionSetting, watchCanUnlockSetting, + watchCrownClockwiseNextSetting, watchMirrorAssistantSetting, watchRemoteEnabledSetting, - watchWakesDisplaySetting, } from "../dashboard-settings"; import { wearBridge } from "../../native/wear-bridge"; import { SettingsPanelLayer, type SettingsSection } from "./settings-panel"; @@ -167,7 +168,7 @@ function settingsSections(): SettingsSection[] { // a watch running the companion app is currently reachable. items: [ toggleSettingMenuItem(watchRemoteEnabledSetting), - toggleSettingMenuItem(watchWakesDisplaySetting), + toggleSettingMenuItem(watchCrownClockwiseNextSetting), toggleSettingMenuItem(watchCanUnlockSetting), toggleSettingMenuItem(watchMirrorAssistantSetting), ], @@ -176,6 +177,9 @@ function settingsSections(): SettingsSection[] { { label: "Developer", items: [ + // Whether the phone opens its own BLE link to the R1 ring; the + // glasses relay ring gestures either way. Applied at connect time. + enumSettingMenuItem(ringConnectionModeSetting), toggleSettingMenuItem(saveVoiceRecordingsSetting), toggleSettingMenuItem(firmwareDebugFlagsSetting), toggleSettingMenuItem(suspendEvenHubWhenScreenOffSetting), diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..bfb8d3ad --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +cd "$(dirname "$0")"; source scripts/before_build.sh + +npx nativescript build android "$@" + diff --git a/build_and_run.sh b/build_and_run.sh new file mode 100755 index 00000000..67c7e0a3 --- /dev/null +++ b/build_and_run.sh @@ -0,0 +1,7 @@ +#!/bin/bash +cd "$(dirname "$0")"; source scripts/before_build.sh + +npx nativescript build android "$@" && \ + adb connect "$DEVICE_ID" >/dev/null && \ + nativescript run android --device "$DEVICE_ID" --justlaunch + diff --git a/build_paths.sh.template b/build_paths.sh.template new file mode 100644 index 00000000..991937b3 --- /dev/null +++ b/build_paths.sh.template @@ -0,0 +1,9 @@ +# Copy this file to build_paths.sh and add any paths or other prelude needed +# before build. Other build scripts will `source` it. + +#export JAVA_HOME= +#export ANDROID_HOME= +#export PATH= +#export ANDROID_KEYSTORE= +#export DEVICE_ID= + diff --git a/build_wear.sh b/build_wear.sh new file mode 100755 index 00000000..6df4e785 --- /dev/null +++ b/build_wear.sh @@ -0,0 +1,5 @@ +#!/bin/bash +cd "$(dirname "$0")"; source scripts/before_build.sh + +cd wear && ./gradlew build "$@" + diff --git a/package.json b/package.json index 9a8b1ee5..c4a1783e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "version": "1.0.0", "private": false, "scripts": { - "build": "nativescript build android", + "build": "./build.sh", + "run": "./build_and_run.sh", "release": "scripts/release.sh", "clean": "rm -rf platforms", "test": "tsc -p tests/tsconfig.json && node --test tests/*.test.cjs" diff --git a/scripts/before_build.sh b/scripts/before_build.sh new file mode 100644 index 00000000..9a1c34f0 --- /dev/null +++ b/scripts/before_build.sh @@ -0,0 +1,7 @@ + +if [ -f build_paths.sh ]; then + source ./build_paths.sh +else + cp build_paths.sh.template build_paths.sh +fi + diff --git a/scripts/release.sh b/scripts/release.sh index dc68483f..471ff59b 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -1,20 +1,24 @@ #!/bin/bash -# Build a signed release APK at dist/Faceclaw-.apk, where -# comes from FACECLAW_VERSION in app/version.ts. +# Build signed release APKs at dist/Faceclaw-.apk (phone) and +# dist/Faceclaw-Wear-.apk (watch), where comes from +# FACECLAW_VERSION in app/version.ts. Both are signed with the same key: +# the Wearable Data Layer only routes between apps with matching package +# names and signing keys. # # Prompts for the keystore passphrase. Override the keystore location with # ANDROID_KEYSTORE=/path/to/store.jks. # -# Note: the passphrase is passed to the nativescript CLI on its command line, -# so it is briefly visible in `ps` on this machine while the build runs. +# Note: the passphrase is passed to the nativescript CLI and Gradle on their +# command lines, so it is briefly visible in `ps` on this machine while the +# build runs. set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT" +source scripts/before_build.sh -KEYSTORE="${ANDROID_KEYSTORE:-$HOME/repositories/AndroidKeystore/jimrandomh-android-keystore.jks}" -if [ ! -f "$KEYSTORE" ]; then - echo "Keystore not found: $KEYSTORE (set ANDROID_KEYSTORE to override)" >&2 +if [ ! -f "$ANDROID_KEYSTORE" ]; then + echo "Keystore not found: $ANDROID_KEYSTORE (set ANDROID_KEYSTORE in build_paths.sh)" >&2 exit 1 fi @@ -34,17 +38,17 @@ if [ -z "$VERSION" ]; then exit 1 fi -read -r -s -p "Keystore passphrase for $(basename "$KEYSTORE"): " STORE_PASS +read -r -s -p "Keystore passphrase for $(basename "$ANDROID_KEYSTORE"): " STORE_PASS echo # Validate the passphrase up front and discover the signing-key alias. -if ! LISTING="$(keytool -list -keystore "$KEYSTORE" -storepass "$STORE_PASS" 2>&1)"; then +if ! LISTING="$(keytool -list -keystore "$ANDROID_KEYSTORE" -storepass "$STORE_PASS" 2>&1)"; then printf '%s\n' "$LISTING" >&2 exit 1 fi ALIAS="$(printf '%s\n' "$LISTING" | awk -F', ' '/PrivateKeyEntry/{print $1; exit}')" if [ -z "$ALIAS" ]; then - echo "No private-key entry found in $KEYSTORE:" >&2 + echo "No private-key entry found in $ANDROID_KEYSTORE:" >&2 printf '%s\n' "$LISTING" >&2 exit 1 fi @@ -55,19 +59,37 @@ echo KEY_PASS="${KEY_PASS:-$STORE_PASS}" OUT="dist/Faceclaw-$VERSION.apk" +WEAR_OUT="dist/Faceclaw-Wear-$VERSION.apk" mkdir -p dist -rm -f "$OUT" +rm -f "$OUT" "$WEAR_OUT" +echo "=== Building Android app ===" npx nativescript build android --release \ - --key-store-path "$KEYSTORE" \ + --key-store-path "$ANDROID_KEYSTORE" \ --key-store-password "$STORE_PASS" \ --key-store-alias "$ALIAS" \ --key-store-alias-password "$KEY_PASS" \ --copy-to "$OUT" +# Wear app: sign with the same key via AGP's injected signing properties, so +# no signing config needs to live in the wear build files. +echo "=== Building Wear app ===" +(cd wear && ./gradlew :app:assembleRelease \ + -Pandroid.injected.signing.store.file="$ANDROID_KEYSTORE" \ + -Pandroid.injected.signing.store.password="$STORE_PASS" \ + -Pandroid.injected.signing.key.alias="$ALIAS" \ + -Pandroid.injected.signing.key.password="$KEY_PASS") +cp wear/app/build/outputs/apk/release/app-release.apk "$WEAR_OUT" + echo echo "Built $OUT" +echo "Built $WEAR_OUT" if [ -n "${ANDROID_HOME:-}" ] && [ -d "$ANDROID_HOME/build-tools" ]; then APKSIGNER="$(printf '%s\n' "$ANDROID_HOME/build-tools"/*/apksigner | sort -V | tail -1)" - [ -x "$APKSIGNER" ] && "$APKSIGNER" verify --print-certs "$OUT" | head -5 + if [ -x "$APKSIGNER" ]; then + for apk in "$OUT" "$WEAR_OUT"; do + echo "== $apk" + "$APKSIGNER" verify --print-certs "$apk" | head -5 + done + fi fi diff --git a/scripts/sync-site.mjs b/scripts/sync-site.mjs new file mode 100755 index 00000000..a699f361 --- /dev/null +++ b/scripts/sync-site.mjs @@ -0,0 +1,126 @@ +#!/usr/bin/env node +// Keeps the website in step with the files that own the content. +// +// website/content/features.md -> README.md and website/index.html +// PRIVACY -> website/privacy.html +// +// Each destination has a `` / `` +// pair; everything between them is replaced. Run after editing either source: +// +// node scripts/sync-site.mjs rewrite the destinations +// node scripts/sync-site.mjs --check exit non-zero if they are out of date + +import { readFileSync, writeFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; +import { dirname, join } from "node:path"; + +const root = join(dirname(fileURLToPath(import.meta.url)), ".."); +const check = process.argv.includes("--check"); +const stale = []; + +// ---------- generic helpers ---------- + +function splice(relPath, key, body) { + const path = join(root, relPath); + const before = readFileSync(path, "utf8"); + const begin = ``; + const end = ``; + const i = before.indexOf(begin); + const j = before.indexOf(end); + if (i < 0 || j < 0) throw new Error(`${relPath}: missing ${begin} / ${end} markers`); + if (j < i) throw new Error(`${relPath}: ${end} comes before ${begin}`); + const after = before.slice(0, i + begin.length) + "\n" + body.replace(/\n+$/, "") + "\n" + before.slice(j); + if (after === before) return; + if (check) stale.push(`${relPath} (${key})`); + else writeFileSync(path, after); +} + +const escapeHtml = (s) => + s.replace(/&/g, "&").replace(//g, ">"); + +// The small markdown subset the sources use: `code`, **bold**, [text](url), bare URLs. +function inlineHtml(text) { + return escapeHtml(text) + .replace(/`([^`]+)`/g, "$1") + .replace(/\*\*([^*]+)\*\*/g, "$1") + .replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, '$1') + // Bare URLs, minus any trailing sentence punctuation. + .replace(/(^|[\s(])(https?:\/\/[^\s<)]+?)([.,;:)]?)(?=$|[\s<)])/g, + (_, lead, url, tail) => `${lead}${url}${tail}`); +} + +function wrap(text, width, firstPrefix, contPrefix) { + const lines = []; + let line = firstPrefix; + let indent = firstPrefix; + for (const word of text.split(/\s+/)) { + if (line !== indent && (line + " " + word).length > width) { + lines.push(line); + indent = contPrefix; + line = contPrefix + word; + } else { + line = line === indent ? line + word : line + " " + word; + } + } + lines.push(line); + return lines.join("\n"); +} + +// ---------- features ---------- + +function parseFeatures(md) { + const body = md.replace(//g, ""); + const features = []; + for (const raw of body.split("\n")) { + const line = raw.trimEnd(); + if (/^- /.test(line)) features.push(line.slice(2).trim()); + else if (/^\s+\S/.test(line) && features.length) { + features[features.length - 1] += " " + line.trim(); + } + } + if (!features.length) throw new Error("website/content/features.md: no `- ` bullets found"); + return features; +} + +const features = parseFeatures(readFileSync(join(root, "website/content/features.md"), "utf8")); + +splice("README.md", "features", + features.map((f) => wrap(f, 78, " * ", " ")).join("\n")); + +splice("website/index.html", "features", + '
    \n' + + features.map((f) => `
  • ${inlineHtml(f)}
  • `).join("\n") + + "\n
"); + +// ---------- privacy ---------- + +function privacyHtml(md) { + const out = []; + for (const block of md.trim().split(/\n\s*\n/)) { + const lines = block.split("\n").filter((l) => l.trim()); + if (/^# /.test(lines[0])) { + out.push(`

${inlineHtml(lines[0].slice(2).trim())}

`); + } else if (/^## /.test(lines[0])) { + out.push(`

${inlineHtml(lines[0].slice(3).trim())}

`); + } else if (lines.every((l) => /^\s{2,}\S/.test(l))) { + // An indented run of "Provider: https://..." lines. + out.push('"); + } else { + out.push(`

${inlineHtml(lines.map((l) => l.trim()).join(" "))}

`); + } + } + return out.map((l) => " " + l).join("\n"); +} + +splice("website/privacy.html", "privacy", + privacyHtml(readFileSync(join(root, "PRIVACY"), "utf8"))); + +// ---------- report ---------- + +if (check && stale.length) { + console.error("Out of date, run `node scripts/sync-site.mjs`:\n " + stale.join("\n ")); + process.exit(1); +} +console.log(check ? "sync-site: up to date" : "sync-site: wrote generated blocks"); diff --git a/tests/glasses-display-state.test.cjs b/tests/glasses-display-state.test.cjs new file mode 100644 index 00000000..eed75ca9 --- /dev/null +++ b/tests/glasses-display-state.test.cjs @@ -0,0 +1,29 @@ +const test = require("node:test"); +const assert = require("node:assert/strict"); + +const { chargingDisplayLabel, glassesDisplayLabel } = require("../.test-build/app/g2/glasses-display-state.js"); + +const connected = { + phase: "connected", + silentMode: false, + screenOn: true, + battery: 72, + foregroundTitle: "Music", +}; + +test("the foreground-title line covers visible, dark, and silent displays", () => { + assert.equal(glassesDisplayLabel(connected), "Music"); + assert.equal(glassesDisplayLabel({ ...connected, foregroundTitle: null }), "Launcher"); + assert.equal(glassesDisplayLabel({ ...connected, screenOn: false }), "Display off"); + assert.equal(glassesDisplayLabel({ ...connected, screenOn: false, silentMode: true }), "Silent mode"); +}); + +test("charging takes precedence and includes the last-known G2 battery", () => { + assert.equal( + glassesDisplayLabel({ ...connected, phase: "charging", silentMode: true, screenOn: false }), + "Charging · G2 72%", + ); + assert.equal(chargingDisplayLabel(null), "Charging"); + assert.equal(chargingDisplayLabel(-1), "Charging"); + assert.equal(chargingDisplayLabel(101), "Charging"); +}); diff --git a/tests/tsconfig.json b/tests/tsconfig.json index ef8e8b08..e554b339 100644 --- a/tests/tsconfig.json +++ b/tests/tsconfig.json @@ -15,6 +15,7 @@ "../app/g2/ble-proximity.ts", "../app/g2/even-advertisement.ts", "../app/g2/glasses-artwork.ts", + "../app/g2/glasses-display-state.ts", "../app/g2/pairing-candidates.ts", "../app/apps/calculator/math/*.ts", "../app/apps/microphones/mic-protocol.ts", diff --git a/wear/PROTOCOL.md b/wear/PROTOCOL.md index b3bc0b46..a94c2a4e 100644 --- a/wear/PROTOCOL.md +++ b/wear/PROTOCOL.md @@ -18,7 +18,7 @@ answered on `/faceclaw/ack`. | Path | Payload | Effect | | --- | --- | --- | -| `/faceclaw/input` | `{gesture, steps?}` | A ring gesture through the same path as the phone UI's test buttons. `gesture` ∈ `click`, `double-click`, `scroll-up`, `scroll-down`, `long-press` (complete short hold), `long-press-start`, `long-press-release`, `wakeword` ("Hey Even"), `swipe-up`, `swipe-down`, `swipe-left`, `swipe-right` (spatial input only a watch can produce: delivered to the glasses UI as `swipe-*` events for components that navigate spatially — launcher grid, settings columns, sidebar, Music — with a scroll / click / double-click fallback elsewhere). `steps` (1–12) repeats a scroll. Refused while the glasses are disconnected. The lock screen is honoured exactly as for the ring (only a double-click reaches it, toggling the locked display). | +| `/faceclaw/input` | `{gesture, steps?}` | A ring gesture through the same path as the phone UI's test buttons. `gesture` ∈ `click`, `double-click`, `scroll-up`, `scroll-down`, `long-press` (complete short hold), `long-press-start`, `long-press-release`, `wakeword` ("Hey Even"), `swipe-up`, `swipe-down`, `swipe-left`, `swipe-right` (spatial input only a watch can produce: delivered to the glasses UI as `swipe-*` events for components that navigate spatially — launcher grid, settings columns, sidebar, Music — with a scroll / click / double-click fallback elsewhere). `steps` (1–12) repeats a scroll. Refused while the glasses are disconnected. The lock screen is honoured exactly as for the ring. While the display is off, only a double-click is accepted and it wakes the display. | | `/faceclaw/command` | `{command, …}` | `launch-app {appId}`, `focus-window {windowId}`, `close-window {windowId}`, `sidebar`, `wake`, `sleep`, `lock`, `unlock`, `connect`, `disconnect`, `close-assistant`, `display-mode {value}` (`value` ∈ `576x288`, `576x480`, `640x480`; sets the phone's Display > Display mode). Everything but connect/disconnect needs a connection; everything but lock/unlock is refused while locked; `unlock` also needs the phone's "Watch can unlock glasses" setting. | | `/faceclaw/assistant` | `{text}` | Send a query to the assistant (`shell.sendToAssistant`) — the reply shows on the glasses and streams back to the watch as events. | | `/faceclaw/text` | `{text}` | Type text into the foreground window (`receiveTextInput`, e.g. the terminal). Refused when the window doesn't take text. | @@ -49,19 +49,26 @@ dashboard state, re-sent whenever it changes (and at least every 30 s): "protocol": 1, "version": "…", "phase": "connected", "status": "…", "connected": true, "screenOn": true, "locked": false, "worn": true, "listening": false, - "battery": 78, "charging": false, + "battery": 78, "charging": false, "silentMode": false, "foreground": {"appId": "music", "title": "Music"}, "windows": [{"windowId": "…", "title": "…", "appId": "…", "focused": true, "closeable": true, "acceptsText": false}], "apps": [{"appId": "timer", "title": "Timer"}], "displayMode": "576x288", - "remoteEnabled": true, "canUnlock": true, "mirrorAssistant": true, + "remoteEnabled": true, "crownClockwiseNext": false, + "canUnlock": true, "mirrorAssistant": true, "assistantAvailable": true } ``` +`battery` is the current or last-known G2 percentage. `charging` and +`silentMode` identify the two states in which the glasses display is not +visible even though the BLE session remains available. + `protocol` is reserved for incompatible revisions of this format (nothing checks it yet); `displayMode` mirrors the phone's Display > Display mode and -is what the `display-mode` command changes. +is what the `display-mode` command changes. `crownClockwiseNext` mirrors the +on-glasses Settings > Watch toggle; when false (the default), clockwise crown +rotation sends previous/up, and when true it sends next/down. `apps` is the launcher grid plus installed EvenHub packages, i.e. exactly what the assistant's `apps.launch` tool accepts. diff --git a/wear/README.md b/wear/README.md index e525dea4..04697424 100644 --- a/wear/README.md +++ b/wear/README.md @@ -15,7 +15,7 @@ the phone it only tells you to install it. | double-tap, or a two-finger tap | **back**, everywhere: closes menus, leaves a settings column, leaves a folder or the launcher grid, returns to the sidebar (and from the sidebar turns the display off, as the ring does) | | press and hold | the app's context menu (a long press, held until you lift your finger) | | swipe ↑ ↓ ← → | **spatial navigation, with no mode to enter first**: the launcher highlights one app and the swipe moves it by a row or a column; the settings panel moves between its columns and down its lists; the sidebar moves up and down; Music skips to the previous / next track. Right goes *into* things (sidebar → window, section → items) and left comes back *out* (first column → sidebar). Anywhere without a spatial meaning, up/down scroll, right selects and left goes back. One step per swipe (long swipes used to repeat, which overshot lists whenever the display lagged); use repeated flicks, the crown, or a two-finger page swipe to cover distance. "Natural swipe" flips the vertical sense; left/right can be remapped in settings. | -| rotate the crown | up / down (one step per detent-ish, sensitivity adjustable) — in the launcher that is rows, elsewhere scrolling | +| rotate the crown | previous / next (one step per detent-ish, sensitivity adjustable) — clockwise is previous by default; reverse it in the on-glasses Settings > Watch section | | two-finger swipe up / down | scroll a page (3 steps) | | **twist the wrist twice** (two brisk flicks, either direction) | back — from the gyroscope; on by default, sensitivity adjustable | | **tip taps** — tap your index finger against your thumb | select; two quick taps = back. From the accelerometer; **off by default** (experimental): on a wrist, ordinary hand movement produced phantom selects in testing. Turn on in Watch settings; needs ~¼ s of stillness before a tap counts, and both motion gestures are ignored while the watch is off the wrist or buzzing. | @@ -31,7 +31,9 @@ ever seeing a difference. long press; button 2 = back; button 3 = "Hey Even". You can also set the watch's button shortcut to open Faceclaw. -**Bottom row buttons**: Assistant, Type into app, Apps, Status. +**Bottom row buttons**: Assistant, Type into app, Apps, Status. They are hidden +by default; swipe up beginning at the bottom edge to slide them in, then swipe +down beginning in the button tray to hide them. - **Assistant** — ask the assistant using the *watch's* microphone (system speech recognition) or the Wear keyboard, and read the reply on the watch as @@ -53,9 +55,9 @@ wrist dropping and freezes the app, so the remote would need a wake-up tap before every gesture. Phone-side switches live in Faceclaw's Settings > Watch: turn watch control -off entirely, decide whether watch input wakes a dark display (on by default — -the ring only wakes it with a double-tap), forbid unlocking from the watch, -or stop mirroring assistant replies. +off entirely, reverse the crown direction, forbid unlocking from the watch, +or stop mirroring assistant replies. While the glasses display is off, every +watch gesture except a double-tap is ignored; double-tap wakes it. The watch buzzes differently when the phone refuses or doesn't answer a gesture (glasses disconnected, locked, watch control off); the pill at the diff --git a/wear/app/build.gradle.kts b/wear/app/build.gradle.kts index b75b32e9..71cd6049 100644 --- a/wear/app/build.gradle.kts +++ b/wear/app/build.gradle.kts @@ -32,6 +32,14 @@ android { buildConfig = true } + lint { + // androidx.lifecycle 2.9.x ships a NullSafeMutableLiveData lint check + // that crashes under this AGP's lint (Kotlin analysis API mismatch: + // "Found class KaCallableMemberCall, but interface was expected"). + // We don't use LiveData, so nothing is lost by disabling it. + disable += "NullSafeMutableLiveData" + } + compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 diff --git a/wear/app/src/main/kotlin/com/faceclaw/wear/MainActivity.kt b/wear/app/src/main/kotlin/com/faceclaw/wear/MainActivity.kt index d1697802..b5c1e6b9 100644 --- a/wear/app/src/main/kotlin/com/faceclaw/wear/MainActivity.kt +++ b/wear/app/src/main/kotlin/com/faceclaw/wear/MainActivity.kt @@ -20,6 +20,7 @@ class MainActivity : ComponentActivity() { private val stemHandler = Handler(Looper.getMainLooper()) private var stemHoldRunnable: Runnable? = null private var stemHoldSent = false + private var stemOneIgnored = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -67,10 +68,16 @@ class MainActivity : ComponentActivity() { if (event.repeatCount == 0) { cancelStemHold() stemHoldSent = false + stemOneIgnored = glassesScreenIsOff() + if (stemOneIgnored) return true val runnable = Runnable { - stemHoldSent = true - haptics.heavy() - link.sendGesture(Gesture.LONG_PRESS_START) + if (glassesScreenIsOff()) { + stemOneIgnored = true + } else { + stemHoldSent = true + haptics.heavy() + link.sendGesture(Gesture.LONG_PRESS_START) + } } stemHoldRunnable = runnable stemHandler.postDelayed(runnable, STEM_HOLD_MS) @@ -85,7 +92,7 @@ class MainActivity : ComponentActivity() { return true } KeyEvent.KEYCODE_STEM_3 -> { - if (event.repeatCount == 0) { + if (event.repeatCount == 0 && !glassesScreenIsOff()) { haptics.click() link.sendGesture(Gesture.WAKEWORD) } @@ -98,11 +105,15 @@ class MainActivity : ComponentActivity() { override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean { if (keyCode == KeyEvent.KEYCODE_STEM_1) { cancelStemHold() + if (stemOneIgnored) { + stemOneIgnored = false + return true + } if (stemHoldSent) { stemHoldSent = false haptics.click() link.sendGesture(Gesture.LONG_PRESS_RELEASE) - } else { + } else if (!glassesScreenIsOff()) { haptics.click() link.sendGesture(Gesture.CLICK) } @@ -117,6 +128,9 @@ class MainActivity : ComponentActivity() { stemHoldRunnable = null } + private fun glassesScreenIsOff(): Boolean = + link.state.value?.let { it.connected && !it.screenOn } == true + private companion object { const val STEM_HOLD_MS = 450L } diff --git a/wear/app/src/main/kotlin/com/faceclaw/wear/Protocol.kt b/wear/app/src/main/kotlin/com/faceclaw/wear/Protocol.kt index 35c6dc3a..f2d0903a 100644 --- a/wear/app/src/main/kotlin/com/faceclaw/wear/Protocol.kt +++ b/wear/app/src/main/kotlin/com/faceclaw/wear/Protocol.kt @@ -100,13 +100,16 @@ data class PhoneState( val listening: Boolean, /** Display mode wire value ("576x288" | "576x480" | "640x480"). */ val displayMode: String, - // The state item also carries "battery"; the watch doesn't show it (the - // glasses' own top bar does), so it is left unparsed. + /** Current or last-known G2 charge percentage. */ + val battery: Int?, val charging: Boolean, + val silentMode: Boolean, val foreground: AppEntry?, val windows: List, val apps: List, val remoteEnabled: Boolean, + /** False by default: clockwise moves to the previous item. */ + val crownClockwiseNext: Boolean, val canUnlock: Boolean, val mirrorAssistant: Boolean, val assistantAvailable: Boolean, @@ -127,7 +130,9 @@ data class PhoneState( worn = if (o.isNull("worn")) null else o.optBoolean("worn"), listening = o.optBoolean("listening", false), displayMode = o.optString("displayMode", "576x288"), + battery = if (o.isNull("battery")) null else o.optInt("battery", -1).takeIf { it in 0..100 }, charging = o.optBoolean("charging", false), + silentMode = o.optBoolean("silentMode", false), foreground = foreground?.let { AppEntry(it.optString("appId", ""), it.optString("title", "")) }, @@ -151,6 +156,7 @@ data class PhoneState( } } ?: emptyList(), remoteEnabled = o.optBoolean("remoteEnabled", true), + crownClockwiseNext = o.optBoolean("crownClockwiseNext", false), canUnlock = o.optBoolean("canUnlock", true), mirrorAssistant = o.optBoolean("mirrorAssistant", true), assistantAvailable = o.optBoolean("assistantAvailable", false), diff --git a/wear/app/src/main/kotlin/com/faceclaw/wear/WatchPrefs.kt b/wear/app/src/main/kotlin/com/faceclaw/wear/WatchPrefs.kt index 734efb13..2cb19e25 100644 --- a/wear/app/src/main/kotlin/com/faceclaw/wear/WatchPrefs.kt +++ b/wear/app/src/main/kotlin/com/faceclaw/wear/WatchPrefs.kt @@ -37,7 +37,7 @@ data class Prefs( * exactly when a remote wants to stay ready. */ val keepScreenOn: Boolean = true, - /** Swipe/crown direction follows the content (touch-scroll style) instead of the ring. */ + /** Swipe direction follows the content (touch-scroll style) instead of the ring. */ val naturalScroll: Boolean = false, /** Tap the top/bottom of the pad to scroll instead of swiping. */ val tapZones: Boolean = false, diff --git a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/Common.kt b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/Common.kt index 975f24f7..e571e861 100644 --- a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/Common.kt +++ b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/Common.kt @@ -63,8 +63,10 @@ fun padLine(state: PhoneState?, link: LinkStatus): StatusLine = when { state == null -> StatusLine("Waiting for phone", StatusTone.BUSY) state.remoteEnabled == false -> StatusLine("Watch control off", StatusTone.PROBLEM) state.connected -> when { + state.charging || state.phase == "charging" -> StatusLine(chargingLine(state.battery), StatusTone.BUSY) + state.silentMode -> StatusLine("Silent mode", StatusTone.OFF) state.locked -> StatusLine("Locked", StatusTone.OFF) - !state.screenOn -> StatusLine("Screen off", StatusTone.OFF) + !state.screenOn -> StatusLine("●● Wake", StatusTone.OFF) state.listening -> StatusLine("Listening…", StatusTone.BUSY) else -> StatusLine(state.foreground?.title ?: "Launcher", StatusTone.GOOD) } @@ -73,6 +75,9 @@ fun padLine(state: PhoneState?, link: LinkStatus): StatusLine = when { else -> StatusLine("Glasses disconnected", StatusTone.OFF) } +private fun chargingLine(battery: Int?): String = + if (battery != null) "Charging · G2 $battery%" else "Charging" + fun StatusTone.color(): Color = when (this) { StatusTone.GOOD -> Color(0xFF7BD88F) StatusTone.BUSY -> Color(0xFFF2C14E) diff --git a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/RemoteScreen.kt b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/RemoteScreen.kt index 66a709e2..f836832f 100644 --- a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/RemoteScreen.kt +++ b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/RemoteScreen.kt @@ -1,15 +1,18 @@ package com.faceclaw.wear.ui -import androidx.compose.foundation.Canvas +import android.text.format.DateFormat +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut +import androidx.compose.animation.slideInVertically +import androidx.compose.animation.slideOutVertically import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.BoxWithConstraints -import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.focusable @@ -24,18 +27,18 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.focus.focusRequester -import androidx.compose.ui.geometry.Offset -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.drawscope.Stroke import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.input.rotary.onRotaryScrollEvent import androidx.compose.ui.layout.onSizeChanged +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.platform.LocalView import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver import androidx.lifecycle.compose.LocalLifecycleOwner @@ -47,7 +50,6 @@ import androidx.wear.compose.material.ButtonDefaults import androidx.wear.compose.material.Icon import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text -import androidx.wear.compose.material.TimeText import com.faceclaw.wear.Command import com.faceclaw.wear.FingerTapDetector import com.faceclaw.wear.Gesture @@ -59,20 +61,15 @@ import com.faceclaw.wear.R import com.faceclaw.wear.SwipeAction import com.faceclaw.wear.WristTwistDetector import kotlinx.coroutines.delay +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale import kotlin.math.abs -private const val MAX_SWIPE_STEPS = 4 /** A two-finger swipe scrolls this many steps: a "page". */ private const val TWO_FINGER_SWIPE_STEPS = 3 -private const val FLASH_MS = 160L -private const val ARROW_LIT_MS = 220L -private const val RING_RADIUS_FRACTION = 0.33f -private const val RING_CENTER_Y_FRACTION = 0.47f -private val ARROW_INSET = 6.dp -private val ARROW_SIZE = 18.dp - -/** The d-pad directions, for lighting the arrow that was just swiped. */ -enum class Arrow { UP, DOWN, LEFT, RIGHT } +private val EDGE_REVEAL_ZONE = 24.dp +private val BUTTON_TRAY_HEIGHT = 62.dp /** * The touchpad. The whole screen is the pad: tap = select, double-tap = @@ -80,8 +77,8 @@ enum class Arrow { UP, DOWN, LEFT, RIGHT } * the hold menu ("right click"), swipes in four directions = spatial * navigation (crown and two-finger vertical swipes = plain scrolling, a page * at a time for the latter). Fingertip pinch-taps from the motion sensors - * select / go back, and two quick wrist twists go back. The small buttons at - * the bottom reach the rest. + * select / go back, and two quick wrist twists go back. An upward swipe that + * begins at the bottom edge reveals the otherwise-hidden action buttons. */ // rememberActiveFocusRequester (rotary focus) is still experimental in Wear Compose 1.4. @OptIn(ExperimentalWearFoundationApi::class) @@ -98,14 +95,13 @@ fun RemoteScreen( val linkStatus by link.link.collectAsStateWithLifecycle() val notice by link.notice.collectAsStateWithLifecycle() val currentPrefs by rememberUpdatedState(prefs) + val currentState by rememberUpdatedState(state) val view = LocalView.current - var holding by remember { mutableStateOf(false) } - // Brief ring highlight acknowledging a sensor (tip-tap) gesture. - var flashUntil by remember { mutableStateOf(0L) } - var flashing by remember { mutableStateOf(false) } - // Which d-pad arrow lights up for the swipe just sent. - var litArrow by remember { mutableStateOf(null) } - var litTick by remember { mutableStateOf(0L) } + val density = LocalDensity.current + val edgeRevealPx = remember(density) { with(density) { EDGE_REVEAL_ZONE.toPx() } } + val buttonTrayHeightPx = remember(density) { with(density) { BUTTON_TRAY_HEIGHT.toPx() } } + var controlsVisible by remember { mutableStateOf(false) } + var longPressSent by remember { mutableStateOf(false) } // Rotary (crown) events are only delivered to a focused node. // rememberActiveFocusRequester requests focus through the hierarchical // focus machinery; the resume observer below takes it back after every @@ -130,17 +126,19 @@ fun RemoteScreen( onUnavailable = { haptics.error() }, ) + fun glassesScreenIsOff(): Boolean = currentState?.connected == true && currentState?.screenOn == false + + fun gestureAllowed(gesture: Gesture): Boolean = + !glassesScreenIsOff() || gesture == Gesture.DOUBLE_CLICK + fun scroll(gesture: Gesture, steps: Int) { + if (!gestureAllowed(gesture)) return haptics.tick() link.sendGesture(gesture, steps) } - fun light(arrow: Arrow) { - litArrow = arrow - litTick = System.currentTimeMillis() - } - fun click() { + if (!gestureAllowed(Gesture.CLICK)) return haptics.click() link.sendGesture(Gesture.CLICK) } @@ -153,12 +151,18 @@ fun RemoteScreen( /** Run a horizontal-swipe action; `left` says which way the finger went. */ fun perform(action: SwipeAction, left: Boolean) { when (action) { - SwipeAction.NAVIGATE -> { haptics.click(); link.sendGesture(if (left) Gesture.SWIPE_LEFT else Gesture.SWIPE_RIGHT) } - SwipeAction.SIDEBAR -> { haptics.click(); link.sendCommand(Command.SIDEBAR) } + SwipeAction.NAVIGATE -> { + val gesture = if (left) Gesture.SWIPE_LEFT else Gesture.SWIPE_RIGHT + if (gestureAllowed(gesture)) { haptics.click(); link.sendGesture(gesture) } + } + SwipeAction.SIDEBAR -> if (!glassesScreenIsOff()) { + haptics.click() + link.sendCommand(Command.SIDEBAR, "source" to "gesture") + } SwipeAction.DOUBLE_CLICK -> doubleClick() SwipeAction.CLICK -> click() - SwipeAction.LONG_PRESS -> { haptics.heavy(); link.sendGesture(Gesture.LONG_PRESS) } - SwipeAction.WAKEWORD -> { haptics.click(); link.sendGesture(Gesture.WAKEWORD) } + SwipeAction.LONG_PRESS -> if (!glassesScreenIsOff()) { haptics.heavy(); link.sendGesture(Gesture.LONG_PRESS) } + SwipeAction.WAKEWORD -> if (!glassesScreenIsOff()) { haptics.click(); link.sendGesture(Gesture.WAKEWORD) } SwipeAction.NONE -> Unit } } @@ -196,28 +200,41 @@ fun RemoteScreen( } }, onLongPressStart = { - holding = true - haptics.heavy() - link.sendGesture(Gesture.LONG_PRESS_START) + longPressSent = !glassesScreenIsOff() + if (longPressSent) { + haptics.heavy() + link.sendGesture(Gesture.LONG_PRESS_START) + } }, onLongPressEnd = { - holding = false - haptics.click() - link.sendGesture(Gesture.LONG_PRESS_RELEASE) + if (longPressSent) { + longPressSent = false + haptics.click() + link.sendGesture(Gesture.LONG_PRESS_RELEASE) + } }, - onSwipe = { dx, dy, _ -> - if (abs(dy) >= abs(dx)) { - // One step per swipe, regardless of length: the glasses - // repaint per step, and multi-step swipes overshot lists - // whenever the display lagged the finger. Fast repeated - // swiping, the crown, or a two-finger page swipe cover - // long distances instead. - val up = swipeIsUp(dy) - light(if (up) Arrow.UP else Arrow.DOWN) - scroll(if (up) Gesture.SWIPE_UP else Gesture.SWIPE_DOWN, 1) - } else { - light(if (dx < 0) Arrow.LEFT else Arrow.RIGHT) - perform(if (dx < 0) currentPrefs.swipeLeft else currentPrefs.swipeRight, left = dx < 0) + onSwipe = { start, dx, dy, _ -> + val vertical = abs(dy) >= abs(dx) + val padBottom = padHeight[0] + when { + vertical && !controlsVisible && dy < 0 && start.y >= padBottom - edgeRevealPx -> { + controlsVisible = true + haptics.click() + } + vertical && controlsVisible && dy > 0 && start.y >= padBottom - buttonTrayHeightPx -> { + controlsVisible = false + haptics.click() + } + vertical -> { + // One step per swipe, regardless of length: the glasses + // repaint per step, and multi-step swipes overshot lists + // whenever the display lagged the finger. Fast repeated + // swiping, the crown, or a two-finger page swipe cover + // long distances instead. + val up = swipeIsUp(dy) + scroll(if (up) Gesture.SWIPE_UP else Gesture.SWIPE_DOWN, 1) + } + else -> perform(if (dx < 0) currentPrefs.swipeLeft else currentPrefs.swipeRight, left = dx < 0) } }, ) @@ -235,8 +252,8 @@ fun RemoteScreen( sensitivity = { currentPrefs.tapSensitivity }, quietUntil = { haptics.quietUntil() }, onBody = { onBody.onBody }, - onTap = { flashUntil = System.currentTimeMillis() + FLASH_MS; click() }, - onDoubleTap = { flashUntil = System.currentTimeMillis() + FLASH_MS; doubleClick() }, + onTap = { click() }, + onDoubleTap = { doubleClick() }, ) } WhileStartedEffect(fingerTapDetector, start = { fingerTapDetector?.start() }, stop = { fingerTapDetector?.stop() }) @@ -248,21 +265,10 @@ fun RemoteScreen( sensitivity = { currentPrefs.twistSensitivity }, quietUntil = { haptics.quietUntil() }, onBody = { onBody.onBody }, - onDoubleTwist = { flashUntil = System.currentTimeMillis() + FLASH_MS; doubleClick() }, + onDoubleTwist = { doubleClick() }, ) } WhileStartedEffect(wristTwistDetector, start = { wristTwistDetector?.start() }, stop = { wristTwistDetector?.stop() }) - LaunchedEffect(litTick) { - if (litTick == 0L) return@LaunchedEffect - delay(ARROW_LIT_MS) - litArrow = null - } - LaunchedEffect(flashUntil) { - if (flashUntil == 0L) return@LaunchedEffect - flashing = true - delay((flashUntil - System.currentTimeMillis()).coerceAtLeast(1L)) - flashing = false - } // A refused or unanswered gesture gets a distinct buzz, so the wrist knows // without looking (the notice pill says why). @@ -275,15 +281,16 @@ fun RemoteScreen( modifier = Modifier .fillMaxSize() .onRotaryScrollEvent { event -> - // Clockwise (positive) scrolls down, as in every Wear list. crownAccumulator += event.verticalScrollPixels val threshold = currentPrefs.crownSensitivity.pixelsPerStep var steps = 0 while (crownAccumulator >= threshold) { crownAccumulator -= threshold; steps++ } while (crownAccumulator <= -threshold) { crownAccumulator += threshold; steps-- } // Capped low: a fast twirl otherwise outruns the display. - if (steps > 0) { light(Arrow.DOWN); scroll(Gesture.SCROLL_DOWN, steps.coerceAtMost(2)) } - if (steps < 0) { light(Arrow.UP); scroll(Gesture.SCROLL_UP, (-steps).coerceAtMost(2)) } + val clockwise = if (currentState?.crownClockwiseNext == true) Gesture.SCROLL_DOWN else Gesture.SCROLL_UP + val counterClockwise = if (currentState?.crownClockwiseNext == true) Gesture.SCROLL_UP else Gesture.SCROLL_DOWN + if (steps > 0) scroll(clockwise, steps.coerceAtMost(2)) + if (steps < 0) scroll(counterClockwise, (-steps).coerceAtMost(2)) true } .focusRequester(focusRequester) @@ -291,68 +298,47 @@ fun RemoteScreen( .onSizeChanged { padHeight[0] = it.height.toFloat() } .pointerInput(callbacks) { detectTouchpadGestures(callbacks) }, ) { - // The pad: a ring with a d-pad arrow at each compass point (the one - // you swiped lights up), the current glasses app in the middle, and - // the tap legend under it. Brightens while a hold is in progress. - BoxWithConstraints(modifier = Modifier.fillMaxSize()) { - val ringRadius = minOf(maxWidth, maxHeight) * RING_RADIUS_FRACTION - val ringCenterY = maxHeight * RING_CENTER_Y_FRACTION - val ringColor = if (holding || flashing) MaterialTheme.colors.primary else Color(0xFF2E2E2E) - Canvas(modifier = Modifier.fillMaxSize()) { - drawCircle( - color = ringColor, - radius = ringRadius.toPx(), - center = Offset(size.width / 2f, ringCenterY.toPx()), - style = Stroke(width = if (holding || flashing) 4f else 2f), - ) - } + StraightTime(modifier = Modifier.align(Alignment.Center)) - TimeText() - - ArrowGlyph("▲", litArrow == Arrow.UP, Modifier.align(Alignment.TopCenter).padding(top = ringCenterY - ringRadius + ARROW_INSET)) - ArrowGlyph("▼", litArrow == Arrow.DOWN, Modifier.align(Alignment.TopCenter).padding(top = ringCenterY + ringRadius - ARROW_INSET - ARROW_SIZE)) - ArrowGlyph("◀", litArrow == Arrow.LEFT, Modifier.align(Alignment.TopStart).padding(start = maxWidth / 2 - ringRadius + ARROW_INSET, top = ringCenterY - ARROW_SIZE / 2)) - ArrowGlyph("▶", litArrow == Arrow.RIGHT, Modifier.align(Alignment.TopEnd).padding(end = maxWidth / 2 - ringRadius + ARROW_INSET, top = ringCenterY - ARROW_SIZE / 2)) - - // The single status indicator: what the next gesture lands on (the - // app on the glasses, or the screen/lock state in the way of it), - // or the connection problem to fix first. Above the centre line; - // the tap legend below it, clear of the side arrows. + AnimatedVisibility( + visible = !controlsVisible, + enter = fadeIn(), + exit = fadeOut(), + modifier = Modifier.align(Alignment.Center).offset(y = 46.dp), + ) { val pad = padLine(state, linkStatus) Text( - text = if (holding) "holding" else pad.text, + text = pad.text, style = MaterialTheme.typography.title3, - color = when { - holding -> MaterialTheme.colors.primary - pad.tone == StatusTone.GOOD -> MaterialTheme.colors.onSurface - else -> pad.tone.color() - }, + color = if (pad.tone == StatusTone.GOOD) MaterialTheme.colors.onSurface else pad.tone.color(), textAlign = TextAlign.Center, maxLines = 1, overflow = TextOverflow.Ellipsis, - modifier = Modifier - .align(Alignment.TopCenter) - .padding(top = ringCenterY - 44.dp, start = 60.dp, end = 60.dp), - ) - Text( - text = if (prefs.tapZones) "▲▼ tap zones · ● select" else "● select ●● back ‒ menu", - style = MaterialTheme.typography.caption3, - color = MaterialTheme.colors.onSurfaceVariant, - textAlign = TextAlign.Center, - maxLines = 1, - modifier = Modifier - .align(Alignment.TopCenter) - .padding(top = ringCenterY + 18.dp, start = 56.dp, end = 56.dp), + modifier = Modifier.padding(horizontal = 42.dp), ) + } + AnimatedVisibility( + visible = controlsVisible, + enter = slideInVertically(initialOffsetY = { it }), + exit = slideOutVertically(targetOffsetY = { it }), + modifier = Modifier.align(Alignment.BottomCenter), + ) { Row( // Four 36dp buttons need 144dp; at this height the round // display's chord is ~186dp wide, so 36dp margins keep every // button inside the glass. modifier = Modifier - .align(Alignment.BottomCenter) .fillMaxWidth() - .padding(horizontal = 36.dp, vertical = 26.dp), + .height(BUTTON_TRAY_HEIGHT) + .pointerInput(Unit) { + detectTrayDismiss { + controlsVisible = false + haptics.click() + } + } + .padding(horizontal = 36.dp) + .padding(bottom = 26.dp), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically, ) { @@ -393,14 +379,27 @@ private fun WhileStartedEffect(key: Any?, start: () -> Unit, stop: () -> Unit) { } } +/** A large, straight clock fixed on the vertical centre of the touchpad. */ @Composable -private fun ArrowGlyph(glyph: String, lit: Boolean, modifier: Modifier) { +private fun StraightTime(modifier: Modifier = Modifier) { + val context = LocalContext.current + var now by remember { mutableStateOf(System.currentTimeMillis()) } + val pattern = remember(context) { if (DateFormat.is24HourFormat(context)) "HH:mm" else "h:mm" } + val formatter = remember(pattern) { SimpleDateFormat(pattern, Locale.getDefault()) } + LaunchedEffect(Unit) { + while (true) { + val current = System.currentTimeMillis() + now = current + delay(60_000L - current % 60_000L) + } + } Text( - text = glyph, - style = MaterialTheme.typography.caption1, - color = if (lit) MaterialTheme.colors.primary else Color(0xFF6E6E6E), + text = formatter.format(Date(now)), + color = MaterialTheme.colors.onSurface, + fontSize = 42.sp, textAlign = TextAlign.Center, - modifier = modifier.size(ARROW_SIZE), + maxLines = 1, + modifier = modifier, ) } diff --git a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/StatusScreen.kt b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/StatusScreen.kt index a95fa84d..d34f659c 100644 --- a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/StatusScreen.kt +++ b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/StatusScreen.kt @@ -42,10 +42,13 @@ fun StatusScreen(link: PhoneLink, haptics: Haptics, onOpenSettings: () -> Unit) ScalingLazyColumn(state = listState, modifier = Modifier.fillMaxSize()) { item { ListHeader { Text("Glasses") } } item { - // No battery figure here: the glasses' own top bar shows it. + // Ordinarily the glasses' own top bar shows battery. While + // charging that screen is inside the case, so show it here. val phaseLabel = when { state == null -> "No status yet" - connected -> "Connected" + if (state?.charging == true) " · charging" else "" + state?.charging == true || state?.phase == "charging" -> + state?.battery?.let { "Charging · G2 $it%" } ?: "Charging" + connected -> "Connected" state?.phase == "connecting" -> "Connecting…" state?.phase == "disconnecting" -> "Disconnecting…" else -> "Disconnected" diff --git a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/TouchpadGestures.kt b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/TouchpadGestures.kt index 1dee96cc..3698af99 100644 --- a/wear/app/src/main/kotlin/com/faceclaw/wear/ui/TouchpadGestures.kt +++ b/wear/app/src/main/kotlin/com/faceclaw/wear/ui/TouchpadGestures.kt @@ -4,8 +4,10 @@ import androidx.compose.foundation.gestures.awaitEachGesture import androidx.compose.foundation.gestures.awaitFirstDown import androidx.compose.foundation.gestures.waitForUpOrCancellation import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.input.pointer.PointerEventPass import androidx.compose.ui.input.pointer.PointerInputScope import androidx.compose.ui.input.pointer.positionChanged +import kotlin.math.abs /** What the remote's touch surface can report. */ class TouchpadCallbacks( @@ -17,7 +19,7 @@ class TouchpadCallbacks( val onLongPressStart: () -> Unit, val onLongPressEnd: () -> Unit, /** Finger travelled past touch slop; dx/dy are the total displacement. */ - val onSwipe: (dx: Float, dy: Float, durationMs: Long) -> Unit, + val onSwipe: (start: Offset, dx: Float, dy: Float, durationMs: Long) -> Unit, ) /** @@ -86,7 +88,7 @@ suspend fun PointerInputScope.detectTouchpadGestures(callbacks: TouchpadCallback callbacks.onLongPressEnd() } maxPointers >= 2 -> if (moved) callbacks.onTwoFingerSwipe(displacement.x, displacement.y) else callbacks.onTwoFingerTap() - moved -> callbacks.onSwipe(displacement.x, displacement.y, duration) + moved -> callbacks.onSwipe(down.position, displacement.x, displacement.y, duration) else -> { // A plain tap; give a second tap a chance to make it a double. val second = withTimeoutOrNull(doubleTapTimeout) { awaitFirstDown() } @@ -108,6 +110,30 @@ suspend fun PointerInputScope.detectTouchpadGestures(callbacks: TouchpadCallback } } +/** + * Observe the button tray before its child buttons consume a pointer. A + * downward drag claims the gesture and dismisses the tray; a tap remains + * untouched so the button below receives its normal click. + */ +suspend fun PointerInputScope.detectTrayDismiss(onDismiss: () -> Unit) { + val slop = viewConfiguration.touchSlop + awaitEachGesture { + val down = awaitFirstDown(requireUnconsumed = false, pass = PointerEventPass.Initial) + var dismissed = false + while (true) { + val event = awaitPointerEvent(PointerEventPass.Initial) + val primary = event.changes.firstOrNull { it.id == down.id } ?: event.changes.first() + val displacement = primary.position - down.position + if (!dismissed && displacement.y > slop && displacement.y >= abs(displacement.x)) { + dismissed = true + onDismiss() + } + if (dismissed) event.changes.forEach { it.consume() } + if (event.changes.none { it.pressed }) break + } + } +} + /** Poll interval while a hold or drag is in progress (no timeout semantics needed). */ private const val HOLD_POLL_MS = 60_000L diff --git a/website/CNAME b/website/CNAME new file mode 100644 index 00000000..c248600c --- /dev/null +++ b/website/CNAME @@ -0,0 +1 @@ +faceclaw.org diff --git a/website/README.md b/website/README.md new file mode 100644 index 00000000..bc65a419 --- /dev/null +++ b/website/README.md @@ -0,0 +1,59 @@ +# faceclaw.org + +The Faceclaw website: plain HTML and one stylesheet, no build step and no +external dependencies. GitHub Actions publishes this directory to GitHub Pages +on every push to `main` that touches it (`.github/workflows/pages.yml`). + +## Layout + + index.html landing page + install.html install instructions + privacy.html privacy policy (body generated, see below) + style.css the whole stylesheet + content/ canonical copies of content shared with the repo root + images/ logo and favicon, derived from ../images/FaceclawAppIcon.png + screenshots/ glasses captures, also used by the root README + CNAME custom domain + +## Shared content + +Two things appear both here and in the repository root, and are generated +rather than copied by hand: + +| Source | Destinations | +| --------------------------- | ------------------------------------- | +| `content/features.md` | `README.md`, `index.html` | +| `../PRIVACY` | `privacy.html` | + +Edit the source, then run: + + node scripts/sync-site.mjs + +Each destination has a `` / `` +pair; the script rewrites what is between them and leaves the rest alone. CI +runs `node scripts/sync-site.mjs --check` and fails the deploy if a +destination is stale. + +## Previewing + +Any static file server will do, since there is nothing to compile: + + python3 -m http.server -d website 8000 + +## Setting up the custom domain + +Publishing needs Settings > Pages > Source set to "GitHub Actions". For +`faceclaw.org`, point the apex at GitHub's Pages addresses: + + A faceclaw.org 185.199.108.153 + A faceclaw.org 185.199.109.153 + A faceclaw.org 185.199.110.153 + A faceclaw.org 185.199.111.153 + AAAA faceclaw.org 2606:50c0:8000::153 + AAAA faceclaw.org 2606:50c0:8001::153 + AAAA faceclaw.org 2606:50c0:8002::153 + AAAA faceclaw.org 2606:50c0:8003::153 + CNAME www jimrandomh.github.io. + +Then set the custom domain in Settings > Pages and enable "Enforce HTTPS" +once the certificate has been issued. diff --git a/website/content/features.md b/website/content/features.md new file mode 100644 index 00000000..b59baa8d --- /dev/null +++ b/website/content/features.md @@ -0,0 +1,24 @@ + + +- **A voice assistant** that wakes up when you say "Hey Even", transcribes text with an on-device model, OpenAI Whisper, ElevenLabs, or Soniox API, and responds to queries and commands using an onboard model (Qwen3 4B, slow) or with an Anthropic or OpenAI model (requires an API key), or using your own long-running OpenClaw agent. +- **Multitasking**, with an app-switcher sidebar and app launcher. +- **Mostly-compatible with EvenHub apps.** +- **A lock screen**; glasses lock automatically when you take them off and unlock when you unlock your phone. +- **The full display.** Full-screen apps can use the full 640x480 display area, rather than the 576x288 that EvenHub apps can use. +- **Integration with Android notifications**: a top bar that shows the same icons your phone does, popups when notifications arrive, and menu items to dismiss or use Android-app-provided custom actions like mark as read or quick reply. +- **Terminal mirroring.** Mirror terminal apps such as Claude Code or Codex CLI with [g2mirror](https://github.com/jimrandomh/g2mirror), view them on the glasses, and send them inputs with the voice assistant. +- **Media player controls** including playlist and media library navigation, compatible with most Android media players. +- **Turn-by-turn directions** (requires a Mapbox API token). +- **Nightscout**, an app for viewing blood-glucose data (requires a cloud server and API token). +- **Power management**: the glasses go to sleep properly when the screen is off, and wake when you double-tap the ring or speak the wakeword, allowing battery life similar to the stock Even app. +- **Connection management** with auto-reconnect, and autodetection of conflict with the official Even Realities app. +- **A Wear OS watch app** that replaces (and outdoes) the R1 ring: tap, swipe, hold and crown gestures, side buttons, app launching and window switching, voice or keyboard queries to the assistant with the reply on your wrist, typing into apps, and glasses status/lock/display control. +- **On-phone screen mirroring with touch control**: tap what you see on the mirror (sidebar icons, launcher cells), or use the phone's own touchpad, d-pad and Back/Menu buttons — the same spatial scheme as the watch — plus a compact ring simulator. A display-mode picker (576×288 band, 576×480 tall, or the full 640×480 panel with an auto-hiding sidebar) and a brightness slider with an Auto toggle sit beside the mirror. +- **Bluetooth pairing** that scans for nearby glasses and identifies each pair before connecting: model, frame shape, and colour decoded from the advertised serial (with product photos), left and right arms matched to each other by that serial, an estimated distance so the pair in your hand sorts first, and the optional R1 ring. +- **Dual-language NativeScript architecture**, with Java for the multithreaded Android API and bluetooth stack bits, Typescript for the bits you want to hack on. diff --git a/website/images/faceclaw-logo.png b/website/images/faceclaw-logo.png new file mode 100644 index 00000000..36053dff Binary files /dev/null and b/website/images/faceclaw-logo.png differ diff --git a/website/images/favicon.png b/website/images/favicon.png new file mode 100644 index 00000000..805cc0c0 Binary files /dev/null and b/website/images/favicon.png differ diff --git a/website/index.html b/website/index.html new file mode 100644 index 00000000..755c4dfb --- /dev/null +++ b/website/index.html @@ -0,0 +1,147 @@ + + + + + +Faceclaw — an unofficial interface for the Even Realities G2 + + + + + + + + + + + + +
+ +
+ +
+ +
+
+ +

Faceclaw

+

An unofficial user interface for the Even Realities G2 smart glasses. Apps, a voice assistant, notifications and a watch remote — running from your Android phone.

+ +
+
+ +
+
+
+

Unofficial

+

Faceclaw is not made by, endorsed by, or supported by Even Realities. It comes with no warranty from them or from anyone. It runs on Android, and it requires installing custom firmware on the glasses — the app can install and uninstall that firmware for you, downloading the stock firmware from Even and applying patches generated from g2flash.

+
+
+
+ +
+
+

What it looks like

+
+
+ The Faceclaw app launcher on the glasses display +
The app launcher, with the app-switcher sidebar on the left.
+
+
+ The music player on the glasses display +
Media controls, working with most Android media players.
+
+
+ Assistant settings on the glasses display +
Assistant settings, edited on the glasses themselves.
+
+
+ Display settings on the glasses display +
Display settings, including height and vertical position.
+
+
+
+
+ +
+
+

Features

+ +
    +
  • A voice assistant that wakes up when you say "Hey Even", transcribes text with an on-device model, OpenAI Whisper, ElevenLabs, or Soniox API, and responds to queries and commands using an onboard model (Qwen3 4B, slow) or with an Anthropic or OpenAI model (requires an API key), or using your own long-running OpenClaw agent.
  • +
  • Multitasking, with an app-switcher sidebar and app launcher.
  • +
  • Mostly-compatible with EvenHub apps.
  • +
  • A lock screen; glasses lock automatically when you take them off and unlock when you unlock your phone.
  • +
  • The full display. Full-screen apps can use the full 640x480 display area, rather than the 576x288 that EvenHub apps can use.
  • +
  • Integration with Android notifications: a top bar that shows the same icons your phone does, popups when notifications arrive, and menu items to dismiss or use Android-app-provided custom actions like mark as read or quick reply.
  • +
  • Terminal mirroring. Mirror terminal apps such as Claude Code or Codex CLI with g2mirror, view them on the glasses, and send them inputs with the voice assistant.
  • +
  • Media player controls including playlist and media library navigation, compatible with most Android media players.
  • +
  • Turn-by-turn directions (requires a Mapbox API token).
  • +
  • Nightscout, an app for viewing blood-glucose data (requires a cloud server and API token).
  • +
  • Power management: the glasses go to sleep properly when the screen is off, and wake when you double-tap the ring or speak the wakeword, allowing battery life similar to the stock Even app.
  • +
  • Connection management with auto-reconnect, and autodetection of conflict with the official Even Realities app.
  • +
  • A Wear OS watch app that replaces (and outdoes) the R1 ring: tap, swipe, hold and crown gestures, side buttons, app launching and window switching, voice or keyboard queries to the assistant with the reply on your wrist, typing into apps, and glasses status/lock/display control.
  • +
  • On-phone screen mirroring with touch control: tap what you see on the mirror (sidebar icons, launcher cells), or use the phone's own touchpad, d-pad and Back/Menu buttons — the same spatial scheme as the watch — plus a compact ring simulator. A display-mode picker (576×288 band, 576×480 tall, or the full 640×480 panel with an auto-hiding sidebar) and a brightness slider with an Auto toggle sit beside the mirror.
  • +
  • Bluetooth pairing that scans for nearby glasses and identifies each pair before connecting: model, frame shape, and colour decoded from the advertised serial (with product photos), left and right arms matched to each other by that serial, an estimated distance so the pair in your hand sorts first, and the optional R1 ring.
  • +
  • Dual-language NativeScript architecture, with Java for the multithreaded Android API and bluetooth stack bits, Typescript for the bits you want to hack on.
  • +
+ +
+
+ +
+
+

Beyond the glasses

+
+
+

Watch remote

+

A Wear OS companion app turns the whole watch face into a touchpad that outdoes the R1 ring: swipes, crown scrolling, side buttons, app launching, and spoken or typed queries with the reply on your wrist.

+
+
+

EvenHub apps

+

Faceclaw runs EvenHub apps through an emulation layer. Install them from the Hub, or sideload your own by opening an .ehpk file on your phone.

+
+
+

Your own agent

+

Instead of calling an LLM API from the phone, the assistant can route queries to your own long-running OpenClaw agent, which also gets access to the glasses' tools.

+
+
+
+
+ +
+
+

Contributing

+

Be bold. Modify Faceclaw into the app that you want it to be for yourself, without worrying about whether other people will like your version — then, if you think your changes might be useful to others, open a pull request. Faceclaw is Free Software under the GPLv3. See the contributing notes for what to test before you send a change.

+
+
+ +
+ + + + + diff --git a/website/install.html b/website/install.html new file mode 100644 index 00000000..66323def --- /dev/null +++ b/website/install.html @@ -0,0 +1,80 @@ + + + + + +Install — Faceclaw + + + + + + +
+ +
+ +
+
+
+

Installing Faceclaw

+ +
+

Read this first

+

Faceclaw is unofficial and unsupported, and it replaces the firmware on your glasses. Installing it means running code that Even Realities did not write and will not help you with. The app can put the stock firmware back, but you are doing this at your own risk.

+
+ +

What you need

+
    +
  • A pair of Even Realities G2 glasses.
  • +
  • An Android phone. Faceclaw runs as a background app and talks to the glasses over Bluetooth LE.
  • +
  • Optionally, a Wear OS 3+ watch, if you want the watch remote instead of the R1 ring.
  • +
+

There is no iOS version, and there will not be one — the app depends on Android APIs for background Bluetooth, notification access and media control.

+ +

Install the app

+

Faceclaw is not on the Play Store. Download the most recent APK from the releases page and open it on your phone; Android will ask you to allow installing apps from that source.

+ +

Install the firmware

+

Faceclaw needs custom firmware on the glasses, and installs it for you. On first run, the onboarding flow will offer to download the stock firmware from Even Realities, apply the g2flash patches locally, and flash the result. You confirm the flash on the glasses themselves.

+

Onboarding also offers a preview-only path, which connects to unmodified glasses so you can look around before committing. Faceclaw can restore the stock firmware later from the same screens.

+ +

Grant permissions

+

Android does not reliably prompt for everything Faceclaw uses. After installing, go to Settings → Apps → Faceclaw and check that permissions are granted — notification access and Bluetooth in particular — or parts of the app will silently do nothing.

+

Also exempt Faceclaw from battery optimization. Being a background app on a locked Android phone is fraught, and manufacturer-specific battery software may pause it or throttle it to low CPU usage.

+ +

Optional extras

+
    +
  • Watch remote. The Wear OS app is a separate Gradle build in wear/, sideloaded over adb; it needs no Play Store, but the phone side requires Google Play services.
  • +
  • API keys. The voice assistant needs a model provider key (Anthropic or OpenAI), cloud transcription needs a key for OpenAI Whisper, ElevenLabs or Soniox, and turn-by-turn directions need a Mapbox token. On-device transcription needs no key.
  • +
  • Terminal mirroring. Install g2mirror on the machine whose terminal you want to see.
  • +
  • External agent. To route assistant queries to your own long-running agent, install the faceclaw-agent-bridge OpenClaw plugin; setup lives in that repository's README.
  • +
+ +

Building from source

+

Faceclaw is a NativeScript app written in TypeScript and Java, and builds with an Android SDK 35 environment and a JDK 21. The README has the current build and adb instructions; they are kept there rather than duplicated here, so they stay in step with the code.

+
+
+
+ +
+
+ +

Faceclaw is Free Software, licensed under the GPLv3. It is unofficial, and is not affiliated with Even Realities.

+
+
+ + + diff --git a/website/privacy.html b/website/privacy.html new file mode 100644 index 00000000..3cd84806 --- /dev/null +++ b/website/privacy.html @@ -0,0 +1,80 @@ + + + + + +Privacy policy — Faceclaw + + + + + + +
+ +
+ +
+
+
+ +

Faceclaw Privacy Policy

+

Faceclaw is a privacy-conscious app. The developers of Faceclaw don't collect or store user data. Faceclaw does integrate with some third-party services, which have their own privacy policies; this document describes what those services are, what they're used for and what data they collect, and links to their privacy policies.

+

Audio

+

Faceclaw allows users to transcribe audio (for use with the voice assistant, the Transcribe app, typing into Terminal, and other apps). The default setting is that this is done using an on-device model running on your phone. If an on-device model is selected, audio never leaves your device, and is not stored after it is processed.

+

Users can also provide their own API key for a third-party transcription service such as OpenAI Whisper, ElevenLabs, or Soniox, which may offer better accuracy. Faceclaw never transmits audio to any party other than a user-selected transcription service. If a third-party transcription service is selected, audio will be sent to that third party, is linked to the account with which that API key was created, and is subject to that party's privacy and retention policies:

+ +

Third party data retention and privacy policies may differ based on the API key provided. API keys are part of a relationship between the user and the API provider; Faceclaw does not manage accounts or process billing information.

+

AI Assistant Transcripts

+

Faceclaw has a builtin AI voice assistant. Using the voice assistant requires providing an API key for a model provider such as Anthropic or OpenAI. Prompts and responses are subject to that model provider's privacy policy:

+ +

AI conversation histories and memory files may be stored on your phone. Faceclaw does not transmit voice-assistant prompts or responses to any party other than a user-selected AI model provider. The voice assistant is given tools with which it is able to access most things on the user's phone, including all content displayed on the glasses, location, notifications, and content accessible through the Terminal app.

+

The AI assistant can take actions on the user's behalf, including sharing any information it has access to. The user is responsible for any instructions they give it.

+

Location

+

Faceclaw has a builtin Navigate app, which provides turn-by-turn directions. Using the Navigate app requires providing an API key for Mapbox. While the Navigate app is active, the user's exact location and selected destination are transmitted to Mapbox, and are subject to Mapbox's privacy policy.

+ +

The Weather app will retrieve the user's coarse location, and will use it to query a third-party weather information provider.

+

EvenHub

+

The EvenHub app store is subject to Even Realities' privacy policy: https://support.evenrealities.com/hc/en-us/articles/14127464826511-Privacy-Policy. Apps downloaded from the EvenHub app store come with their own privacy policies.

+

Wear OS Watch

+

The optional Faceclaw watch app (wear/) talks to the phone over Google Play services' Wearable Data Layer, the same channel the watch uses for notifications and other companion apps. Gestures, commands, the watch's own speech-recognition results, and the mirrored glasses status and assistant replies travel between your watch and your phone over their Bluetooth (or, when paired that way, Wi-Fi) link; Faceclaw does not send any of it to a server. Speech recognized on the watch uses the watch's system speech recognizer, which may send audio to Google under Google's privacy policy:

+ +

The phone does nothing watch-related on phones without Google Play services.

+ +

This page is generated from the PRIVACY file in the Faceclaw repository, which is the authoritative copy.

+
+
+
+ + + + + diff --git a/screenshots/launcher.png b/website/screenshots/launcher.png similarity index 100% rename from screenshots/launcher.png rename to website/screenshots/launcher.png diff --git a/screenshots/music-player.png b/website/screenshots/music-player.png similarity index 100% rename from screenshots/music-player.png rename to website/screenshots/music-player.png diff --git a/screenshots/settings-assistant.png b/website/screenshots/settings-assistant.png similarity index 100% rename from screenshots/settings-assistant.png rename to website/screenshots/settings-assistant.png diff --git a/screenshots/settings-display.png b/website/screenshots/settings-display.png similarity index 100% rename from screenshots/settings-display.png rename to website/screenshots/settings-display.png diff --git a/website/style.css b/website/style.css new file mode 100644 index 00000000..e067c5e5 --- /dev/null +++ b/website/style.css @@ -0,0 +1,178 @@ +/* Faceclaw website. Hand-written, no build step, no external assets. */ + +:root { + --bg: #0d1226; + --bg-raised: #141b38; + --line: #26305a; + --fg: #e9ecf7; + --fg-dim: #98a1c4; + --accent: #f5c531; + --accent-warm: #e8503a; + --lens: #000; + --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace; + --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; +} + +* { box-sizing: border-box; } + +body { + margin: 0; + background: var(--bg); + color: var(--fg); + font: 16px/1.65 var(--sans); + -webkit-font-smoothing: antialiased; +} + +.wrap { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 24px; } + +a { color: var(--accent); text-decoration-color: rgba(245, 197, 49, 0.4); text-underline-offset: 2px; } +a:hover { text-decoration-color: var(--accent); } + +h1, h2, h3 { line-height: 1.2; letter-spacing: -0.015em; } +h2 { font-size: 1.5rem; margin: 0 0 16px; } +h3 { font-size: 1.05rem; margin: 0 0 8px; } +p { margin: 0 0 16px; } + +code, kbd { font-family: var(--mono); font-size: 0.9em; } +code { + background: var(--bg-raised); + border: 1px solid var(--line); + border-radius: 4px; + padding: 1px 5px; +} +pre { + background: var(--bg-raised); + border: 1px solid var(--line); + border-radius: 8px; + padding: 14px 16px; + overflow-x: auto; + margin: 0 0 16px; +} +pre code { background: none; border: 0; padding: 0; } + +/* ---- site chrome ---- */ + +.topbar { + border-bottom: 1px solid var(--line); + position: sticky; + top: 0; + background: rgba(13, 18, 38, 0.9); + backdrop-filter: blur(8px); + z-index: 10; +} +.topbar .wrap { display: flex; align-items: center; gap: 20px; height: 56px; } +.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; color: var(--fg); text-decoration: none; } +.brand img { width: 22px; height: 22px; } +.topbar nav { margin-left: auto; display: flex; gap: 20px; font-size: 0.94rem; } +.topbar nav a { color: var(--fg-dim); text-decoration: none; } +.topbar nav a:hover, .topbar nav a[aria-current="page"] { color: var(--fg); } + +section { padding: 56px 0; border-top: 1px solid var(--line); } +section:first-of-type { border-top: 0; } + +footer { + border-top: 1px solid var(--line); + padding: 32px 0 56px; + color: var(--fg-dim); + font-size: 0.9rem; +} +footer a { color: var(--fg-dim); } +footer .links { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 12px; } + +/* ---- hero ---- */ + +.hero { text-align: center; padding: 72px 0 56px; } +.hero img.logo { width: 104px; height: 104px; } +.hero h1 { font-size: clamp(2.2rem, 6vw, 3.1rem); margin: 18px 0 10px; } +.hero .tagline { font-size: 1.2rem; color: var(--fg-dim); max-width: 34em; margin: 0 auto 28px; } + +.buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; } +.btn { + display: inline-block; + padding: 11px 22px; + border-radius: 8px; + border: 1px solid var(--line); + font-weight: 600; + text-decoration: none; + color: var(--fg); +} +.btn:hover { border-color: var(--fg-dim); } +.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1400; } +.btn.primary:hover { background: #ffd44f; border-color: #ffd44f; } + +.eyebrow { + font-family: var(--mono); + font-size: 0.78rem; + letter-spacing: 0.08em; + text-transform: uppercase; + color: var(--accent-warm); +} + +/* ---- callout ---- */ + +.callout { + border: 1px solid var(--line); + border-left: 3px solid var(--accent-warm); + border-radius: 8px; + background: var(--bg-raised); + padding: 16px 20px; + margin: 0 0 24px; +} +.callout p:last-child { margin-bottom: 0; } + +/* ---- screenshots ---- */ + +.shots { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; } +.shot { margin: 0; } +.shot img { + display: block; + width: 100%; + background: var(--lens); + border: 1px solid var(--line); + border-radius: 6px; + image-rendering: pixelated; +} +.shot figcaption { color: var(--fg-dim); font-size: 0.88rem; margin-top: 8px; } + +/* ---- features ---- */ + +.features { list-style: none; padding: 0; margin: 0; columns: 2; column-gap: 40px; } +.features li { + break-inside: avoid; + margin: 0 0 18px; + padding-left: 20px; + position: relative; + color: var(--fg-dim); +} +.features li::before { content: "▸"; position: absolute; left: 0; color: var(--accent); } +.features li strong { color: var(--fg); font-weight: 600; } + +/* ---- cards ---- */ + +.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; } +.card { + border: 1px solid var(--line); + border-radius: 10px; + background: var(--bg-raised); + padding: 20px; +} +.card p { color: var(--fg-dim); font-size: 0.94rem; margin: 0; } + +/* ---- long-form prose (privacy, install) ---- */ + +.prose { max-width: 44em; } +.prose h2 { margin-top: 40px; padding-top: 8px; } +.prose h2:first-child { margin-top: 0; } +.prose ul { padding-left: 22px; } +.prose li { margin-bottom: 6px; } +.prose ul.links { list-style: none; padding-left: 0; font-family: var(--mono); font-size: 0.88rem; } +.prose ul.links li { margin-bottom: 4px; } +.prose .meta { color: var(--fg-dim); font-size: 0.9rem; } + +@media (max-width: 700px) { + .shots { grid-template-columns: 1fr; } + .features { columns: 1; } + .cards { grid-template-columns: 1fr; } + .topbar nav { gap: 14px; } + section { padding: 40px 0; } +}