Add options to load an app from a URL or a QR code

(The QR code reading does not work yet)
This commit is contained in:
James Babcock committed 2026-08-21 12:03:24 -07:00
1 parent 6e4ece5dc7
commit 92cd05b6ca
22 files changed
+685 -93

No files matched your search

+2 -2
View File
@@ -16,7 +16,7 @@ import blocksApp from "./blocks";
import minesweeperApp from "./minesweeper";
import freecellApp from "./freecell";
import pinballApp from "./pinball";
import debugTestsApp from "./debug-tests";
import developerApp from "./developer";
import evenhubApp from "./evenhub";
import settingsApp from "./settings";
@@ -43,7 +43,7 @@ export const ALL_APPS: readonly AppDefinition[] = [
minesweeperApp,
freecellApp,
pinballApp,
debugTestsApp,
developerApp,
evenhubApp,
settingsApp,
];
-70
View File
@@ -1,70 +0,0 @@
import { MenuLayer } from "../../ui/menu";
import { ScreenTestLayer } from "./screen-test";
import { BuzzerDemoLayer } from "./buzzer-demo";
import { AccelerometerDemoLayer } from "./accelerometer-demo";
import { ResourceUsageLayer } from "./resource-usage";
import { appViewportSize } from "../../ui/shell/geometry";
import {
createInProcessWindow,
YieldAtRootLayer,
type InProcessAppOptions,
type InProcessWindow,
} from "../../ui/shell/in-process-window";
export const DEBUG_TESTS_WINDOW_ID = "debug-tests";
export const DEBUG_TESTS_SURFACE_ID = "window:debug-tests";
/** Debug/diagnostic pages (screen test, buzzer demo) as an in-process app. */
export function createDebugTestsAppWindow(options: InProcessAppOptions): InProcessWindow {
const menu = new MenuLayer(
"Debug tests",
[
{
label: "Dither test",
onSelect: (ctx) => {
ctx.stack.push(new ScreenTestLayer());
},
},
{
label: "Buzzer demo",
onSelect: (ctx) => {
ctx.stack.push(new BuzzerDemoLayer());
},
},
{
label: "Accelerometer demo",
onSelect: (ctx) => {
ctx.stack.push(new AccelerometerDemoLayer(DEBUG_TESTS_WINDOW_ID, ctx.actions.requestRender));
},
},
{
label: "Show resource usage",
onSelect: (ctx) => {
ctx.stack.push(new ResourceUsageLayer(DEBUG_TESTS_WINDOW_ID, ctx.actions.requestRender));
},
},
],
{
x: 8,
y: 8,
width: 272,
showBorder: false,
minHeight: 0,
maxHeight: appViewportSize("min").height - 16,
},
);
return createInProcessWindow({
appId: "debug-tests",
windowId: DEBUG_TESTS_WINDOW_ID,
title: "Debug tests",
iconLetter: "Db",
icon: "flask-conical",
closeable: true,
actions: options.actions,
baseLayer: new YieldAtRootLayer(menu),
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface,
onClosed: options.onClosed,
});
}
-11
View File
@@ -1,11 +0,0 @@
import { type AppDefinition } from "../app-definition";
import { createDebugTestsAppWindow, DEBUG_TESTS_SURFACE_ID, DEBUG_TESTS_WINDOW_ID } from "./debug-tests-app";
const debugTestsApp: AppDefinition = {
appId: "debug-tests",
title: "Debug tests",
icon: "flask-conical",
launch: (ctx) => ctx.launchInProcessApp(DEBUG_TESTS_WINDOW_ID, DEBUG_TESTS_SURFACE_ID, createDebugTestsAppWindow),
};
export default debugTestsApp;
@@ -16,7 +16,7 @@ const RECONCILE_INTERVAL_MS = 400;
/**
* Accelerometer demo: turns the IMU stream on while this page is visible (the
* Debug tests window is foregrounded and the screen is on), off otherwise, and
* Developer window is foregrounded and the screen is on), off otherwise, and
* shows the latest x/y/z reading with a simple per-axis bar.
*
* The IMU stream is experimental — the firmware may never populate it — so the
File renamed without changes.
+131
View File
@@ -0,0 +1,131 @@
import { MenuLayer, drawSubmenuIndicator, type MenuItem } from "../../ui/menu";
import { ScreenTestLayer } from "./screen-test";
import { BuzzerDemoLayer } from "./buzzer-demo";
import { AccelerometerDemoLayer } from "./accelerometer-demo";
import { ResourceUsageLayer } from "./resource-usage";
import { LoadAppFromQrLayer, LoadAppFromUrlLayer } from "./load-app";
import { type AppContext } from "../app-definition";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { appViewportSize } from "../../ui/shell/geometry";
import { LIST_ROW_TEXT_INSET } from "../../ui/metrics";
import {
createInProcessWindow,
YieldAtRootLayer,
type InProcessAppOptions,
type InProcessWindow,
} from "../../ui/shell/in-process-window";
export const DEVELOPER_WINDOW_ID = "developer";
export const DEVELOPER_SURFACE_ID = "window:developer";
const MENU_LAYOUT = {
x: 8,
y: 8,
width: 272,
showBorder: false,
minHeight: 0,
maxHeight: appViewportSize("min").height - 16,
};
/** A row that opens a nested page: the label plus a right-edge ">". */
function submenuItem(label: string, onSelect: MenuItem["onSelect"]): MenuItem {
return {
label,
onSelect,
render: ({ image, x, y, width, height, selected, disabled, text }) => {
const font = getDefaultSmallFont();
const value = disabled ? 70 : selected ? 255 : 200;
image.drawText(font, x, y + LIST_ROW_TEXT_INSET, text, value);
drawSubmenuIndicator(image, font, x, y, width, height, value);
},
};
}
/** The diagnostic demos, one level down from the root menu. */
function debugTestsMenu(): MenuLayer {
return new MenuLayer(
"Debug tests",
[
{
label: "Dither test",
onSelect: (ctx) => {
ctx.stack.push(new ScreenTestLayer());
},
},
{
label: "Buzzer demo",
onSelect: (ctx) => {
ctx.stack.push(new BuzzerDemoLayer());
},
},
{
label: "Accelerometer demo",
onSelect: (ctx) => {
ctx.stack.push(new AccelerometerDemoLayer(DEVELOPER_WINDOW_ID, ctx.actions.requestRender));
},
},
],
MENU_LAYOUT,
);
}
/**
* The Developer app: tools for building and debugging on the glasses. The two
* "Load app" entries run an EvenHub app straight off a web server, without
* packaging it into an .ehpk first; the diagnostic demos live one level down
* under "Debug tests".
*/
export function createDeveloperAppWindow(appContext: AppContext, options: InProcessAppOptions): InProcessWindow {
const menu = new MenuLayer(
"Developer",
[
{
label: "Load app from URL",
onSelect: (ctx) => {
const layer = new LoadAppFromUrlLayer(appContext);
ctx.stack.push(layer);
layer.open(ctx);
},
},
{
label: "Load app from QR code",
onSelect: (ctx) => {
const layer = new LoadAppFromQrLayer(appContext);
ctx.stack.push(layer);
layer.open(ctx);
},
},
{
label: "Show resource usage",
onSelect: (ctx) => {
ctx.stack.push(new ResourceUsageLayer(DEVELOPER_WINDOW_ID, ctx.actions.requestRender));
},
},
submenuItem("Debug tests", (ctx) => {
ctx.stack.push(debugTestsMenu());
}),
],
MENU_LAYOUT,
);
let created: InProcessWindow | null = null;
created = createInProcessWindow({
appId: "developer",
windowId: DEVELOPER_WINDOW_ID,
title: "Developer",
iconLetter: "Dv",
icon: "wrench",
closeable: true,
actions: options.actions,
// Dictating a URL is the one thing worth speaking at in this app; the
// load pages take the text and every other page ignores it.
receiveTextInput: (text) => {
if (created?.stack.receiveTextInput(text)) created.requestRender();
},
baseLayer: new YieldAtRootLayer(menu),
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface,
onClosed: options.onClosed,
});
return created;
}
+14
View File
@@ -0,0 +1,14 @@
import { type AppDefinition } from "../app-definition";
import { createDeveloperAppWindow, DEVELOPER_SURFACE_ID, DEVELOPER_WINDOW_ID } from "./developer-app";
const developerApp: AppDefinition = {
appId: "developer",
title: "Developer",
icon: "wrench",
launch: (ctx) =>
ctx.launchInProcessApp(DEVELOPER_WINDOW_ID, DEVELOPER_SURFACE_ID, (options) =>
createDeveloperAppWindow(ctx, options),
),
};
export default developerApp;
+207
View File
@@ -0,0 +1,207 @@
import { GrayImage } from "../../graphics/image";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { wrapText } from "../../graphics/textwrap";
import { type AppContext } from "../app-definition";
import { isLoadableAppUrl, openEvenHubUrl } from "../evenhub";
import { GESTURE_CLICK, GESTURE_DOUBLE_CLICK } from "../../ui/gestures";
import { Layer, type DashboardInputEvent, type LayerContext } from "../../ui/layers";
import { lineStep } from "../../ui/metrics";
import { developerAppUrlSetting } from "../../ui/dashboard-settings";
import { isQrScannerAvailable, scanQrCode } from "../../native/qr-scan";
const MARGIN = 20;
/**
* "Load app from URL": the glasses side of the phone text editor. Entering the
* page opens the editor on developerAppUrlSetting, the typed URL echoes here
* as it changes, and a click (or the phone keyboard's done key) launches it as
* an EvenHub app. The draft persists, so reloading after an edit-and-rebuild is
* one click.
*/
export class LoadAppFromUrlLayer implements Layer {
private error = "";
private launching = false;
constructor(private readonly ctx: AppContext) {}
/** Opens the phone editor; call right after pushing the layer. */
open(ctx: LayerContext): void {
void ctx.actions.startTextSettingsEdit([developerAppUrlSetting], "Load app from URL", () => {
void this.launch(ctx);
});
}
/** Leaving the page by any route closes the phone editor with it. */
onRemoved(): void {
void this.ctx.actions.endTextSettingEdit();
}
/** Dictated text fills the draft, same as typing it on the phone. */
receiveTextInput(text: string): void {
developerAppUrlSetting.set(text);
this.error = "";
}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const step = lineStep(font);
const textWidth = width - 2 * MARGIN;
image.drawText(font, MARGIN, 8, "Load app from URL", 220);
let y = 8 + step + 6;
image.drawText(font, MARGIN, y, "Type the app's URL in the phone app", 150);
y += step;
image.drawText(font, MARGIN, y, "(or use voice input from the menu).", 150);
y += step + 8;
const url = developerAppUrlSetting.get();
for (const line of wrapText(font, url || "(empty)", textWidth).slice(0, 3)) {
image.drawText(font, MARGIN, y, line, url ? 230 : 110);
y += step;
}
if (this.error) {
y += 4;
for (const line of wrapText(font, this.error, textWidth).slice(0, 2)) {
image.drawText(font, MARGIN, y, line, 150);
y += step;
}
}
const footer = this.launching
? "Loading..."
: `${GESTURE_CLICK} load ${GESTURE_DOUBLE_CLICK} cancel`;
image.drawText(font, MARGIN, height - font.lineHeight - 12, footer, 110);
return image;
}
handleInput(event: DashboardInputEvent, ctx: LayerContext): void {
switch (event.type) {
case "click":
void this.launch(ctx);
return;
case "double-click":
ctx.stack.pop();
return;
default:
return;
}
}
private async launch(ctx: LayerContext): Promise<void> {
if (this.launching) return;
const url = developerAppUrlSetting.get();
if (!isLoadableAppUrl(url)) {
this.error = url ? "Not an http:// or https:// URL." : "Enter a URL first.";
ctx.actions.requestRender();
return;
}
this.launching = true;
this.error = "";
ctx.actions.requestRender();
try {
await openEvenHubUrl(this.ctx, url);
ctx.stack.pop();
} catch (error) {
this.error = cleanError(error);
this.ctx.appendLog(`evenhub url launch failed: ${this.error}`);
} finally {
this.launching = false;
ctx.actions.requestRender();
}
}
}
/**
* "Load app from QR code": hand off to an installed scanner app, then launch
* whatever URL it decodes. The scanned URL is kept in developerAppUrlSetting so
* the URL page can reload it later without rescanning.
*/
export class LoadAppFromQrLayer implements Layer {
private status = "Starting scanner...";
private busy = false;
constructor(private readonly ctx: AppContext) {}
/** Launches the scanner; call right after pushing the layer. */
open(ctx: LayerContext): void {
if (!isQrScannerAvailable()) {
this.status = "No QR scanner app is installed on the phone.";
ctx.actions.requestRender();
return;
}
this.busy = true;
void this.scan(ctx);
}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const { width, height } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const step = lineStep(font);
image.drawText(font, MARGIN, 8, "Load app from QR code", 220);
let y = 8 + step + 6;
for (const line of wrapText(font, this.status, width - 2 * MARGIN).slice(0, 5)) {
image.drawText(font, MARGIN, y, line, 170);
y += step;
}
const footer = this.busy ? `${GESTURE_DOUBLE_CLICK} back` : `${GESTURE_CLICK} scan again ${GESTURE_DOUBLE_CLICK} back`;
image.drawText(font, MARGIN, height - font.lineHeight - 12, footer, 110);
return image;
}
handleInput(event: DashboardInputEvent, ctx: LayerContext): void {
switch (event.type) {
case "click":
if (!this.busy && isQrScannerAvailable()) {
this.busy = true;
this.status = "Starting scanner...";
ctx.actions.requestRender();
void this.scan(ctx);
}
return;
case "double-click":
ctx.stack.pop();
return;
default:
return;
}
}
private async scan(ctx: LayerContext): Promise<void> {
try {
this.status = "Point the phone camera at the QR code.";
ctx.actions.requestRender();
const scanned = await scanQrCode();
if (scanned === null) {
this.status = "Scan cancelled.";
return;
}
if (!isLoadableAppUrl(scanned)) {
this.status = `Not a URL: ${scanned}`;
return;
}
developerAppUrlSetting.set(scanned);
this.status = `Loading ${scanned}`;
ctx.actions.requestRender();
await openEvenHubUrl(this.ctx, scanned);
ctx.stack.pop();
} catch (error) {
this.status = cleanError(error);
this.ctx.appendLog(`evenhub qr launch failed: ${this.status}`);
} finally {
this.busy = false;
ctx.actions.requestRender();
}
}
}
function cleanError(error: unknown): string {
return String((error as Error)?.message ?? error)
.replace(/[\x00-\x1f]+/g, " ")
.replace(/\s+/g, " ")
.trim();
}
File renamed without changes.
@@ -17,7 +17,7 @@ export class ScreenTestLayer implements Layer {
private scrollRow = 0;
paint(ctx: LayerContext): GrayImage {
// Sized to the hosting stack (the Debug tests app viewport).
// Sized to the hosting stack (the Developer app viewport).
const { width, height } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const font = getDefaultSmallFont();
+15 -1
View File
@@ -10,7 +10,7 @@
import { type AppContext, type AppDefinition } from "../app-definition";
import { shell } from "../../ui/shell/shell";
import { EvenHubStoreLayer } from "./store-layer";
import { launchPackage } from "./manager";
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";
@@ -26,6 +26,20 @@ export function openEvenHubPackage(ctx: AppContext, ehpkPath: string): Promise<v
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<void> {
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;
}
const evenhubApp: AppDefinition = {
appId: "evenhub",
title: "EvenHub",
+73 -2
View File
@@ -18,7 +18,8 @@ import {
readBinaryFile,
writeBinaryFile,
} from "../../native/file-access";
import { parseEhpk, parseManifest, utf8Decode } from "./ehpk";
import { parseEhpk, parseManifest, utf8Decode, type EvenHubManifest } from "./ehpk";
import { type EvenHubPermission } from "./permissions";
import { EvenHubSession } from "./session";
import { createEvenHubWindow } from "./evenhub-window";
import { createEvenHubWebView, type EvenHubWebView } from "./webview";
@@ -96,8 +97,23 @@ export async function launchPackage(
}
}
await startApp(ctx, manifest, `${baseDir}/dist`, "", appId);
}
/**
* Shared tail of every launch: build the session and its WebView, register the
* pair, and open the glasses window. `distDir` serves a packaged app offline;
* `remoteUrl`, when set, loads the app from the network instead.
*/
async function startApp(
ctx: AppContext,
manifest: EvenHubManifest,
distDir: string,
remoteUrl: string,
appId: string,
): Promise<void> {
const windowId = `evenhub:app:${nextSerial++}`;
const session = new EvenHubSession(manifest, `${baseDir}/dist`, ctx.appendLog);
const session = new EvenHubSession(manifest, distDir, ctx.appendLog, remoteUrl);
const webView = createEvenHubWebView(session);
session.attachWebView({
evaluateJs: webView.evaluateJs,
@@ -119,6 +135,61 @@ export async function launchPackage(
);
}
/**
* Launch an EvenHub app served by a live web server (the Developer app's
* "Load app from URL" / QR flows), rather than one unpacked from an .ehpk.
*
* There is no manifest to read, so one is synthesized: the URL identifies the
* app (a stable packageId keeps its localStorage across reloads) and every
* permission is treated as declared, on the grounds that the user pointed
* Faceclaw at this URL themselves. Loading the same URL again replaces the
* running instance, which is what a reload after an edit should do.
*/
export async function launchUrl(ctx: AppContext, url: string): Promise<void> {
const normalized = normalizeAppUrl(url);
if (!normalized) {
ctx.appendLog(`evenhub: not an http(s) URL: ${url}`);
throw new Error("Not an http:// or https:// URL.");
}
const manifest = synthesizeUrlManifest(normalized);
closeRunningPackage(manifest.packageId);
await startApp(ctx, manifest, "", normalized, "evenhub");
}
/** Accept a bare "example.com/app" as https; reject anything not http(s). */
export function normalizeAppUrl(raw: string): string | null {
const trimmed = raw.trim();
if (!trimmed) return null;
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
if (!/^https?:\/\/[^/?#\s]+/i.test(withScheme)) return null;
return withScheme;
}
/** Every permission name the host knows how to honor, granted to URL apps. */
const DEV_URL_PERMISSIONS: EvenHubPermission[] = [
{ name: "network" },
{ name: "location" },
{ name: "g2-microphone" },
{ name: "phone-microphone" },
];
function synthesizeUrlManifest(url: string): EvenHubManifest {
const match = /^https?:\/\/([^/?#]+)([^?#]*)/i.exec(url);
const authority = match?.[1] ?? url;
const path = (match?.[2] ?? "").replace(/\/index\.html?$/i, "").replace(/\/+$/, "");
const idSource = `${authority}${path}`.toLowerCase().replace(/[^a-z0-9.-]+/g, "-");
return {
packageId: `dev.url.${idSource.slice(0, 96)}`,
name: authority,
version: "dev",
entrypoint: "",
networkWhitelist: [],
permissions: DEV_URL_PERMISSIONS,
privacyPolicyUrl: "",
raw: { url },
};
}
/** Launch an installed app as a launcher-addressable singleton. */
export function launchInstalledPackage(ctx: AppContext, app: InstalledEvenHubApp): Promise<void> {
return launchPackage(ctx, installedEvenHubPackagePath(app.packageId), {
+13 -1
View File
@@ -314,6 +314,12 @@ export type EvenHubWindowHooks = {
export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenHubCompassClient {
readonly manifest: EvenHubManifest;
readonly distDir: string;
/**
* For a developer-loaded app served from a live web server: the absolute
* URL to open. Empty for a packaged app, which is served offline out of
* distDir instead (see webview.ts).
*/
readonly remoteUrl: string;
private page: EvenHubPage | null = null;
private pageCreated = false;
@@ -352,9 +358,15 @@ export class EvenHubSession implements EvenHubMicClient, EvenHubImuClient, EvenH
private readonly grantedApiKeys = new Set<string>();
private log: (message: string) => void;
constructor(manifest: EvenHubManifest, distDir: string, log: (message: string) => void) {
constructor(
manifest: EvenHubManifest,
distDir: string,
log: (message: string) => void,
remoteUrl = "",
) {
this.manifest = manifest;
this.distDir = distDir;
this.remoteUrl = remoteUrl;
this.log = log;
}
+31 -3
View File
@@ -10,6 +10,11 @@
* from a fake per-app origin plus document-start injection of the
* flutter_inappwebview bridge shim) and so the page keeps running JS while the
* host app is backgrounded (see FaceclawEvenHubWebView / the host).
*
* A session with a remoteUrl (the Developer app's "Load app from URL") skips
* the offline serving entirely and loads that URL from the network; the shim
* is registered as a document-start script instead of being spliced into the
* served HTML.
*/
import { Application, Utils } from "@nativescript/core";
import { EVENHUB_BRIDGE_INJECT_SCRIPT, buildFaceclawExtensionsScript, type EvenHubSession } from "./session";
@@ -33,6 +38,15 @@ function originHost(session: EvenHubSession): string {
return `${safe}.evenhub.invalid`;
}
/**
* The allowed-origin rule for a remote app's document-start script: the
* loaded URL's own origin, so the shim isn't handed to third-party frames.
*/
function originRule(url: string): string {
const match = /^(https?:\/\/[^/?#]+)/i.exec(url);
return match ? match[1]! : "*";
}
/**
* Build the app's WebView, wire it to the session, attach it to the keep-alive
* host, and start loading. Must run on the main thread.
@@ -56,12 +70,26 @@ export function createEvenHubWebView(session: EvenHubSession): EvenHubWebView {
},
});
const host = originHost(session);
const remoteUrl = session.remoteUrl;
// Remote apps load from their own server, so nothing is intercepted and the
// fake per-app origin is unused.
const host = remoteUrl ? "" : originHost(session);
// Stock bridge shim first, then the Faceclaw extensions global (both at
// document-start, before any app JS).
const injectScript = EVENHUB_BRIDGE_INJECT_SCRIPT + buildFaceclawExtensionsScript(`Faceclaw/${FACECLAW_VERSION}`);
const documentStartInstalled = remoteUrl
? com.faceclaw.app.FaceclawEvenHubDocumentStart.install(webView, injectScript, originRule(remoteUrl)) === true
: false;
webView.setWebViewClient(
new com.faceclaw.app.FaceclawEvenHubWebViewClient(session.distDir, host, injectScript, listener),
new com.faceclaw.app.FaceclawEvenHubWebViewClient(
session.distDir,
host,
injectScript,
// onPageStarted injection is the fallback when the document-start API
// is unavailable; packaged apps get the shim spliced into their HTML.
!!remoteUrl && !documentStartInstalled,
listener,
),
);
webView.addJavascriptInterface(new com.faceclaw.app.FaceclawEvenHubJsBridge(listener), "__faceclawEvenHub");
@@ -79,7 +107,7 @@ export function createEvenHubWebView(session: EvenHubSession): EvenHubWebView {
const nativeHost = com.faceclaw.app.FaceclawEvenHubWebViewHost.getInstance();
nativeHost.attach(activity, webView);
webView.loadUrl(`https://${host}/${session.manifest.entrypoint}`);
webView.loadUrl(remoteUrl || `https://${host}/${session.manifest.entrypoint}`);
return {
native: webView,
+2
View File
@@ -66,6 +66,8 @@ export const ICON_SVGS = {
'<svg viewBox="0 0 24 24" fill="none"><path d="M12 2v2"/><path d="m4.93 4.93 1.42 1.42"/><path d="M20 12h2"/><path d="m19.07 4.93-1.42 1.42"/><path d="M15.947 12.65a4 4 0 0 0-5.925-4.128"/><path d="M13 22H7a5 5 0 1 1 4.9-6H13a3 3 0 0 1 0 6Z"/></svg>',
"flask-conical":
'<svg viewBox="0 0 24 24" fill="none"><path d="M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2"/><path d="M6.453 15h11.094"/><path d="M8.5 2h7"/></svg>',
wrench:
'<svg viewBox="0 0 24 24" fill="none"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg>',
settings:
'<svg viewBox="0 0 24 24" fill="none"><path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"/><circle cx="12" cy="12" r="3"/></svg>',
mic:
+76
View File
@@ -0,0 +1,76 @@
import { Application } from "@nativescript/core";
declare const android: any;
declare const global: any;
/**
* QR scanning by delegating to whatever scanner app the phone has installed,
* via the de-facto-standard ZXing "SCAN" intent (Barcode Scanner, Binary Eye,
* QR & Barcode Scanner, and others register for it). Faceclaw ships no decoder
* and needs no camera permission of its own: the scanner app owns the camera
* and hands back the decoded text.
*
* The cost is that scanning only works if such an app is installed;
* isQrScannerAvailable reports that up front so the caller can say so instead
* of launching into nothing. (resolveActivity can see other apps only because
* the manifest already holds QUERY_ALL_PACKAGES for notification icons;
* without it Android 11+ would need a <queries> entry for the action.)
*/
const SCAN_ACTION = "com.google.zxing.client.android.SCAN";
// Arbitrary, only has to be distinct from other startActivityForResult callers.
const SCAN_REQUEST_CODE = 0x51d0;
function buildScanIntent(): any {
const intent = new android.content.Intent(SCAN_ACTION);
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
// Ask the scanner not to keep its own history of what we scanned.
intent.putExtra("SAVE_HISTORY", false);
return intent;
}
/** Whether any installed app answers the scan intent. */
export function isQrScannerAvailable(): boolean {
if (!global.isAndroid) return false;
const activity = Application.android?.foregroundActivity ?? Application.android?.startActivity;
if (!activity) return false;
try {
return buildScanIntent().resolveActivity(activity.getPackageManager()) !== null;
} catch {
return false;
}
}
/**
* Launch the scanner and resolve with the decoded text, or null if the user
* backed out. Rejects when no scanner app is installed or the activity can't
* be reached.
*/
export function scanQrCode(): Promise<string | null> {
if (!global.isAndroid) return Promise.reject(new Error("QR scanning needs Android."));
const activity = Application.android?.foregroundActivity ?? Application.android?.startActivity;
if (!activity) return Promise.reject(new Error("No foreground activity to scan from."));
const intent = buildScanIntent();
if (intent.resolveActivity(activity.getPackageManager()) === null) {
return Promise.reject(new Error("No QR scanner app installed."));
}
return new Promise<string | null>((resolve, reject) => {
const onResult = (args: { requestCode: number; resultCode: number; intent: any }) => {
if (args.requestCode !== SCAN_REQUEST_CODE) return;
Application.android.off(Application.android.activityResultEvent, onResult);
if (args.resultCode !== android.app.Activity.RESULT_OK || !args.intent) {
resolve(null);
return;
}
const text = args.intent.getStringExtra("SCAN_RESULT");
resolve(text === null || text === undefined ? null : String(text));
};
Application.android.on(Application.android.activityResultEvent, onResult);
try {
activity.startActivityForResult(intent, SCAN_REQUEST_CODE);
} catch (error) {
Application.android.off(Application.android.activityResultEvent, onResult);
reject(error instanceof Error ? error : new Error(String(error)));
}
});
}
+17
View File
@@ -503,6 +503,23 @@ export const terminalNewConnectionSetting = new ConfigSettingString({
normalize: (value) => (value ?? "").replace(/[\x00-\x1f]+/g, "").trim(),
});
/**
* Staging buffer for the Developer app's "Load app from URL" flow: the app
* opens the phone text editor on this setting, the user types (or scans, or
* dictates) the URL, and the app reads it back when the load is confirmed on
* the glasses. Kept across launches so a reload after an edit-and-rebuild only
* takes a click. Deliberately not listed in the Settings app.
*/
export const developerAppUrlSetting = new ConfigSettingString({
id: "developer-app-url",
label: "App URL",
storageKey: "developer.appUrl",
defaultValue: "",
editorTitle: "EvenHub app URL (http:// or https://)",
glassesEditTitle: "Load app from URL",
normalize: (value) => (value ?? "").replace(/[\x00-\x1f]+/g, "").trim(),
});
export const terminalLaunchPresetsSetting = new ConfigSettingString({
id: "terminal-launch-presets",
label: "Launch presets",
+16
View File
@@ -98,6 +98,13 @@ export interface Layer {
handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> | void;
/** Called when the layer leaves the stack by any path (pop or clearToBase). */
onRemoved?(): void;
/**
* Accept a finished text string aimed at this window (voice input, and
* anything else the shell routes through sendTextToForegroundWindow).
* Layers that have somewhere to put text implement it; the rest don't, and
* the shell then has no app destination to offer.
*/
receiveTextInput?(text: string, ctx: LayerContext): void;
}
export class LayerStack {
@@ -191,6 +198,15 @@ export class LayerStack {
await this.layers[this.layers.length - 1]!.handleInput(event, this.ctx);
}
/** Hand text to the top layer; false if it doesn't take text input. */
receiveTextInput(text: string): boolean {
const layer = this.layers[this.layers.length - 1]!;
if (!layer.receiveTextInput) return false;
layer.receiveTextInput(text, this.ctx);
return true;
}
private paintLayer(index: number): Plane[] {
const layer = this.layers[index]!;
let canvas: GrayImage | null = null;
+7
View File
@@ -37,6 +37,12 @@ export type InProcessWindowOptions = {
menuItems?: () => MenuItem[];
/** Shared actions; requestRender is rebound to this window's render. */
actions: LayerActions;
/**
* Accept text aimed at this window (voice input). Supply it for apps with a
* layer that takes dictation; leaving it out is what tells the shell not to
* offer "Type Into App" for this window.
*/
receiveTextInput?: (text: string) => void;
baseLayer: Layer;
submitFrame: (planes: Plane[], paintMs: number, frameId: number) => Promise<void>;
setSurfaceVisible: (visible: boolean) => void;
@@ -189,6 +195,7 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
await render(frameId);
},
requestRender,
receiveTextInput: options.receiveTextInput,
setForeground: (foreground) => {
options.setSurfaceVisible(foreground);
},