Don't show the Compass app on hardware (ie G1s) that can't support it

This commit is contained in:
James Babcock committed 2026-11-06 15:13:46 -08:00
1 parent 38c52ebc31
commit 0cc263c5d2
16 files changed
+202 -49

No files matched your search

+1 -1
View File
@@ -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 }) },
+1 -1
View File
@@ -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,
+11
View File
@@ -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);
});
+46 -3
View File
@@ -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();
});
+1 -1
View File
@@ -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() {},
+71
View File
@@ -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']);
});