forked from Blendman974/faceclaw
Ehpk app permission prompts scroll if too long
This commit is contained in:
1 parent
052398d401
commit
641e8e322e
2 files changed
+106
-37
No files matched your search
@@ -3,6 +3,8 @@
|
|||||||
## 0.6.3 - Future
|
## 0.6.3 - Future
|
||||||
* Update custom firmware base version from 2.2.6 to 2.2.9
|
* Update custom firmware base version from 2.2.6 to 2.2.9
|
||||||
* Add support for the short-then-long-press gesture
|
* Add support for the short-then-long-press gesture
|
||||||
|
* Update EvenHub compatibility layer to include new functions from 0.0.14
|
||||||
|
* EvenHub permissions dialog scrolls when it overflows
|
||||||
|
|
||||||
## 0.6.2 - 2026-08-30
|
## 0.6.2 - 2026-08-30
|
||||||
* Preview Only mode works
|
* Preview Only mode works
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { GrayImage } from "../../graphics/image";
|
|||||||
import { truncateText } from "../../graphics/textwrap";
|
import { truncateText } from "../../graphics/textwrap";
|
||||||
import { type InputEvent } from "../../ui/gestures";
|
import { type InputEvent } from "../../ui/gestures";
|
||||||
import { Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
|
import { Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||||
import { drawSelectionHighlight } from "../../ui/menu";
|
import { drawListScrollbar, drawSelectionHighlight } from "../../ui/menu";
|
||||||
import { permissionDetail, permissionLabel, type EvenHubPermission } from "./permissions";
|
import { permissionDetail, permissionLabel, type EvenHubPermission } from "./permissions";
|
||||||
import { openPrivacyPolicyOnPhone } from "./privacy-policy";
|
import { openPrivacyPolicyOnPhone } from "./privacy-policy";
|
||||||
import { lineStep, listRowHeight } from "../../ui/metrics";
|
import { lineStep, listRowHeight } from "../../ui/metrics";
|
||||||
@@ -19,10 +19,20 @@ const PERM_GAP = 4;
|
|||||||
* before installing it or running an uninstalled package. Allow proceeds;
|
* before installing it or running an uninstalled package. Allow proceeds;
|
||||||
* Cancel (or double-click) backs out. A privacy-policy-only app still reaches
|
* 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.
|
* this dialog so the user can review the policy before allowing first run.
|
||||||
|
*
|
||||||
|
* When the list overflows the viewport the dialog scrolls: scroll events move
|
||||||
|
* through the content row by row, and only once the bottom is fully visible do
|
||||||
|
* further scrolls move the action selection. The actions are inert until then
|
||||||
|
* (a click just scrolls), so the user can't Allow without having had the whole
|
||||||
|
* list on screen.
|
||||||
*/
|
*/
|
||||||
export class EvenHubPermissionDialogLayer implements Layer {
|
export class EvenHubPermissionDialogLayer implements Layer {
|
||||||
/** Starts on Allow; the optional privacy-policy action is inserted after it. */
|
/** Starts on Allow; the optional privacy-policy action is inserted after it. */
|
||||||
private selectedIndex = 0;
|
private selectedIndex = 0;
|
||||||
|
/** First content row drawn; rows above it are scrolled off. */
|
||||||
|
private firstRow = 0;
|
||||||
|
/** Scroll position at which the last row is fully visible; set by paint. */
|
||||||
|
private maxFirstRow = 0;
|
||||||
private resolved = false;
|
private resolved = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -33,6 +43,11 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
|||||||
private readonly onCancel: () => void,
|
private readonly onCancel: () => void,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
/** Whether the dialog is scrolled to the bottom, making the actions live. */
|
||||||
|
private atBottom(): boolean {
|
||||||
|
return this.firstRow >= this.maxFirstRow;
|
||||||
|
}
|
||||||
|
|
||||||
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
||||||
const font = getDefaultSmallFont();
|
const font = getDefaultSmallFont();
|
||||||
const { height: viewportHeight } = ctx.stack.getBaseSize();
|
const { height: viewportHeight } = ctx.stack.getBaseSize();
|
||||||
@@ -44,48 +59,88 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
|||||||
const permLabelStep = lineStep(font) + 1;
|
const permLabelStep = lineStep(font) + 1;
|
||||||
const permDetailStep = lineStep(font) - 1;
|
const permDetailStep = lineStep(font) - 1;
|
||||||
const actionRowH = listRowHeight(font);
|
const actionRowH = listRowHeight(font);
|
||||||
const permsHeight = this.permissions.reduce(
|
const actions = this.actions();
|
||||||
(sum, permission) => sum + permLabelStep + (permissionDetail(permission) ? permDetailStep : 0) + PERM_GAP,
|
const focused = ctx.stack.isFocused();
|
||||||
0,
|
|
||||||
);
|
// The dialog body as scrollable rows; each row's height includes the gap
|
||||||
const emptyPermissionsHeight = this.permissions.length === 0 ? permLabelStep + PERM_GAP : 0;
|
// below it, so scrolling and visibility checks work on whole rows.
|
||||||
const bodyTop = PADDING + headerStep + 6 + permsHeight + emptyPermissionsHeight + 6;
|
type Row = { height: number; draw: (top: number) => void };
|
||||||
const height = Math.min(bodyTop + this.actions().length * actionRowH + PADDING, viewportHeight - 2 * DIALOG_Y);
|
const rows: Row[] = [];
|
||||||
|
const heading = this.permissions.length ? `${this.appName} needs:` : `${this.appName} is ready to run`;
|
||||||
|
rows.push({
|
||||||
|
height: headerStep + 6,
|
||||||
|
draw: (top) => image.drawText(font, left, top, truncateText(font, heading, textWidth), 235),
|
||||||
|
});
|
||||||
|
if (this.permissions.length === 0) {
|
||||||
|
rows.push({
|
||||||
|
height: permLabelStep + PERM_GAP + 2,
|
||||||
|
draw: (top) => image.drawText(font, left, top, "No special permissions requested.", 140),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (let index = 0; index < this.permissions.length; index++) {
|
||||||
|
const permission = this.permissions[index]!;
|
||||||
|
const detail = permissionDetail(permission);
|
||||||
|
const gapBelow = PERM_GAP + (index === this.permissions.length - 1 ? 2 : 0);
|
||||||
|
rows.push({
|
||||||
|
height: permLabelStep + (detail ? 0 : gapBelow),
|
||||||
|
draw: (top) => image.drawText(font, left, top, truncateText(font, permissionLabel(permission.name), textWidth), 220),
|
||||||
|
});
|
||||||
|
if (detail) {
|
||||||
|
rows.push({
|
||||||
|
height: permDetailStep + gapBelow,
|
||||||
|
draw: (top) => image.drawText(font, left + 8, top, truncateText(font, detail, textWidth - 8), 140),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let index = 0; index < actions.length; index++) {
|
||||||
|
rows.push({
|
||||||
|
height: actionRowH,
|
||||||
|
draw: (top) => {
|
||||||
|
const selected = this.atBottom() && index === this.selectedIndex;
|
||||||
|
if (selected) {
|
||||||
|
drawSelectionHighlight(image, DIALOG_X + 12, top, DIALOG_WIDTH - 24, actionRowH - 1, focused, 8);
|
||||||
|
}
|
||||||
|
image.drawText(font, DIALOG_X + 22, top + 3, actions[index]!, selected ? 255 : 200);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const contentHeight = rows.reduce((sum, row) => sum + row.height, 0);
|
||||||
|
const height = Math.min(contentHeight + 2 * PADDING, viewportHeight - 2 * DIALOG_Y);
|
||||||
|
const visibleHeight = height - 2 * PADDING;
|
||||||
|
|
||||||
|
// The bottommost scroll position: the largest suffix of rows that fits.
|
||||||
|
let maxFirstRow = rows.length;
|
||||||
|
for (let suffixHeight = 0; maxFirstRow > 0; maxFirstRow--) {
|
||||||
|
const rowHeight = rows[maxFirstRow - 1]!.height;
|
||||||
|
if (suffixHeight + rowHeight > visibleHeight) break;
|
||||||
|
suffixHeight += rowHeight;
|
||||||
|
}
|
||||||
|
this.maxFirstRow = maxFirstRow;
|
||||||
|
this.firstRow = Math.max(0, Math.min(this.firstRow, maxFirstRow));
|
||||||
|
|
||||||
// Fill 1 (transparent color key is 0), outline for the dialog edge.
|
// Fill 1 (transparent color key is 0), outline for the dialog edge.
|
||||||
image.fillRoundedRect(DIALOG_X, DIALOG_Y, DIALOG_WIDTH, height, 1);
|
image.fillRoundedRect(DIALOG_X, DIALOG_Y, DIALOG_WIDTH, height, 1);
|
||||||
image.drawRoundedRect(DIALOG_X, DIALOG_Y, DIALOG_WIDTH, height, 72);
|
image.drawRoundedRect(DIALOG_X, DIALOG_Y, DIALOG_WIDTH, height, 72);
|
||||||
|
|
||||||
let y = DIALOG_Y + PADDING;
|
let y = DIALOG_Y + PADDING;
|
||||||
const heading = this.permissions.length ? `${this.appName} needs:` : `${this.appName} is ready to run`;
|
for (let index = this.firstRow; index < rows.length; index++) {
|
||||||
image.drawText(font, left, y, truncateText(font, heading, textWidth), 235);
|
const row = rows[index]!;
|
||||||
y += headerStep + 6;
|
if (y + row.height > DIALOG_Y + PADDING + visibleHeight) break;
|
||||||
|
row.draw(y);
|
||||||
if (this.permissions.length === 0) {
|
y += row.height;
|
||||||
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 += permLabelStep;
|
|
||||||
const detail = permissionDetail(permission);
|
|
||||||
if (detail) {
|
|
||||||
image.drawText(font, left + 8, y, truncateText(font, detail, textWidth - 8), 140);
|
|
||||||
y += permDetailStep;
|
|
||||||
}
|
|
||||||
y += PERM_GAP;
|
|
||||||
}
|
|
||||||
y += 2;
|
|
||||||
|
|
||||||
const focused = ctx.stack.isFocused();
|
if (maxFirstRow > 0) {
|
||||||
const actions = this.actions();
|
drawListScrollbar(
|
||||||
for (let index = 0; index < actions.length; index++) {
|
image,
|
||||||
const rowY = y + index * actionRowH;
|
DIALOG_X + DIALOG_WIDTH - 7,
|
||||||
const selected = index === this.selectedIndex;
|
DIALOG_Y + PADDING,
|
||||||
if (selected) {
|
visibleHeight,
|
||||||
drawSelectionHighlight(image, DIALOG_X + 12, rowY, DIALOG_WIDTH - 24, actionRowH - 1, focused, 8);
|
this.firstRow,
|
||||||
}
|
rows.length - maxFirstRow,
|
||||||
image.drawText(font, DIALOG_X + 22, rowY + 3, actions[index]!, selected ? 255 : 200);
|
rows.length,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
@@ -94,12 +149,24 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
|||||||
const actions = this.actions();
|
const actions = this.actions();
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case "scroll-up":
|
case "scroll-up":
|
||||||
this.selectedIndex = (this.selectedIndex + actions.length - 1) % actions.length;
|
if (this.atBottom() && this.selectedIndex > 0) {
|
||||||
|
this.selectedIndex -= 1;
|
||||||
|
} else if (this.firstRow > 0) {
|
||||||
|
this.firstRow -= 1;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
case "scroll-down":
|
case "scroll-down":
|
||||||
this.selectedIndex = (this.selectedIndex + 1) % actions.length;
|
if (!this.atBottom()) {
|
||||||
|
this.firstRow += 1;
|
||||||
|
} else {
|
||||||
|
this.selectedIndex = Math.min(actions.length - 1, this.selectedIndex + 1);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
case "click":
|
case "click":
|
||||||
|
if (!this.atBottom()) {
|
||||||
|
this.firstRow += 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (actions[this.selectedIndex] === "Privacy policy") {
|
if (actions[this.selectedIndex] === "Privacy policy") {
|
||||||
openPrivacyPolicyOnPhone(this.privacyPolicyUrl, this.appName);
|
openPrivacyPolicyOnPhone(this.privacyPolicyUrl, this.appName);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in new issue
Block a user