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

+7
View File
@@ -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;
/**
+5 -10
View File
@@ -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) => {
+2
View File
@@ -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),
};
+26 -13
View File
@@ -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<GlanceSlotChoice>[] {
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<GlanceSlotChoice>({
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<GlanceSlotChoice>({
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.`,
});
});
}
/**
+1 -1
View File
@@ -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,