@pmate/bridge 0.1.8 → 0.1.9
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/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/internal.ts +22 -1
- package/src/types.ts +3 -1
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/internal.ts
CHANGED
|
@@ -253,5 +253,26 @@ export async function openApp(options: import("./types").OpenAppOptions): Promis
|
|
|
253
253
|
if ((url.protocol !== "https:" && !(local && url.protocol === "http:")) || url.username || url.password) {
|
|
254
254
|
return Promise.reject(new Error("App URL must use HTTPS (or loopback HTTP) without credentials"))
|
|
255
255
|
}
|
|
256
|
-
|
|
256
|
+
const notificationId = options.notificationId
|
|
257
|
+
if (notificationId !== undefined && (!notificationId || notificationId.length > 512)) throw new Error("Invalid notification ID")
|
|
258
|
+
const result = await requireBridge<import("./types").OpenAppResult>("container.openApp", { url: url.href, ...(notificationId === undefined ? {} : { notificationId }) })
|
|
259
|
+
if (result?.opened !== true) throw new Error("Native app opening was not confirmed")
|
|
260
|
+
return result
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Available only to a native host's designated launcher. Older hosts reject it. */
|
|
264
|
+
export async function getPendingAppOpen(): Promise<import("./types").AppOpenIntent | null> {
|
|
265
|
+
const result = await requireBridge<import("./types").AppOpenIntent | null>("container.getPendingAppOpen")
|
|
266
|
+
if (result === null) return null
|
|
267
|
+
if (!result || typeof result.appId !== "string" || !result.appId || result.appId.length > 128
|
|
268
|
+
|| typeof result.notificationId !== "string" || !result.notificationId || result.notificationId.length > 512
|
|
269
|
+
|| typeof result.origin !== "string" || result.origin.length > 2048) throw new Error("Invalid application notification")
|
|
270
|
+
const origin = new URL(result.origin)
|
|
271
|
+
if (origin.protocol !== "https:" || origin.username || origin.password || origin.pathname !== "/" || origin.search || origin.hash) throw new Error("Invalid application notification origin")
|
|
272
|
+
return { appId: result.appId, notificationId: result.notificationId, origin: origin.origin }
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** A hint to re-read the pending intent; the event itself never supplies a URL to open. */
|
|
276
|
+
export function onAppOpenRequested(handler: () => void): () => void {
|
|
277
|
+
return hasWindow() ? (window as PmateWindow).PmateBridge?.on?.("container.appOpenRequested", handler) ?? (() => {}) : () => {}
|
|
257
278
|
}
|
package/src/types.ts
CHANGED
|
@@ -209,5 +209,7 @@ export interface BluetoothDataEvent {
|
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
/** Opens a separate native WebView. The caller resolves the app URL via the apps API. */
|
|
212
|
-
export interface OpenAppOptions { url: string }
|
|
212
|
+
export interface OpenAppOptions { url: string; notificationId?: string }
|
|
213
213
|
export interface OpenAppResult { opened: true }
|
|
214
|
+
/** Destination only; notification content is delivered to the target app after authentication. */
|
|
215
|
+
export interface AppOpenIntent { appId: string; notificationId: string; origin: string }
|