@glassly/miniapp 0.3.4-dev.704 → 0.3.5-beta.707
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/README.md +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/manifest.d.ts +4 -1
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +3 -0
- package/dist/manifest.js.map +1 -1
- package/dist/modules/widgets.d.ts +147 -0
- package/dist/modules/widgets.d.ts.map +1 -0
- package/dist/modules/widgets.js +188 -0
- package/dist/modules/widgets.js.map +1 -0
- package/dist/protocol.d.ts +25 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +28 -0
- package/dist/protocol.js.map +1 -1
- package/dist/session.d.ts +7 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +23 -0
- package/dist/session.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +12 -0
- package/src/manifest.ts +6 -0
- package/src/modules/widgets.ts +286 -0
- package/src/protocol.ts +30 -0
- package/src/session.ts +35 -0
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
|
}
|