@glassly/miniapp 0.4.0 → 0.4.1-dev.1137

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 (90) hide show
  1. package/README.md +1 -1
  2. package/dist/background/index.d.ts +1 -1
  3. package/dist/background/index.d.ts.map +1 -1
  4. package/dist/background/index.js.map +1 -1
  5. package/dist/display/index.d.ts +1 -1
  6. package/dist/display/index.d.ts.map +1 -1
  7. package/dist/display/index.js +1 -1
  8. package/dist/display/index.js.map +1 -1
  9. package/dist/display/profiles/index.d.ts +1 -0
  10. package/dist/display/profiles/index.d.ts.map +1 -1
  11. package/dist/display/profiles/index.js +1 -0
  12. package/dist/display/profiles/index.js.map +1 -1
  13. package/dist/display/profiles/nimo.d.ts +9 -0
  14. package/dist/display/profiles/nimo.d.ts.map +1 -0
  15. package/dist/display/profiles/nimo.js +142 -0
  16. package/dist/display/profiles/nimo.js.map +1 -0
  17. package/dist/display/profiles/types.d.ts.map +1 -1
  18. package/dist/display/scene/types.d.ts.map +1 -1
  19. package/dist/display/scene/types.js.map +1 -1
  20. package/dist/display/wrapper/normalize.d.ts.map +1 -1
  21. package/dist/display/wrapper/normalize.js +2 -0
  22. package/dist/display/wrapper/normalize.js.map +1 -1
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/manifest.d.ts.map +1 -1
  27. package/dist/manifest.js +10 -1
  28. package/dist/manifest.js.map +1 -1
  29. package/dist/mirror/canvas.js +1 -1
  30. package/dist/mirror/canvas.js.map +1 -1
  31. package/dist/modules/events.d.ts +9 -0
  32. package/dist/modules/events.d.ts.map +1 -1
  33. package/dist/modules/events.js +17 -1
  34. package/dist/modules/events.js.map +1 -1
  35. package/dist/modules/keys.d.ts +1 -1
  36. package/dist/modules/keys.js +1 -1
  37. package/dist/modules/phone.d.ts +17 -7
  38. package/dist/modules/phone.d.ts.map +1 -1
  39. package/dist/modules/phone.js +26 -6
  40. package/dist/modules/phone.js.map +1 -1
  41. package/dist/modules/settings.d.ts +1 -1
  42. package/dist/modules/settings.js +1 -1
  43. package/dist/modules/widgets.d.ts.map +1 -1
  44. package/dist/modules/widgets.js.map +1 -1
  45. package/dist/protocol.d.ts +13 -7
  46. package/dist/protocol.d.ts.map +1 -1
  47. package/dist/protocol.js +13 -7
  48. package/dist/protocol.js.map +1 -1
  49. package/dist/react/MiniappHeader.d.ts.map +1 -1
  50. package/dist/react/MiniappHeader.js +3 -1
  51. package/dist/react/MiniappHeader.js.map +1 -1
  52. package/dist/react/index.d.ts +1 -0
  53. package/dist/react/index.d.ts.map +1 -1
  54. package/dist/react/index.js +1 -0
  55. package/dist/react/index.js.map +1 -1
  56. package/dist/react/useRailBackButton.d.ts +2 -0
  57. package/dist/react/useRailBackButton.d.ts.map +1 -0
  58. package/dist/react/useRailBackButton.js +40 -0
  59. package/dist/react/useRailBackButton.js.map +1 -0
  60. package/dist/session.d.ts +5 -4
  61. package/dist/session.d.ts.map +1 -1
  62. package/dist/session.js.map +1 -1
  63. package/dist/transport/mock.js.map +1 -1
  64. package/dist/ui/index.d.ts +2 -0
  65. package/dist/ui/index.d.ts.map +1 -1
  66. package/dist/ui/index.js +1 -0
  67. package/dist/ui/index.js.map +1 -1
  68. package/package.json +5 -5
  69. package/src/background/index.ts +1 -0
  70. package/src/display/index.ts +1 -0
  71. package/src/display/profiles/index.ts +2 -0
  72. package/src/display/profiles/nimo.ts +148 -0
  73. package/src/display/profiles/types.ts +1 -9
  74. package/src/display/scene/types.ts +1 -6
  75. package/src/display/wrapper/normalize.ts +2 -0
  76. package/src/index.ts +1 -0
  77. package/src/manifest.ts +10 -1
  78. package/src/mirror/canvas.ts +5 -5
  79. package/src/modules/events.ts +28 -1
  80. package/src/modules/keys.ts +1 -1
  81. package/src/modules/phone.ts +36 -7
  82. package/src/modules/settings.ts +1 -1
  83. package/src/modules/widgets.ts +11 -2
  84. package/src/protocol.ts +14 -7
  85. package/src/react/MiniappHeader.tsx +3 -1
  86. package/src/react/index.ts +1 -0
  87. package/src/react/useRailBackButton.ts +50 -0
  88. package/src/session.ts +6 -9
  89. package/src/transport/mock.ts +4 -4
  90. package/src/ui/index.ts +2 -0
@@ -19,7 +19,14 @@
19
19
 
20
20
  import {MiniappRequestType, MiniappStreamType} from "../protocol"
21
21
  import {MiniappSession} from "../session"
22
- import type {BatteryData, HeadingData, NotificationDismissedData, PhoneNotificationData, UnsubscribeFn} from "./events"
22
+ import type {
23
+ BatteryData,
24
+ HeadingData,
25
+ NotificationDismissedData,
26
+ PhoneNotificationData,
27
+ PostNotificationOptions,
28
+ UnsubscribeFn,
29
+ } from "./events"
23
30
 
24
31
  class TrackedSubs {
25
32
  private readonly unsubs = new Set<UnsubscribeFn>()
@@ -54,13 +61,13 @@ export class PhoneNotificationsModule extends TrackedSubs {
54
61
  }
55
62
 
56
63
  /**
57
- * Subscribe to dismiss events for phone notifications. Fires when the user
58
- * dismisses (swipes away or clears) a notification.
64
+ * Subscribe to dismiss events. Fires when the user dismisses (swipes away
65
+ * or clears) a phone notification, and when a miniapp dismisses one it
66
+ * posted.
59
67
  *
60
- * **Android only.** iOS does not expose dismiss callbacks to apps (Apple
61
- * privacy restriction); subscribing on iOS succeeds but no events ever
62
- * fire. The matching `notifications.on()` post-event still works on both
63
- * platforms.
68
+ * Phone dismissals are **Android only**: iOS does not expose dismiss
69
+ * callbacks to apps (Apple privacy restriction). Miniapp dismissals arrive
70
+ * on both platforms.
64
71
  */
65
72
  onDismissed(handler: (data: NotificationDismissedData) => void): UnsubscribeFn {
66
73
  return this.track(
@@ -85,6 +92,28 @@ export class PhoneNotificationsModule extends TrackedSubs {
85
92
  })
86
93
  return result ?? []
87
94
  }
95
+
96
+ /**
97
+ * Post a notification down the same path as the phone's own. It reaches the
98
+ * running dashboard and every `on()` subscriber as `system: false` with
99
+ * `source` set to this miniapp, and the glasses the way a phone
100
+ * notification would. Resolves with its id; posting again with that id
101
+ * replaces it. Needs `POST_NOTIFICATIONS`.
102
+ */
103
+ async post(notification: PostNotificationOptions): Promise<string> {
104
+ const result = await this.session.sendRequest<{id: string}>({
105
+ type: MiniappRequestType.NOTIFICATION_POST,
106
+ title: notification.title ?? "",
107
+ content: notification.content ?? "",
108
+ ...(notification.id !== undefined ? {id: notification.id} : {}),
109
+ })
110
+ return result.id
111
+ }
112
+
113
+ /** Withdraw a notification this miniapp posted. Needs `POST_NOTIFICATIONS`. */
114
+ async dismiss(id: string): Promise<void> {
115
+ await this.session.sendRequest<void>({type: MiniappRequestType.NOTIFICATION_DISMISS, id})
116
+ }
88
117
  }
89
118
 
90
119
  export interface NotificationAppInfo {
@@ -8,7 +8,7 @@
8
8
  * truth. A miniapp's own preferences belong in `session.storage`.
9
9
  *
10
10
  * Keys are the engine's setting keys (e.g. `notifications_popups`,
11
- * `menu_apps`, `twelve_hour_time`); values are their JSON values. The host
11
+ * `menu_apps`, `head_up_angle`); values are their JSON values. The host
12
12
  * also serves a few derived read-only keys (`phone_active`,
13
13
  * `foreground_app_on_screen`, `controllers`) that the engine computes rather
14
14
  * than stores. `set` on a read-only or unknown key rejects.
@@ -234,7 +234,13 @@ export class WidgetsModule {
234
234
  * @internal — called by MiniappSession.handleIncoming on a WIDGET_CALL.
235
235
  * Routes to the widget's hooks, or waits briefly for `provide`.
236
236
  */
237
- _deliverCall(callId: string, widgetId: string, kind: "box" | "event", box: WidgetBox | null, event: WidgetEvent | null): void {
237
+ _deliverCall(
238
+ callId: string,
239
+ widgetId: string,
240
+ kind: "box" | "event",
241
+ box: WidgetBox | null,
242
+ event: WidgetEvent | null,
243
+ ): void {
238
244
  const handle = this.handles.get(widgetId)
239
245
  if (handle) {
240
246
  void this.dispatch(handle, callId, kind, box, event)
@@ -357,7 +363,10 @@ export class WidgetsModule {
357
363
  try {
358
364
  listener(frame)
359
365
  } catch (err) {
360
- console.warn(`[@glassly/miniapp] widgets.onFrame listener threw for ${widgetKey(frame.packageName, frame.widgetId)}`, err)
366
+ console.warn(
367
+ `[@glassly/miniapp] widgets.onFrame listener threw for ${widgetKey(frame.packageName, frame.widgetId)}`,
368
+ err,
369
+ )
361
370
  }
362
371
  }
363
372
  }
package/src/protocol.ts CHANGED
@@ -102,6 +102,15 @@ export enum MiniappRequestType {
102
102
  */
103
103
  NOTIFICATION_APPS_LIST = "miniapp_notification_apps_list",
104
104
 
105
+ /**
106
+ * Post or dismiss a miniapp notification. It reaches the dashboard, other
107
+ * readers and the glasses the way a phone notification does.
108
+ * POST_NOTIFICATIONS permission. POST takes `title`, `content` and an
109
+ * optional `id` (same id replaces) and answers `{id}`; DISMISS takes `id`.
110
+ */
111
+ NOTIFICATION_POST = "miniapp_notification_post",
112
+ NOTIFICATION_DISMISS = "miniapp_notification_dismiss",
113
+
105
114
  /**
106
115
  * The engine's settings store behind an allowlist (session.settings).
107
116
  * PLATFORM_SETTINGS permission. GET takes optional `keys` and answers
@@ -141,7 +150,7 @@ export enum MiniappRequestType {
141
150
  NAVIGATION_REQUEST_PERMISSION = "miniapp_navigation_request_permission",
142
151
 
143
152
  /**
144
- * Read a user-supplied provider API key (Settings > API Keys) by provider
153
+ * Read a user-supplied provider API key (Settings > Privacy > API Keys) by provider
145
154
  * name. Requires the API_KEYS manifest permission; the host only serves an
146
155
  * allowlisted provider set (see KeysModule) — notably the Soniox key is
147
156
  * excluded. Keys are device-local; the value never transits any server.
@@ -152,7 +161,7 @@ export enum MiniappRequestType {
152
161
  * Run one LLM completion turn through the platform. Requires the AI manifest
153
162
  * permission. The host routes to the cloud LLM service, which picks the
154
163
  * provider and pays with the platform key — or with the user's own key when
155
- * they've saved one for that provider (Settings > API Keys), in which case
164
+ * they've saved one for that provider (Settings > Privacy > API Keys), in which case
156
165
  * the call isn't metered against their plan.
157
166
  *
158
167
  * Single-shot or a client-side tool loop: when the model wants a tool run,
@@ -517,11 +526,9 @@ export enum MiniappStreamType {
517
526
  */
518
527
  SETTINGS_CHANGED = "settings_changed",
519
528
  /**
520
- * A previously-posted notification was dismissed by the user.
521
- *
522
- * Android-only today. iOS does not expose dismiss callbacks to apps
523
- * (Apple privacy restriction); subscribing on iOS succeeds but no events
524
- * fire.
529
+ * A previously-posted notification was dismissed: by the user on the phone
530
+ * (Android only; iOS exposes no dismiss callbacks to apps) or by the
531
+ * miniapp that posted it (both platforms).
525
532
  */
526
533
  PHONE_NOTIFICATION_DISMISSED = "phone_notification_dismissed",
527
534
  // Photos, streaming
@@ -20,6 +20,7 @@
20
20
  import type {CSSProperties, ReactNode} from "react"
21
21
 
22
22
  import {useCapsuleHeaderStyle, type UseCapsuleHeaderStyleOptions} from "./useCapsuleHeaderStyle"
23
+ import {useRailBackButton} from "./useRailBackButton"
23
24
 
24
25
  export interface MiniappHeaderProps extends UseCapsuleHeaderStyleOptions {
25
26
  /** Title — string renders as <h1>; pass a node for custom markup. */
@@ -82,7 +83,8 @@ export function MiniappHeader({
82
83
  ...styleOptions
83
84
  }: MiniappHeaderProps): ReactNode {
84
85
  const computedStyle = useCapsuleHeaderStyle(styleOptions)
85
- const resolvedLeft = left ?? (onBack ? <BackChevron onBack={onBack} /> : null)
86
+ const backInRail = useRailBackButton(left ? null : onBack)
87
+ const resolvedLeft = left ?? (onBack && !backInRail ? <BackChevron onBack={onBack} /> : null)
86
88
 
87
89
  return (
88
90
  <>
@@ -4,6 +4,7 @@ export {useColorScheme} from "./useColorScheme"
4
4
  export {useCapabilities} from "./useCapabilities"
5
5
  export {useConnected} from "./useConnected"
6
6
  export {useCapsuleHeaderStyle} from "./useCapsuleHeaderStyle"
7
+ export {useRailBackButton} from "./useRailBackButton"
7
8
  export type {UseCapsuleHeaderStyleOptions} from "./useCapsuleHeaderStyle"
8
9
  export {MiniappHeader} from "./MiniappHeader"
9
10
  export type {MiniappHeaderProps} from "./MiniappHeader"
@@ -0,0 +1,50 @@
1
+ import {useEffect, useRef, useState} from "react"
2
+
3
+ import {getHostGlobals} from "../globals"
4
+
5
+ interface BackBridge {
6
+ setBackAction?: (handler: (() => void) | null) => void
7
+ }
8
+
9
+ function bridge(): BackBridge | undefined {
10
+ return typeof window === "undefined" ? undefined : (window as unknown as {glassly?: BackBridge}).glassly
11
+ }
12
+
13
+ const backStack: Array<{press: () => void}> = []
14
+
15
+ function syncHost(): void {
16
+ const top = backStack[backStack.length - 1]
17
+ bridge()?.setBackAction?.(top ? top.press : null)
18
+ }
19
+
20
+ function hostDrawsBack(): boolean {
21
+ return getHostGlobals().capsuleMenu?.placement === "rail" && typeof bridge()?.setBackAction === "function"
22
+ }
23
+
24
+ export function useRailBackButton(onBack: (() => void) | null | undefined): boolean {
25
+ const onBackRef = useRef(onBack)
26
+ onBackRef.current = onBack
27
+ const active = typeof onBack === "function"
28
+
29
+ useEffect(() => {
30
+ if (!active) return
31
+ const entry = {press: () => onBackRef.current?.()}
32
+ backStack.push(entry)
33
+ syncHost()
34
+ return () => {
35
+ const index = backStack.indexOf(entry)
36
+ if (index >= 0) backStack.splice(index, 1)
37
+ syncHost()
38
+ }
39
+ }, [active])
40
+
41
+ const [inRail, setInRail] = useState(hostDrawsBack)
42
+ useEffect(() => {
43
+ const update = () => setInRail(hostDrawsBack())
44
+ update()
45
+ window.addEventListener("glassly:safe-area-change", update)
46
+ return () => window.removeEventListener("glassly:safe-area-change", update)
47
+ }, [])
48
+
49
+ return active && inRail
50
+ }
package/src/session.ts CHANGED
@@ -146,9 +146,10 @@ export interface MiniappSessionOptions extends CreateTransportOptions {
146
146
  export type MiniappUnitSystem = "metric" | "imperial"
147
147
 
148
148
  /**
149
- * Host user preferences a miniapp should follow by default (Settings >
150
- * Appearance). Sent in CONNECT_ACK and pushed on change. Miniapps may still
151
- * offer their own override on top.
149
+ * Host user preferences a miniapp should follow by default: the metric
150
+ * toggle (Settings > Appearance) and the phone's own clock format. Sent in
151
+ * CONNECT_ACK and pushed on change. Miniapps may still offer their own
152
+ * override on top.
152
153
  */
153
154
  export interface MiniappPreferences {
154
155
  unitSystem: MiniappUnitSystem
@@ -338,7 +339,7 @@ export class MiniappSession<TChannels extends object = any> {
338
339
  public readonly compass: CompassModule
339
340
  public readonly input: InputModule
340
341
  /**
341
- * User-supplied provider API keys (Settings > API Keys). Requires the
342
+ * User-supplied provider API keys (Settings > Privacy > API Keys). Requires the
342
343
  * API_KEYS manifest permission; only an allowlisted provider set is
343
344
  * readable (anthropic / gemini / openai / deepseek / elevenlabs / mapbox — never soniox).
344
345
  */
@@ -580,11 +581,7 @@ export class MiniappSession<TChannels extends object = any> {
580
581
  * session.transcription.on(...)
581
582
  * etc. instead."
582
583
  */
583
- _subscribe(
584
- streamType: string,
585
- handler: (data: unknown) => void,
586
- options: StreamRouteOptions = {},
587
- ): UnsubscribeFn {
584
+ _subscribe(streamType: string, handler: (data: unknown) => void, options: StreamRouteOptions = {}): UnsubscribeFn {
588
585
  return this.events.subscribe(streamType, handler, options)
589
586
  }
590
587
 
@@ -219,10 +219,10 @@ function syntheticDataFor(requestId: string, requestType: string, requestPayload
219
219
  requestPayload.preset === "narrow"
220
220
  ? 82
221
221
  : requestPayload.preset === "wide"
222
- ? 118
223
- : requestPayload.preset === "standard"
224
- ? 102
225
- : undefined
222
+ ? 118
223
+ : requestPayload.preset === "standard"
224
+ ? 102
225
+ : undefined
226
226
  const fov = typeof requestPayload.fov === "number" ? requestPayload.fov : (presetFov ?? 102)
227
227
  const roi = requestPayload.roiPosition
228
228
  const roiPosition = roi === "bottom" ? "bottom" : roi === "top" ? "top" : "center"
package/src/ui/index.ts CHANGED
@@ -87,6 +87,7 @@ export interface UiGlobal<TChannels extends object = Record<string, unknown>> {
87
87
  * theme background. Call on mount and again on color-scheme changes.
88
88
  */
89
89
  setBackgroundColor(color: string): void
90
+ setBackAction?(handler: (() => void) | null): void
90
91
  }
91
92
 
92
93
  // React adapters are re-exported here so authors can import everything
@@ -99,6 +100,7 @@ export {useCapabilities} from "../react/useCapabilities"
99
100
  export {useConnected} from "../react/useConnected"
100
101
  export {useSafeArea} from "../react/useSafeArea"
101
102
  export {useCapsuleHeaderStyle} from "../react/useCapsuleHeaderStyle"
103
+ export {useRailBackButton} from "../react/useRailBackButton"
102
104
  export {useRpc, type RpcCallable} from "../react/useRpc"
103
105
 
104
106
  /**