@glassly/miniapp 0.3.4-dev.703 → 0.3.5-dev.705

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/src/session.ts CHANGED
@@ -51,6 +51,7 @@ import {StreamModule} from "./modules/stream"
51
51
  import {SystemModule} from "./modules/system"
52
52
  import {MiniappsModule} from "./modules/miniapps"
53
53
  import {ActionsModule} from "./modules/actions"
54
+ import {WidgetsModule, type WidgetBox, type WidgetEvent, type WidgetFrame} from "./modules/widgets"
54
55
  import {BlobModule} from "./modules/blob"
55
56
 
56
57
  // ---------------------------------------------------------------------------
@@ -212,6 +213,7 @@ export type PermissionType =
212
213
  | "displayMirror"
213
214
  | "manageMiniapps"
214
215
  | "platformSettings"
216
+ | "hostWidgets"
215
217
  export type PermissionRecord = Record<PermissionType, boolean>
216
218
 
217
219
  const ALL_PERMISSION_TYPES: readonly PermissionType[] = [
@@ -227,6 +229,7 @@ const ALL_PERMISSION_TYPES: readonly PermissionType[] = [
227
229
  "displayMirror",
228
230
  "manageMiniapps",
229
231
  "platformSettings",
232
+ "hostWidgets",
230
233
  ] as const
231
234
 
232
235
  export class NotConnectedError extends Error {
@@ -398,6 +401,11 @@ export class MiniappSession<TChannels extends object = any> {
398
401
  * action; `handle` exposes one of your own. Both are open to all.
399
402
  */
400
403
  public readonly actions: ActionsModule
404
+ /**
405
+ * Dashboard widgets. `provide` serves a widget this miniapp declares; the
406
+ * host side (`list`, `place`, `send`, `onFrame`) needs HOST_WIDGETS.
407
+ */
408
+ public readonly widgets: WidgetsModule
401
409
 
402
410
  /** Phone-declared glasses capabilities. Null until CONNECT_ACK arrives. */
403
411
  public capabilities: GlassesCapabilities | null = null
@@ -458,6 +466,7 @@ export class MiniappSession<TChannels extends object = any> {
458
466
  displayMirror: false,
459
467
  manageMiniapps: false,
460
468
  platformSettings: false,
469
+ hostWidgets: false,
461
470
  }
462
471
 
463
472
  constructor(options: MiniappSessionOptions = {}) {
@@ -503,6 +512,7 @@ export class MiniappSession<TChannels extends object = any> {
503
512
  this.ui = new UIModuleImpl<TChannels>(this)
504
513
  this.miniapps = new MiniappsModule(this)
505
514
  this.actions = new ActionsModule(this)
515
+ this.widgets = new WidgetsModule(this)
506
516
  }
507
517
 
508
518
  /**
@@ -928,6 +938,29 @@ export class MiniappSession<TChannels extends object = any> {
928
938
  return
929
939
  }
930
940
 
941
+ case MiniappResponseType.WIDGET_CALL: {
942
+ const callId = payload.callId as string | undefined
943
+ const widgetId = payload.widgetId as string | undefined
944
+ const kind = payload.kind
945
+ if (!callId || !widgetId || (kind !== "box" && kind !== "event")) return
946
+ this.widgets._deliverCall(
947
+ callId,
948
+ widgetId,
949
+ kind,
950
+ (payload.box as WidgetBox | null | undefined) ?? null,
951
+ (payload.event as WidgetEvent | null | undefined) ?? null,
952
+ )
953
+ return
954
+ }
955
+
956
+ case MiniappResponseType.WIDGET_FRAME: {
957
+ const packageName = payload.packageName as string | undefined
958
+ const widgetId = payload.widgetId as string | undefined
959
+ if (!packageName || !widgetId || !Array.isArray(payload.elements)) return
960
+ this.widgets._deliverFrame({packageName, widgetId, elements: payload.elements} as WidgetFrame)
961
+ return
962
+ }
963
+
931
964
  case MiniappResponseType.CAPABILITIES_UPDATE: {
932
965
  const cap = (payload.capabilities as GlassesCapabilities | null) ?? null
933
966
  this.capabilities = cap
@@ -1147,6 +1180,8 @@ function manifestKeyToCanonical(manifestKey: string): PermissionType | null {
1147
1180
  return "manageMiniapps"
1148
1181
  case "PLATFORM_SETTINGS":
1149
1182
  return "platformSettings"
1183
+ case "HOST_WIDGETS":
1184
+ return "hostWidgets"
1150
1185
  default:
1151
1186
  return null
1152
1187
  }