/** * EvenHub compatibility host: runs apps built for Even Realities' EvenHub * API (webview apps talking to the glasses through the phone) inside * Faceclaw. Launched by picking an .ehpk file in the Files app; the app gets * a phone WebView (its runtime + phone UI) and a 576x288 glasses window * composited by Faceclaw instead of the stock firmware. * * With a RayNeo iO paired the store is unavailable and sideloaded apps warn * on first run that they won't display correctly; see glasses-compat.ts. * * Design notes: notes/evenhub_compatibility.txt. */ import { type AppContext, type AppDefinition } from "../app-definition"; import { shell } from "../../ui/shell/shell"; import { EvenHubStoreLayer } from "./store-layer"; import { launchPackage, launchUrl, normalizeAppUrl } from "./manager"; import { createInProcessWindow, type InProcessWindow } from "../../ui/shell/in-process-window"; import { renderEvenRealitiesLogo } from "../../graphics/even-realities-logo"; import { makeImageWindowIcon, windowIcon } from "../../ui/shell/chrome-layer"; import { type InstalledEvenHubApp } from "./installed-apps"; import { isEvenHubStoreAvailable } from "./glasses-compat"; const EVENHUB_STORE_WINDOW_ID = "evenhub:store"; const EVENHUB_STORE_SURFACE_ID = "window:evenhub:store"; /** * Unpack an .ehpk and launch it as a concurrent EvenHub app (own glasses * window + persistent WebView). The phone stays on the dashboard; see manager. */ export function openEvenHubPackage(ctx: AppContext, ehpkPath: string): Promise { return launchPackage(ctx, ehpkPath); } /** * Launch an app straight from a live web server instead of an .ehpk — the * Developer app's "Load app from URL" / "Load app from QR code" entries, for * running an app off a dev server without packaging it first. */ export function openEvenHubUrl(ctx: AppContext, url: string): Promise { return launchUrl(ctx, url); } /** Whether a string can be loaded by openEvenHubUrl, for validating input. */ export function isLoadableAppUrl(url: string): boolean { return normalizeAppUrl(url) !== null; } /** The open store window, so a second launch focuses it and deep links can reach its layer. */ let storeWindow: { window: InProcessWindow; store: EvenHubStoreLayer } | null = null; /** Open the store window, or focus the one already open. */ async function ensureStoreWindow(ctx: AppContext): Promise<{ window: InProcessWindow; store: EvenHubStoreLayer }> { if (storeWindow && shell.getWindows().some((window) => window.windowId === EVENHUB_STORE_WINDOW_ID)) { shell.focusWindow(EVENHUB_STORE_WINDOW_ID); ctx.requestShellRender(); return storeWindow; } let created: InProcessWindow | null = null; const store = new EvenHubStoreLayer({ launchApp: (appId) => ctx.launchApp(appId), appendLog: ctx.appendLog, }); await ctx.launchInProcessApp(EVENHUB_STORE_WINDOW_ID, EVENHUB_STORE_SURFACE_ID, (options) => { created = createInProcessWindow({ appId: "evenhub", windowId: EVENHUB_STORE_WINDOW_ID, title: "EvenHub", iconLetter: "EH", icon: "package", drawIcon: makeImageWindowIcon(renderEvenRealitiesLogo, windowIcon("package", "EH")), closeable: true, menuItems: () => (created?.stack.isAtBase() ? store.buildMenuItems() : []), actions: options.actions, // Dictated text runs a store search (when the store page itself is on top). receiveTextInput: (text) => { if (created?.stack.receiveTextInput(text)) created.requestRender(); }, baseLayer: store, submitFrame: options.submitFrame, setSurfaceVisible: options.setSurfaceVisible, removeSurface: options.removeSurface, onClosed: () => { store.onWindowClosed(options.actions); if (storeWindow?.store === store) storeWindow = null; options.onClosed(); }, }); return created; }); if (!created) throw new Error("EvenHub store window was not created."); storeWindow = { window: created, store }; return storeWindow; } /** * Open the store on an installed app's page. The launcher uses it when the * registry lists a package whose EHPK is gone (a settings import after a * reinstall), so the tap lands on a Reinstall button instead of failing. */ export async function openEvenHubStoreForPackage(ctx: AppContext, installed: InstalledEvenHubApp): Promise { const { window, store } = await ensureStoreWindow(ctx); store.showInstalledPackage(window.stack, installed); window.requestRender(); } const evenhubApp: AppDefinition = { appId: "evenhub", title: "EvenHub", icon: "package", renderIcon: renderEvenRealitiesLogo, // Off the launcher with a RayNeo iO paired. A store window that opens // anyway (restored from before a re-pair, or the launcher's route for an // installed app whose package is missing) says why instead of loading. isSupported: isEvenHubStoreAvailable, launch: async (ctx) => { const { window } = await ensureStoreWindow(ctx); if (!isEvenHubStoreAvailable()) { // Store pages opened while Even glasses were paired would cover the notice. window.stack.clearToBase(); window.requestRender(); } }, }; export default evenhubApp;