mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
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>
This commit is contained in:
1 parent
ab963974e5
commit
97fad7ae2b
9 files changed
+435
-17
No files matched your search
+31
@@ -199,6 +199,29 @@ Button.pairing-link {
|
||||
border-width: 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Permissions screen (phone-ui/permissions-page). Cards reuse the pairing-row
|
||||
* / pairing-title / pairing-badge look above; these add the explanation body
|
||||
* and the already-granted checkmark.
|
||||
*/
|
||||
.permissions-description {
|
||||
font-size: 13;
|
||||
color: #555555;
|
||||
margin-top: 2;
|
||||
}
|
||||
|
||||
.permissions-check {
|
||||
font-size: 24;
|
||||
color: #2e7d32;
|
||||
margin-left: 10;
|
||||
}
|
||||
|
||||
/* Continue with required permissions still missing: looks disabled but stays
|
||||
* tappable (the tap raises an are-you-sure prompt instead of being ignored). */
|
||||
Button.permissions-primary-dimmed {
|
||||
opacity: 0.45;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dark-mode pairing page. The cards keep their light-mode look above; here
|
||||
* they go dark-gray, and every text colour set above gets a light counterpart
|
||||
@@ -277,3 +300,11 @@ Button.pairing-link {
|
||||
.ns-dark Button.pairing-link {
|
||||
color: #7da7f5;
|
||||
}
|
||||
|
||||
.ns-dark .permissions-description {
|
||||
color: #b0b0b0;
|
||||
}
|
||||
|
||||
.ns-dark .permissions-check {
|
||||
color: #7bc47f;
|
||||
}
|
||||
@@ -5,6 +5,8 @@ const VOICE_PERMISSION_REQUEST_CODE = 4243;
|
||||
const CALENDAR_PERMISSION_REQUEST_CODE = 4244;
|
||||
const LOCATION_PERMISSION_REQUEST_CODE = 4245;
|
||||
const FINE_LOCATION_PERMISSION_REQUEST_CODE = 4246;
|
||||
const BLE_ONLY_PERMISSION_REQUEST_CODE = 4247;
|
||||
const POST_NOTIFICATIONS_PERMISSION_REQUEST_CODE = 4248;
|
||||
const POST_NOTIFICATIONS_PERMISSION = "android.permission.POST_NOTIFICATIONS";
|
||||
const RECORD_AUDIO_PERMISSION = "android.permission.RECORD_AUDIO";
|
||||
const READ_CALENDAR_PERMISSION = "android.permission.READ_CALENDAR";
|
||||
@@ -31,23 +33,22 @@ function toJavaStringArray(values: string[]): string[] {
|
||||
return result;
|
||||
}
|
||||
|
||||
function getRequiredPermissions(): string[] {
|
||||
const sdk = android.os.Build.VERSION.SDK_INT;
|
||||
const permissions: string[] = [];
|
||||
|
||||
if (sdk >= 31) {
|
||||
permissions.push(
|
||||
/** The runtime permissions this Android version needs for BLE scan + connect. */
|
||||
function getBlePermissions(): string[] {
|
||||
if (android.os.Build.VERSION.SDK_INT >= 31) {
|
||||
return [
|
||||
android.Manifest.permission.BLUETOOTH_SCAN,
|
||||
android.Manifest.permission.BLUETOOTH_CONNECT,
|
||||
);
|
||||
} else {
|
||||
permissions.push(android.Manifest.permission.ACCESS_FINE_LOCATION);
|
||||
];
|
||||
}
|
||||
return [android.Manifest.permission.ACCESS_FINE_LOCATION];
|
||||
}
|
||||
|
||||
if (sdk >= 33) {
|
||||
function getRequiredPermissions(): string[] {
|
||||
const permissions = getBlePermissions();
|
||||
if (android.os.Build.VERSION.SDK_INT >= 33) {
|
||||
permissions.push(POST_NOTIFICATIONS_PERMISSION);
|
||||
}
|
||||
|
||||
return permissions;
|
||||
}
|
||||
|
||||
@@ -107,6 +108,69 @@ export async function ensureVoicePermissions(): Promise<void> {
|
||||
await ensurePermissions([RECORD_AUDIO_PERMISSION], VOICE_PERMISSION_REQUEST_CODE, "Voice control");
|
||||
}
|
||||
|
||||
/** Whether the BLE scan/connect permissions have been granted (false off-Android). */
|
||||
export function hasBlePermissions(): boolean {
|
||||
if (!global.isAndroid) return false;
|
||||
return getBlePermissions().every((permission) => isPermissionGranted(permission));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt for just the BLE permissions (without POST_NOTIFICATIONS, which the
|
||||
* Permissions screen presents as its own card). Resolves true when granted.
|
||||
*/
|
||||
export async function requestBlePermissions(): Promise<boolean> {
|
||||
if (!global.isAndroid) return false;
|
||||
try {
|
||||
await ensurePermissions(getBlePermissions(), BLE_ONLY_PERMISSION_REQUEST_CODE, "Bluetooth");
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether posting notifications is allowed. Before Android 13 (sdk 33) there
|
||||
* is no runtime permission for this, so it reports as granted.
|
||||
*/
|
||||
export function hasPostNotificationsPermission(): boolean {
|
||||
if (!global.isAndroid) return false;
|
||||
if (android.os.Build.VERSION.SDK_INT < 33) return true;
|
||||
return isPermissionGranted(POST_NOTIFICATIONS_PERMISSION);
|
||||
}
|
||||
|
||||
/** Prompt for POST_NOTIFICATIONS. Resolves true when the permission is held afterward. */
|
||||
export async function requestPostNotificationsPermission(): Promise<boolean> {
|
||||
if (!global.isAndroid) return false;
|
||||
if (android.os.Build.VERSION.SDK_INT < 33) return true;
|
||||
try {
|
||||
await ensurePermissions(
|
||||
[POST_NOTIFICATIONS_PERMISSION],
|
||||
POST_NOTIFICATIONS_PERMISSION_REQUEST_CODE,
|
||||
"Notification",
|
||||
);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether RECORD_AUDIO has been granted (false off-Android). */
|
||||
export function hasMicrophonePermission(): boolean {
|
||||
if (!global.isAndroid) return false;
|
||||
return isPermissionGranted(RECORD_AUDIO_PERMISSION);
|
||||
}
|
||||
|
||||
/** Prompt for RECORD_AUDIO. Resolves true when granted, false on denial. */
|
||||
export async function requestMicrophonePermission(): Promise<boolean> {
|
||||
if (!global.isAndroid) return false;
|
||||
try {
|
||||
await ensureVoicePermissions();
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether READ_CALENDAR has been granted (false off-Android). */
|
||||
export function hasCalendarPermission(): boolean {
|
||||
if (!global.isAndroid) return false;
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -484,6 +484,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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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,7 +62,12 @@ 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
|
||||
|
||||
@@ -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