Files
faceclaw/app/phone-ui/onboarding-view-model.ts
T
James Babcock 97fad7ae2b Add Permissions screen to the onboarding flow, replacing scattered permissions prompts happening later
<details>
<summary>Prompts Used</summary>
Let's add a Permissions screen, to concentrate the various Android permissions requests. This will be shown during onboarding, in between the "Before You Continue" screen and the "Custom Firmware Required" screen. There will also be a "Permissions" menu item in the main screen menu.

Each permission will be a card, styled similarly to the device-selection cards on the Pair Your Glasses screen. Each card will have the title for the permission, some text explaining what the permission is used for, and a checkmark if the permission is already present. The permissions needed are:

Nearby Devices: Needed to communicate with your smart glasses over bluetooth
Send Notifications: A notification will be pinned, to keep Faceclaw running while your phone screen is off.
Battery Optimization: Needed to keep running while your phone screen is off.
Read Notifications: (Optional) Needed to display your Android notification on the glasses.
Microphone: (Optional) Needed to use voice input.
Location: (Optional) Needed to use location-based features like navigation inside glasses apps.
Calendar: (Optional) Needed to display your calendar on the glasses.

> Done — the Permissions screen is in place, builds cleanly, and all the permissions it requests were already declared in the manifest.
>
> **What was added:**
>
> - **New screen** (`app/phone-ui/permissions-page.{xml,ts}` + `permissions-view-model.ts`): one card per permission, reusing the pairing page's card styling (`pairing-row`, `pairing-title`, `pairing-badge`) so they match the device-selection cards. Each card shows the title, the explanation text you specified, and a green ✓ when granted. Tapping an ungranted card launches its grant flow; granted cards ignore taps. The four optional permissions get an "Optional" badge (matching the pairing page's badge style) instead of a "(Optional)" text prefix.
> - **Onboarding wiring**: "Agree" on Before You Continue now navigates to the permissions page, and its "Next" button navigates forward to a fresh onboarding page starting at the Custom Firmware Required step (`onboarding-page.ts` now accepts a `step` context; `OnboardingViewModel` takes an initial step). "Back" returns to the disclaimer.
> - **Main menu**: a "Permissions" popup item on the main page opens the same screen in standalone mode — action bar shown, single "Done" button.
> - **Permission plumbing** (`app/g2/android-permissions.ts`): new granular helpers — `hasBlePermissions`/`requestBlePermissions` (BLE only, split out of the old combined BLE+notifications request), `hasPostNotificationsPermission`/`requestPostNotificationsPermission` (reports granted pre-Android 13, where no runtime permission exists), and `hasMicrophonePermission`/`requestMicrophonePermission`. Existing `ensureBlePermissions` behavior is unchanged for its current callers.
>
> Two of the cards — Battery Optimization and Read Notifications — aren't runtime permissions; they open system screens (the existing `battery-optimization.ts` and `notification-access.ts` natives). Since Android reports their state only on return, the page re-checks all statuses on `Application.resume` (listener attached on page load, detached on unload) so checkmarks appear when you come back.
>
> Two judgment calls worth flagging: the Location checkmark tracks **fine** location (navigation needs precise fixes — "approximate only" leaves it unchecked and re-tappable), and I wrote "your Android notifications" (plural) in the Read Notifications card. This is all hardware-test pending, as usual — the flows to exercise are onboarding step 2 → Permissions → step 3, each card's grant dialog, and the resume-refresh after the battery/notification-access settings detours.
<hr>
Thanks. Let's make it so that the Continue button looks grayed out if you haven't selected all of the required permissions. It will still be active in this case, but will open a "You haven't enabled all of the necessary permissions. Are you sure you want to continue?" prompt. Also, let's add 8px of extra margin between the permission titles and the Optional badge.

> Both changes are in and the build passes.
>
> - **Grayed-out Continue**: the onboarding primary button now binds a `primaryClass` — while any of the three required permissions (Nearby Devices, Send Notifications, Battery Optimization) is missing, it gets a `permissions-primary-dimmed` class (opacity 0.45) so it looks disabled while staying tappable. Tapping it in that state shows a confirm dialog — "You haven't enabled all of the necessary permissions. Are you sure you want to continue?" with Continue/Go Back buttons — and only proceeds to the firmware step on Continue. The class re-evaluates on every refresh, so granting the last required permission un-dims the button immediately. I also renamed the onboarding label from "Next" to "Continue" to match how you referred to it (and the pairing page's onboarding button). Menu mode's "Done" never dims, since there's nothing to warn about when just closing the screen.
> - **Badge spacing**: the "Optional" badge's left margin went from the `m-l-6` class to an explicit `marginLeft="14"` (+8), set inline since the theme doesn't generate an `m-l-14` class.
</details>
2026-08-25 11:28:53 -07:00

161 lines
5.8 KiB
TypeScript

import { Frame, Observable, Screen } from "@nativescript/core";
import { setOnboardingCompleted, setPreviewOnlyMode } from "./onboarding-state";
type OnboardingStep = 1 | 2 | 3;
type StepContent = {
headline: string;
tagline: string;
body: string;
primaryLabel: string;
secondaryLabel: string;
/** Step 1 renders as the vertically-centered splash (headline + tagline + logo) instead of the scrolling body. */
splash: boolean;
showSecondary: boolean;
};
const STEP_CONTENT: Record<OnboardingStep, StepContent> = {
1: {
headline: "Faceclaw",
tagline: "Perching on the faces of giants",
body: "",
primaryLabel: "Next",
secondaryLabel: "",
splash: true,
showSecondary: false,
},
2: {
headline: "Before You Continue",
tagline: "",
body:
"This unofficial software provides a custom user interface and functionality for the Even Realities G2 smart glasses. It is not created or supported by Even Realities. If this software somehow breaks my headset, this is not Even's fault and is not covered by the hardware's warranty. If this software doesn't break my headset, using this software may void the hardware's warranty anyways, at the sole discretion of Even Realities. This software is a development prototype and may not be relied on for anything important. This software may be broken at any time by software or firmware updates created by Even, and this will not be Even's fault.",
primaryLabel: "Agree",
secondaryLabel: "Back",
splash: false,
showSecondary: true,
},
3: {
headline: "Custom Firmware Required",
tagline: "",
body:
"Faceclaw only runs on Even Realities G2 glasses that have Faceclaw's custom firmware installed. You have two choices:\n\n• Preview Only — explore Faceclaw's interface on your phone's screen without pairing any glasses. Nothing is written to a headset.\n\n• Flash Firmware — install the custom firmware on your glasses now, then use Faceclaw for real. Faceclaw first scans for nearby glasses so you can pick yours by model, colour, and serial, then connects, asks for confirmation on the lens, and downloads and prepares the firmware.\n\nFlashing replaces the official firmware. It may void your warranty and, like any firmware update, carries a risk of bricking the device. You can only be connected to one app at a time, so disconnect the official Even app before flashing (open it, go to Home, select your glasses, open Connection, and press Disconnect).",
primaryLabel: "Flash Firmware",
secondaryLabel: "Preview Only",
splash: false,
showSecondary: true,
},
};
export class OnboardingViewModel extends Observable {
private _step: OnboardingStep = 1;
constructor(initialStep?: number) {
super();
if (initialStep === 2 || initialStep === 3) this._step = initialStep;
this.publish();
}
onPrimaryTap(): void {
if (this._step === 1) {
this.setStep(2);
return;
}
if (this._step === 2) {
// The Permissions screen sits between the disclaimer and the firmware
// step; it navigates forward to a fresh onboarding page at step 3.
Frame.topmost()?.navigate({
moduleName: "phone-ui/permissions-page",
context: { onboarding: true },
});
return;
}
// Step 3 primary: begin the flashing setup — scan for and pick the glasses
// (manual address entry is offered from that page), then unpair the
// official app, then check firmware and flash.
Frame.topmost()?.navigate({
moduleName: "phone-ui/pairing-page",
context: { onboarding: true },
});
}
onSecondaryTap(): void {
if (this._step === 2) {
this.setStep(1);
return;
}
if (this._step === 3) {
// Step 3 secondary: skip flashing, use the on-phone preview only.
setPreviewOnlyMode(true);
setOnboardingCompleted(true);
Frame.topmost()?.navigate({
moduleName: "phone-ui/main-page",
clearHistory: true,
});
}
}
get headline(): string {
return STEP_CONTENT[this._step].headline;
}
get tagline(): string {
return STEP_CONTENT[this._step].tagline;
}
get body(): string {
return STEP_CONTENT[this._step].body;
}
get primaryLabel(): string {
return STEP_CONTENT[this._step].primaryLabel;
}
get secondaryLabel(): string {
return STEP_CONTENT[this._step].secondaryLabel;
}
get showSecondary(): boolean {
return STEP_CONTENT[this._step].showSecondary;
}
get splashVisibility(): "visible" | "collapse" {
return STEP_CONTENT[this._step].splash ? "visible" : "collapse";
}
get contentVisibility(): "visible" | "collapse" {
return STEP_CONTENT[this._step].splash ? "collapse" : "visible";
}
/**
* The logo scales with the screen (~40% of its height) so it reads as a
* splash on tablets too, capped near the source PNG's height so it doesn't
* upscale into mush.
*/
get logoHeight(): number {
return Math.min(480, Math.round(Screen.mainScreen.heightDIPs * 0.4));
}
get secondaryVisibility(): "visible" | "collapse" {
return this.showSecondary ? "visible" : "collapse";
}
private setStep(step: OnboardingStep): void {
if (this._step === step) return;
this._step = step;
this.publish();
}
private publish(): void {
this.notifyPropertyChange("headline", this.headline);
this.notifyPropertyChange("tagline", this.tagline);
this.notifyPropertyChange("body", this.body);
this.notifyPropertyChange("primaryLabel", this.primaryLabel);
this.notifyPropertyChange("secondaryLabel", this.secondaryLabel);
this.notifyPropertyChange("showSecondary", this.showSecondary);
this.notifyPropertyChange("splashVisibility", this.splashVisibility);
this.notifyPropertyChange("contentVisibility", this.contentVisibility);
this.notifyPropertyChange("secondaryVisibility", this.secondaryVisibility);
}
}