forked from Blendman974/faceclaw
Merge branch 'main' of https://github.com/jimrandomh/faceclaw into android-wear-integration
This commit is contained in:
commit
b33d858fbc
22 files changed
+578
-87
No files matched your search
@@ -4,8 +4,8 @@ import { ConfigViewModel } from "./config-view-model";
|
||||
|
||||
export function navigatingTo(args: NavigatedData): void {
|
||||
const page = args.object as Page;
|
||||
// Preserve the model across back-navigation (returning from the unpair page)
|
||||
// so the onboarding "Continue" flow isn't lost.
|
||||
// Preserve the model across back-navigation (returning from the firmware
|
||||
// check page) so the onboarding "Continue" flow isn't lost.
|
||||
if (!page.bindingContext) {
|
||||
const context = (args.context as { onboarding?: boolean } | undefined) ?? undefined;
|
||||
page.bindingContext = new ConfigViewModel({ onboarding: context?.onboarding ?? false });
|
||||
|
||||
@@ -232,8 +232,8 @@ export class ConfigViewModel extends Observable {
|
||||
return;
|
||||
}
|
||||
if (this.onboarding) {
|
||||
// Continue the onboarding chain: unpair the official app next.
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-unpair-page" });
|
||||
// Continue the onboarding chain: check the glasses' firmware next.
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-firmware-check-page" });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Frame, NavigatedData, Page, knownFolders } from "@nativescript/core";
|
||||
|
||||
/** Phone-side viewer for the project docs that webpack.config.js copies into
|
||||
* the bundle under about/ (LICENSE, PRIVACY, ...). The glasses-side
|
||||
* equivalent lives in ui/dashboard/settings-menus.ts. */
|
||||
type DocumentContext = { fileName?: string; title?: string } | undefined;
|
||||
|
||||
export function navigatingTo(args: NavigatedData): void {
|
||||
const page = args.object as Page;
|
||||
const context = args.context as DocumentContext;
|
||||
const fileName = context?.fileName ?? "";
|
||||
page.bindingContext = {
|
||||
title: context?.title ?? fileName,
|
||||
text: readBundledDoc(fileName),
|
||||
onBackTap: () => Frame.topmost()?.goBack(),
|
||||
};
|
||||
}
|
||||
|
||||
function readBundledDoc(fileName: string): string {
|
||||
try {
|
||||
const text = knownFolders.currentApp().getFile(`about/${fileName}`).readTextSync();
|
||||
return text || `(${fileName} is missing from this build)`;
|
||||
} catch {
|
||||
return `(${fileName} is missing from this build)`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo">
|
||||
<ActionBar title="{{ title }}">
|
||||
<NavigationButton android.systemIcon="ic_menu_back" tap="{{ onBackTap }}" />
|
||||
</ActionBar>
|
||||
|
||||
<ScrollView>
|
||||
<Label text="{{ text }}" textWrap="true" class="document-text p-16" />
|
||||
</ScrollView>
|
||||
</Page>
|
||||
@@ -3,6 +3,7 @@
|
||||
<ActionItem text="{{ buttonLabel }}" tap="{{ onTap }}" isEnabled="{{ connectItemEnabled }}" android.position="popup" />
|
||||
<ActionItem text="Pair glasses" tap="{{ onPairGlassesTap }}" isEnabled="{{ canRun }}" android.position="popup" />
|
||||
<ActionItem text="Configure devices" tap="{{ onConfigureTap }}" isEnabled="{{ canRun }}" android.position="popup" />
|
||||
<ActionItem text="Permissions" tap="{{ onPermissionsTap }}" android.position="popup" />
|
||||
<ActionItem text="Take screenshot" tap="{{ onTakeScreenshotTap }}" android.position="popup" />
|
||||
<ActionItem text="Record screen" tap="{{ onRecordScreenTap }}" android.position="popup" />
|
||||
<ActionItem text="Uninstall custom firmware" tap="{{ onUninstallFirmwareTap }}" isEnabled="{{ canRun }}" android.position="popup" />
|
||||
|
||||
@@ -536,6 +536,13 @@ export class MainViewModel extends Observable {
|
||||
Frame.topmost()?.navigate("phone-ui/config-page");
|
||||
}
|
||||
|
||||
onPermissionsTap(): void {
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/permissions-page",
|
||||
context: { onboarding: false },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Live scan that names each nearby pair by model, colour, and serial and
|
||||
* checks both arms belong together. A connected arm stops advertising, so
|
||||
|
||||
@@ -125,7 +125,11 @@ export class OnboardingFirmwareCheckViewModel extends Observable {
|
||||
frame.goBack();
|
||||
return;
|
||||
}
|
||||
frame?.navigate({ moduleName: "phone-ui/onboarding-unpair-page", clearHistory: true });
|
||||
frame?.navigate({
|
||||
moduleName: "phone-ui/pairing-page",
|
||||
context: { onboarding: true },
|
||||
clearHistory: true,
|
||||
});
|
||||
}
|
||||
|
||||
/** Escape hatch when the check itself fails: flash as if stock firmware had been detected. */
|
||||
|
||||
@@ -253,7 +253,7 @@ export class OnboardingFlashViewModel extends Observable {
|
||||
|
||||
private startCommunicator(addresses: { right: string; left: string }): void {
|
||||
this.disposePrompt();
|
||||
const prompt = new FlashPromptCommunicator(addresses, this.glassesWarning);
|
||||
const prompt = new FlashPromptCommunicator(addresses.right, this.glassesWarning);
|
||||
this.prompt = prompt;
|
||||
|
||||
this.promptUnsubscribers.push(
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
import { EventData, Page } from "@nativescript/core";
|
||||
import { NavigatedData, Page } from "@nativescript/core";
|
||||
|
||||
import { OnboardingViewModel } from "./onboarding-view-model";
|
||||
|
||||
export function navigatingTo(args: EventData): void {
|
||||
type OnboardingContext = { step?: number } | undefined;
|
||||
|
||||
export function navigatingTo(args: NavigatedData): void {
|
||||
const page = args.object as Page;
|
||||
// Preserve the step when returning from the flashing page (back navigation
|
||||
// re-fires navigatingTo); only build a fresh model on first entry.
|
||||
// re-fires navigatingTo); only build a fresh model on first entry. The
|
||||
// permissions page navigates here with { step: 3 } to continue the flow.
|
||||
if (!page.bindingContext) {
|
||||
page.bindingContext = new OnboardingViewModel();
|
||||
const context = args.context as OnboardingContext;
|
||||
page.bindingContext = new OnboardingViewModel(context?.step);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" actionBarHidden="true">
|
||||
<GridLayout rows="*,auto" class="p-20">
|
||||
<GridLayout rows="*,auto,auto" class="p-20">
|
||||
<StackLayout row="0" verticalAlignment="middle" visibility="{{ splashVisibility }}">
|
||||
<Label text="{{ headline }}" class="h1 text-center" textWrap="true" />
|
||||
<Label text="{{ tagline }}" class="body-text text-center m-t-8" textWrap="true" />
|
||||
@@ -13,7 +13,13 @@
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
|
||||
<GridLayout row="1" columns="*,*" class="m-t-20">
|
||||
<StackLayout row="1" orientation="horizontal" horizontalAlignment="center" class="m-t-16" visibility="{{ footerVisibility }}">
|
||||
<Label text="License (GPLv3)" class="footer-link" tap="{{ onLicenseTap }}" />
|
||||
<Label text="·" class="footer-link-separator" />
|
||||
<Label text="Privacy Policy" class="footer-link" tap="{{ onPrivacyTap }}" />
|
||||
</StackLayout>
|
||||
|
||||
<GridLayout row="2" columns="*,*" class="m-t-20">
|
||||
<Button col="0" text="{{ secondaryLabel }}" tap="{{ onSecondaryTap }}" visibility="{{ secondaryVisibility }}" />
|
||||
<Button col="1" text="{{ primaryLabel }}" tap="{{ onPrimaryTap }}" class="-primary" />
|
||||
</GridLayout>
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
<GridLayout rows="*,auto" class="p-20">
|
||||
<ScrollView row="0">
|
||||
<StackLayout>
|
||||
<Label text="Disconnect the Even App" class="h1 text-center m-t-24" textWrap="true" />
|
||||
<Label text="Disconnect Other Apps" class="h1 text-center m-t-24" textWrap="true" />
|
||||
<Label
|
||||
text="Faceclaw and the official Even Realities app can't both be connected to the glasses at once. Before continuing, open the Even app, go to Home, select your glasses, open the Connection submenu, and press Disconnect (or turn off the Even app's Bluetooth)."
|
||||
text="Faceclaw and the official Even Realities app can't both be connected to the glasses at once. Before continuing, open the Even app, go to Home, select your glasses, open the Connection submenu, and press Disconnect (or turn off the Even app's Bluetooth). If any other glasses app is installed (such as Mentra), disconnect it too."
|
||||
class="body-text m-t-24" textWrap="true" />
|
||||
<Button text="Open Even App Settings" tap="{{ onOpenEvenAppSettingsTap }}" class="-primary m-t-24" />
|
||||
<Button text="Open Even App Settings" tap="{{ onOpenEvenAppSettingsTap }}" width="{{ settingsButtonWidth }}" horizontalAlignment="center" class="-primary m-t-24" />
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Frame, Observable } from "@nativescript/core";
|
||||
import { Frame, Observable, Screen } from "@nativescript/core";
|
||||
|
||||
import { openEvenAppSettings } from "../native/even-app-conflict";
|
||||
|
||||
@@ -8,7 +8,10 @@ export class OnboardingUnpairViewModel extends Observable {
|
||||
}
|
||||
|
||||
onContinueTap(): void {
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-firmware-check-page" });
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/pairing-page",
|
||||
context: { onboarding: true },
|
||||
});
|
||||
}
|
||||
|
||||
onBackTap(): void {
|
||||
@@ -18,9 +21,17 @@ export class OnboardingUnpairViewModel extends Observable {
|
||||
return;
|
||||
}
|
||||
frame?.navigate({
|
||||
moduleName: "phone-ui/pairing-page",
|
||||
context: { onboarding: true },
|
||||
moduleName: "phone-ui/onboarding-page",
|
||||
context: { step: 3 },
|
||||
clearHistory: true,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The settings button fills the page's width on phones but is capped so it
|
||||
* doesn't stretch edge-to-edge on tablets.
|
||||
*/
|
||||
get settingsButtonWidth(): number {
|
||||
return Math.min(320, Math.round(Screen.mainScreen.widthDIPs) - 40);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ const STEP_CONTENT: Record<OnboardingStep, StepContent> = {
|
||||
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).",
|
||||
"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 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. The glasses can only be connected to one app at a time, so the next step will walk you through disconnecting the official Even app (and any other glasses apps) first.",
|
||||
primaryLabel: "Flash Firmware",
|
||||
secondaryLabel: "Preview Only",
|
||||
splash: false,
|
||||
@@ -50,8 +50,9 @@ const STEP_CONTENT: Record<OnboardingStep, StepContent> = {
|
||||
export class OnboardingViewModel extends Observable {
|
||||
private _step: OnboardingStep = 1;
|
||||
|
||||
constructor() {
|
||||
constructor(initialStep?: number) {
|
||||
super();
|
||||
if (initialStep === 2 || initialStep === 3) this._step = initialStep;
|
||||
this.publish();
|
||||
}
|
||||
|
||||
@@ -61,15 +62,33 @@ export class OnboardingViewModel extends Observable {
|
||||
return;
|
||||
}
|
||||
if (this._step === 2) {
|
||||
this.setStep(3);
|
||||
// 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.
|
||||
// Step 3 primary: begin the flashing setup — disconnect other glasses apps
|
||||
// first (a connected app blocks our BLE access, including pairing), then
|
||||
// scan for and pick the glasses (manual address entry is offered from that
|
||||
// page), then check firmware and flash.
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-unpair-page" });
|
||||
}
|
||||
|
||||
onLicenseTap(): void {
|
||||
this.openDocument("LICENSE", "License (GPLv3)");
|
||||
}
|
||||
|
||||
onPrivacyTap(): void {
|
||||
this.openDocument("PRIVACY", "Privacy Policy");
|
||||
}
|
||||
|
||||
private openDocument(fileName: string, title: string): void {
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/pairing-page",
|
||||
context: { onboarding: true },
|
||||
moduleName: "phone-ui/document-page",
|
||||
context: { fileName, title },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -134,6 +153,11 @@ export class OnboardingViewModel extends Observable {
|
||||
return this.showSecondary ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
/** License and privacy-policy links, shown only under the disclaimer step. */
|
||||
get footerVisibility(): "visible" | "collapse" {
|
||||
return this._step === 2 ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
private setStep(step: OnboardingStep): void {
|
||||
if (this._step === step) return;
|
||||
this._step = step;
|
||||
@@ -150,5 +174,6 @@ export class OnboardingViewModel extends Observable {
|
||||
this.notifyPropertyChange("splashVisibility", this.splashVisibility);
|
||||
this.notifyPropertyChange("contentVisibility", this.contentVisibility);
|
||||
this.notifyPropertyChange("secondaryVisibility", this.secondaryVisibility);
|
||||
this.notifyPropertyChange("footerVisibility", this.footerVisibility);
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,9 @@ type PairingContext = { onboarding?: boolean } | undefined;
|
||||
|
||||
export function navigatingTo(args: NavigatedData): void {
|
||||
const page = args.object as Page;
|
||||
// Preserve the model across back-navigation (returning from the unpair or
|
||||
// manual-entry pages) so the selection isn't lost; the model restarts its
|
||||
// scan on re-entry.
|
||||
// Preserve the model across back-navigation (returning from the firmware
|
||||
// check or manual-entry pages) so the selection isn't lost; the model
|
||||
// restarts its scan on re-entry.
|
||||
let model = page.bindingContext as PairingViewModel | undefined;
|
||||
if (!model) {
|
||||
const context = args.context as PairingContext;
|
||||
|
||||
@@ -333,8 +333,8 @@ export class PairingViewModel extends Observable {
|
||||
this.dispose();
|
||||
if (this.onboarding) {
|
||||
setPreviewOnlyMode(false);
|
||||
// Continue the onboarding chain: unpair the official app next.
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-unpair-page" });
|
||||
// Continue the onboarding chain: check the glasses' firmware next.
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/onboarding-firmware-check-page" });
|
||||
return;
|
||||
}
|
||||
Frame.topmost()?.navigate({ moduleName: "phone-ui/main-page", clearHistory: true });
|
||||
@@ -348,7 +348,7 @@ export class PairingViewModel extends Observable {
|
||||
return;
|
||||
}
|
||||
frame?.navigate({
|
||||
moduleName: this.onboarding ? "phone-ui/onboarding-page" : "phone-ui/main-page",
|
||||
moduleName: this.onboarding ? "phone-ui/onboarding-unpair-page" : "phone-ui/main-page",
|
||||
clearHistory: true,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { EventData, NavigatedData, Page } from "@nativescript/core";
|
||||
|
||||
import { PermissionsViewModel } from "./permissions-view-model";
|
||||
|
||||
type PermissionsContext = { onboarding?: boolean } | undefined;
|
||||
|
||||
export function navigatingTo(args: NavigatedData): void {
|
||||
const page = args.object as Page;
|
||||
// Preserve the model when returning via back navigation (from the step-3
|
||||
// onboarding page); statuses are re-checked in the loaded handler.
|
||||
if (!page.bindingContext) {
|
||||
const context = args.context as PermissionsContext;
|
||||
page.bindingContext = new PermissionsViewModel({ onboarding: context?.onboarding ?? false });
|
||||
}
|
||||
}
|
||||
|
||||
export function loaded(args: EventData): void {
|
||||
const page = args.object as Page;
|
||||
(page.bindingContext as PermissionsViewModel | undefined)?.onPageLoaded();
|
||||
}
|
||||
|
||||
export function unloaded(args: EventData): void {
|
||||
const page = args.object as Page;
|
||||
(page.bindingContext as PermissionsViewModel | undefined)?.onPageUnloaded();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" loaded="loaded" unloaded="unloaded" actionBarHidden="{{ actionBarHidden }}">
|
||||
<ActionBar title="Permissions" />
|
||||
|
||||
<GridLayout rows="auto,*,auto" class="p-16">
|
||||
<StackLayout row="0">
|
||||
<Label text="Permissions" class="h1 text-center" textWrap="true" visibility="{{ headlineVisibility }}" />
|
||||
<Label text="{{ instructions }}" class="m-t-8 pairing-instructions" textWrap="true" />
|
||||
</StackLayout>
|
||||
|
||||
<ScrollView row="1" class="m-t-12">
|
||||
<StackLayout>
|
||||
<Repeater items="{{ cards }}">
|
||||
<Repeater.itemsLayout>
|
||||
<StackLayout />
|
||||
</Repeater.itemsLayout>
|
||||
<Repeater.itemTemplate>
|
||||
<GridLayout columns="*,auto" rows="auto" class="pairing-row" tap="{{ onCardTap }}">
|
||||
<StackLayout col="0">
|
||||
<GridLayout columns="auto,auto">
|
||||
<Label col="0" text="{{ title }}" class="pairing-title" />
|
||||
<Label col="1" text="Optional" class="pairing-badge" marginLeft="14" visibility="{{ optionalVisibility }}" />
|
||||
</GridLayout>
|
||||
<Label text="{{ description }}" class="permissions-description" textWrap="true" />
|
||||
</StackLayout>
|
||||
<Label col="1" text="✓" class="permissions-check" verticalAlignment="center" visibility="{{ checkVisibility }}" />
|
||||
</GridLayout>
|
||||
</Repeater.itemTemplate>
|
||||
</Repeater>
|
||||
</StackLayout>
|
||||
</ScrollView>
|
||||
|
||||
<GridLayout row="2" columns="*,*" class="m-t-12">
|
||||
<Button col="0" text="Back" tap="{{ onSecondaryTap }}" visibility="{{ secondaryVisibility }}" />
|
||||
<Button col="1" text="{{ primaryLabel }}" tap="{{ onPrimaryTap }}" class="{{ primaryClass }}" />
|
||||
</GridLayout>
|
||||
</GridLayout>
|
||||
</Page>
|
||||
@@ -0,0 +1,243 @@
|
||||
import { Application, Dialogs, EventData, Frame, Observable, View } from "@nativescript/core";
|
||||
|
||||
import {
|
||||
ensureCalendarPermission,
|
||||
ensureFineLocationPermission,
|
||||
hasBlePermissions,
|
||||
hasCalendarPermission,
|
||||
hasFineLocationPermission,
|
||||
hasMicrophonePermission,
|
||||
hasPostNotificationsPermission,
|
||||
requestBlePermissions,
|
||||
requestMicrophonePermission,
|
||||
requestPostNotificationsPermission,
|
||||
} from "../g2/android-permissions";
|
||||
import { isIgnoringBatteryOptimizations, requestIgnoreBatteryOptimizations } from "../native/battery-optimization";
|
||||
import { isNotificationListenerEnabled, requestNotificationListenerAccess } from "../native/notification-access";
|
||||
|
||||
type PermissionDefinition = {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
optional: boolean;
|
||||
isGranted: () => boolean;
|
||||
/** Show the grant UI: a runtime-permission dialog or a system settings screen. */
|
||||
request: () => void | Promise<unknown>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Battery Optimization and Read Notifications are not runtime permissions:
|
||||
* their request() opens a system screen, so the granted state can only be
|
||||
* re-checked when the app resumes (the page refreshes on Application.resume).
|
||||
*/
|
||||
const PERMISSIONS: PermissionDefinition[] = [
|
||||
{
|
||||
id: "nearby-devices",
|
||||
title: "Nearby Devices",
|
||||
description: "Needed to communicate with your smart glasses over Bluetooth.",
|
||||
optional: false,
|
||||
isGranted: hasBlePermissions,
|
||||
request: requestBlePermissions,
|
||||
},
|
||||
{
|
||||
id: "post-notifications",
|
||||
title: "Send Notifications",
|
||||
description: "A notification will be pinned, to keep Faceclaw running while your phone screen is off.",
|
||||
optional: false,
|
||||
isGranted: hasPostNotificationsPermission,
|
||||
request: requestPostNotificationsPermission,
|
||||
},
|
||||
{
|
||||
id: "battery-optimization",
|
||||
title: "Battery Optimization",
|
||||
description: "Needed to keep running while your phone screen is off.",
|
||||
optional: false,
|
||||
isGranted: isIgnoringBatteryOptimizations,
|
||||
request: requestIgnoreBatteryOptimizations,
|
||||
},
|
||||
{
|
||||
id: "read-notifications",
|
||||
title: "Read Notifications",
|
||||
description: "Needed to display your Android notifications on the glasses.",
|
||||
optional: true,
|
||||
isGranted: isNotificationListenerEnabled,
|
||||
request: requestNotificationListenerAccess,
|
||||
},
|
||||
{
|
||||
id: "microphone",
|
||||
title: "Microphone",
|
||||
description: "Needed to use voice input.",
|
||||
optional: true,
|
||||
isGranted: hasMicrophonePermission,
|
||||
request: requestMicrophonePermission,
|
||||
},
|
||||
{
|
||||
id: "location",
|
||||
title: "Location",
|
||||
description: "Needed to use location-based features like navigation inside glasses apps.",
|
||||
optional: true,
|
||||
// Navigation needs precise fixes, so the checkmark tracks fine location;
|
||||
// "approximate only" leaves the card unchecked and re-tappable.
|
||||
isGranted: hasFineLocationPermission,
|
||||
request: ensureFineLocationPermission,
|
||||
},
|
||||
{
|
||||
id: "calendar",
|
||||
title: "Calendar",
|
||||
description: "Needed to display your calendar on the glasses.",
|
||||
optional: true,
|
||||
isGranted: hasCalendarPermission,
|
||||
request: ensureCalendarPermission,
|
||||
},
|
||||
];
|
||||
|
||||
/** One Repeater card: the permission's copy plus the display-only fields the XML binds. */
|
||||
export type PermissionCardItem = {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
optionalVisibility: "visible" | "collapse";
|
||||
checkVisibility: "visible" | "collapse";
|
||||
onCardTap: (args: EventData) => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* The Permissions screen: one card per Android permission Faceclaw uses, with
|
||||
* a checkmark when it is already granted and tap-to-grant otherwise. Reached
|
||||
* both from onboarding (between the disclaimer and the firmware step) and from
|
||||
* the main-screen menu.
|
||||
*/
|
||||
export class PermissionsViewModel extends Observable {
|
||||
private readonly onboarding: boolean;
|
||||
private _cards: PermissionCardItem[] = [];
|
||||
private requesting = false;
|
||||
|
||||
constructor(options?: { onboarding?: boolean }) {
|
||||
super();
|
||||
this.onboarding = options?.onboarding ?? false;
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Battery Optimization and Read Notifications grant flows leave the app for
|
||||
* a system screen; re-check everything whenever the app comes back.
|
||||
*/
|
||||
private readonly onAppResume = (): void => this.refresh();
|
||||
|
||||
onPageLoaded(): void {
|
||||
Application.on(Application.resumeEvent, this.onAppResume);
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
onPageUnloaded(): void {
|
||||
Application.off(Application.resumeEvent, this.onAppResume);
|
||||
}
|
||||
|
||||
// --- observable properties -------------------------------------------------
|
||||
|
||||
get actionBarHidden(): boolean {
|
||||
return this.onboarding;
|
||||
}
|
||||
|
||||
get headlineVisibility(): "visible" | "collapse" {
|
||||
return this.onboarding ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
get instructions(): string {
|
||||
return this.onboarding
|
||||
? "Faceclaw uses these Android permissions. Tap a card to grant one; a checkmark means it is already granted. " +
|
||||
"Optional permissions can also be granted later, from the Permissions item in the main-screen menu."
|
||||
: "Tap a card to grant a permission; a checkmark means it is already granted.";
|
||||
}
|
||||
|
||||
get cards(): PermissionCardItem[] {
|
||||
return this._cards;
|
||||
}
|
||||
|
||||
get primaryLabel(): string {
|
||||
return this.onboarding ? "Continue" : "Done";
|
||||
}
|
||||
|
||||
/**
|
||||
* Continue looks grayed out (but stays tappable — tapping it asks for
|
||||
* confirmation instead) while a required permission is missing. Done, in
|
||||
* menu mode, never dims: there is nothing to warn about when closing.
|
||||
*/
|
||||
get primaryClass(): string {
|
||||
return this.onboarding && !this.requiredPermissionsGranted()
|
||||
? "-primary permissions-primary-dimmed"
|
||||
: "-primary";
|
||||
}
|
||||
|
||||
get secondaryVisibility(): "visible" | "collapse" {
|
||||
return this.onboarding ? "visible" : "collapse";
|
||||
}
|
||||
|
||||
// --- actions ---------------------------------------------------------------
|
||||
|
||||
// Arrow property: NativeScript fires XML event handlers with `this` bound to
|
||||
// the tapped view's bindingContext (the card item), not the view model.
|
||||
readonly onCardTap = (args: EventData): void => {
|
||||
const item = (args.object as View).bindingContext as PermissionCardItem | undefined;
|
||||
if (!item || this.requesting) return;
|
||||
const definition = PERMISSIONS.find((permission) => permission.id === item.id);
|
||||
if (!definition || definition.isGranted()) return;
|
||||
void this.requestPermission(definition);
|
||||
};
|
||||
|
||||
async onPrimaryTap(): Promise<void> {
|
||||
if (this.onboarding) {
|
||||
if (!this.requiredPermissionsGranted()) {
|
||||
const proceed = await Dialogs.confirm({
|
||||
title: "Missing Permissions",
|
||||
message: "You haven't enabled all of the necessary permissions. Are you sure you want to continue?",
|
||||
okButtonText: "Continue",
|
||||
cancelButtonText: "Go Back",
|
||||
});
|
||||
if (!proceed) return;
|
||||
}
|
||||
// Continue the onboarding chain at the Custom Firmware Required step.
|
||||
Frame.topmost()?.navigate({
|
||||
moduleName: "phone-ui/onboarding-page",
|
||||
context: { step: 3 },
|
||||
});
|
||||
return;
|
||||
}
|
||||
Frame.topmost()?.goBack();
|
||||
}
|
||||
|
||||
onSecondaryTap(): void {
|
||||
Frame.topmost()?.goBack();
|
||||
}
|
||||
|
||||
// --- rendering -------------------------------------------------------------
|
||||
|
||||
private async requestPermission(definition: PermissionDefinition): Promise<void> {
|
||||
this.requesting = true;
|
||||
try {
|
||||
await definition.request();
|
||||
} catch {
|
||||
// A denial simply leaves the card unchecked; the user can tap again.
|
||||
} finally {
|
||||
this.requesting = false;
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private requiredPermissionsGranted(): boolean {
|
||||
return PERMISSIONS.every((definition) => definition.optional || definition.isGranted());
|
||||
}
|
||||
|
||||
refresh(): void {
|
||||
this._cards = PERMISSIONS.map((definition) => ({
|
||||
id: definition.id,
|
||||
title: definition.title,
|
||||
description: definition.description,
|
||||
optionalVisibility: definition.optional ? "visible" : "collapse",
|
||||
checkVisibility: definition.isGranted() ? "visible" : "collapse",
|
||||
onCardTap: this.onCardTap,
|
||||
}));
|
||||
this.notifyPropertyChange("cards", this._cards);
|
||||
this.notifyPropertyChange("primaryClass", this.primaryClass);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user