新增 Expo 与 Tauri 原生宿主壳
新增 HostBridge 原生宿主契约和 H5 native_app transport 新增 Expo React Native 移动壳并收紧 WebView 外链边界 新增 Tauri 桌面壳并用 capability 收口受控命令 更新宿主壳方案、文档索引和共享记忆
This commit is contained in:
106
packages/shared/src/contracts/hostBridge.ts
Normal file
106
packages/shared/src/contracts/hostBridge.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
export const HOST_BRIDGE_PROTOCOL = 'GenarrativeHostBridge';
|
||||
export const HOST_BRIDGE_VERSION = 1;
|
||||
|
||||
export type HostShellKind = 'browser' | 'wechat_mini_program' | 'native_app';
|
||||
|
||||
export type NativeHostShell = 'expo_mobile' | 'tauri_desktop';
|
||||
|
||||
export type NativeHostPlatform =
|
||||
| 'ios'
|
||||
| 'android'
|
||||
| 'macos'
|
||||
| 'windows'
|
||||
| 'linux'
|
||||
| 'unknown';
|
||||
|
||||
export type HostBridgeMethod =
|
||||
| 'host.getRuntime'
|
||||
| 'auth.requestLogin'
|
||||
| 'payment.request'
|
||||
| 'share.setTarget'
|
||||
| 'share.open'
|
||||
| 'navigation.openNativePage'
|
||||
| 'app.openExternalUrl'
|
||||
| 'clipboard.writeText'
|
||||
| 'haptics.impact';
|
||||
|
||||
export type HostBridgeCapability =
|
||||
| HostBridgeMethod
|
||||
| 'host.events'
|
||||
| 'navigation.canGoBack';
|
||||
|
||||
export type HostBridgeRuntimeResult = {
|
||||
shell: NativeHostShell;
|
||||
platform: NativeHostPlatform;
|
||||
hostVersion: string | null;
|
||||
bridgeVersion: number;
|
||||
capabilities: HostBridgeCapability[];
|
||||
};
|
||||
|
||||
export type HostBridgeRequest<Payload = unknown> = {
|
||||
bridge: typeof HOST_BRIDGE_PROTOCOL;
|
||||
version: typeof HOST_BRIDGE_VERSION;
|
||||
id: string;
|
||||
method: HostBridgeMethod;
|
||||
payload?: Payload;
|
||||
timeoutMs?: number;
|
||||
};
|
||||
|
||||
export type HostBridgeError = {
|
||||
code:
|
||||
| 'invalid_request'
|
||||
| 'unsupported_method'
|
||||
| 'unsupported_capability'
|
||||
| 'timeout'
|
||||
| 'cancelled'
|
||||
| 'host_error';
|
||||
message: string;
|
||||
};
|
||||
|
||||
export type HostBridgeResponse<Result = unknown> = {
|
||||
bridge: typeof HOST_BRIDGE_PROTOCOL;
|
||||
version: typeof HOST_BRIDGE_VERSION;
|
||||
id: string;
|
||||
} & (
|
||||
| {
|
||||
ok: true;
|
||||
result?: Result;
|
||||
}
|
||||
| {
|
||||
ok: false;
|
||||
error: HostBridgeError;
|
||||
}
|
||||
);
|
||||
|
||||
export type HostBridgeEvent<Payload = unknown> = {
|
||||
bridge: typeof HOST_BRIDGE_PROTOCOL;
|
||||
version: typeof HOST_BRIDGE_VERSION;
|
||||
event: string;
|
||||
payload?: Payload;
|
||||
};
|
||||
|
||||
export type NavigateNativePagePayload = {
|
||||
url: string;
|
||||
};
|
||||
|
||||
export type OpenExternalUrlPayload = {
|
||||
url: string;
|
||||
};
|
||||
|
||||
export type ClipboardWriteTextPayload = {
|
||||
text: string;
|
||||
};
|
||||
|
||||
export type HapticsImpactPayload = {
|
||||
style?: 'light' | 'medium' | 'heavy';
|
||||
};
|
||||
|
||||
export type ShareSetTargetPayload = {
|
||||
target: unknown;
|
||||
};
|
||||
|
||||
export type ShareOpenPayload = {
|
||||
title?: string;
|
||||
message?: string;
|
||||
url?: string;
|
||||
};
|
||||
@@ -1,11 +1,12 @@
|
||||
export type * from './creativeAgent';
|
||||
export type * from './barkBattle';
|
||||
export type * from './creationAudio';
|
||||
export type * from './creativeAgent';
|
||||
export * from './hostBridge';
|
||||
export type * from './hyper3d';
|
||||
export type * from './jumpHop';
|
||||
export type * from './puzzleCreativeTemplate';
|
||||
export type * from './puzzleClear';
|
||||
export * from './playTypes';
|
||||
export type * from './publicWork';
|
||||
export type * from './puzzleClear';
|
||||
export type * from './puzzleCreativeTemplate';
|
||||
export type * from './visualNovel';
|
||||
export type * from './barkBattle';
|
||||
export type * from './woodenFish';
|
||||
|
||||
Reference in New Issue
Block a user