Refactor (move some files around)

This commit is contained in:
James Babcock committed 2026-05-13 20:38:58 -07:00
1 parent bcb162ecaf
commit ef6cb3bf55
13 files changed
+10 -10

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
import { EventData, Page } from "@nativescript/core";
import { ConfigViewModel } from "./config-view-model";
export function navigatingTo(args: EventData): void {
const page = args.object as Page;
page.bindingContext = new ConfigViewModel();
}
+38
View File
@@ -0,0 +1,38 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
<ActionBar title="Configure Devices" />
<GridLayout rows="auto,auto,auto,auto,auto,auto,auto,*" class="p-20">
<Label row="0" text="Configure the MAC addresses for the G2 headset arms and optional R1 ring. This page does not test a connection." textWrap="true" />
<StackLayout row="1" class="m-t-16">
<Label text="Right arm MAC" />
<TextField text="{{ rightAddress }}" textChange="{{ onRightAddressTextChange }}" autocorrect="false" autocapitalizationType="none" />
</StackLayout>
<StackLayout row="2" class="m-t-12">
<Label text="Left arm MAC" />
<TextField text="{{ leftAddress }}" textChange="{{ onLeftAddressTextChange }}" autocorrect="false" autocapitalizationType="none" />
</StackLayout>
<StackLayout row="3" class="m-t-12">
<Label text="R1 ring MAC (optional)" />
<TextField text="{{ ringAddress }}" textChange="{{ onRingAddressTextChange }}" autocorrect="false" autocapitalizationType="none" />
</StackLayout>
<GridLayout row="4" columns="*,*" class="m-t-16">
<Button col="0" text="Load paired devices" tap="{{ onLoadPairedTap }}" class="-primary" isEnabled="{{ canDiscover }}" />
<Button col="1" text="Scan nearby" tap="{{ onScanTap }}" class="-primary" isEnabled="{{ canDiscover }}" />
</GridLayout>
<Label row="5" text="{{ status }}" class="m-t-16" textWrap="true" />
<GridLayout row="6" columns="*,*" class="m-t-16">
<Button col="0" text="Save" tap="{{ onSaveTap }}" class="-primary" />
<Button col="1" text="Back" tap="{{ onBackTap }}" />
</GridLayout>
<ScrollView row="7" class="m-t-16">
<Label text="{{ discoveryLog }}" textWrap="true" verticalAlignment="top" />
</ScrollView>
</GridLayout>
</Page>
+174
View File
@@ -0,0 +1,174 @@
import { Frame, Observable } from "@nativescript/core";
import { ensureBlePermissions } from "../g2/android-permissions";
import { isValidMacAddress, loadDeviceAddresses, normalizeMacAddress, saveDeviceAddresses } from "../g2/device-addresses";
import { buildAddressSet, DeviceDiscoveryBridge } from "../native/device-discovery";
type TextChangeArgs = { value?: string; object?: { text?: string } };
export class ConfigViewModel extends Observable {
private readonly discovery = new DeviceDiscoveryBridge();
private _rightAddress = "";
private _leftAddress = "";
private _ringAddress = "";
private _status = "";
private _discoveryLog = "";
private _discovering = false;
constructor() {
super();
const stored = loadDeviceAddresses();
this.rightAddress = stored.right;
this.leftAddress = stored.left;
this.ringAddress = stored.ring;
this.status = "Edit addresses manually, or load them from paired devices or a scan.";
}
get rightAddress(): string {
return this._rightAddress;
}
set rightAddress(value: string) {
if (this._rightAddress !== value) {
this._rightAddress = value;
this.notifyPropertyChange("rightAddress", value);
}
}
get leftAddress(): string {
return this._leftAddress;
}
set leftAddress(value: string) {
if (this._leftAddress !== value) {
this._leftAddress = value;
this.notifyPropertyChange("leftAddress", value);
}
}
get ringAddress(): string {
return this._ringAddress;
}
set ringAddress(value: string) {
if (this._ringAddress !== value) {
this._ringAddress = value;
this.notifyPropertyChange("ringAddress", value);
}
}
get status(): string {
return this._status;
}
set status(value: string) {
if (this._status !== value) {
this._status = value;
this.notifyPropertyChange("status", value);
}
}
get discoveryLog(): string {
return this._discoveryLog;
}
set discoveryLog(value: string) {
if (this._discoveryLog !== value) {
this._discoveryLog = value;
this.notifyPropertyChange("discoveryLog", value);
}
}
get canDiscover(): boolean {
return !this._discovering;
}
private setDiscovering(value: boolean): void {
if (this._discovering !== value) {
this._discovering = value;
this.notifyPropertyChange("canDiscover", this.canDiscover);
}
}
onRightAddressTextChange(args: TextChangeArgs): void {
this.rightAddress = args.object?.text ?? args.value ?? "";
}
onLeftAddressTextChange(args: TextChangeArgs): void {
this.leftAddress = args.object?.text ?? args.value ?? "";
}
onRingAddressTextChange(args: TextChangeArgs): void {
this.ringAddress = args.object?.text ?? args.value ?? "";
}
async onLoadPairedTap(): Promise<void> {
await this.populateFromDiscovery(async () => this.discovery.getBondedCandidates(), "Loaded paired devices.");
}
async onScanTap(): Promise<void> {
await this.populateFromDiscovery(async () => this.discovery.scanCandidates(6000), "Scanned nearby devices.");
}
onBackTap(): void {
Frame.topmost()?.navigate({
moduleName: "phone-ui/main-page",
clearHistory: true,
});
}
onSaveTap(): void {
const right = normalizeMacAddress(this.rightAddress);
const left = normalizeMacAddress(this.leftAddress);
const ring = normalizeMacAddress(this.ringAddress);
if (!isValidMacAddress(right)) {
this.status = "Right arm MAC address is invalid.";
return;
}
if (!isValidMacAddress(left)) {
this.status = "Left arm MAC address is invalid.";
return;
}
if (!isValidMacAddress(ring, true)) {
this.status = "Ring MAC address is invalid.";
return;
}
saveDeviceAddresses({ right, left, ring });
this.rightAddress = right;
this.leftAddress = left;
this.ringAddress = ring;
this.status = "Saved device addresses.";
}
private async populateFromDiscovery(
load: () => Promise<Parameters<typeof buildAddressSet>[0]>,
successMessage: string,
): Promise<void> {
if (!global.isAndroid) {
this.status = "Discovery is only available on Android.";
return;
}
this.setDiscovering(true);
try {
await ensureBlePermissions();
const candidates = await load();
const selection = buildAddressSet(candidates);
if (selection.right) this.rightAddress = selection.right;
if (selection.left) this.leftAddress = selection.left;
if (selection.ring) this.ringAddress = selection.ring;
this.discoveryLog = selection.summary;
this.status = successMessage;
} catch (error) {
this.status = this.formatError(error);
} finally {
this.setDiscovering(false);
}
}
private formatError(error: unknown): string {
const raw = (error as Error)?.message ?? String(error);
return raw.replace(/[\x00-\x1f]+/g, " ").replace(/\s+/g, " ").trim();
}
}
+14
View File
@@ -0,0 +1,14 @@
import { EventData, Frame, Page } from "@nativescript/core";
import { hasCompletedOnboarding } from "./onboarding-state";
export function navigatingTo(args: EventData): void {
const page = args.object as Page;
page.on(Page.loadedEvent, () => {
Frame.topmost()?.navigate({
moduleName: hasCompletedOnboarding() ? "phone-ui/main-page" : "phone-ui/onboarding-page",
clearHistory: true,
animated: false,
});
});
}
+3
View File
@@ -0,0 +1,3 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" actionBarHidden="true">
<GridLayout />
</Page>
+133
View File
@@ -0,0 +1,133 @@
import { Color, EventData, isAndroid, Observable, Page, ScrollView, TextField } from '@nativescript/core'
import { MainViewModel } from './main-view-model'
import { dashboardController } from '../g2/dashboard-controller'
const SETTINGS_TEXT_COLOR = new Color('#222222')
const SETTINGS_BACKGROUND_COLOR = new Color('#ffffff')
const SETTINGS_PLACEHOLDER_COLOR = new Color('#666666')
export function navigatingTo(args: EventData) {
const page = <Page>args.object
page.bindingContext = new MainViewModel()
}
type MainPageState = {
isPinnedToBottom: boolean
scrollHandler: () => void
propertyChangeHandler: (args: EventData & { propertyName?: string }) => void
}
function getPageState(page: Page): MainPageState | undefined {
return (page as Page & { __mainPageState?: MainPageState }).__mainPageState
}
function setPageState(page: Page, state?: MainPageState): void {
;(page as Page & { __mainPageState?: MainPageState }).__mainPageState = state
}
function cleanupPage(page: Page): void {
const state = getPageState(page)
const model = page.bindingContext as MainViewModel | null
const scrollView = page.getViewById<ScrollView>('logScrollView')
if (!state || !model || !scrollView) {
setPageState(page, undefined)
return
}
scrollView.off(ScrollView.scrollEvent, state.scrollHandler)
model.off(Observable.propertyChangeEvent, state.propertyChangeHandler)
setPageState(page, undefined)
}
function isAtBottom(scrollView: ScrollView): boolean {
return scrollView.scrollableHeight <= 0 || scrollView.verticalOffset >= scrollView.scrollableHeight - 8
}
function scrollToBottom(scrollView: ScrollView): void {
setTimeout(() => {
scrollView.scrollToVerticalOffset(scrollView.scrollableHeight, false)
}, 0)
}
function applySettingsTextFieldContrast(textField: TextField): void {
textField.color = SETTINGS_TEXT_COLOR
textField.backgroundColor = SETTINGS_BACKGROUND_COLOR
textField.placeholderColor = SETTINGS_PLACEHOLDER_COLOR
if (!isAndroid) {
return
}
const nativeTextField = (textField as TextField & { nativeView?: android.widget.EditText }).nativeView
if (!nativeTextField) {
return
}
nativeTextField.setTextColor(android.graphics.Color.rgb(34, 34, 34))
nativeTextField.setHintTextColor(android.graphics.Color.rgb(102, 102, 102))
}
function focusSystemNameField(page: Page): void {
setTimeout(() => {
const textField = page.getViewById<TextField>('settingsTextField')
if (textField) {
applySettingsTextFieldContrast(textField)
}
textField?.focus()
}, 0)
}
export function loaded(args: EventData) {
const page = args.object as Page
cleanupPage(page)
dashboardController.refreshEvenAppStatus()
const model = page.bindingContext as MainViewModel | null
const scrollView = page.getViewById<ScrollView>('logScrollView')
const settingsTextField = page.getViewById<TextField>('settingsTextField')
if (settingsTextField) {
applySettingsTextFieldContrast(settingsTextField)
}
if (!model || !scrollView) {
return
}
const state: MainPageState = {
isPinnedToBottom: true,
scrollHandler: () => {
state.isPinnedToBottom = isAtBottom(scrollView)
},
propertyChangeHandler: (propertyArgs) => {
if (propertyArgs.propertyName === 'showLog') {
if (model.showLog) {
state.isPinnedToBottom = true
scrollToBottom(scrollView)
}
return
}
if (propertyArgs.propertyName === 'activeTextSettingEditorKind') {
if (model.isTextSettingEditorActive) {
focusSystemNameField(page)
}
return
}
if (propertyArgs.propertyName !== 'log') {
return
}
if (state.isPinnedToBottom) {
scrollToBottom(scrollView)
}
},
}
scrollView.on(ScrollView.scrollEvent, state.scrollHandler)
model.on(Observable.propertyChangeEvent, state.propertyChangeHandler)
setPageState(page, state)
scrollToBottom(scrollView)
if (model.isTextSettingEditorActive) {
focusSystemNameField(page)
}
}
export function unloaded(args: EventData) {
cleanupPage(args.object as Page)
}
+46
View File
@@ -0,0 +1,46 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" loaded="loaded" unloaded="unloaded">
<ActionBar title="Faceclaw">
<ActionItem text="{{ buttonLabel }}" tap="{{ onTap }}" isEnabled="{{ canRun }}" android.position="popup" />
<ActionItem text="Configure devices" tap="{{ onConfigureTap }}" isEnabled="{{ canRun }}" android.position="popup" />
<ActionItem text="{{ showLogMenuLabel }}" tap="{{ onToggleLogTap }}" android.position="popup" />
</ActionBar>
<GridLayout rows="auto,*">
<StackLayout row="0" visibility="{{ displayPreviewVisibility }}">
<Image src="{{ displayPreview }}" stretch="fill" height="{{ displayPreviewHeight }}" />
</StackLayout>
<GridLayout row="1" rows="auto,auto,auto,*" class="p-20">
<StackLayout row="0" class="m-b-8" visibility="{{ evenAppConflictWarningVisibility }}">
<Label text="{{ evenAppConflictMessage }}" textWrap="true" />
<Button text="Open Even app settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary" />
</StackLayout>
<StackLayout row="1">
<GridLayout rows="auto,auto,auto" columns="*,*,*" class="m-t-8">
<Button row="0" col="1" text="Swipe up" tap="{{ onSyntheticUpTap }}" />
<Button row="1" col="0" text="Double-click" tap="{{ onSyntheticLeftTap }}" />
<Button row="1" col="2" text="Click" tap="{{ onSyntheticRightTap }}" />
<Button row="2" col="1" text="Swipe down" tap="{{ onSyntheticDownTap }}" />
</GridLayout>
</StackLayout>
<Label row="2" text="{{ status }}" class="m-t-16" textWrap="true" />
<ScrollView id="logScrollView" row="3" class="m-t-16" visibility="{{ showLogVisibility }}">
<Label text="{{ log }}" textWrap="true" verticalAlignment="top" />
</ScrollView>
</GridLayout>
<StackLayout
row="0"
class="system-name-modal"
visibility="{{ textSettingEditorVisibility }}"
horizontalAlignment="stretch"
verticalAlignment="top">
<Label text="{{ activeTextSettingTitle }}" />
<TextField
id="settingsTextField"
text="{{ activeTextSettingValue }}"
textChange="{{ onTextSettingTextChange }}"
autocorrect="false"
autocapitalizationType="words"
returnKeyType="done" />
</StackLayout>
</GridLayout>
</Page>
+296
View File
@@ -0,0 +1,296 @@
import { Frame, ImageSource, Observable, Screen } from "@nativescript/core";
import { dashboardController, type TextSettingEditorKind } from "../g2/dashboard-controller";
export class MainViewModel extends Observable {
private _status = "Disconnected.";
private _log = "";
private _displayPreview: ImageSource | null = null;
private _systemCardName = "Faceclaw";
private _editingSystemCardName = false;
private _activeTextSettingEditorKind: TextSettingEditorKind | null = null;
private _activeTextSettingTitle = "";
private _activeTextSettingValue = "";
private _evenAppConflictMessage = "";
private _evenAppConflictWarningVisible = false;
private _showLog = false;
private _phase: "disconnected" | "connecting" | "connected" | "disconnecting" = "disconnected";
constructor() {
super();
dashboardController.subscribe((snapshot) => {
this.status = snapshot.status;
this.log = snapshot.log;
this.displayPreview = snapshot.displayPreview;
this.phase = snapshot.phase;
this.systemCardName = snapshot.systemCardName;
this.editingSystemCardName = snapshot.editingSystemCardName;
this.activeTextSettingEditorKind = snapshot.activeTextSettingEditorKind;
this.activeTextSettingTitle = snapshot.activeTextSettingTitle;
this.activeTextSettingValue = snapshot.activeTextSettingValue;
this.evenAppConflictMessage = snapshot.evenAppConflictMessage;
this.evenAppConflictWarningVisible = snapshot.evenAppConflictWarningVisible;
});
}
get status(): string {
return this._status;
}
set status(value: string) {
if (this._status !== value) {
this._status = value;
this.notifyPropertyChange("status", value);
}
}
get log(): string {
return this._log;
}
set log(value: string) {
if (this._log !== value) {
this._log = value;
this.notifyPropertyChange("log", value);
}
}
get displayPreview(): ImageSource | null {
return this._displayPreview;
}
set displayPreview(value: ImageSource | null) {
if (this._displayPreview !== value) {
this._displayPreview = value;
this.notifyPropertyChange("displayPreview", value);
this.notifyPropertyChange("hasDisplayPreview", this.hasDisplayPreview);
this.notifyPropertyChange("displayPreviewVisibility", this.displayPreviewVisibility);
}
}
get hasDisplayPreview(): boolean {
return this._displayPreview !== null;
}
get displayPreviewVisibility(): "visible" | "collapse" {
return this.hasDisplayPreview ? "visible" : "collapse";
}
get displayPreviewHeight(): number {
return Screen.mainScreen.widthDIPs / 2;
}
get showLog(): boolean {
return this._showLog;
}
set showLog(value: boolean) {
if (this._showLog !== value) {
this._showLog = value;
this.notifyPropertyChange("showLog", value);
this.notifyPropertyChange("showLogVisibility", this.showLogVisibility);
this.notifyPropertyChange("showLogMenuLabel", this.showLogMenuLabel);
}
}
get showLogVisibility(): "visible" | "collapse" {
return this._showLog ? "visible" : "collapse";
}
get showLogMenuLabel(): string {
return this._showLog ? "Hide Log" : "Show Log";
}
get systemCardName(): string {
return this._systemCardName;
}
set systemCardName(value: string) {
if (this._systemCardName !== value) {
this._systemCardName = value;
this.notifyPropertyChange("systemCardName", value);
}
}
get editingSystemCardName(): boolean {
return this._editingSystemCardName;
}
set editingSystemCardName(value: boolean) {
if (this._editingSystemCardName !== value) {
this._editingSystemCardName = value;
this.notifyPropertyChange("editingSystemCardName", value);
this.notifyPropertyChange("systemCardNameEditorVisibility", this.systemCardNameEditorVisibility);
}
}
get systemCardNameEditorVisibility(): "visible" | "collapse" {
return this._editingSystemCardName ? "visible" : "collapse";
}
get activeTextSettingEditorKind(): TextSettingEditorKind | null {
return this._activeTextSettingEditorKind;
}
set activeTextSettingEditorKind(value: TextSettingEditorKind | null) {
if (this._activeTextSettingEditorKind !== value) {
this._activeTextSettingEditorKind = value;
this.notifyPropertyChange("activeTextSettingEditorKind", value);
this.notifyPropertyChange("textSettingEditorVisibility", this.textSettingEditorVisibility);
this.notifyPropertyChange("isTextSettingEditorActive", this.isTextSettingEditorActive);
}
}
get activeTextSettingTitle(): string {
return this._activeTextSettingTitle;
}
set activeTextSettingTitle(value: string) {
if (this._activeTextSettingTitle !== value) {
this._activeTextSettingTitle = value;
this.notifyPropertyChange("activeTextSettingTitle", value);
}
}
get activeTextSettingValue(): string {
return this._activeTextSettingValue;
}
set activeTextSettingValue(value: string) {
if (this._activeTextSettingValue !== value) {
this._activeTextSettingValue = value;
this.notifyPropertyChange("activeTextSettingValue", value);
}
}
get isTextSettingEditorActive(): boolean {
return this._activeTextSettingEditorKind !== null;
}
get textSettingEditorVisibility(): "visible" | "collapse" {
return this.isTextSettingEditorActive ? "visible" : "collapse";
}
get evenAppConflictMessage(): string {
return this._evenAppConflictMessage;
}
set evenAppConflictMessage(value: string) {
if (this._evenAppConflictMessage !== value) {
this._evenAppConflictMessage = value;
this.notifyPropertyChange("evenAppConflictMessage", value);
}
}
get evenAppConflictWarningVisible(): boolean {
return this._evenAppConflictWarningVisible;
}
set evenAppConflictWarningVisible(value: boolean) {
if (this._evenAppConflictWarningVisible !== value) {
this._evenAppConflictWarningVisible = value;
this.notifyPropertyChange("evenAppConflictWarningVisible", value);
this.notifyPropertyChange("evenAppConflictWarningVisibility", this.evenAppConflictWarningVisibility);
}
}
get evenAppConflictWarningVisibility(): "visible" | "collapse" {
return this._evenAppConflictWarningVisible ? "visible" : "collapse";
}
get phase(): "disconnected" | "connecting" | "connected" | "disconnecting" {
return this._phase;
}
set phase(value: "disconnected" | "connecting" | "connected" | "disconnecting") {
if (this._phase !== value) {
this._phase = value;
this.notifyPropertyChange("phase", value);
this.notifyPropertyChange("buttonLabel", this.buttonLabel);
this.notifyPropertyChange("canRun", this.canRun);
}
}
get buttonLabel(): string {
switch (this.phase) {
case "connecting":
return "Connecting...";
case "connected":
return "Disconnect";
case "disconnecting":
return "Disconnecting...";
default:
return "Connect";
}
}
get canRun(): boolean {
return this.phase !== "connecting" && this.phase !== "disconnecting";
}
async onTap(): Promise<void> {
if (!this.canRun) return;
try {
if (this.phase === "connected") {
await dashboardController.disconnect();
} else {
await dashboardController.connect();
}
} catch (error) {
const message = this.formatError(error);
if (!this.status.startsWith("Failed:")) {
this.status = `Failed: ${message}`;
this.appendLog(`error: ${message}`);
}
}
}
onConfigureTap(): void {
if (!this.canRun) return;
Frame.topmost()?.navigate("phone-ui/config-page");
}
onToggleLogTap(): void {
this.showLog = !this.showLog;
}
onSystemCardNameTextChange(args: { value?: string; object?: { text?: string } }): void {
dashboardController.setSystemCardName(args.object?.text ?? args.value ?? "");
}
onTextSettingTextChange(args: { value?: string; object?: { text?: string } }): void {
dashboardController.setActiveTextSettingValue(args.object?.text ?? args.value ?? "");
}
onOpenEvenAppSettingsTap(): void {
dashboardController.openEvenAppSettings();
}
async onSyntheticUpTap(): Promise<void> {
await dashboardController.injectSyntheticRingInput("scroll-up");
}
async onSyntheticDownTap(): Promise<void> {
await dashboardController.injectSyntheticRingInput("scroll-down");
}
async onSyntheticLeftTap(): Promise<void> {
await dashboardController.injectSyntheticRingInput("double-click");
}
async onSyntheticRightTap(): Promise<void> {
await dashboardController.injectSyntheticRingInput("click");
}
private appendLog(line: string): void {
const stamp = new Date().toISOString().slice(11, 19);
this.log = this.log ? `${this.log}\n[${stamp}] ${line}` : `[${stamp}] ${line}`;
}
private formatError(error: unknown): string {
const raw = (error as Error)?.message ?? String(error);
const sanitized = raw.replace(/[\x00-\x1f]+/g, " ").replace(/\s+/g, " ").trim();
if (sanitized.length <= 240) return sanitized;
return `${sanitized.slice(0, 237)}...`;
}
}
+8
View File
@@ -0,0 +1,8 @@
import { EventData, Page } from "@nativescript/core";
import { OnboardingViewModel } from "./onboarding-view-model";
export function navigatingTo(args: EventData): void {
const page = args.object as Page;
page.bindingContext = new OnboardingViewModel();
}
+17
View File
@@ -0,0 +1,17 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" actionBarHidden="true">
<GridLayout rows="*,auto" class="p-20">
<ScrollView row="0">
<StackLayout>
<Image src="res://logo" stretch="aspectFit" height="140" horizontalAlignment="center" visibility="{{ logoVisibility }}" class="m-t-24" />
<Label text="{{ headline }}" class="h1 text-center m-t-24" textWrap="true" />
<Label text="{{ tagline }}" class="text-center m-t-8" textWrap="true" visibility="{{ taglineVisibility }}" />
<Label text="{{ body }}" class="m-t-24" textWrap="true" />
</StackLayout>
</ScrollView>
<GridLayout row="1" columns="*,*" class="m-t-20">
<Button col="0" text="{{ secondaryLabel }}" tap="{{ onSecondaryTap }}" visibility="{{ secondaryVisibility }}" />
<Button col="1" text="{{ primaryLabel }}" tap="{{ onPrimaryTap }}" class="-primary" />
</GridLayout>
</GridLayout>
</Page>
+11
View File
@@ -0,0 +1,11 @@
import { ApplicationSettings } from "@nativescript/core";
const ONBOARDING_COMPLETE_KEY = "onboarding.complete";
export function hasCompletedOnboarding(): boolean {
return ApplicationSettings.getBoolean(ONBOARDING_COMPLETE_KEY, false);
}
export function setOnboardingCompleted(completed: boolean): void {
ApplicationSettings.setBoolean(ONBOARDING_COMPLETE_KEY, completed);
}
+150
View File
@@ -0,0 +1,150 @@
import { Frame, Observable } from "@nativescript/core";
import { setOnboardingCompleted } from "./onboarding-state";
type OnboardingStep = 1 | 2 | 3;
type StepContent = {
headline: string;
tagline: string;
body: string;
primaryLabel: string;
secondaryLabel: string;
showLogo: boolean;
showTagline: boolean;
showSecondary: boolean;
};
const STEP_CONTENT: Record<OnboardingStep, StepContent> = {
1: {
headline: "Faceclaw",
tagline: "Perching on the faces of giants",
body: "",
primaryLabel: "Next",
secondaryLabel: "",
showLogo: true,
showTagline: 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",
showLogo: false,
showTagline: false,
showSecondary: true,
},
3: {
headline: "Disconnect Even First",
tagline: "",
body:
"You can switch back and forth between Faceclaw and the official Even Realities application at any time. However, they can't both be connected to the headset simultaneously. The Even app will reconnect to the glasses whenever you launch it. To disconnect the official Even app, open it, go to the Home tab, select your glasses, open the Connection submenu, and press Disconnect.",
primaryLabel: "Configure",
secondaryLabel: "Back",
showLogo: false,
showTagline: false,
showSecondary: true,
},
};
export class OnboardingViewModel extends Observable {
private _step: OnboardingStep = 1;
constructor() {
super();
this.publish();
}
onPrimaryTap(): void {
if (this._step === 1) {
this.setStep(2);
return;
}
if (this._step === 2) {
this.setStep(3);
return;
}
setOnboardingCompleted(true);
Frame.topmost()?.navigate({
moduleName: "phone-ui/config-page",
clearHistory: true,
});
}
onSecondaryTap(): void {
if (this._step === 2) {
this.setStep(1);
return;
}
if (this._step === 3) {
this.setStep(2);
}
}
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 showLogo(): boolean {
return STEP_CONTENT[this._step].showLogo;
}
get showTagline(): boolean {
return STEP_CONTENT[this._step].showTagline;
}
get showSecondary(): boolean {
return STEP_CONTENT[this._step].showSecondary;
}
get logoVisibility(): "visible" | "collapse" {
return this.showLogo ? "visible" : "collapse";
}
get taglineVisibility(): "visible" | "collapse" {
return this.showTagline ? "visible" : "collapse";
}
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("showLogo", this.showLogo);
this.notifyPropertyChange("showTagline", this.showTagline);
this.notifyPropertyChange("showSecondary", this.showSecondary);
this.notifyPropertyChange("logoVisibility", this.logoVisibility);
this.notifyPropertyChange("taglineVisibility", this.taglineVisibility);
this.notifyPropertyChange("secondaryVisibility", this.secondaryVisibility);
}
}