@glassly/engine 0.3.7 → 0.3.8-beta.984

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.
Files changed (187) hide show
  1. package/README.md +4 -0
  2. package/build/engine.d.ts +8 -2
  3. package/build/engine.d.ts.map +1 -1
  4. package/build/engine.js +7 -4
  5. package/build/engine.js.map +1 -1
  6. package/build/facades/backup.d.ts +14 -0
  7. package/build/facades/backup.d.ts.map +1 -0
  8. package/build/facades/backup.js +22 -0
  9. package/build/facades/backup.js.map +1 -0
  10. package/build/facades/glasses.d.ts +4 -4
  11. package/build/facades/glasses.d.ts.map +1 -1
  12. package/build/facades/glasses.js +4 -4
  13. package/build/facades/glasses.js.map +1 -1
  14. package/build/generated/releaseMetadata.js +4 -4
  15. package/build/generated/releaseMetadata.js.map +1 -1
  16. package/build/index.d.ts +1 -0
  17. package/build/index.d.ts.map +1 -1
  18. package/build/index.js.map +1 -1
  19. package/build/services/AppRegistry.d.ts +2 -1
  20. package/build/services/AppRegistry.d.ts.map +1 -1
  21. package/build/services/AppRegistry.js +38 -8
  22. package/build/services/AppRegistry.js.map +1 -1
  23. package/build/services/AppStateBackup.d.ts +98 -0
  24. package/build/services/AppStateBackup.d.ts.map +1 -0
  25. package/build/services/AppStateBackup.js +224 -0
  26. package/build/services/AppStateBackup.js.map +1 -0
  27. package/build/services/BlobStore.d.ts.map +1 -1
  28. package/build/services/BlobStore.js +5 -12
  29. package/build/services/BlobStore.js.map +1 -1
  30. package/build/services/CloudClientService.d.ts +1 -0
  31. package/build/services/CloudClientService.d.ts.map +1 -1
  32. package/build/services/CloudClientService.js +34 -2
  33. package/build/services/CloudClientService.js.map +1 -1
  34. package/build/services/DisplayDiagnostics.d.ts.map +1 -1
  35. package/build/services/DisplayDiagnostics.js +4 -2
  36. package/build/services/DisplayDiagnostics.js.map +1 -1
  37. package/build/services/DisplayProcessor.d.ts +2 -0
  38. package/build/services/DisplayProcessor.d.ts.map +1 -1
  39. package/build/services/DisplayProcessor.js +15 -1
  40. package/build/services/DisplayProcessor.js.map +1 -1
  41. package/build/services/GlassesTouchInput.d.ts.map +1 -1
  42. package/build/services/GlassesTouchInput.js +4 -2
  43. package/build/services/GlassesTouchInput.js.map +1 -1
  44. package/build/services/JSCrashloopReportService.d.ts.map +1 -1
  45. package/build/services/JSCrashloopReportService.js +5 -0
  46. package/build/services/JSCrashloopReportService.js.map +1 -1
  47. package/build/services/JSRouter.d.ts +11 -3
  48. package/build/services/JSRouter.d.ts.map +1 -1
  49. package/build/services/JSRouter.js +36 -6
  50. package/build/services/JSRouter.js.map +1 -1
  51. package/build/services/LocalDisplayManager.d.ts +2 -0
  52. package/build/services/LocalDisplayManager.d.ts.map +1 -1
  53. package/build/services/LocalDisplayManager.js +4 -0
  54. package/build/services/LocalDisplayManager.js.map +1 -1
  55. package/build/services/LocalMiniappRuntime.d.ts +19 -0
  56. package/build/services/LocalMiniappRuntime.d.ts.map +1 -1
  57. package/build/services/LocalMiniappRuntime.js +79 -22
  58. package/build/services/LocalMiniappRuntime.js.map +1 -1
  59. package/build/services/MiniappEngine.d.ts +9 -0
  60. package/build/services/MiniappEngine.d.ts.map +1 -1
  61. package/build/services/MiniappEngine.js +60 -27
  62. package/build/services/MiniappEngine.js.map +1 -1
  63. package/build/services/MiniappLauncher.d.ts +2 -0
  64. package/build/services/MiniappLauncher.d.ts.map +1 -1
  65. package/build/services/MiniappLauncher.js +6 -0
  66. package/build/services/MiniappLauncher.js.map +1 -1
  67. package/build/services/NavigationService.d.ts +1 -0
  68. package/build/services/NavigationService.d.ts.map +1 -1
  69. package/build/services/NavigationService.js +20 -6
  70. package/build/services/NavigationService.js.map +1 -1
  71. package/build/services/PhoneCalendarService.d.ts.map +1 -1
  72. package/build/services/PhoneCalendarService.js +8 -0
  73. package/build/services/PhoneCalendarService.js.map +1 -1
  74. package/build/services/PhoneNotificationsSync.d.ts.map +1 -1
  75. package/build/services/PhoneNotificationsSync.js +7 -3
  76. package/build/services/PhoneNotificationsSync.js.map +1 -1
  77. package/build/services/SceneRenderer.d.ts +8 -0
  78. package/build/services/SceneRenderer.d.ts.map +1 -1
  79. package/build/services/SceneRenderer.js +29 -1
  80. package/build/services/SceneRenderer.js.map +1 -1
  81. package/build/services/appStateBackupFile.d.ts +32 -0
  82. package/build/services/appStateBackupFile.d.ts.map +1 -0
  83. package/build/services/appStateBackupFile.js +135 -0
  84. package/build/services/appStateBackupFile.js.map +1 -0
  85. package/build/services/controllers.d.ts.map +1 -1
  86. package/build/services/controllers.js +11 -3
  87. package/build/services/controllers.js.map +1 -1
  88. package/build/services/effectiveCapabilities.js +3 -0
  89. package/build/services/effectiveCapabilities.js.map +1 -1
  90. package/build/services/pages/pageEligibility.d.ts.map +1 -1
  91. package/build/services/pages/pageEligibility.js +8 -1
  92. package/build/services/pages/pageEligibility.js.map +1 -1
  93. package/build/services/settingsBridge.d.ts.map +1 -1
  94. package/build/services/settingsBridge.js +1 -0
  95. package/build/services/settingsBridge.js.map +1 -1
  96. package/build/services/{appleWatch/AppleWatchLink.d.ts → watch/WatchLink.d.ts} +8 -7
  97. package/build/services/watch/WatchLink.d.ts.map +1 -0
  98. package/build/services/{appleWatch/AppleWatchLink.js → watch/WatchLink.js} +14 -15
  99. package/build/services/watch/WatchLink.js.map +1 -0
  100. package/build/stores/apps.d.ts.map +1 -1
  101. package/build/stores/apps.js +22 -10
  102. package/build/stores/apps.js.map +1 -1
  103. package/build/stores/settings.d.ts.map +1 -1
  104. package/build/stores/settings.js +56 -6
  105. package/build/stores/settings.js.map +1 -1
  106. package/build/types/capabilities/even-realities-g1.d.ts.map +1 -1
  107. package/build/types/capabilities/even-realities-g1.js +3 -0
  108. package/build/types/capabilities/even-realities-g1.js.map +1 -1
  109. package/build/types/capabilities/memomind-one.d.ts +3 -0
  110. package/build/types/capabilities/memomind-one.d.ts.map +1 -0
  111. package/build/types/capabilities/memomind-one.js +41 -0
  112. package/build/types/capabilities/memomind-one.js.map +1 -0
  113. package/build/types/enums.d.ts +6 -2
  114. package/build/types/enums.d.ts.map +1 -1
  115. package/build/types/enums.js +4 -0
  116. package/build/types/enums.js.map +1 -1
  117. package/build/types/hardware.d.ts +3 -1
  118. package/build/types/hardware.d.ts.map +1 -1
  119. package/build/types/hardware.js +3 -1
  120. package/build/types/hardware.js.map +1 -1
  121. package/build/utils/display/index.d.ts +2 -1
  122. package/build/utils/display/index.d.ts.map +1 -1
  123. package/build/utils/display/index.js +3 -2
  124. package/build/utils/display/index.js.map +1 -1
  125. package/build/utils/display/profiles/index.d.ts +2 -1
  126. package/build/utils/display/profiles/index.d.ts.map +1 -1
  127. package/build/utils/display/profiles/index.js +3 -2
  128. package/build/utils/display/profiles/index.js.map +1 -1
  129. package/build/utils/display/profiles/rayneo-io.d.ts +1 -1
  130. package/build/utils/display/profiles/rayneo-io.d.ts.map +1 -1
  131. package/build/utils/display/profiles/rayneo-io.js +1 -1
  132. package/build/utils/display/profiles/rayneo-io.js.map +1 -1
  133. package/build/utils/display/scene/index.d.ts +1 -1
  134. package/build/utils/display/scene/index.d.ts.map +1 -1
  135. package/build/utils/display/scene/index.js +1 -1
  136. package/build/utils/display/scene/index.js.map +1 -1
  137. package/build/utils/display/scene/process.d.ts +6 -0
  138. package/build/utils/display/scene/process.d.ts.map +1 -1
  139. package/build/utils/display/scene/process.js +22 -7
  140. package/build/utils/display/scene/process.js.map +1 -1
  141. package/build/utils/miniappGlobals.d.ts +13 -17
  142. package/build/utils/miniappGlobals.d.ts.map +1 -1
  143. package/build/utils/miniappGlobals.js +24 -56
  144. package/build/utils/miniappGlobals.js.map +1 -1
  145. package/package.json +7 -7
  146. package/src/engine.ts +7 -4
  147. package/src/facades/backup.ts +28 -0
  148. package/src/facades/glasses.ts +5 -5
  149. package/src/generated/releaseMetadata.ts +4 -4
  150. package/src/index.ts +1 -0
  151. package/src/services/AppRegistry.ts +36 -9
  152. package/src/services/AppStateBackup.ts +283 -0
  153. package/src/services/BlobStore.ts +5 -11
  154. package/src/services/CloudClientService.ts +35 -4
  155. package/src/services/DisplayDiagnostics.ts +4 -2
  156. package/src/services/DisplayProcessor.ts +20 -8
  157. package/src/services/GlassesTouchInput.ts +6 -2
  158. package/src/services/JSCrashloopReportService.ts +5 -0
  159. package/src/services/JSRouter.ts +37 -6
  160. package/src/services/LocalDisplayManager.ts +5 -0
  161. package/src/services/LocalMiniappRuntime.ts +81 -22
  162. package/src/services/MiniappEngine.ts +62 -27
  163. package/src/services/MiniappLauncher.ts +7 -0
  164. package/src/services/NavigationService.ts +28 -8
  165. package/src/services/PhoneCalendarService.ts +7 -0
  166. package/src/services/PhoneNotificationsSync.ts +8 -3
  167. package/src/services/SceneRenderer.ts +29 -1
  168. package/src/services/appStateBackupFile.ts +171 -0
  169. package/src/services/controllers.ts +12 -3
  170. package/src/services/effectiveCapabilities.ts +3 -0
  171. package/src/services/pages/pageEligibility.ts +9 -1
  172. package/src/services/settingsBridge.ts +1 -0
  173. package/src/services/{appleWatch/AppleWatchLink.ts → watch/WatchLink.ts} +20 -20
  174. package/src/stores/apps.ts +22 -11
  175. package/src/stores/settings.ts +63 -10
  176. package/src/types/capabilities/even-realities-g1.ts +4 -0
  177. package/src/types/capabilities/memomind-one.ts +42 -0
  178. package/src/types/enums.ts +4 -0
  179. package/src/types/hardware.ts +14 -1
  180. package/src/utils/display/index.ts +4 -2
  181. package/src/utils/display/profiles/index.ts +9 -2
  182. package/src/utils/display/profiles/rayneo-io.ts +6 -1
  183. package/src/utils/display/scene/index.ts +1 -1
  184. package/src/utils/display/scene/process.ts +22 -7
  185. package/src/utils/miniappGlobals.ts +32 -64
  186. package/build/services/appleWatch/AppleWatchLink.d.ts.map +0 -1
  187. package/build/services/appleWatch/AppleWatchLink.js.map +0 -1
@@ -9,6 +9,7 @@ import {mentraLive} from "./capabilities/mentra-live"
9
9
  import {simulatedGlasses} from "./capabilities/simulated-glasses"
10
10
  import {nimo} from "./capabilities/nimo"
11
11
  import {rayneoIO} from "./capabilities/rayneo-io"
12
+ import {memoMindOne} from "./capabilities/memomind-one"
12
13
  import {vuzixZ100} from "./capabilities/vuzix-z100"
13
14
  import {none} from "./capabilities/none"
14
15
  import {DeviceTypes} from "./enums"
@@ -217,6 +218,7 @@ export interface Capabilities {
217
218
  // (reading the phone's stream, or an upload from the phone) is the driver's
218
219
  // business; the engine only decides who presents.
219
220
  hasNativeNotifications?: boolean
221
+ hasNotificationRelay?: boolean
220
222
  // Popup durations the firmware accepts, in seconds (0 = firmware default).
221
223
  // Drivers snap other values; the settings UI offers exactly these.
222
224
  nativeNotificationPopupSeconds?: number[]
@@ -236,6 +238,7 @@ export const HARDWARE_CAPABILITIES: Record<string, Capabilities> = {
236
238
  [vuzixZ100.modelName]: vuzixZ100,
237
239
  [nimo.modelName]: nimo,
238
240
  [rayneoIO.modelName]: rayneoIO,
241
+ [memoMindOne.modelName]: memoMindOne,
239
242
  [DeviceTypes.MACH1]: vuzixZ100, // Mach1 uses same Vuzix Ultralite hardware as Z100
240
243
  [DeviceTypes.AR99]: {
241
244
  ...evenRealitiesG1,
@@ -265,4 +268,14 @@ export const getModelCapabilities = (deviceType: DeviceTypes): Capabilities => {
265
268
  }
266
269
 
267
270
  // export * from "./capabilities"
268
- export {simulatedGlasses, evenRealitiesG1, evenRealitiesG2, mentraLive, vuzixZ100, mentraDisplay, nimo, rayneoIO}
271
+ export {
272
+ simulatedGlasses,
273
+ evenRealitiesG1,
274
+ evenRealitiesG2,
275
+ mentraLive,
276
+ vuzixZ100,
277
+ mentraDisplay,
278
+ nimo,
279
+ rayneoIO,
280
+ memoMindOne,
281
+ }
@@ -70,8 +70,8 @@ export {Z100_PROFILE, Z100_HYPHEN_WIDTH_PX, Z100_SPACE_WIDTH_PX} from "./profile
70
70
  // Mentra Nex Profile (a.k.a. Mentra Display)
71
71
  export {NEX_PROFILE, NEX_HYPHEN_WIDTH_PX, NEX_SPACE_WIDTH_PX} from "./profiles"
72
72
 
73
- // RayNeo iO Profile (stock subtitle page)
74
- export {RAYNEO_IO_PROFILE, RAYNEO_IO_HYPHEN_WIDTH_PX, RAYNEO_IO_SPACE_WIDTH_PX} from "./profiles"
73
+ // RayNeo iO Profiles (stock subtitle page, Glassly CFW scene page)
74
+ export {RAYNEO_IO_PROFILE, RAYNEO_IO_CFW_PROFILE, RAYNEO_IO_HYPHEN_WIDTH_PX, RAYNEO_IO_SPACE_WIDTH_PX} from "./profiles"
75
75
 
76
76
  // =============================================================================
77
77
  // Measurer - Pixel-accurate text measurement
@@ -274,3 +274,5 @@ export function createNexToolkit(): {
274
274
  breakMode: "character-no-hyphen",
275
275
  })
276
276
  }
277
+
278
+ export {MEMOMIND_ONE_PROFILE} from "./profiles"
@@ -27,5 +27,12 @@ export {G2_PROFILE, G2_HYPHEN_WIDTH_PX, G2_SPACE_WIDTH_PX} from "./g2"
27
27
  // Mentra Nex Profile (a.k.a. Mentra Display)
28
28
  export {NEX_PROFILE, NEX_HYPHEN_WIDTH_PX, NEX_SPACE_WIDTH_PX} from "./nex"
29
29
 
30
- // RayNeo iO Profile (stock subtitle page)
31
- export {RAYNEO_IO_PROFILE, RAYNEO_IO_HYPHEN_WIDTH_PX, RAYNEO_IO_SPACE_WIDTH_PX} from "./rayneo-io"
30
+ // RayNeo iO Profiles (stock subtitle page, Glassly CFW scene page)
31
+ export {
32
+ RAYNEO_IO_PROFILE,
33
+ RAYNEO_IO_CFW_PROFILE,
34
+ RAYNEO_IO_HYPHEN_WIDTH_PX,
35
+ RAYNEO_IO_SPACE_WIDTH_PX,
36
+ } from "./rayneo-io"
37
+
38
+ export {MEMOMIND_ONE_PROFILE} from "@glassly/miniapp/display"
@@ -1,2 +1,7 @@
1
1
  // Moved into the SDK (@glassly/miniapp/display) so miniapps lay text out the way the host measures it; this path re-exports it for the engine.
2
- export {RAYNEO_IO_PROFILE, RAYNEO_IO_HYPHEN_WIDTH_PX, RAYNEO_IO_SPACE_WIDTH_PX} from "@glassly/miniapp/display"
2
+ export {
3
+ RAYNEO_IO_PROFILE,
4
+ RAYNEO_IO_CFW_PROFILE,
5
+ RAYNEO_IO_HYPHEN_WIDTH_PX,
6
+ RAYNEO_IO_SPACE_WIDTH_PX,
7
+ } from "@glassly/miniapp/display"
@@ -24,7 +24,7 @@ export {resolveAnchors} from "./anchor"
24
24
  export type {DiffResult, DiffableElement} from "./differ"
25
25
  export {diffScene} from "./differ"
26
26
  export type {ProcessedScene} from "./process"
27
- export {processScene, profileLineHeightPx} from "./process"
27
+ export {processScene, profileLineHeightPx, wrapsOnDevice} from "./process"
28
28
  export type {DegradedScene} from "./degrade"
29
29
  export {degradeScene} from "./degrade"
30
30
  export {SceneStore} from "./store"
@@ -9,6 +9,7 @@
9
9
  */
10
10
 
11
11
  import {compileSvgPath} from "./svgPath"
12
+ import {isUnsupportedScript} from "../measurer/script-detection"
12
13
  import {TextMeasurer} from "../measurer/TextMeasurer"
13
14
  import {TextWrapper} from "../wrapper/TextWrapper"
14
15
  import type {DisplayProfile} from "../profiles/types"
@@ -47,6 +48,18 @@ function clampBox(box: SceneBox, width: number, height: number): SceneBox | null
47
48
 
48
49
  const isFinite = (n: unknown): n is number => typeof n === "number" && Number.isFinite(n)
49
50
 
51
+ /**
52
+ * Text the host cannot wrap: a script the measurer has no widths or break
53
+ * rules for (Thai has no spaces between words, for one). It is passed through
54
+ * unwrapped and the device's text engine lays it out in the box.
55
+ */
56
+ export function wrapsOnDevice(text: string): boolean {
57
+ for (const char of text) {
58
+ if (isUnsupportedScript(char)) return true
59
+ }
60
+ return false
61
+ }
62
+
50
63
  /** Integer points, or null when the count/values are invalid for the type. */
51
64
  function validPoints(el: SceneElementInput): ScenePoint[] | null {
52
65
  const raw = (el as {points?: unknown}).points
@@ -372,10 +385,11 @@ export function processScene(
372
385
  // Height clipping only applies with a CALIBRATED line height — otherwise
373
386
  // the firmware clips vertically in-box (legacy behavior).
374
387
  const style: SceneTextStyle = el.style ?? {}
375
- if (style.font === "mono" || style.font === "builtin") {
376
- // Grid text is laid out by the app (cols × rows) and builtin text by the
377
- // glasses' own font engine; the host's proportional wrap metrics don't
378
- // apply to either. Pass lines through and let the device clip.
388
+ if (style.font === "mono" || style.font === "builtin" || wrapsOnDevice(el.text ?? "")) {
389
+ // Grid text is laid out by the app (cols × rows), builtin text by the
390
+ // glasses' own font engine and unsupported scripts by the device's text
391
+ // engine; the host's proportional wrap metrics don't apply to any of
392
+ // them. Pass lines through and let the device wrap and clip.
379
393
  const monoText = el.text ?? ""
380
394
  out.push({
381
395
  id: el.id,
@@ -390,8 +404,9 @@ export function processScene(
390
404
  continue
391
405
  }
392
406
  const maxLines = lineHeight ? Math.max(1, Math.floor(clamped.h / lineHeight)) : profile.maxLines
407
+ const maxWidthPx = Math.max(1, clamped.w - 2 * (profile.textInsetPx ?? 0))
393
408
  const result = wrapper.wrap(el.text ?? "", {
394
- maxWidthPx: clamped.w,
409
+ maxWidthPx,
395
410
  maxLines,
396
411
  ...(style.breakMode ? {breakMode: style.breakMode} : {}),
397
412
  })
@@ -402,12 +417,12 @@ export function processScene(
402
417
  // Trim the last line until it fits WITH the ellipsis appended —
403
418
  // otherwise the extra glyph can overflow the clamped box width.
404
419
  let last = lines[lines.length - 1]
405
- while (last.length > 0 && !measurer.fitsInWidth(`${last}…`, clamped.w)) {
420
+ while (last.length > 0 && !measurer.fitsInWidth(`${last}…`, maxWidthPx)) {
406
421
  last = last.slice(0, -1)
407
422
  }
408
423
  // A box narrower than the ellipsis glyph itself gets an empty line —
409
424
  // never emit a line wider than the clamped box.
410
- const ellipsized = last.length > 0 || measurer.fitsInWidth("…", clamped.w) ? `${last}…` : ""
425
+ const ellipsized = last.length > 0 || measurer.fitsInWidth("…", maxWidthPx) ? `${last}…` : ""
411
426
  lines = [...lines.slice(0, -1), ellipsized]
412
427
  }
413
428
  }
@@ -7,7 +7,7 @@
7
7
  * same API surface.
8
8
  */
9
9
 
10
- import {Dimensions, Platform} from "react-native"
10
+ import {Platform} from "react-native"
11
11
 
12
12
  export interface MiniappSafeArea {
13
13
  top: number
@@ -16,6 +16,11 @@ export interface MiniappSafeArea {
16
16
  right: number
17
17
  }
18
18
 
19
+ /**
20
+ * The host's capsule menu in the WebView's own coordinate space. `corner`
21
+ * floats over the page's top-right; `rail` sits in the iPhone Duo's status
22
+ * rail, inside the side safe-area inset and clear of the page content.
23
+ */
19
24
  export interface CapsuleMenuRect {
20
25
  top: number
21
26
  right: number
@@ -23,36 +28,7 @@ export interface CapsuleMenuRect {
23
28
  left: number
24
29
  width: number
25
30
  height: number
26
- }
27
-
28
- /**
29
- * The capsule menu bounding rect in the WebView's own coordinate space.
30
- *
31
- * Keep in sync with CapsuleMenu.tsx:
32
- * - CapsuleButton height ≈ h-7.5 (30px), width ≈ 73px
33
- * - Positioned at right-2 (8px), top = theme.spacing.s2 (8px) below insets.top
34
- */
35
- const CAPSULE_MENU_HEIGHT = 30
36
- const CAPSULE_MENU_WIDTH = 73
37
- const CAPSULE_MENU_PADDING = 8
38
-
39
- /**
40
- * @param topInsetOffset extra top offset to add when the WebView container does
41
- * NOT already pad by the safe-area inset (i.e. WebView fills edge-to-edge under
42
- * the status bar). Pass `insets.top` in that case, or 0 when the container
43
- * already applies top padding.
44
- */
45
- export function getCapsuleMenuRect(topInsetOffset = 0): CapsuleMenuRect {
46
- const screenWidth = Dimensions.get("window").width
47
- const top = topInsetOffset + CAPSULE_MENU_PADDING
48
- return {
49
- top,
50
- right: CAPSULE_MENU_PADDING,
51
- bottom: top + CAPSULE_MENU_HEIGHT,
52
- left: screenWidth - CAPSULE_MENU_PADDING - CAPSULE_MENU_WIDTH,
53
- width: CAPSULE_MENU_WIDTH,
54
- height: CAPSULE_MENU_HEIGHT,
55
- }
31
+ placement: "corner" | "rail"
56
32
  }
57
33
 
58
34
  export type MiniappColorScheme = "light" | "dark"
@@ -63,37 +39,48 @@ export interface BuildMiniappGlobalsOptions {
63
39
  miniappLocal?: boolean
64
40
  miniappDeveloperMode?: boolean
65
41
  safeAreaInsets: MiniappSafeArea
66
- /**
67
- * True when the WebView container renders edge-to-edge (no top padding for
68
- * the status bar). In that case the capsule menu rect needs to shift down by
69
- * the top inset so its coords match where it's actually drawn on screen.
70
- */
71
- webviewFillsStatusBar?: boolean
42
+ /** Where the host draws its capsule menu over this WebView. */
43
+ capsuleMenu: CapsuleMenuRect
72
44
  /** Current host color scheme. Miniapps may follow this to match the phone. */
73
45
  colorScheme?: MiniappColorScheme
74
46
  }
75
47
 
76
- function safeAreaCssVars(insets: MiniappSafeArea): Record<string, string> {
48
+ // CSS custom properties that mirror the safe-area and capsule menu data, so
49
+ // miniapp CSS (or Tailwind arbitrary values) can read them without touching
50
+ // JS: e.g. `style="margin-top: var(--glassly-capsule-top)"`.
51
+ function layoutCssVars(insets: MiniappSafeArea, capsule: CapsuleMenuRect): Record<string, string> {
77
52
  return {
78
53
  "--glassly-safe-top": `${insets.top}px`,
79
54
  "--glassly-safe-bottom": `${insets.bottom}px`,
80
55
  "--glassly-safe-left": `${insets.left}px`,
81
56
  "--glassly-safe-right": `${insets.right}px`,
57
+ "--glassly-capsule-top": `${capsule.top}px`,
58
+ "--glassly-capsule-bottom": `${capsule.bottom}px`,
59
+ "--glassly-capsule-left": `${capsule.left}px`,
60
+ "--glassly-capsule-right": `${capsule.right}px`,
61
+ "--glassly-capsule-width": `${capsule.width}px`,
62
+ "--glassly-capsule-height": `${capsule.height}px`,
63
+ "--glassly-capsule-center-y": `${capsule.top + capsule.height / 2}px`,
64
+ // Right-side gutter to reserve so content doesn't slide under the
65
+ // capsule: its width + 16px breathing room, none when it sits in the rail.
66
+ "--glassly-capsule-gutter": `${capsule.placement === "rail" ? 0 : capsule.width + 16}px`,
82
67
  }
83
68
  }
84
69
 
85
70
  /**
86
- * JS to inject into a running miniapp when the host's safe area changes (an
87
- * iPhone Duo folding moves its status rail): updates window.Glassly and the
88
- * CSS variables, then fires `glassly:safe-area-change`.
71
+ * JS to inject into a running miniapp when the host's safe area or capsule
72
+ * menu moves (an iPhone Duo folding, or its rail's reserved regions growing):
73
+ * updates window.Glassly and the CSS variables, then fires
74
+ * `glassly:safe-area-change`.
89
75
  */
90
- export function buildSafeAreaUpdateScript(insets: MiniappSafeArea): string {
91
- const sets = Object.entries(safeAreaCssVars(insets))
76
+ export function buildSafeAreaUpdateScript(insets: MiniappSafeArea, capsuleMenu: CapsuleMenuRect): string {
77
+ const sets = Object.entries(layoutCssVars(insets, capsuleMenu))
92
78
  .map(([k, v]) => `document.documentElement.style.setProperty(${JSON.stringify(k)}, ${JSON.stringify(v)});`)
93
79
  .join("\n ")
94
80
  return `
95
81
  window.Glassly = window.Glassly || {};
96
82
  window.Glassly.safeAreaInsets = ${JSON.stringify(insets)};
83
+ window.Glassly.capsuleMenu = ${JSON.stringify(capsuleMenu)};
97
84
  try {
98
85
  ${sets}
99
86
  } catch (e) { /* ignore */ }
@@ -115,37 +102,18 @@ export function buildSafeAreaUpdateScript(insets: MiniappSafeArea): string {
115
102
  * assign to it before the native bridge wires in.
116
103
  */
117
104
  export function buildMiniappGlobalsScript(opts: BuildMiniappGlobalsOptions): string {
118
- const capsuleTopOffset = opts.webviewFillsStatusBar ? opts.safeAreaInsets.top : 0
119
105
  const globals: Record<string, unknown> = {
120
106
  platform: Platform.OS,
121
107
  capabilities: opts.capabilities ?? ["share", "open_url", "copy_clipboard", "download"],
122
108
  safeAreaInsets: opts.safeAreaInsets,
123
- capsuleMenu: getCapsuleMenuRect(capsuleTopOffset),
109
+ capsuleMenu: opts.capsuleMenu,
124
110
  }
125
111
  if (opts.packageName) globals.packageName = opts.packageName
126
112
  if (opts.miniappLocal) globals.miniappLocal = true
127
113
  if (opts.miniappDeveloperMode) globals.miniappDeveloperMode = true
128
114
  if (opts.colorScheme) globals.colorScheme = opts.colorScheme
129
115
 
130
- // CSS custom properties that mirror the capsule menu / safe-area data.
131
- // Miniapp CSS (or Tailwind arbitrary values) can read these without
132
- // touching JS: e.g. `style="margin-top: var(--glassly-capsule-top)"`.
133
- const capsule = globals.capsuleMenu as CapsuleMenuRect
134
- const insets = opts.safeAreaInsets
135
- const capsuleCenter = capsule.top + capsule.height / 2
136
- const cssVars: Record<string, string> = {
137
- ...safeAreaCssVars(insets),
138
- "--glassly-capsule-top": `${capsule.top}px`,
139
- "--glassly-capsule-bottom": `${capsule.bottom}px`,
140
- "--glassly-capsule-left": `${capsule.left}px`,
141
- "--glassly-capsule-right": `${capsule.right}px`,
142
- "--glassly-capsule-width": `${capsule.width}px`,
143
- "--glassly-capsule-height": `${capsule.height}px`,
144
- "--glassly-capsule-center-y": `${capsuleCenter}px`,
145
- // Right-side gutter to reserve so content doesn't slide under the
146
- // capsule: capsule width + 16px breathing room.
147
- "--glassly-capsule-gutter": `${capsule.width + 16}px`,
148
- }
116
+ const cssVars = layoutCssVars(opts.safeAreaInsets, opts.capsuleMenu)
149
117
  const cssVarsBlock = Object.entries(cssVars)
150
118
  .map(([k, v]) => `${k}: ${v};`)
151
119
  .join(" ")
@@ -1 +0,0 @@
1
- {"version":3,"file":"AppleWatchLink.d.ts","sourceRoot":"","sources":["../../../src/services/appleWatch/AppleWatchLink.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAC,sBAAsB,EAAC,MAAM,wBAAwB,CAAA;AAElE,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAA;AAOpD,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,aAAa,CAAA;AAO1C,eAAO,MAAM,cAAc,0BAA0B,CAAA;AACrD,eAAO,MAAM,aAAa,QAAQ,CAAA;AAQlC,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAC,CAAA;IAC7D,IAAI,EAAE,SAAS,SAAS,EAAE,CAAA;IAC1B,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,OAAO,CAAA;CAChB;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAA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YACH,IAAI,KAAK;gBAAE,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;YACtC,KAAK,GAAG,IAAI,CAAA;QACd,CAAC;KACF,CAAA;IACD,UAAU,CAAC,aAAa,EAAE,CAAC,CAAA;IAC3B,QAAQ,EAAE,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;IACzC,UAAU,CAAC,KAAK,CAAC,CAAA;AACnB,CAAC","sourcesContent":["/**\n * The Apple Watch remote's phone half: the watch app's status context (glasses, the miniapp in\n * front, launchable miniapps, whether Assist takes questions, the mirror setting), mirror frames\n * while the setting is on, and the commands the watch sends back. Native adds whether the active\n * watch is paired and keeps the newest frame for when the watch app opens. Gestures ride\n * `touch_event` like any controller's.\n */\nimport type {AppleWatchCommandEvent} from \"@glassly/bluetooth-sdk\"\nimport BluetoothSdk from \"@glassly/bluetooth-sdk/internal\"\nimport type {MirrorSnapshot} from \"@glassly/miniapp\"\nimport {MiniappStreamType} from \"@glassly/miniapp\"\nimport {Platform} from \"react-native\"\n\nimport {useAppStatusStore} from \"../../stores/apps\"\nimport {useGlassesStore} from \"../../stores/glasses\"\nimport {SETTINGS, useSettingsStore} from \"../../stores/settings\"\nimport type {ClientApp} from \"../../types\"\nimport {BgTimer} from \"../../utils/timers\"\nimport {isGlassesConnected} from \"../GlassesReadiness\"\nimport localMiniappRuntime from \"../LocalMiniappRuntime\"\nimport {mirrorService} from \"../MirrorService\"\nimport {keyEventsForTextChange} from \"../neuralBand/NeuralBandInput\"\n\nexport const ASSIST_PACKAGE = \"com.glassly.assistant\"\nexport const ASSIST_ACTION = \"ask\"\n/** WatchConnectivity messages top out near 64 KB; frames past this are skipped, not truncated. */\nconst MAX_FRAME_BYTES = 48_000\nconst MAX_IMAGE_CHARS = 16_000\nconst MAX_APPS = 24\nconst STATE_DEBOUNCE_MS = 250\nconst MIRROR_INTERVAL_MS = 500\n\nexport interface WatchStateInput {\n glasses: {connected: boolean; model: string; battery: number}\n apps: readonly ClientApp[]\n assist: boolean\n mirror: boolean\n}\n\n/** Miniapps the watch can open: shown, compatible, and drawing on the glasses. */\nexport function launchableApps(apps: readonly ClientApp[]): {packageName: string; name: string}[] {\n return apps\n .filter((app) => app.type === \"standard\" && !app.hidden && app.compatibility?.isCompatible !== false)\n .filter((app) => app.packageName && !app.packageName.includes(\"@empty\"))\n .slice(0, MAX_APPS)\n .map((app) => ({packageName: app.packageName, name: app.name}))\n}\n\nexport function watchState({glasses, apps, assist, mirror}: WatchStateInput): Record<string, unknown> {\n const front = apps.find((app) => app.foregrounded && app.running && app.type === \"standard\")\n const state: Record<string, unknown> = {\n glasses: {connected: glasses.connected, name: glasses.model || \"Glasses\", battery: glasses.battery},\n apps: launchableApps(apps),\n assist,\n mirror,\n }\n if (front) state.app = {packageName: front.packageName, name: front.name}\n return state\n}\n\ntype WatchElement = Record<string, string | number | boolean | number[]>\n\nconst level = (color: unknown, fallback = 15) =>\n typeof color === \"number\" ? Math.max(0, Math.min(15, color)) : fallback\n\n/** The glasses frame in the watch's drawing vocabulary; null when there is nothing to draw. */\nexport function mirrorFrame(snapshot: MirrorSnapshot): Record<string, unknown> | null {\n const canvas = snapshot.canvas\n if (!canvas) return null\n const content = snapshot.content\n if (content.kind === \"bitmap\") {\n if (content.data.length > MAX_FRAME_BYTES) return null\n return {width: canvas.width, height: canvas.height, bitmap: content.data, elements: []}\n }\n if (content.kind !== \"scene\") return null\n const elements: WatchElement[] = []\n for (const element of content.elements) {\n const {x, y, w, h} = element.box\n const style = element.style ?? {}\n switch (element.type) {\n case \"text\":\n if (!element.text) break\n elements.push({\n type: \"text\",\n x,\n y,\n w,\n h,\n text: element.text,\n size: style.fontSize ?? 20,\n color: level(style.color),\n })\n break\n case \"rect\":\n elements.push({\n type: \"rect\",\n x,\n y,\n w,\n h,\n fill: style.fill === true,\n border: style.border ?? 1,\n radius: style.radius ?? 0,\n color: level(style.color),\n })\n break\n case \"circle\":\n elements.push({\n type: \"circle\",\n x,\n y,\n w,\n h,\n fill: style.fill === true,\n border: style.border ?? 1,\n color: level(style.color),\n })\n break\n case \"line\":\n case \"triangle\":\n case \"quad\": {\n const points = (element.points ?? []).flatMap((point) => [point.x, point.y])\n if (points.length < 4) break\n const closed = element.type !== \"line\"\n elements.push({\n type: \"line\",\n points,\n width: style.width ?? style.border ?? 1,\n color: level(style.color),\n closed,\n fill: closed && style.fill === true,\n })\n break\n }\n case \"image\":\n if (element.data && element.data.length <= MAX_IMAGE_CHARS)\n elements.push({type: \"image\", x, y, w, h, data: element.data})\n break\n }\n }\n const frame = {width: canvas.width, height: canvas.height, elements}\n return JSON.stringify(frame).length > MAX_FRAME_BYTES ? null : frame\n}\n\nexport interface AppleWatchCommandDeps {\n apps: () => readonly ClientApp[]\n start: (app: ClientApp) => Promise<unknown>\n stop: (packageName: string) => Promise<unknown>\n ask: (query: string) => Promise<unknown>\n type: (stream: string, payload: unknown) => void\n now: () => number\n}\n\nconst defaultDeps: AppleWatchCommandDeps = {\n apps: () => useAppStatusStore.getState().apps,\n start: (app) => useAppStatusStore.getState().start(app),\n stop: (packageName) => useAppStatusStore.getState().stop(packageName),\n ask: (query) => localMiniappRuntime.invokeActionFromHost(ASSIST_PACKAGE, ASSIST_ACTION, {query}),\n type: (stream, payload) => localMiniappRuntime.forwardEvent(stream, payload),\n now: () => Date.now(),\n}\n\nexport async function handleAppleWatchCommand(\n event: AppleWatchCommandEvent,\n deps: AppleWatchCommandDeps = defaultDeps,\n): Promise<void> {\n switch (event.command) {\n case \"launch\": {\n const app = launchableApps(deps.apps()).some((entry) => entry.packageName === event.packageName)\n ? deps.apps().find((entry) => entry.packageName === event.packageName)\n : undefined\n if (!app) {\n console.warn(`AppleWatch: launch of unknown miniapp ${event.packageName}`)\n return\n }\n await deps.start(app)\n return\n }\n case \"stop\": {\n const front = deps.apps().find((app) => app.foregrounded && app.running && app.type === \"standard\")\n if (front) await deps.stop(front.packageName)\n return\n }\n case \"assist\": {\n const query = event.text.trim()\n if (query) await deps.ask(query)\n return\n }\n case \"text\":\n for (const key of keyEventsForTextChange(\"\", event.text, deps.now()))\n deps.type(MiniappStreamType.KEYBOARD_EVENT, key)\n return\n }\n}\n\nlet stops: (() => void)[] = []\nlet stopMirror: (() => void) | null = null\n\nfunction currentState(): Record<string, unknown> {\n const glasses = useGlassesStore.getState()\n return watchState({\n glasses: {\n connected: isGlassesConnected(glasses.connection),\n model: glasses.deviceModel,\n battery: glasses.batteryLevel,\n },\n apps: useAppStatusStore.getState().apps,\n assist: localMiniappRuntime.hostActionAvailable(ASSIST_PACKAGE, ASSIST_ACTION),\n mirror: useSettingsStore.getState().getSetting(SETTINGS.apple_watch_mirror.key) === true,\n })\n}\n\nfunction syncMirror(enabled: boolean): void {\n if (!enabled) {\n if (stopMirror) {\n stopMirror()\n stopMirror = null\n void BluetoothSdk.setWatchMirror(null).catch(() => {})\n }\n return\n }\n if (stopMirror) return\n let lastSentAt = 0\n let pending: MirrorSnapshot | null = null\n let timer: ReturnType<typeof BgTimer.setTimeout> | null = null\n const send = (snapshot: MirrorSnapshot) => {\n lastSentAt = Date.now()\n void BluetoothSdk.setWatchMirror(mirrorFrame(snapshot)).catch((err) =>\n console.warn(\"AppleWatch: mirror push failed:\", err),\n )\n }\n const unsubscribe = mirrorService.subscribe((snapshot) => {\n const wait = lastSentAt + MIRROR_INTERVAL_MS - Date.now()\n if (wait <= 0 && !timer) {\n send(snapshot)\n return\n }\n pending = snapshot\n timer ??= BgTimer.setTimeout(\n () => {\n timer = null\n if (pending) send(pending)\n pending = null\n },\n Math.max(wait, 0),\n )\n })\n stopMirror = () => {\n unsubscribe()\n if (timer) BgTimer.clearTimeout(timer)\n timer = null\n }\n}\n\nexport function startAppleWatchLink(): void {\n if (Platform.OS !== \"ios\" || stops.length > 0) return\n let lastKey = \"\"\n let timer: ReturnType<typeof BgTimer.setTimeout> | null = null\n const push = () => {\n timer = null\n const state = currentState()\n const key = JSON.stringify(state)\n if (key === lastKey) return\n lastKey = key\n void BluetoothSdk.setWatchState(state).catch((err) => console.warn(\"AppleWatch: state push failed:\", err))\n }\n const schedule = () => {\n timer ??= BgTimer.setTimeout(push, STATE_DEBOUNCE_MS)\n }\n const mirrorEnabled = () => useSettingsStore.getState().getSetting(SETTINGS.apple_watch_mirror.key) === true\n const commands = BluetoothSdk.addListener(\"apple_watch_command\", (event) => {\n handleAppleWatchCommand(event).catch((err) => console.warn(`AppleWatch: ${event.command} failed:`, err))\n })\n stops = [\n () => commands.remove(),\n useGlassesStore.subscribe(schedule),\n useAppStatusStore.subscribe(schedule),\n useSettingsStore.subscribe(\n (s) => s.getSetting(SETTINGS.apple_watch_mirror.key),\n () => {\n syncMirror(mirrorEnabled())\n schedule()\n },\n ),\n () => {\n if (timer) BgTimer.clearTimeout(timer)\n timer = null\n },\n ]\n syncMirror(mirrorEnabled())\n schedule()\n}\n\nexport function stopAppleWatchLink(): void {\n stops.splice(0).forEach((stop) => stop())\n syncMirror(false)\n}\n"]}