forked from Blendman974/faceclaw
Merge branch 'main' into microphone-fixes
This commit is contained in:
commit
10865fc0cb
32 files changed
+832
-160
No files matched your search
@@ -51,9 +51,19 @@ export function installedEvenHubPackageId(appId: string): string | null {
|
||||
}
|
||||
}
|
||||
|
||||
// The parsed index for the last stored value: the launcher and the watch
|
||||
// state both list installed apps on every refresh, and the sort's
|
||||
// localeCompare dominated the cost.
|
||||
let parsedIndex: { raw: string; apps: InstalledEvenHubApp[] } | null = null;
|
||||
|
||||
export function getInstalledEvenHubApps(): InstalledEvenHubApp[] {
|
||||
const raw = getStringSetting(STORAGE_KEY, "");
|
||||
if (!raw) return [];
|
||||
if (parsedIndex?.raw !== raw) parsedIndex = { raw, apps: parseInstalledIndex(raw) };
|
||||
return parsedIndex.apps.map((app) => ({ ...app }));
|
||||
}
|
||||
|
||||
function parseInstalledIndex(raw: string): InstalledEvenHubApp[] {
|
||||
try {
|
||||
const parsed = JSON.parse(raw);
|
||||
if (!Array.isArray(parsed)) return [];
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
*
|
||||
* Glasses-first: launching does NOT take over the phone screen. The phone
|
||||
* stays on the Faceclaw dashboard; an app's phone UI is shown on demand
|
||||
* (window menu -> "Show phone UI"), overlaying the dashboard, and the Back
|
||||
* button returns to it. Apps are kept alive until explicitly closed (no memory
|
||||
* eviction yet).
|
||||
* (window menu -> "Show phone UI", or the app-icon button in the phone's
|
||||
* action bar while the app is foreground on the glasses), overlaying the
|
||||
* dashboard, and the Back button or the overlay's close button returns to it.
|
||||
* Apps are kept alive until explicitly closed (no memory eviction yet).
|
||||
*/
|
||||
import { Application } from "@nativescript/core";
|
||||
import { Application, type ImageSource } from "@nativescript/core";
|
||||
import { type AppContext } from "../app-definition";
|
||||
import {
|
||||
appFilesDirPath,
|
||||
@@ -23,6 +24,8 @@ import { EvenHubSession } from "./session";
|
||||
import { createEvenHubWindow } from "./evenhub-window";
|
||||
import { createEvenHubWebView, type EvenHubWebView } from "./webview";
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { grayImageToWhiteIconSource } from "../../native/gray-image-preview";
|
||||
import {
|
||||
readEvenHubPackageManifest,
|
||||
installedEvenHubAppId,
|
||||
@@ -36,12 +39,31 @@ type RunningApp = {
|
||||
packageId: string;
|
||||
session: EvenHubSession;
|
||||
webView: EvenHubWebView;
|
||||
/** The app's icon for the phone action bar, rendered on first use. */
|
||||
phoneIcon?: ImageSource | null;
|
||||
};
|
||||
|
||||
/** The phone action bar's button for opening the foreground app's phone UI. */
|
||||
export type PhoneUiButton = { windowId: string; title: string; icon: ImageSource | null };
|
||||
|
||||
/** Pixel size the action-bar icon is rendered at (~21dp at xxhdpi). */
|
||||
const PHONE_ICON_SIZE = 63;
|
||||
|
||||
const running = new Map<string, RunningApp>();
|
||||
let nextSerial = 1;
|
||||
let phoneShownWindowId: string | null = null;
|
||||
let backHandlerRegistered = false;
|
||||
const phoneShownListeners = new Set<() => void>();
|
||||
|
||||
/** Called whenever an app's phone UI is shown or hidden. Returns an unsubscribe. */
|
||||
export function onPhoneShownChanged(listener: () => void): () => void {
|
||||
phoneShownListeners.add(listener);
|
||||
return () => phoneShownListeners.delete(listener);
|
||||
}
|
||||
|
||||
function notifyPhoneShownChanged(): void {
|
||||
for (const listener of phoneShownListeners) listener();
|
||||
}
|
||||
|
||||
/** Intercept Android Back while an app's phone UI is overlaying the dashboard. */
|
||||
function ensureBackHandler(): void {
|
||||
@@ -112,6 +134,7 @@ async function startApp(
|
||||
if (phoneShownWindowId === windowId) {
|
||||
webView.hideOnPhone();
|
||||
phoneShownWindowId = null;
|
||||
notifyPhoneShownChanged();
|
||||
}
|
||||
webView.destroy();
|
||||
cleanup?.();
|
||||
@@ -205,15 +228,35 @@ export function showOnPhone(windowId: string): void {
|
||||
const app = running.get(windowId);
|
||||
if (!app) return;
|
||||
if (phoneShownWindowId && phoneShownWindowId !== windowId) hidePhone();
|
||||
app.webView.showOnPhone();
|
||||
app.webView.showOnPhone(hidePhone);
|
||||
phoneShownWindowId = windowId;
|
||||
notifyPhoneShownChanged();
|
||||
}
|
||||
|
||||
/** Return the phone to the dashboard (Back, or the shown app closing). */
|
||||
/** Return the phone to the dashboard (Back, the close button, or the shown app closing). */
|
||||
export function hidePhone(): void {
|
||||
if (!phoneShownWindowId) return;
|
||||
running.get(phoneShownWindowId)?.webView.hideOnPhone();
|
||||
phoneShownWindowId = null;
|
||||
notifyPhoneShownChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* The foreground glasses window, when it is an EvenHub app whose phone UI
|
||||
* isn't showing: the phone action bar then offers a button to show it.
|
||||
*/
|
||||
export function phoneUiButton(): PhoneUiButton | null {
|
||||
const window = shell.foregroundWindow();
|
||||
const app = window ? running.get(window.windowId) : undefined;
|
||||
if (!window || !app || phoneShownWindowId === app.windowId) return null;
|
||||
if (app.phoneIcon === undefined) {
|
||||
// The same artwork as the glasses sidebar (installed icon, else the
|
||||
// generic package icon), drawn white.
|
||||
const image = new GrayImage(PHONE_ICON_SIZE, PHONE_ICON_SIZE, 0);
|
||||
window.drawIcon(image, 0, 0, PHONE_ICON_SIZE);
|
||||
app.phoneIcon = grayImageToWhiteIconSource(image);
|
||||
}
|
||||
return { windowId: app.windowId, title: window.title, icon: app.phoneIcon };
|
||||
}
|
||||
|
||||
export function runningAppCount(): number {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { truncateText } from "../../graphics/textwrap";
|
||||
import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||
import { type InputEvent } from "../../ui/gestures";
|
||||
import { Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||
import { drawListScrollbar, drawSelectionHighlight } from "../../ui/menu";
|
||||
@@ -8,9 +8,9 @@ import { permissionDetail, permissionLabel, type EvenHubPermission } from "./per
|
||||
import { openPrivacyPolicyOnPhone } from "./privacy-policy";
|
||||
import { lineStep, listRowHeight } from "../../ui/metrics";
|
||||
|
||||
const DIALOG_X = 8;
|
||||
const DIALOG_Y = 8;
|
||||
const DIALOG_WIDTH = 272;
|
||||
/** Minimum gap between the dialog and the edges of the window it's centered in. */
|
||||
const DIALOG_MARGIN = 8;
|
||||
const DIALOG_WIDTH = 320;
|
||||
const PADDING = 10;
|
||||
const PERM_GAP = 4;
|
||||
|
||||
@@ -27,6 +27,8 @@ const PERM_GAP = 4;
|
||||
* list on screen.
|
||||
*/
|
||||
export class EvenHubPermissionDialogLayer implements Layer {
|
||||
/** Floats in front of the window content, like the context menus. */
|
||||
readonly depth = 2;
|
||||
/** Starts on Allow; the optional privacy-policy action is inserted after it. */
|
||||
private selectedIndex = 0;
|
||||
/** First content row drawn; rows above it are scrolled off. */
|
||||
@@ -50,10 +52,12 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
|
||||
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const { height: viewportHeight } = ctx.stack.getBaseSize();
|
||||
const { width: viewportWidth, height: viewportHeight } = ctx.stack.getBaseSize();
|
||||
const image = paintBelow();
|
||||
const textWidth = DIALOG_WIDTH - 2 * PADDING - 4;
|
||||
const left = DIALOG_X + PADDING + 2;
|
||||
const dialogWidth = Math.min(DIALOG_WIDTH, viewportWidth - 2 * DIALOG_MARGIN);
|
||||
const dialogX = ((viewportWidth - dialogWidth) / 2) | 0;
|
||||
const textWidth = dialogWidth - 2 * PADDING - 4;
|
||||
const left = dialogX + PADDING + 2;
|
||||
|
||||
const headerStep = lineStep(font) + 2;
|
||||
const permLabelStep = lineStep(font) + 1;
|
||||
@@ -80,15 +84,17 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
for (let index = 0; index < this.permissions.length; index++) {
|
||||
const permission = this.permissions[index]!;
|
||||
const detail = permissionDetail(permission);
|
||||
// One row per wrapped line, so the explanation scrolls line by line.
|
||||
const detailLines = detail ? wrapText(font, detail, textWidth - 8) : [];
|
||||
const gapBelow = PERM_GAP + (index === this.permissions.length - 1 ? 2 : 0);
|
||||
rows.push({
|
||||
height: permLabelStep + (detail ? 0 : gapBelow),
|
||||
height: permLabelStep + (detailLines.length ? 0 : gapBelow),
|
||||
draw: (top) => image.drawText(font, left, top, truncateText(font, permissionLabel(permission.name), textWidth), 220),
|
||||
});
|
||||
if (detail) {
|
||||
for (let line = 0; line < detailLines.length; line++) {
|
||||
rows.push({
|
||||
height: permDetailStep + gapBelow,
|
||||
draw: (top) => image.drawText(font, left + 8, top, truncateText(font, detail, textWidth - 8), 140),
|
||||
height: permDetailStep + (line === detailLines.length - 1 ? gapBelow : 0),
|
||||
draw: (top) => image.drawText(font, left + 8, top, detailLines[line]!, 140),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -98,15 +104,16 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
draw: (top) => {
|
||||
const selected = this.atBottom() && index === this.selectedIndex;
|
||||
if (selected) {
|
||||
drawSelectionHighlight(image, DIALOG_X + 12, top, DIALOG_WIDTH - 24, actionRowH - 1, focused, 8);
|
||||
drawSelectionHighlight(image, dialogX + 12, top, dialogWidth - 24, actionRowH - 1, focused, 8);
|
||||
}
|
||||
image.drawText(font, DIALOG_X + 22, top + 3, actions[index]!, selected ? 255 : 200);
|
||||
image.drawText(font, dialogX + 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 height = Math.min(contentHeight + 2 * PADDING, viewportHeight - 2 * DIALOG_MARGIN);
|
||||
const dialogY = ((viewportHeight - height) / 2) | 0;
|
||||
const visibleHeight = height - 2 * PADDING;
|
||||
|
||||
// The bottommost scroll position: the largest suffix of rows that fits.
|
||||
@@ -120,13 +127,13 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
this.firstRow = Math.max(0, Math.min(this.firstRow, maxFirstRow));
|
||||
|
||||
// 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);
|
||||
image.fillRoundedRect(dialogX, dialogY, dialogWidth, height, 1);
|
||||
image.drawRoundedRect(dialogX, dialogY, dialogWidth, height, 72);
|
||||
|
||||
let y = DIALOG_Y + PADDING;
|
||||
let y = dialogY + PADDING;
|
||||
for (let index = this.firstRow; index < rows.length; index++) {
|
||||
const row = rows[index]!;
|
||||
if (y + row.height > DIALOG_Y + PADDING + visibleHeight) break;
|
||||
if (y + row.height > dialogY + PADDING + visibleHeight) break;
|
||||
row.draw(y);
|
||||
y += row.height;
|
||||
}
|
||||
@@ -134,8 +141,8 @@ export class EvenHubPermissionDialogLayer implements Layer {
|
||||
if (maxFirstRow > 0) {
|
||||
drawListScrollbar(
|
||||
image,
|
||||
DIALOG_X + DIALOG_WIDTH - 7,
|
||||
DIALOG_Y + PADDING,
|
||||
dialogX + dialogWidth - 7,
|
||||
dialogY + PADDING,
|
||||
visibleHeight,
|
||||
this.firstRow,
|
||||
rows.length - maxFirstRow,
|
||||
|
||||
@@ -22,11 +22,13 @@ import { FACECLAW_VERSION } from "../../version";
|
||||
|
||||
declare const android: any;
|
||||
declare const com: any;
|
||||
declare const java: any;
|
||||
|
||||
export type EvenHubWebView = {
|
||||
evaluateJs: (js: string) => void;
|
||||
destroy: () => void;
|
||||
showOnPhone: () => void;
|
||||
/** Show the app's phone UI; `onClose` runs when its top bar's close button is tapped. */
|
||||
showOnPhone: (onClose: () => void) => void;
|
||||
hideOnPhone: () => void;
|
||||
/** The native android.webkit.WebView, for the host. */
|
||||
native: unknown;
|
||||
@@ -118,8 +120,13 @@ export function createEvenHubWebView(session: EvenHubSession): EvenHubWebView {
|
||||
console.warn(`evenhub webview destroy failed: ${error}`);
|
||||
}
|
||||
},
|
||||
showOnPhone: () =>
|
||||
nativeHost.showOnPhone(Application.android?.foregroundActivity ?? Application.android?.startActivity ?? null, webView),
|
||||
showOnPhone: (onClose: () => void) =>
|
||||
nativeHost.showOnPhone(
|
||||
Application.android?.foregroundActivity ?? Application.android?.startActivity ?? null,
|
||||
webView,
|
||||
session.manifest.name,
|
||||
new java.lang.Runnable({ run: onClose }),
|
||||
),
|
||||
hideOnPhone: () => nativeHost.hideOnPhone(),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user