EvenHub phone UI: add top bar, add open icon

This commit is contained in:
James Babcock committed 2026-09-27 21:38:04 -07:00
1 parent c6949fde3b
commit e879c58d9c
9 files changed
+284 -30

No files matched your search

+13 -2
View File
@@ -16,8 +16,9 @@ ActionItem {
color: #ffffff;
}
/* The main page's custom titleView: title left, connection status and the
* warning triangle right-aligned beside the overflow menu. */
/* The main page's custom titleView: title left; the EvenHub app icon,
* connection status and the warning triangle right-aligned beside the
* overflow menu. */
.action-bar-title {
color: #ffffff;
font-size: 18;
@@ -32,6 +33,16 @@ ActionItem {
vertical-align: center;
}
/* The foreground EvenHub app's icon (opens its phone UI); the padding widens
* the tap target. */
.action-bar-app-icon {
width: 32;
height: 32;
padding: 5.5;
margin-right: 8;
vertical-align: center;
}
/* The emoji brings its own yellow; the padding widens the tap target. */
.action-bar-warning {
font-size: 18;
+49 -6
View File
@@ -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 {
+10 -3
View File
@@ -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(),
};
}
+21 -1
View File
@@ -78,7 +78,14 @@ import {
installedEvenHubPackageId,
uninstallEvenHubPackage,
} from "../apps/evenhub/installed-apps";
import { closeRunningPackage, launchInstalledPackage } from "../apps/evenhub/manager";
import {
closeRunningPackage,
launchInstalledPackage,
onPhoneShownChanged,
phoneUiButton,
showOnPhone as showEvenHubPhoneUi,
type PhoneUiButton,
} from "../apps/evenhub/manager";
import { openEvenHubStoreForPackage } from "../apps/evenhub";
import { isInstalledPackagePresent } from "../apps/evenhub/updates";
import { wearerVerificationOptions } from "../apps/microphones/speakers";
@@ -133,6 +140,11 @@ export type DashboardSnapshot = {
* nothing is paired, so "Disconnected" would be the wrong label.
*/
previewMode: boolean;
/**
* The foreground glasses window's EvenHub phone UI, when it can be opened
* (the action bar's app-icon button); null otherwise.
*/
evenHubPhoneUi: PhoneUiButton | null;
};
type DashboardListener = (snapshot: DashboardSnapshot) => void;
@@ -361,6 +373,8 @@ class DashboardController {
launchApp: (appId) => this.launchApp(appId),
requestShellRender: () => this.requestShellRender(),
});
// The action bar's EvenHub phone-UI button hides while that UI is showing.
onPhoneShownChanged(() => this.emit());
shell.configure({
actions: {
...sharedActions,
@@ -1025,9 +1039,15 @@ class DashboardController {
fontsMissingWarningVisible: this.fontsMissingWarningVisible,
alarmReliabilityMessage: this.alarmReliabilityMessage,
previewMode: this.isPreviewDisplayActive(),
evenHubPhoneUi: phoneUiButton(),
};
}
/** Overlay an EvenHub app's phone UI (the action bar's app-icon button). */
showEvenHubPhoneUi(windowId: string): void {
showEvenHubPhoneUi(windowId);
}
/**
* Message to show in place of the display preview, or "" to show the preview.
*
+18
View File
@@ -27,3 +27,21 @@ export function grayImageToPreviewSource(image: GrayImage): ImageSource | null {
);
return new ImageSource(bitmap);
}
/**
* A glasses icon as a white-on-transparent phone image (gray becomes alpha),
* for the dark action bar.
*/
export function grayImageToWhiteIconSource(image: GrayImage): ImageSource | null {
if (!global.isAndroid) {
return null;
}
const baked = image.withDrawsBaked();
const bitmap = com.faceclaw.app.PreviewBitmapUtil.whiteIconFromGray(
copyToJavaByteBuffer(baked.pixels),
baked.width,
baked.height,
);
return new ImageSource(bitmap);
}
+7 -5
View File
@@ -1,11 +1,13 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:rc="phone-ui" navigatingTo="navigatingTo" loaded="loaded" unloaded="unloaded">
<ActionBar>
<!-- Custom titleView: app title on the left; connection status and the
warning-triangle indicator right-aligned beside the overflow menu. -->
<GridLayout columns="auto,*,auto,auto" width="100%" verticalAlignment="center">
<!-- Custom titleView: app title on the left; the foreground EvenHub
app's phone-UI button, connection status and the warning-triangle
indicator right-aligned beside the overflow menu. -->
<GridLayout columns="auto,*,auto,auto,auto" width="100%" verticalAlignment="center">
<Label col="0" text="Faceclaw" class="action-bar-title" />
<Label col="2" text="{{ connectionStatusLabel }}" tap="{{ onConnectionStatusTap }}" class="action-bar-status" />
<Label col="3" text="&#x26A0;&#xFE0F;" tap="{{ onWarningIconTap }}" visibility="{{ warningIconVisibility }}" class="action-bar-warning" />
<Image col="2" src="{{ evenHubPhoneUiIcon }}" tap="{{ onEvenHubPhoneUiTap }}" visibility="{{ evenHubPhoneUiVisibility }}" class="action-bar-app-icon" />
<Label col="3" text="{{ connectionStatusLabel }}" tap="{{ onConnectionStatusTap }}" class="action-bar-status" />
<Label col="4" text="&#x26A0;&#xFE0F;" tap="{{ onWarningIconTap }}" visibility="{{ warningIconVisibility }}" class="action-bar-warning" />
</GridLayout>
<ActionItem text="{{ buttonLabel }}" tap="{{ onTap }}" isEnabled="{{ connectItemEnabled }}" visibility="{{ glassesMenuItemsVisibility }}" android.position="popup" />
<ActionItem text="Pair glasses" tap="{{ onPairGlassesTap }}" isEnabled="{{ canRun }}" android.position="popup" />
+25
View File
@@ -25,6 +25,7 @@ import { isAutoReconnectSuppressed, resumeAutoReconnect } from "../g2/reconnect-
import { isPreviewOnlyMode } from "./onboarding-state";
import { formatErrorMessage } from "../util/format-error";
import { G2_LENS_HEIGHT, G2_LENS_WIDTH } from "../graphics/image";
import { type PhoneUiButton } from "../apps/evenhub/manager";
const LENS_ASPECT_RATIO = G2_LENS_WIDTH / G2_LENS_HEIGHT;
@@ -63,6 +64,7 @@ export class MainViewModel extends RemoteControlsViewModel {
private _alarmReliabilityMessage = "";
private _warningsModalVisible = false;
private _previewMode = false;
private _evenHubPhoneUi: PhoneUiButton | null = null;
private _phase: "disconnected" | "connecting" | "connected" | "charging" | "disconnecting" = "disconnected";
// A new view model is built on every navigation to the main page; these
@@ -112,6 +114,7 @@ export class MainViewModel extends RemoteControlsViewModel {
this.batteryOptimizationWarningVisible = snapshot.batteryOptimizationWarningVisible;
this.fontsMissingWarningVisible = snapshot.fontsMissingWarningVisible;
this.alarmReliabilityMessage = snapshot.alarmReliabilityMessage;
this.evenHubPhoneUi = snapshot.evenHubPhoneUi;
this.refreshPadFocusLine();
}));
// Brightness / display mode can change from the glasses' Settings app too.
@@ -773,6 +776,28 @@ export class MainViewModel extends RemoteControlsViewModel {
return this._warningsModalVisible ? "visible" : "collapse";
}
set evenHubPhoneUi(value: PhoneUiButton | null) {
const current = this._evenHubPhoneUi;
if (current?.windowId === value?.windowId && current?.icon === value?.icon) return;
this._evenHubPhoneUi = value;
this.notifyPropertyChange("evenHubPhoneUiIcon", this.evenHubPhoneUiIcon);
this.notifyPropertyChange("evenHubPhoneUiVisibility", this.evenHubPhoneUiVisibility);
}
/** The foreground EvenHub app's icon, which opens its phone UI when tapped. */
get evenHubPhoneUiIcon(): ImageSource | null {
return this._evenHubPhoneUi?.icon ?? null;
}
get evenHubPhoneUiVisibility(): "visible" | "collapse" {
return this._evenHubPhoneUi?.icon ? "visible" : "collapse";
}
onEvenHubPhoneUiTap(): void {
const windowId = this._evenHubPhoneUi?.windowId;
if (windowId) dashboardController.showEvenHubPhoneUi(windowId);
}
onWarningIconTap(): void {
this.setWarningsModalVisible(true);
}