release: WRNexusJS 0.8.0
This commit is contained in:
@@ -79,6 +79,9 @@ const position = await native.run(
|
||||
Built-ins include `camera`, `clipboard.write`, `share`, `geolocation`, `network`,
|
||||
`haptics`, storage, filesystem, notifications, and device information.
|
||||
|
||||
`defineNativeManifest` declares required capabilities and typed permissions, while
|
||||
`PermissionManager` normalizes permission query/request flows across platform adapters.
|
||||
|
||||
## Requirements / Notes
|
||||
|
||||
Use `supports()` before showing optional controls. Mobile capabilities require their
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/native",
|
||||
"version": "0.7.0",
|
||||
"version": "0.8.0",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"exports": {
|
||||
|
||||
@@ -31,5 +31,6 @@ export {
|
||||
export type {
|
||||
NativeCapabilityManifestEntry,
|
||||
NativeCapabilityManifest,
|
||||
NativePermission,
|
||||
PermissionAdapter,
|
||||
} from "./manifest.ts";
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { registered, supports } from "./registry.ts";
|
||||
import type { NativeTarget } from "./types.ts";
|
||||
export type NativePermission =
|
||||
"camera" | "geolocation" | "microphone" | "notifications" | "photos" | "storage" | (string & {});
|
||||
export interface NativeCapabilityManifestEntry {
|
||||
name: string;
|
||||
description?: string;
|
||||
permissions?: string[];
|
||||
permissions?: NativePermission[];
|
||||
targets?: NativeTarget[];
|
||||
optional?: boolean;
|
||||
}
|
||||
@@ -40,15 +42,15 @@ export function missingNativeCapabilities(
|
||||
);
|
||||
}
|
||||
export interface PermissionAdapter {
|
||||
query(name: string): Promise<"granted" | "denied" | "prompt" | "unavailable">;
|
||||
request?(name: string): Promise<"granted" | "denied">;
|
||||
query(name: NativePermission): Promise<"granted" | "denied" | "prompt" | "unavailable">;
|
||||
request?(name: NativePermission): Promise<"granted" | "denied">;
|
||||
}
|
||||
export class PermissionManager {
|
||||
constructor(private readonly adapter: PermissionAdapter) {}
|
||||
query(name: string) {
|
||||
query(name: NativePermission) {
|
||||
return this.adapter.query(name);
|
||||
}
|
||||
async ensure(name: string): Promise<boolean> {
|
||||
async ensure(name: NativePermission): Promise<boolean> {
|
||||
const state = await this.adapter.query(name);
|
||||
if (state === "granted") return true;
|
||||
if (state === "prompt" && this.adapter.request)
|
||||
|
||||
Reference in New Issue
Block a user