mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-29 13:03:11 +00:00
Display link to EvenHub apps' privacy policy on first run
This commit is contained in:
1 parent
604da990a1
commit
526a236193
9 files changed
+361
-29
No files matched your search
@@ -4,6 +4,7 @@ import { truncateText } from "../../graphics/textwrap";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||
import { drawSelectionHighlight } from "../../ui/menu";
|
||||
import { permissionDetail, permissionLabel, type EvenHubPermission } from "./permissions";
|
||||
import { openPrivacyPolicyOnPhone } from "./privacy-policy";
|
||||
|
||||
const DIALOG_X = 8;
|
||||
const DIALOG_Y = 8;
|
||||
@@ -18,17 +19,18 @@ const ACTION_ROW_HEIGHT = 20;
|
||||
/**
|
||||
* Confirmation dialog listing the permissions an EvenHub app declares, shown
|
||||
* before installing it or running an uninstalled package. Allow proceeds;
|
||||
* Cancel (or double-click) backs out. Apps that declare no permissions never
|
||||
* reach this dialog — the caller runs them directly.
|
||||
* Cancel (or double-click) backs out. A privacy-policy-only app still reaches
|
||||
* this dialog so the user can review the policy before allowing first run.
|
||||
*/
|
||||
export class EvenHubPermissionDialogLayer implements Layer {
|
||||
/** 0 = Allow, 1 = Cancel. */
|
||||
/** Starts on Allow; the optional privacy-policy action is inserted after it. */
|
||||
private selectedIndex = 0;
|
||||
private resolved = false;
|
||||
|
||||
constructor(
|
||||
private readonly appName: string,
|
||||
private readonly permissions: EvenHubPermission[],
|
||||
private readonly privacyPolicyUrl: string,
|
||||
private readonly onConfirm: () => void,
|
||||
private readonly onCancel: () => void,
|
||||
) {}
|
||||
@@ -44,17 +46,23 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
(sum, permission) => sum + PERM_LABEL_STEP + (permissionDetail(permission) ? PERM_DETAIL_STEP : 0) + PERM_GAP,
|
||||
0,
|
||||
);
|
||||
const bodyTop = PADDING + HEADER_STEP + 6 + permsHeight + 6;
|
||||
const height = Math.min(bodyTop + 2 * ACTION_ROW_HEIGHT + PADDING, viewportHeight - 2 * DIALOG_Y);
|
||||
const emptyPermissionsHeight = this.permissions.length === 0 ? PERM_LABEL_STEP + PERM_GAP : 0;
|
||||
const bodyTop = PADDING + HEADER_STEP + 6 + permsHeight + emptyPermissionsHeight + 6;
|
||||
const height = Math.min(bodyTop + this.actions().length * ACTION_ROW_HEIGHT + PADDING, viewportHeight - 2 * DIALOG_Y);
|
||||
|
||||
// Fill 1 (transparent color key is 0), outline for the dialog edge.
|
||||
image.fillRoundedRect(DIALOG_X, DIALOG_Y, DIALOG_WIDTH, height, 1);
|
||||
image.drawRoundedRect(DIALOG_X, DIALOG_Y, DIALOG_WIDTH, height, 72);
|
||||
|
||||
let y = DIALOG_Y + PADDING;
|
||||
image.drawText(font, left, y, truncateText(font, `${this.appName} needs:`, textWidth), 235);
|
||||
const heading = this.permissions.length ? `${this.appName} needs:` : `${this.appName} is ready to run`;
|
||||
image.drawText(font, left, y, truncateText(font, heading, textWidth), 235);
|
||||
y += HEADER_STEP + 6;
|
||||
|
||||
if (this.permissions.length === 0) {
|
||||
image.drawText(font, left, y, "No special permissions requested.", 140);
|
||||
y += emptyPermissionsHeight;
|
||||
}
|
||||
for (const permission of this.permissions) {
|
||||
image.drawText(font, left, y, truncateText(font, permissionLabel(permission.name), textWidth), 220);
|
||||
y += PERM_LABEL_STEP;
|
||||
@@ -68,7 +76,7 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
y += 2;
|
||||
|
||||
const focused = ctx.stack.isFocused();
|
||||
const actions = ["Allow", "Cancel"];
|
||||
const actions = this.actions();
|
||||
for (let index = 0; index < actions.length; index++) {
|
||||
const rowY = y + index * ACTION_ROW_HEIGHT;
|
||||
const selected = index === this.selectedIndex;
|
||||
@@ -81,15 +89,20 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
}
|
||||
|
||||
handleInput(event: DashboardInputEvent, ctx: LayerContext): void {
|
||||
const actions = this.actions();
|
||||
switch (event.type) {
|
||||
case "scroll-up":
|
||||
this.selectedIndex = (this.selectedIndex + 1) % 2;
|
||||
this.selectedIndex = (this.selectedIndex + actions.length - 1) % actions.length;
|
||||
return;
|
||||
case "scroll-down":
|
||||
this.selectedIndex = (this.selectedIndex + 1) % 2;
|
||||
this.selectedIndex = (this.selectedIndex + 1) % actions.length;
|
||||
return;
|
||||
case "click":
|
||||
this.resolve(ctx, this.selectedIndex === 0);
|
||||
if (actions[this.selectedIndex] === "Privacy policy") {
|
||||
openPrivacyPolicyOnPhone(this.privacyPolicyUrl, this.appName);
|
||||
} else {
|
||||
this.resolve(ctx, actions[this.selectedIndex] === "Allow");
|
||||
}
|
||||
return;
|
||||
case "double-click":
|
||||
this.resolve(ctx, false);
|
||||
@@ -114,4 +127,8 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
if (confirmed) this.onConfirm();
|
||||
else this.onCancel();
|
||||
}
|
||||
|
||||
private actions(): string[] {
|
||||
return this.privacyPolicyUrl ? ["Allow", "Privacy policy", "Cancel"] : ["Allow", "Cancel"];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user