@glassly/miniapp-cli 0.1.19-beta.0 → 0.1.19-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glassly/miniapp-cli",
3
- "version": "0.1.19-beta.0",
3
+ "version": "0.1.19-dev.1",
4
4
  "description": "Build tooling for Glassly miniapps: dev server, packer, manifest validation, and JSON Schema. The `glassly` command that drives it ships in @glassly/cli.",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -130,6 +130,10 @@
130
130
  <span class="label">Glasses connected</span>
131
131
  <input id="connected" type="checkbox" class="switch" checked />
132
132
  </label>
133
+ <label class="row" id="worn-row">
134
+ <span class="label">Glasses worn</span>
135
+ <input id="worn" type="checkbox" class="switch" checked />
136
+ </label>
133
137
  <label class="row">
134
138
  <span class="label">Glasses battery</span>
135
139
  <input id="battery" type="range" min="0" max="100" value="80" />
@@ -22,7 +22,12 @@ interface Status {
22
22
  display: {view: string | null; frames: number; elements: number}
23
23
  device: {model: string; label: string; canvas: {width: number; height: number} | null; gestures: string[]}
24
24
  speaker: string
25
- sensors: {glassesBattery: {level: number}; location: {lat: number; lng: number}; glassesConnected: boolean}
25
+ sensors: {
26
+ glassesBattery: {level: number}
27
+ glassesWorn: boolean | null
28
+ location: {lat: number; lng: number}
29
+ glassesConnected: boolean
30
+ }
26
31
  colorScheme: string
27
32
  phone: "iphone" | "duo"
28
33
  unsimulated: string[]
@@ -122,6 +127,8 @@ function showStatus(status: Status): void {
122
127
  if (document.activeElement !== battery) battery.value = String(status.sensors.glassesBattery.level)
123
128
  $("battery-value").textContent = `${battery.value}%`
124
129
  $<HTMLInputElement>("connected").checked = status.sensors.glassesConnected
130
+ $("worn-row").hidden = status.sensors.glassesWorn === null
131
+ $<HTMLInputElement>("worn").checked = status.sensors.glassesWorn !== false
125
132
  document.querySelectorAll<HTMLButtonElement>("[data-scheme]").forEach((button) => {
126
133
  button.setAttribute("aria-pressed", String(button.dataset.scheme === status.colorScheme))
127
134
  })
@@ -244,6 +251,9 @@ $("send-location").addEventListener("click", () => {
244
251
  $("connected").addEventListener("change", (event) => {
245
252
  void post("connection", {connected: (event.target as HTMLInputElement).checked})
246
253
  })
254
+ $("worn").addEventListener("change", (event) => {
255
+ void post("wear", {worn: (event.target as HTMLInputElement).checked})
256
+ })
247
257
  document.querySelectorAll<HTMLButtonElement>("[data-scheme]").forEach((button) => {
248
258
  button.addEventListener("click", () => void post("color-scheme", {colorScheme: button.dataset.scheme}))
249
259
  })
@@ -58,6 +58,9 @@ test("custom firmware turns off the firmware's own navigation and G2 gates its m
58
58
  expect(SIM_DEVICES.g2.capabilities.hasNativeNavigation).toBe(true)
59
59
  expect(SIM_DEVICES["g2-cfw"].capabilities.hasNativeNavigation).toBe(false)
60
60
  expect(SIM_DEVICES["g2-cfw"].capabilities.microphone).toEqual({count: 1, hasVAD: false, volumeGate: true})
61
+ expect(SIM_DEVICES["g2-cfw"].capabilities.hasWearDetection).toBe(true)
62
+ expect(SIM_DEVICES["g1-cfw"].capabilities.hasWearDetection).toBe(true)
63
+ expect(SIM_DEVICES.g2.capabilities.hasWearDetection).toBeUndefined()
61
64
  })
62
65
 
63
66
  test("Mentra Live has a camera and speaker but no display", () => {
package/src/sim/device.ts CHANGED
@@ -32,6 +32,7 @@ interface CustomFirmware {
32
32
  canvas: {width: number; height: number}
33
33
  stereo?: boolean
34
34
  volumeGate?: boolean
35
+ wearDetection?: boolean
35
36
  }
36
37
 
37
38
  interface DeviceSpec {
@@ -75,7 +76,7 @@ const SPECS: DeviceSpec[] = [
75
76
  model: "Even Realities G1",
76
77
  label: "Even Realities G1, Glassly custom firmware",
77
78
  gestures: ["single_tap", "double_tap", "triple_tap", "long_press", ...HEAD],
78
- cfw: {canvas: {width: 640, height: 200}},
79
+ cfw: {canvas: {width: 640, height: 200}, wearDetection: true},
79
80
  },
80
81
  {id: "g2", model: "Even Realities G2", label: "Even Realities G2, stock firmware", gestures: [...EVEN_TOUCH, ...HEAD]},
81
82
  {
@@ -83,7 +84,7 @@ const SPECS: DeviceSpec[] = [
83
84
  model: "Even Realities G2",
84
85
  label: "Even Realities G2, Glassly custom firmware",
85
86
  gestures: [...EVEN_TOUCH, ...HEAD],
86
- cfw: {canvas: {width: 576, height: 288}, volumeGate: true},
87
+ cfw: {canvas: {width: 576, height: 288}, volumeGate: true, wearDetection: true},
87
88
  },
88
89
  {
89
90
  id: "rayneo-io",
@@ -137,6 +138,7 @@ function capabilitiesOf(spec: DeviceSpec): SimDevice["capabilities"] {
137
138
  if (cfw && base.display) {
138
139
  if (base.hasNativeNavigation === true) base.hasNativeNavigation = false
139
140
  if (cfw.volumeGate) base.microphone = {...(base.microphone as object), volumeGate: true}
141
+ if (cfw.wearDetection) base.hasWearDetection = true
140
142
  base.display = {
141
143
  ...base.display,
142
144
  width: cfw.canvas.width,
@@ -462,6 +462,29 @@ describe("phone", () => {
462
462
  expect(await session.location.getOnce()).toMatchObject({lat: 48.8566, lng: 2.3522})
463
463
  })
464
464
 
465
+ test("wear state reaches onWear on glasses that report it", async () => {
466
+ const {session, host} = await connect({}, "g2-cfw")
467
+ const seen: boolean[] = []
468
+ session.glasses.onWear(({worn}) => seen.push(worn))
469
+ await settle()
470
+ host.setWorn(false)
471
+ host.setWorn(true)
472
+ await settle()
473
+ expect(session.capabilities?.hasWearDetection).toBe(true)
474
+ expect(seen).toEqual([true, false, true])
475
+ })
476
+
477
+ test("glasses that report no wear state stay silent and refuse the control", async () => {
478
+ const {session, host} = await connect({}, "g2")
479
+ const seen: boolean[] = []
480
+ session.glasses.onWear(({worn}) => seen.push(worn))
481
+ await settle()
482
+ expect(() => host.setWorn(false)).toThrow("reports no wear state")
483
+ await settle()
484
+ expect(session.capabilities?.hasWearDetection).toBeUndefined()
485
+ expect(seen).toEqual([])
486
+ })
487
+
465
488
  test("a disconnect pauses the miniapp and holds back its streams", async () => {
466
489
  const {session, host} = await connect()
467
490
  const taps: string[] = []
@@ -576,7 +599,7 @@ describe("daily state", () => {
576
599
  expect(changes).toEqual([{key: "head_up_angle", value: 30}])
577
600
 
578
601
  const again = await connect(manifest, "simulated", {settings: settings()})
579
- expect(await again.session.settings.get("head_up_angle")).toBe(30)
602
+ expect(await again.session.settings.get<number>("head_up_angle")).toBe(30)
580
603
  })
581
604
 
582
605
  test("a reading speed one app sets reaches every app in the sim, and only open keys reach apps without the permission", async () => {
@@ -601,7 +624,7 @@ describe("daily state", () => {
601
624
  {key: "reading_wpm", value: 260},
602
625
  {key: "brightness", value: 30},
603
626
  ])
604
- expect(await news.session.settings.get("reading_wpm")).toBe(260)
627
+ expect(await news.session.settings.get<number>("reading_wpm")).toBe(260)
605
628
  })
606
629
 
607
630
  test("an app reads only its own per-app reading speed", async () => {
package/src/sim/host.ts CHANGED
@@ -251,6 +251,7 @@ export class SimHost {
251
251
 
252
252
  private glassesConnected = true
253
253
  private glassesBattery = {level: 80, charging: false}
254
+ private glassesWorn = true
254
255
  private phoneBattery = {level: 90, charging: false}
255
256
  private location: SimLocation = {lat: 37.7749, lng: -122.4194, accuracy: 5, timestamp: Date.now()}
256
257
  private visibility: "foreground" | "background" = "foreground"
@@ -927,6 +928,7 @@ export class SimHost {
927
928
  else if (stream === "phone_battery") this.push(stream, {...this.phoneBattery, timestamp: Date.now()})
928
929
  else if (stream === "glasses_connection") this.push(stream, this.connectionData())
929
930
  else if (stream === "glasses_wifi") this.push(stream, {connected: false})
931
+ else if (stream === "glasses_wear" && this.reportsWear()) this.push(stream, {worn: this.glassesWorn})
930
932
  else if (stream === MiniappStreamType.MIRROR_UPDATE) this.push(stream, this.snapshot())
931
933
  else if (stream === MiniappStreamType.SETTINGS_CHANGED) {
932
934
  for (const key of hostRules.selectSettingsBridgeKeys?.(undefined, this.platformSettings) ?? []) {
@@ -1524,6 +1526,23 @@ export class SimHost {
1524
1526
  this.emit({type: "status"})
1525
1527
  }
1526
1528
 
1529
+ private reportsWear(): boolean {
1530
+ return this.device.capabilities.hasWearDetection === true
1531
+ }
1532
+
1533
+ /** Lands at once; a phone holds a take-off back about 5 seconds. */
1534
+ setWorn(worn: boolean): void {
1535
+ if (!this.reportsWear()) {
1536
+ throw new Error(
1537
+ `${this.device.label} reports no wear state. Start the simulator with --device g1-cfw or --device g2-cfw.`,
1538
+ )
1539
+ }
1540
+ if (worn === this.glassesWorn) return
1541
+ this.glassesWorn = worn
1542
+ this.push("glasses_wear", {worn})
1543
+ this.emit({type: "status"})
1544
+ }
1545
+
1527
1546
  /** The pause lands after the disconnect event and lifts before the reconnect event, as on a phone. */
1528
1547
  setGlassesConnected(connected: boolean): void {
1529
1548
  if (connected === this.glassesConnected) return
@@ -1689,6 +1708,7 @@ export class SimHost {
1689
1708
  sensors: {
1690
1709
  glassesConnected: this.glassesConnected,
1691
1710
  glassesBattery: this.glassesBattery,
1711
+ glassesWorn: this.reportsWear() ? this.glassesWorn : null,
1692
1712
  phoneBattery: this.phoneBattery,
1693
1713
  location: this.location,
1694
1714
  },
package/src/sim/server.ts CHANGED
@@ -418,6 +418,9 @@ export function startSimServer(options: SimServerOptions): SimServer {
418
418
  case "connection":
419
419
  host.setGlassesConnected(body.connected !== false)
420
420
  break
421
+ case "wear":
422
+ host.setWorn(body.worn !== false)
423
+ break
421
424
  case "notify":
422
425
  return json({ok: true, notificationId: host.notification(body as Record<string, string>)})
423
426
  case "visibility":