From 0cc263c5d28654afaf19863580f980e8db617350 Mon Sep 17 00:00:00 2001 From: James Babcock Date: Fri, 6 Nov 2026 15:13:46 -0800 Subject: [PATCH] Don't show the Compass app on hardware (ie G1s) that can't support it --- app/apps/app-definition.ts | 7 ++ app/apps/compass/compass-app.ts | 15 ++--- app/apps/compass/index.ts | 2 + app/apps/glanceboard/glanceboard-settings.ts | 39 +++++++---- app/apps/launcher/index.ts | 2 +- app/assistant/window-tools.ts | 22 +++--- app/g2/dashboard-controller.ts | 8 +-- app/g2/ios-preview-controller.ts | 4 +- app/g2/wear-remote.ts | 6 +- app/ui/dashboard-settings.ts | 9 +++ tests/compass-readout.test.cjs | 2 +- tests/compass-texture-cache.test.cjs | 2 +- tests/display-layout-setting.test.cjs | 11 +++ tests/glanceboard-settings.test.cjs | 49 +++++++++++++- tests/ios-watch-remote.test.cjs | 2 +- tests/unsupported-apps.test.cjs | 71 ++++++++++++++++++++ 16 files changed, 202 insertions(+), 49 deletions(-) create mode 100644 tests/unsupported-apps.test.cjs diff --git a/app/apps/app-definition.ts b/app/apps/app-definition.ts index b46c809d..a51adf4f 100644 --- a/app/apps/app-definition.ts +++ b/app/apps/app-definition.ts @@ -30,6 +30,13 @@ export type AppDefinition = { boot?: (ctx: AppContext) => void; /** False for apps that must not appear in the launcher grid (the launcher itself). */ showInLauncher?: boolean; + /** + * False while the paired glasses can't run the app (absent means they can). + * It then leaves the launcher grid and what mirrors it: the watch remote and + * the apps.launch tool. A window restored from before a re-pair still opens, + * so the app needs to say what's wrong rather than assume it never runs. + */ + isSupported?: () => boolean; /** Present on the app that handles text shared via the Android share intent. */ openSharedText?: (ctx: AppContext, title: string, text: string) => void; /** diff --git a/app/apps/compass/compass-app.ts b/app/apps/compass/compass-app.ts index 9559ea42..8c01ff0f 100644 --- a/app/apps/compass/compass-app.ts +++ b/app/apps/compass/compass-app.ts @@ -10,7 +10,7 @@ import { type CompassDiagnostics, } from "../../native/compass"; import { wrapText } from "../../graphics/textwrap"; -import { glassesTypeSetting } from "../../ui/dashboard-settings"; +import { glassesHaveCompass } from "../../ui/dashboard-settings"; import { type InputEvent } from "../../ui/gestures"; import { type Layer, type LayerContext } from "../../ui/layers"; import { lineStep } from "../../ui/metrics"; @@ -152,7 +152,7 @@ class CompassLayer implements Layer { } private statusText(): string { - if (noCompassSensor()) return "These glasses have no compass sensor"; + if (!glassesHaveCompass()) return "These glasses have no compass sensor"; if (this.firmwareStatus !== null) return this.firmwareStatus; if (!this.enabled) return "Compass paused"; if (this.rawHeading === null) return "Waiting for compass data…"; @@ -208,7 +208,7 @@ class CompassLayer implements Layer { image.drawText(small, Math.round(cx - small.measureText(line) / 2), y, line, 125); y += smallStep; } - if (!noCompassSensor()) { + if (glassesHaveCompass()) { const accuracyText = magneticAccuracyText(this.diagnostics); image.drawText(small, width - ACCURACY_RIGHT_PAD - small.measureText(accuracyText), ACCURACY_TOP_PAD, accuracyText, 175); } @@ -220,15 +220,10 @@ class CompassLayer implements Layer { // "Uncalibrated" prompt advertises, and re-calibrating is a normal thing to // want once the glasses have been taken off and put back on. handleInput(event: InputEvent, ctx: LayerContext): void { - if (event.type === "click" && !noCompassSensor()) this.openCalibration(ctx); + if (event.type === "click" && glassesHaveCompass()) this.openCalibration(ctx); } } -/** A G1 has an accelerometer and a gyroscope, but no magnetometer. */ -function noCompassSensor(): boolean { - return glassesTypeSetting.get() === "g1"; -} - export function createCompassAppWindow(options: InProcessAppOptions): InProcessWindow { let requestRender = () => {}; const layer = new CompassLayer(() => requestRender()); @@ -240,7 +235,7 @@ export function createCompassAppWindow(options: InProcessAppOptions): InProcessW icon: "compass", closeable: true, actions: options.actions, - menuItems: () => noCompassSensor() ? [] : [ + menuItems: () => !glassesHaveCompass() ? [] : [ { label: "Calibrate", onSelect: (ctx) => { diff --git a/app/apps/compass/index.ts b/app/apps/compass/index.ts index 4b8442a8..6741a735 100644 --- a/app/apps/compass/index.ts +++ b/app/apps/compass/index.ts @@ -1,3 +1,4 @@ +import { glassesHaveCompass } from "../../ui/dashboard-settings"; import { type AppDefinition } from "../app-definition"; import { COMPASS_SURFACE_ID, COMPASS_WINDOW_ID, createCompassAppWindow } from "./compass-app"; @@ -5,6 +6,7 @@ const compassApp: AppDefinition = { appId: "compass", title: "Compass", icon: "compass", + isSupported: glassesHaveCompass, launch: (ctx) => ctx.launchInProcessApp(COMPASS_WINDOW_ID, COMPASS_SURFACE_ID, createCompassAppWindow), }; diff --git a/app/apps/glanceboard/glanceboard-settings.ts b/app/apps/glanceboard/glanceboard-settings.ts index 4d729490..eebc91f8 100644 --- a/app/apps/glanceboard/glanceboard-settings.ts +++ b/app/apps/glanceboard/glanceboard-settings.ts @@ -1,4 +1,4 @@ -import { ConfigSettingBoolean, ConfigSettingEnum } from "../../ui/dashboard-settings"; +import { ConfigSettingBoolean, ConfigSettingEnum, glassesHaveCompass } from "../../ui/dashboard-settings"; import { QUADRANT_LAYOUT, SIX_SLOT_LAYOUT, slotsVerticallyAdjacent, type GlanceLayout } from "./layout"; import { type GlanceWidgetId } from "./widget"; import { glanceWidgetSpans } from "./widgets"; @@ -23,6 +23,11 @@ export function glanceSlotChoiceLabel(choice: GlanceSlotChoice): string { return SLOT_CHOICE_LABELS[choice] ?? choice; } +/** Whether the paired glasses can drive this widget; if not, it is left out of the slot picker. */ +function slotChoiceAvailable(choice: GlanceSlotChoice): boolean { + return choice !== "compass" || glassesHaveCompass(); +} + /** * Slot order follows QUADRANT_LAYOUT: top left, top right, bottom left, bottom * right. Calendar in both right slots merges into one double-height region. @@ -146,18 +151,26 @@ export const glanceShowLinesSetting = new ConfigSettingBoolean({ export function glanceSlotSettings(layout: GlanceLayout = glanceLayout()): ConfigSettingEnum[] { const grid = layout === QUADRANT_LAYOUT || layout === SIX_SLOT_LAYOUT; const storageId = grid ? QUADRANT_LAYOUT.id : layout.id; - return layout.slots.map( - (slot, index) => - new ConfigSettingEnum({ - id: `glanceboard-${layout.id}-slot-${index}`, - label: slot.label, - storageKey: `glanceboard.${storageId}.slot.${index}`, - defaultValue: (grid ? DEFAULT_QUADRANT_CHOICES[index] : undefined) ?? "none", - values: SLOT_CHOICES, - formatValue: glanceSlotChoiceLabel, - description: `Which widget fills the ${slot.label.toLowerCase()} slot of the Glanceboard.`, - }), - ); + return layout.slots.map((slot, index) => { + const defaultValue: GlanceSlotChoice = (grid ? DEFAULT_QUADRANT_CHOICES[index] : undefined) ?? "none"; + return new ConfigSettingEnum({ + id: `glanceboard-${layout.id}-slot-${index}`, + label: slot.label, + storageKey: `glanceboard.${storageId}.slot.${index}`, + defaultValue, + values: SLOT_CHOICES.filter(slotChoiceAvailable), + // A stored choice the glasses can't drive reads as Empty, not the slot's + // default (which could put a widget on the board twice). The stored value + // stays, so pairing glasses that can drive it brings it back. + normalize: (value) => { + const choice = value as GlanceSlotChoice; + if (!SLOT_CHOICES.includes(choice)) return defaultValue; + return slotChoiceAvailable(choice) ? choice : "none"; + }, + formatValue: glanceSlotChoiceLabel, + description: `Which widget fills the ${slot.label.toLowerCase()} slot of the Glanceboard.`, + }); + }); } /** diff --git a/app/apps/launcher/index.ts b/app/apps/launcher/index.ts index 1c16f4b9..40448347 100644 --- a/app/apps/launcher/index.ts +++ b/app/apps/launcher/index.ts @@ -11,7 +11,7 @@ import { export function launcherEntries(apps: readonly AppDefinition[]) { return [ ...apps - .filter((app) => app.showInLauncher !== false) + .filter((app) => app.showInLauncher !== false && app.isSupported?.() !== false) .map((app) => ({ appId: app.appId, label: app.title, diff --git a/app/assistant/window-tools.ts b/app/assistant/window-tools.ts index 44350606..9724550a 100644 --- a/app/assistant/window-tools.ts +++ b/app/assistant/window-tools.ts @@ -5,11 +5,11 @@ * mirrors what the user can do from the launcher grid and the sidebar. * * The launchable set is the built-in launcher apps plus whatever EvenHub - * packages are installed right now, matching the launcher grid. Installs and - * uninstalls change that set at runtime, so the tools re-register (replacing - * themselves by name) whenever it changes to keep the id enums and - * descriptions current; register() fires the tools-changed broadcast that - * propagates the new specs to the assistant backends. + * packages are installed right now, matching the launcher grid. Installs, + * uninstalls and pairing different glasses change that set at runtime, so the + * tools re-register (replacing themselves by name) whenever it changes to keep + * the id enums and descriptions current; register() fires the tools-changed + * broadcast that propagates the new specs to the assistant backends. */ import { shell, type ShellWindow } from "../ui/shell/shell"; import type { AppDefinition } from "../apps/app-definition"; @@ -30,8 +30,8 @@ import { onAnySettingChanged } from "../ui/dashboard-settings"; import { toolRegistry, type ToolRegistry, type ToolResult } from "./tool-registry"; export type WindowToolsOptions = { - /** The built-in launcher apps; installed EvenHub apps are added dynamically. */ - apps: readonly AppDefinition[]; + /** The built-in launcher apps for the paired glasses; installed EvenHub apps are added dynamically. */ + apps: () => readonly AppDefinition[]; /** Launch (or focus) an app exactly as the launcher grid would. */ launchApp: (appId: string) => Promise | void; /** Repaint the shell surface so the sidebar reflects a focus change. */ @@ -47,9 +47,11 @@ export function registerWindowTools( if (registered) return; registered = true; registerTools(options, registry); - let fingerprint = getInstalledEvenHubFingerprint(); + const launchableFingerprint = () => + `${getInstalledEvenHubFingerprint()}\n${options.apps().map((app) => app.appId).join()}`; + let fingerprint = launchableFingerprint(); onAnySettingChanged(() => { - const current = getInstalledEvenHubFingerprint(); + const current = launchableFingerprint(); if (current === fingerprint) return; fingerprint = current; registerTools(options, registry); @@ -58,7 +60,7 @@ export function registerWindowTools( function registerTools(options: WindowToolsOptions, registry: ToolRegistry): void { const installedApps = getInstalledEvenHubApps(); - const apps = new Map(options.apps.map((app) => [app.appId, app.title])); + const apps = new Map(options.apps().map((app) => [app.appId, app.title])); for (const app of installedApps) { apps.set(installedEvenHubAppId(app.packageId), app.name); } diff --git a/app/g2/dashboard-controller.ts b/app/g2/dashboard-controller.ts index 2d798e68..b52caef1 100644 --- a/app/g2/dashboard-controller.ts +++ b/app/g2/dashboard-controller.ts @@ -195,8 +195,8 @@ const LOW_BATTERY_PERCENT = 5; const EVEN_APP_DETECTED_MESSAGE = "The Even Realities app appears to be running. If Faceclaw has trouble connecting, open its app settings and force stop it."; -// The launcher grid's app list; also fixes the app ids apps.launch accepts. -const LAUNCHABLE_APPS = ALL_APPS.filter((app) => app.showInLauncher !== false); +// The launcher grid's app list for the paired glasses; also fixes the app ids apps.launch accepts. +const launchableApps = () => ALL_APPS.filter((app) => app.showInLauncher !== false && app.isSupported?.() !== false); /** * The global settings window viewport sizes depend on: the paired glasses' @@ -422,7 +422,7 @@ class DashboardController { registerRoamTools((appId) => this.launchApp(appId)); // apps.* tools mirror the launcher grid and sidebar (launch, focus, close). registerWindowTools({ - apps: LAUNCHABLE_APPS, + apps: launchableApps, launchApp: (appId) => this.launchApp(appId), requestShellRender: () => this.requestShellRender(), }); @@ -506,7 +506,7 @@ class DashboardController { assistant: text => shell.sendToAssistant(text), }); this.wearRemote = new WearRemote({ - apps: LAUNCHABLE_APPS, + apps: launchableApps, injectInput: (kind) => this.injectSyntheticRingInput(kind, "watch"), launchApp: (appId) => this.launchApp(appId), connect: () => this.connect(), diff --git a/app/g2/ios-preview-controller.ts b/app/g2/ios-preview-controller.ts index 247d8f1d..61d219be 100644 --- a/app/g2/ios-preview-controller.ts +++ b/app/g2/ios-preview-controller.ts @@ -272,7 +272,7 @@ export class IosPreviewController { // The header's EvenHub phone-UI button hides while that UI is showing. onPhoneShownChanged(() => this.syncEvenHubPhoneUi()) registerSystemTools() - registerWindowTools({ apps: ALL_APPS.filter(app => !iosAppUnavailableReason(app.appId)), + registerWindowTools({ apps: () => ALL_APPS.filter(app => app.isSupported?.() !== false && !iosAppUnavailableReason(app.appId)), launchApp: id => this.launchApp(id), requestShellRender: () => this.requestShellRender() }) registerNavigateTools(id => this.launchApp(id)) registerRoamTools(id => this.launchApp(id)) @@ -280,7 +280,7 @@ export class IosPreviewController { iosVoiceInput.onSpeechEnd(() => this.syncContinuousCapture()) for (const app of ALL_APPS) if (app.appId !== 'launcher' && !iosAppUnavailableReason(app.appId)) app.boot?.(this.buildAppContext(app)) this.wearRemote = new WearRemote({ - apps: ALL_APPS.filter(app => app.showInLauncher !== false && !iosAppUnavailableReason(app.appId)), + apps: () => ALL_APPS.filter(app => app.showInLauncher !== false && app.isSupported?.() !== false && !iosAppUnavailableReason(app.appId)), injectInput: kind => this.injectWatchInput(kind), launchApp: id => this.launchApp(id), // The watch's Connect/Disconnect are explicit user choices, like the phone's own buttons. diff --git a/app/g2/wear-remote.ts b/app/g2/wear-remote.ts index c2e2b597..e865b32a 100644 --- a/app/g2/wear-remote.ts +++ b/app/g2/wear-remote.ts @@ -115,8 +115,8 @@ const WATCH_BATTERY_MAX_AGE_MS = 4 * 60 * 60_000; /** What the dashboard controller lends the watch remote. */ export type WearRemoteHost = { - /** The launcher-grid apps; installed EvenHub packages are added dynamically. */ - apps: readonly AppDefinition[]; + /** The launcher-grid apps for the paired glasses; installed EvenHub packages are added dynamically. */ + apps: () => readonly AppDefinition[]; injectInput: (kind: WearRemoteInputKind) => Promise; launchApp: (appId: string) => Promise; connect: () => Promise; @@ -320,7 +320,7 @@ export class WearRemote { /** Launchable apps, matching the launcher grid and the apps.launch tool. */ private listApps(): Array<{ appId: string; title: string }> { - const apps = this.host.apps.map((app) => ({ appId: app.appId, title: app.title })); + const apps = this.host.apps().map((app) => ({ appId: app.appId, title: app.title })); for (const installed of getInstalledEvenHubApps()) { apps.push({ appId: installedEvenHubAppId(installed.packageId), title: installed.name }); } diff --git a/app/ui/dashboard-settings.ts b/app/ui/dashboard-settings.ts index 212945e8..e8d6a5c1 100644 --- a/app/ui/dashboard-settings.ts +++ b/app/ui/dashboard-settings.ts @@ -396,6 +396,15 @@ export const glassesTypeSetting = new ConfigSettingEnum({ reportInAnalytics: false, }); +/** + * Whether the paired glasses can report a heading. A G1 has an accelerometer + * and a gyroscope but no magnetometer; the RayNeo iO's firmware has no compass + * messages. + */ +export function glassesHaveCompass(): boolean { + return glassesTypeSetting.get() === "g2"; +} + const APP_SWITCHER_POSITION_LABELS: Record = { left: "Left", right: "Right", diff --git a/tests/compass-readout.test.cjs b/tests/compass-readout.test.cjs index 05acf06f..fd772a58 100644 --- a/tests/compass-readout.test.cjs +++ b/tests/compass-readout.test.cjs @@ -55,7 +55,7 @@ function compass(width = 576, height = 260, glasses = 'g2') { }, '../../ui/shell/shell': { shell: { isWindowVisible: () => true } }, '../../native/location-permissions': { hasLocationPermission: () => false }, - '../../ui/dashboard-settings': { glassesTypeSetting: { get: () => glasses } }, + '../../ui/dashboard-settings': { glassesHaveCompass: () => glasses === 'g2' }, './calibration': calibration, './calibration-layer': {}, './declination': { onDeclinationChanged: () => () => {} }, './heading': { getNorthReference: () => 'magnetic', resolveHeading: (v) => ({ displayDegrees: v }) }, diff --git a/tests/compass-texture-cache.test.cjs b/tests/compass-texture-cache.test.cjs index 4326f5ba..702daebe 100644 --- a/tests/compass-texture-cache.test.cjs +++ b/tests/compass-texture-cache.test.cjs @@ -44,7 +44,7 @@ const compass = load('app/apps/compass/compass-app.ts', { '../../ui/shell/in-process-window': {}, '../../ui/shell/shell': {}, '../../native/location-permissions': {}, - '../../ui/dashboard-settings': { glassesTypeSetting: { get: () => 'g2' } }, + '../../ui/dashboard-settings': { glassesHaveCompass: () => true }, './calibration': calibration, './calibration-layer': {}, './compass-rose': rose, diff --git a/tests/display-layout-setting.test.cjs b/tests/display-layout-setting.test.cjs index d17d5666..8c583682 100644 --- a/tests/display-layout-setting.test.cjs +++ b/tests/display-layout-setting.test.cjs @@ -98,3 +98,14 @@ test('a RayNeo iO always takes the R1 directly, leaving the G2\'s ring connectio api.glassesTypeSetting.set('g2'); assert.equal(api.effectiveRingConnectionMode(), 'health'); }); + +test('only a G2 has a compass', () => { + const api = settingsFixture(); + assert.equal(api.glassesHaveCompass(), true); + api.glassesTypeSetting.set('g1'); + assert.equal(api.glassesHaveCompass(), false); + api.glassesTypeSetting.set('rayneo-io'); + assert.equal(api.glassesHaveCompass(), false); + api.glassesTypeSetting.set('g2'); + assert.equal(api.glassesHaveCompass(), true); +}); diff --git a/tests/glanceboard-settings.test.cjs b/tests/glanceboard-settings.test.cjs index ebb171f9..47dc8358 100644 --- a/tests/glanceboard-settings.test.cjs +++ b/tests/glanceboard-settings.test.cjs @@ -20,18 +20,26 @@ function load(file, dependencies) { function harness() { const values = new Map(); const listeners = new Set(); + const live = new Set(); + const glasses = { haveCompass: true }; class Setting { constructor(options) { Object.assign(this, options); } - get() { return values.get(this.storageKey) ?? this.defaultValue; } + get() { + const value = values.get(this.storageKey) ?? this.defaultValue; + return this.normalize ? this.normalize(value) : value; + } set(value) { values.set(this.storageKey, value); } } const config = { ConfigSettingBoolean: Setting, ConfigSettingEnum: Setting, + glassesHaveCompass: () => glasses.haveCompass, onAnySettingChanged: (listener) => { listeners.add(listener); return () => listeners.delete(listener); }, }; const widgets = { glanceWidgetSpans: (choice) => choice === 'calendar' || choice === 'terminal', - findGlanceWidget: () => ({ create: () => ({ start() {}, stop() {}, paint() {} }) }), + findGlanceWidget: (choice) => ({ create: () => ({ + start() { live.add(choice); }, stop() { live.delete(choice); }, paint() {}, + }) }), }; const settings = load('app/apps/glanceboard/glanceboard-settings.ts', { '../../ui/dashboard-settings': config, './layout': layout, './widgets': widgets, @@ -45,7 +53,7 @@ function harness() { '../../graphics/image': { GrayImage }, '../../ui/dashboard-settings': config, './glanceboard-settings': settings, './layout': layout, './widgets': widgets, }); - return { settings, GlanceBoard, values, listeners, notify: () => [...listeners].forEach((listener) => listener()) }; + return { settings, GlanceBoard, values, listeners, live, glasses, notify: () => [...listeners].forEach((listener) => listener()) }; } test('layout defaults to 2x2; expanding preserves stored slots and remembers the extra row', () => { @@ -97,3 +105,38 @@ test('an active empty board resizes and requests a frame when the layout changes board.stop(); assert.equal(h.listeners.size, 0); }); + +test('glasses without a compass: no compass in the picker, and a stored one reads as Empty until a G2 returns', () => { + const h = harness(); + h.values.set('glanceboard.quadrants.slot.0', 'compass'); + assert.ok(h.settings.glanceSlotSettings()[0].values.includes('compass')); + assert.equal(h.settings.glanceSlotSettings()[0].get(), 'compass'); + + h.glasses.haveCompass = false; + const [slot] = h.settings.glanceSlotSettings(); + assert.ok(!slot.values.includes('compass')); + // Empty, not the slot's default: System card may already be elsewhere on the board. + assert.equal(slot.get(), 'none'); + assert.equal(h.values.get('glanceboard.quadrants.slot.0'), 'compass'); + + h.glasses.haveCompass = true; + assert.equal(h.settings.glanceSlotSettings()[0].get(), 'compass'); +}); + +test('an unknown stored slot value still falls back to the slot default', () => { + const { settings: s, values } = harness(); + values.set('glanceboard.quadrants.slot.0', 'removed-widget'); + assert.equal(s.glanceSlotSettings()[0].get(), 'system-card'); +}); + +test('a live board drops the compass widget when the paired glasses have no compass', () => { + const h = harness(); + h.values.set('glanceboard.quadrants.slot.0', 'compass'); + const board = new h.GlanceBoard(() => {}); + board.start(); + assert.ok(h.live.has('compass')); + h.glasses.haveCompass = false; + h.notify(); + assert.ok(!h.live.has('compass')); + board.stop(); +}); diff --git a/tests/ios-watch-remote.test.cjs b/tests/ios-watch-remote.test.cjs index 316b854b..57047b60 100644 --- a/tests/ios-watch-remote.test.cjs +++ b/tests/ios-watch-remote.test.cjs @@ -135,7 +135,7 @@ function loadRemote({ phase = 'disconnected', preview = false, now = 1_800_000_0 })[id] ?? {}, }); const remote = new WearRemote({ - apps: [{ appId: 'timer', title: 'Timer' }], + apps: () => [{ appId: 'timer', title: 'Timer' }], injectInput: async kind => { inputs.push(kind); }, launchApp: async () => {}, connect: async () => {}, disconnect: async () => {}, setGlassesLocked() {}, requestShellRender() {}, diff --git a/tests/unsupported-apps.test.cjs b/tests/unsupported-apps.test.cjs new file mode 100644 index 00000000..8a283494 --- /dev/null +++ b/tests/unsupported-apps.test.cjs @@ -0,0 +1,71 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); +const ts = require('typescript'); + +function load(file, dependencies) { + const context = { exports: {}, console, require: (name) => { + assert.ok(name in dependencies, name); + return dependencies[name]; + } }; + vm.runInNewContext(ts.transpileModule(fs.readFileSync(path.join(__dirname, '..', file), 'utf8'), { + compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, + }).outputText, context); + return context.exports; +} + +const installedApps = { + getInstalledEvenHubApps: () => [], + getInstalledEvenHubFingerprint: () => '', + installedEvenHubAppId: (packageId) => packageId, + renderInstalledEvenHubIcon: () => null, +}; + +test('the launcher grid leaves out an app the paired glasses cannot run', () => { + const { launcherEntries } = load('app/apps/launcher/index.ts', { + '../../ui/shell/shell': { shell: {} }, + './launcher-app': {}, + '../evenhub/installed-apps': installedApps, + }); + let supported = true; + const apps = [ + { appId: 'launcher', title: 'Apps', showInLauncher: false }, + { appId: 'timer', title: 'Timer' }, + { appId: 'compass', title: 'Compass', isSupported: () => supported }, + ]; + const ids = () => Array.from(launcherEntries(apps), (entry) => entry.appId); + assert.deepEqual(ids(), ['timer', 'compass']); + supported = false; + assert.deepEqual(ids(), ['timer']); +}); + +test('apps.launch follows the paired glasses', async () => { + const listeners = []; + const { registerWindowTools } = load('app/assistant/window-tools.ts', { + '../ui/shell/shell': { shell: { wake() {} } }, + '../apps/launcher/launcher-folders': {}, + '../apps/evenhub/installed-apps': installedApps, + '../ui/dashboard-settings': { onAnySettingChanged: (listener) => listeners.push(listener) }, + './tool-registry': { toolRegistry: null }, + }); + const tools = new Map(); + const registry = { registerSystemTool: (spec, handler) => tools.set(spec.name, { spec, handler }) }; + const launched = []; + const timer = { appId: 'timer', title: 'Timer' }; + const compass = { appId: 'compass', title: 'Compass' }; + let apps = [timer, compass]; + registerWindowTools({ apps: () => apps, launchApp: (appId) => launched.push(appId), requestShellRender() {} }, registry); + const launch = () => tools.get('apps.launch'); + const launchIds = () => Array.from(launch().spec.inputSchema.properties.app_id.enum); + assert.deepEqual(launchIds(), ['compass', 'timer']); + + apps = [timer]; + listeners.forEach((listener) => listener()); + assert.deepEqual(launchIds(), ['timer']); + await launch().handler({ app_id: 'compass' }); + assert.deepEqual(launched, []); + await launch().handler({ app_id: 'timer' }); + assert.deepEqual(launched, ['timer']); +});