@mentra/miniapp 0.3.0-dev.0
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 +259 -0
- package/dist/background/index.d.ts +59 -0
- package/dist/background/index.d.ts.map +1 -0
- package/dist/background/index.js +25 -0
- package/dist/background/index.js.map +1 -0
- package/dist/background/register.d.ts +38 -0
- package/dist/background/register.d.ts.map +1 -0
- package/dist/background/register.js +75 -0
- package/dist/background/register.js.map +1 -0
- package/dist/dev-reload.d.ts +21 -0
- package/dist/dev-reload.d.ts.map +1 -0
- package/dist/dev-reload.js +62 -0
- package/dist/dev-reload.js.map +1 -0
- package/dist/envelope.d.ts +23 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +47 -0
- package/dist/envelope.js.map +1 -0
- package/dist/globals.d.ts +54 -0
- package/dist/globals.d.ts.map +1 -0
- package/dist/globals.js +12 -0
- package/dist/globals.js.map +1 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/actions.d.ts +54 -0
- package/dist/modules/actions.d.ts.map +1 -0
- package/dist/modules/actions.js +122 -0
- package/dist/modules/actions.js.map +1 -0
- package/dist/modules/auth.d.ts +25 -0
- package/dist/modules/auth.d.ts.map +1 -0
- package/dist/modules/auth.js +52 -0
- package/dist/modules/auth.js.map +1 -0
- package/dist/modules/base64.d.ts +16 -0
- package/dist/modules/base64.d.ts.map +1 -0
- package/dist/modules/base64.js +92 -0
- package/dist/modules/base64.js.map +1 -0
- package/dist/modules/blob.d.ts +161 -0
- package/dist/modules/blob.d.ts.map +1 -0
- package/dist/modules/blob.js +277 -0
- package/dist/modules/blob.js.map +1 -0
- package/dist/modules/camera.d.ts +137 -0
- package/dist/modules/camera.d.ts.map +1 -0
- package/dist/modules/camera.js +104 -0
- package/dist/modules/camera.js.map +1 -0
- package/dist/modules/cloud.d.ts +34 -0
- package/dist/modules/cloud.d.ts.map +1 -0
- package/dist/modules/cloud.js +70 -0
- package/dist/modules/cloud.js.map +1 -0
- package/dist/modules/dashboard.d.ts +16 -0
- package/dist/modules/dashboard.d.ts.map +1 -0
- package/dist/modules/dashboard.js +27 -0
- package/dist/modules/dashboard.js.map +1 -0
- package/dist/modules/display.d.ts +106 -0
- package/dist/modules/display.d.ts.map +1 -0
- package/dist/modules/display.js +57 -0
- package/dist/modules/display.js.map +1 -0
- package/dist/modules/events.d.ts +167 -0
- package/dist/modules/events.d.ts.map +1 -0
- package/dist/modules/events.js +123 -0
- package/dist/modules/events.js.map +1 -0
- package/dist/modules/glasses.d.ts +28 -0
- package/dist/modules/glasses.d.ts.map +1 -0
- package/dist/modules/glasses.js +39 -0
- package/dist/modules/glasses.js.map +1 -0
- package/dist/modules/heading.d.ts +16 -0
- package/dist/modules/heading.d.ts.map +1 -0
- package/dist/modules/heading.js +20 -0
- package/dist/modules/heading.js.map +1 -0
- package/dist/modules/imu.d.ts +31 -0
- package/dist/modules/imu.d.ts.map +1 -0
- package/dist/modules/imu.js +40 -0
- package/dist/modules/imu.js.map +1 -0
- package/dist/modules/input.d.ts +34 -0
- package/dist/modules/input.d.ts.map +1 -0
- package/dist/modules/input.js +50 -0
- package/dist/modules/input.js.map +1 -0
- package/dist/modules/led.d.ts +35 -0
- package/dist/modules/led.d.ts.map +1 -0
- package/dist/modules/led.js +39 -0
- package/dist/modules/led.js.map +1 -0
- package/dist/modules/location.d.ts +27 -0
- package/dist/modules/location.d.ts.map +1 -0
- package/dist/modules/location.js +35 -0
- package/dist/modules/location.js.map +1 -0
- package/dist/modules/mic.d.ts +44 -0
- package/dist/modules/mic.d.ts.map +1 -0
- package/dist/modules/mic.js +67 -0
- package/dist/modules/mic.js.map +1 -0
- package/dist/modules/miniapps.d.ts +72 -0
- package/dist/modules/miniapps.d.ts.map +1 -0
- package/dist/modules/miniapps.js +48 -0
- package/dist/modules/miniapps.js.map +1 -0
- package/dist/modules/navigation.d.ts +326 -0
- package/dist/modules/navigation.d.ts.map +1 -0
- package/dist/modules/navigation.js +386 -0
- package/dist/modules/navigation.js.map +1 -0
- package/dist/modules/permissions.d.ts +58 -0
- package/dist/modules/permissions.d.ts.map +1 -0
- package/dist/modules/permissions.js +66 -0
- package/dist/modules/permissions.js.map +1 -0
- package/dist/modules/phone.d.ts +61 -0
- package/dist/modules/phone.d.ts.map +1 -0
- package/dist/modules/phone.js +94 -0
- package/dist/modules/phone.js.map +1 -0
- package/dist/modules/pivots/engine.d.ts +169 -0
- package/dist/modules/pivots/engine.d.ts.map +1 -0
- package/dist/modules/pivots/engine.js +779 -0
- package/dist/modules/pivots/engine.js.map +1 -0
- package/dist/modules/pivots/geometry.d.ts +84 -0
- package/dist/modules/pivots/geometry.d.ts.map +1 -0
- package/dist/modules/pivots/geometry.js +371 -0
- package/dist/modules/pivots/geometry.js.map +1 -0
- package/dist/modules/pivots/instructions.d.ts +139 -0
- package/dist/modules/pivots/instructions.d.ts.map +1 -0
- package/dist/modules/pivots/instructions.js +280 -0
- package/dist/modules/pivots/instructions.js.map +1 -0
- package/dist/modules/speaker.d.ts +163 -0
- package/dist/modules/speaker.d.ts.map +1 -0
- package/dist/modules/speaker.js +250 -0
- package/dist/modules/speaker.js.map +1 -0
- package/dist/modules/storage.d.ts +50 -0
- package/dist/modules/storage.d.ts.map +1 -0
- package/dist/modules/storage.js +99 -0
- package/dist/modules/storage.js.map +1 -0
- package/dist/modules/stream.d.ts +129 -0
- package/dist/modules/stream.d.ts.map +1 -0
- package/dist/modules/stream.js +52 -0
- package/dist/modules/stream.js.map +1 -0
- package/dist/modules/system.d.ts +45 -0
- package/dist/modules/system.d.ts.map +1 -0
- package/dist/modules/system.js +42 -0
- package/dist/modules/system.js.map +1 -0
- package/dist/modules/transcription.d.ts +67 -0
- package/dist/modules/transcription.d.ts.map +1 -0
- package/dist/modules/transcription.js +106 -0
- package/dist/modules/transcription.js.map +1 -0
- package/dist/modules/translation.d.ts +59 -0
- package/dist/modules/translation.d.ts.map +1 -0
- package/dist/modules/translation.js +119 -0
- package/dist/modules/translation.js.map +1 -0
- package/dist/modules/ui.d.ts +186 -0
- package/dist/modules/ui.d.ts.map +1 -0
- package/dist/modules/ui.js +293 -0
- package/dist/modules/ui.js.map +1 -0
- package/dist/protocol.d.ts +294 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +320 -0
- package/dist/protocol.js.map +1 -0
- package/dist/react/MentraProvider.d.ts +33 -0
- package/dist/react/MentraProvider.d.ts.map +1 -0
- package/dist/react/MentraProvider.js +15 -0
- package/dist/react/MentraProvider.js.map +1 -0
- package/dist/react/MiniappHeader.d.ts +44 -0
- package/dist/react/MiniappHeader.d.ts.map +1 -0
- package/dist/react/MiniappHeader.js +32 -0
- package/dist/react/MiniappHeader.js.map +1 -0
- package/dist/react/index.d.ts +13 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +9 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useCapabilities.d.ts +26 -0
- package/dist/react/useCapabilities.d.ts.map +1 -0
- package/dist/react/useCapabilities.js +27 -0
- package/dist/react/useCapabilities.js.map +1 -0
- package/dist/react/useCapsuleHeaderStyle.d.ts +27 -0
- package/dist/react/useCapsuleHeaderStyle.d.ts.map +1 -0
- package/dist/react/useCapsuleHeaderStyle.js +36 -0
- package/dist/react/useCapsuleHeaderStyle.js.map +1 -0
- package/dist/react/useColorScheme.d.ts +18 -0
- package/dist/react/useColorScheme.d.ts.map +1 -0
- package/dist/react/useColorScheme.js +24 -0
- package/dist/react/useColorScheme.js.map +1 -0
- package/dist/react/useConnected.d.ts +17 -0
- package/dist/react/useConnected.d.ts.map +1 -0
- package/dist/react/useConnected.js +39 -0
- package/dist/react/useConnected.js.map +1 -0
- package/dist/react/useRpc.d.ts +29 -0
- package/dist/react/useRpc.d.ts.map +1 -0
- package/dist/react/useRpc.js +82 -0
- package/dist/react/useRpc.js.map +1 -0
- package/dist/react/useSafeArea.d.ts +21 -0
- package/dist/react/useSafeArea.d.ts.map +1 -0
- package/dist/react/useSafeArea.js +22 -0
- package/dist/react/useSafeArea.js.map +1 -0
- package/dist/session.d.ts +310 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +653 -0
- package/dist/session.js.map +1 -0
- package/dist/sub-path-types.test-d.d.ts +28 -0
- package/dist/sub-path-types.test-d.d.ts.map +1 -0
- package/dist/sub-path-types.test-d.js +37 -0
- package/dist/sub-path-types.test-d.js.map +1 -0
- package/dist/transport/auto.d.ts +35 -0
- package/dist/transport/auto.d.ts.map +1 -0
- package/dist/transport/auto.js +125 -0
- package/dist/transport/auto.js.map +1 -0
- package/dist/transport/dispatch.d.ts +43 -0
- package/dist/transport/dispatch.d.ts.map +1 -0
- package/dist/transport/dispatch.js +91 -0
- package/dist/transport/dispatch.js.map +1 -0
- package/dist/transport/local-socket.d.ts +28 -0
- package/dist/transport/local-socket.d.ts.map +1 -0
- package/dist/transport/local-socket.js +80 -0
- package/dist/transport/local-socket.js.map +1 -0
- package/dist/transport/mock.d.ts +54 -0
- package/dist/transport/mock.d.ts.map +1 -0
- package/dist/transport/mock.js +205 -0
- package/dist/transport/mock.js.map +1 -0
- package/dist/transport/postmessage.d.ts +36 -0
- package/dist/transport/postmessage.d.ts.map +1 -0
- package/dist/transport/postmessage.js +78 -0
- package/dist/transport/postmessage.js.map +1 -0
- package/dist/transport/types.d.ts +25 -0
- package/dist/transport/types.d.ts.map +1 -0
- package/dist/transport/types.js +11 -0
- package/dist/transport/types.js.map +1 -0
- package/dist/ui/index.d.ts +98 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +32 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +75 -0
- package/src/background/index.ts +152 -0
- package/src/background/register.ts +85 -0
- package/src/dev-reload.ts +60 -0
- package/src/envelope.ts +54 -0
- package/src/globals.ts +62 -0
- package/src/index.ts +171 -0
- package/src/modules/actions.ts +156 -0
- package/src/modules/auth.ts +68 -0
- package/src/modules/base64.ts +87 -0
- package/src/modules/blob.ts +341 -0
- package/src/modules/camera.ts +196 -0
- package/src/modules/cloud.ts +94 -0
- package/src/modules/dashboard.ts +31 -0
- package/src/modules/display.ts +122 -0
- package/src/modules/events.ts +264 -0
- package/src/modules/glasses.ts +44 -0
- package/src/modules/heading.ts +23 -0
- package/src/modules/imu.ts +44 -0
- package/src/modules/input.ts +71 -0
- package/src/modules/led.ts +61 -0
- package/src/modules/location.ts +39 -0
- package/src/modules/mic.ts +74 -0
- package/src/modules/miniapps.ts +90 -0
- package/src/modules/navigation.ts +670 -0
- package/src/modules/permissions.ts +84 -0
- package/src/modules/phone.ts +120 -0
- package/src/modules/pivots/engine.ts +863 -0
- package/src/modules/pivots/geometry.ts +409 -0
- package/src/modules/pivots/instructions.ts +343 -0
- package/src/modules/speaker.ts +328 -0
- package/src/modules/storage.ts +109 -0
- package/src/modules/stream.ts +163 -0
- package/src/modules/system.ts +76 -0
- package/src/modules/transcription.ts +128 -0
- package/src/modules/translation.ts +149 -0
- package/src/modules/ui.ts +498 -0
- package/src/protocol.ts +371 -0
- package/src/react/MentraProvider.tsx +50 -0
- package/src/react/MiniappHeader.tsx +122 -0
- package/src/react/index.ts +12 -0
- package/src/react/useCapabilities.ts +29 -0
- package/src/react/useCapsuleHeaderStyle.ts +54 -0
- package/src/react/useColorScheme.ts +26 -0
- package/src/react/useConnected.ts +47 -0
- package/src/react/useRpc.ts +106 -0
- package/src/react/useSafeArea.ts +40 -0
- package/src/session.ts +878 -0
- package/src/sub-path-types.test-d.ts +49 -0
- package/src/transport/auto.ts +143 -0
- package/src/transport/dispatch.ts +106 -0
- package/src/transport/local-socket.ts +93 -0
- package/src/transport/mock.ts +248 -0
- package/src/transport/postmessage.ts +95 -0
- package/src/transport/types.ts +26 -0
- package/src/ui/index.ts +122 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview useConnected — React hook that returns true while the miniapp's
|
|
3
|
+
* UI WebView is bridged to its background JSContext.
|
|
4
|
+
*
|
|
5
|
+
* WebView-side hook. "Connected" here means the `window.mentra` bridge is open:
|
|
6
|
+
* the shim has fired `mentra.ready()` and the host has bound the WebView so
|
|
7
|
+
* `mentra.send/on/request` flow. Tracked via the shim's `onOpen` / `onClose`.
|
|
8
|
+
* `onOpen` fires its callback immediately if the bridge is already open (see
|
|
9
|
+
* the shim), so late mounts still observe the connected state.
|
|
10
|
+
*
|
|
11
|
+
* IMPORTANT: this hook must NOT construct a `MiniappSession`. That is the
|
|
12
|
+
* *background* (JSContext) API; inside a UI WebView its `CONNECT` never gets an
|
|
13
|
+
* ACK from the host's UI router and `session.connect()` times out
|
|
14
|
+
* ("CONNECT_ACK timeout").
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {useEffect, useState} from "react"
|
|
18
|
+
|
|
19
|
+
interface MentraBridge {
|
|
20
|
+
onOpen?: (cb: () => void) => () => void
|
|
21
|
+
onClose?: (cb: () => void) => () => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getBridge(): MentraBridge | null {
|
|
25
|
+
if (typeof window === "undefined") return null
|
|
26
|
+
return (window as unknown as {mentra?: MentraBridge}).mentra ?? null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function useConnected(): boolean {
|
|
30
|
+
const [connected, setConnected] = useState<boolean>(false)
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const bridge = getBridge()
|
|
34
|
+
if (!bridge) return
|
|
35
|
+
|
|
36
|
+
// onOpen fires immediately when the bridge is already open, so this also
|
|
37
|
+
// seeds the initial value without a separate synchronous read.
|
|
38
|
+
const offOpen = bridge.onOpen?.(() => setConnected(true))
|
|
39
|
+
const offClose = bridge.onClose?.(() => setConnected(false))
|
|
40
|
+
return () => {
|
|
41
|
+
offOpen?.()
|
|
42
|
+
offClose?.()
|
|
43
|
+
}
|
|
44
|
+
}, [])
|
|
45
|
+
|
|
46
|
+
return connected
|
|
47
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useRpc — React hook around `mentra.request(channel, ...)`.
|
|
3
|
+
*
|
|
4
|
+
* Returns a stable callable plus an `.abort()` method. The internal
|
|
5
|
+
* AbortController is recreated per call and bound to component lifecycle:
|
|
6
|
+
*
|
|
7
|
+
* - Calling the returned function once: abort() the previous in-flight
|
|
8
|
+
* call (if any), then issue a fresh request. Useful for per-keystroke
|
|
9
|
+
* autocomplete — every keystroke aborts the stale request.
|
|
10
|
+
* - Unmount: all in-flight calls abort.
|
|
11
|
+
* - Caller-provided `options.signal` is merged with the internal one
|
|
12
|
+
* via `AbortSignal.any` when available; manual fan-out otherwise.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {useCallback, useEffect, useRef} from "react"
|
|
16
|
+
|
|
17
|
+
import type {RpcReq, RpcRes, RpcRequestOptions} from "../modules/ui"
|
|
18
|
+
|
|
19
|
+
type RequestFn = (channel: string, payload: unknown, options?: RpcRequestOptions) => Promise<unknown>
|
|
20
|
+
|
|
21
|
+
/** Walk to the global `mentra.request` (typed). */
|
|
22
|
+
function getMentraRequest(): RequestFn {
|
|
23
|
+
const m = (globalThis as unknown as {mentra?: {request?: RequestFn}}).mentra
|
|
24
|
+
if (!m || typeof m.request !== "function") {
|
|
25
|
+
throw new Error(
|
|
26
|
+
"useRpc: window.mentra.request is not available — is this miniapp running in a UI WebView with the shim injected?",
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
return m.request
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** AbortSignal.any polyfill — combine multiple signals into one. */
|
|
33
|
+
function mergeSignals(signals: AbortSignal[]): AbortSignal {
|
|
34
|
+
type WithAny = {any?: (s: AbortSignal[]) => AbortSignal}
|
|
35
|
+
const ctor = AbortSignal as unknown as WithAny
|
|
36
|
+
if (typeof ctor.any === "function") return ctor.any(signals)
|
|
37
|
+
const ctrl = new AbortController()
|
|
38
|
+
const onAbort = (sig: AbortSignal) => {
|
|
39
|
+
if (!ctrl.signal.aborted) ctrl.abort(sig.reason)
|
|
40
|
+
}
|
|
41
|
+
for (const s of signals) {
|
|
42
|
+
if (s.aborted) {
|
|
43
|
+
onAbort(s)
|
|
44
|
+
break
|
|
45
|
+
}
|
|
46
|
+
s.addEventListener("abort", () => onAbort(s))
|
|
47
|
+
}
|
|
48
|
+
return ctrl.signal
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface RpcCallable<TChannels extends object, C extends keyof TChannels & string> {
|
|
52
|
+
(payload: RpcReq<TChannels[C]>, options?: RpcRequestOptions): Promise<RpcRes<TChannels[C]>>
|
|
53
|
+
/** Abort the current in-flight call (if any). No-op if nothing is pending. */
|
|
54
|
+
abort(): void
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns a stable callable for an RPC channel. The callable auto-aborts
|
|
59
|
+
* on unmount and exposes `.abort()` for cancel-previous patterns.
|
|
60
|
+
*
|
|
61
|
+
* const autocomplete = useRpc<Channels, "places:autocomplete">("places:autocomplete")
|
|
62
|
+
* const suggestions = await autocomplete({query: "..."})
|
|
63
|
+
* autocomplete.abort() // cancel the latest in-flight call
|
|
64
|
+
*/
|
|
65
|
+
export function useRpc<
|
|
66
|
+
TChannels extends object,
|
|
67
|
+
C extends keyof TChannels & string,
|
|
68
|
+
>(channel: C): RpcCallable<TChannels, C> {
|
|
69
|
+
// Latest in-flight controller. Replaced on each call.
|
|
70
|
+
const currentRef = useRef<AbortController | null>(null)
|
|
71
|
+
// Mount controller — aborts every in-flight call on unmount.
|
|
72
|
+
const mountRef = useRef<AbortController | null>(null)
|
|
73
|
+
if (mountRef.current == null) mountRef.current = new AbortController()
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const mount = mountRef.current!
|
|
77
|
+
return () => {
|
|
78
|
+
mount.abort()
|
|
79
|
+
currentRef.current?.abort()
|
|
80
|
+
currentRef.current = null
|
|
81
|
+
}
|
|
82
|
+
}, [])
|
|
83
|
+
|
|
84
|
+
const callable = useCallback(
|
|
85
|
+
(payload: RpcReq<TChannels[C]>, options?: RpcRequestOptions) => {
|
|
86
|
+
// Abort any previous call for this hook.
|
|
87
|
+
currentRef.current?.abort()
|
|
88
|
+
const ctrl = new AbortController()
|
|
89
|
+
currentRef.current = ctrl
|
|
90
|
+
const signals: AbortSignal[] = [ctrl.signal, mountRef.current!.signal]
|
|
91
|
+
if (options?.signal) signals.push(options.signal)
|
|
92
|
+
const signal = mergeSignals(signals)
|
|
93
|
+
return getMentraRequest()(channel, payload, {signal, timeout: options?.timeout}) as Promise<
|
|
94
|
+
RpcRes<TChannels[C]>
|
|
95
|
+
>
|
|
96
|
+
},
|
|
97
|
+
[channel],
|
|
98
|
+
) as RpcCallable<TChannels, C>
|
|
99
|
+
|
|
100
|
+
callable.abort = () => {
|
|
101
|
+
currentRef.current?.abort()
|
|
102
|
+
currentRef.current = null
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return callable
|
|
106
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview useSafeArea — React hook exposing the host's safe-area insets
|
|
3
|
+
* and the capsule menu rect to miniapp UIs.
|
|
4
|
+
*
|
|
5
|
+
* The host injects these via window.MentraOS before content loads. This hook
|
|
6
|
+
* reads them once at mount — they don't currently change at runtime (the host
|
|
7
|
+
* would have to force a reload to update them, e.g. on orientation change).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {useState} from "react"
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
getMentraOSGlobals,
|
|
14
|
+
type MiniappCapsuleMenuRect,
|
|
15
|
+
type MiniappSafeAreaInsets,
|
|
16
|
+
} from "../globals"
|
|
17
|
+
|
|
18
|
+
const EMPTY_INSETS: MiniappSafeAreaInsets = {top: 0, bottom: 0, left: 0, right: 0}
|
|
19
|
+
|
|
20
|
+
export interface UseSafeAreaResult {
|
|
21
|
+
/** Pixel insets around the WebView content. Apply as padding on your root element. */
|
|
22
|
+
insets: MiniappSafeAreaInsets
|
|
23
|
+
/**
|
|
24
|
+
* Bounding rect of the host's floating capsule menu (top-right overlay).
|
|
25
|
+
* Null when the host doesn't render one (e.g. older builds). Use this to
|
|
26
|
+
* avoid placing clickable content underneath the menu.
|
|
27
|
+
*/
|
|
28
|
+
capsuleMenu: MiniappCapsuleMenuRect | null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useSafeArea(): UseSafeAreaResult {
|
|
32
|
+
const [result] = useState<UseSafeAreaResult>(() => {
|
|
33
|
+
const globals = getMentraOSGlobals()
|
|
34
|
+
return {
|
|
35
|
+
insets: globals.safeAreaInsets ?? EMPTY_INSETS,
|
|
36
|
+
capsuleMenu: globals.capsuleMenu ?? null,
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
return result
|
|
40
|
+
}
|