M4: 通用网页容器 + SettingsProxy + NavProvider + 子游戏切换
T-M4-01/02/03 GenericWebContainer(§11.3 第二套机制,不挂桥):
- javaScriptProxy 注入 settings 对象 6 方法(SettingsProxy,函数回调避开 ArkTS 对象字面量限制)
- 首次 100% runJavaScript 直调 getWebdata('<data>');返回键 isbackfinishweb→gamebackkeydown /
isexitdialogeshow→退出确认→backgameData();关闭 pop({data}) 101 语义回上层
- orientation "1"竖/其他横(window.setPreferredOrientation);browser 隐式 want
T-M3-06 NavProvider:OpenurlTitleData(开通用容器,onPop→callHandler getWebdata)、
SwitchOverGameData(同容器 loadUrl 切子游戏+重注入 app_data(launchtype'1')+方向+复位首屏标志)、
getGameinstall(同步 1/0 查 <解压根>/<dir>/index.html)、backgameData(重载大厅+待加载后 getWebdata)
导航解耦:common NavEvents(名+具名 payload interface);NavProvider 发 EventBus → BridgeGameContainer 执行
(容器持 pathStack/controller)。EventBus payload 放宽为 Object(ArkTS 禁 Record 字面量),用 GenericEventData
domain AppDataInjector.buildValues 复用(StartupOrchestrator + 子游戏切换共用,去重)
组装根装配 NavProvider
devecocli build 通过。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,14 +7,14 @@
|
||||
*/
|
||||
import { emitter } from '@kit.BasicServicesKit';
|
||||
|
||||
/** 事件载荷:键值对,值为 Object(需可跨线程时只放 Sendable/基本类型)。 */
|
||||
export type EventPayload = Record<string, Object>;
|
||||
/** 事件载荷:基类型 Object(ArkTS 严格禁 Record 字面量;传具名 interface 实例,订阅侧 as 还原)。 */
|
||||
export type EventPayload = Object;
|
||||
|
||||
export class EventBus {
|
||||
/** 持续订阅。返回取消函数——调用它仅注销本次订阅(per-subscriber,不影响其他订阅者)。
|
||||
* 多容器/多订阅者共享同一 eventId(如 appservice 前后台)时务必用返回值退订,勿用 off(eventId)。 */
|
||||
static on(eventId: string, callback: (payload?: EventPayload) => void): () => void {
|
||||
const wrapper = (ev: emitter.EventData) => {
|
||||
const wrapper = (ev: emitter.GenericEventData<Object>) => {
|
||||
callback(ev.data);
|
||||
};
|
||||
emitter.on(eventId, wrapper);
|
||||
@@ -25,7 +25,7 @@ export class EventBus {
|
||||
|
||||
/** 单次订阅,触发后自动取消。返回取消函数(触发前可主动退订)。 */
|
||||
static once(eventId: string, callback: (payload?: EventPayload) => void): () => void {
|
||||
const wrapper = (ev: emitter.EventData) => {
|
||||
const wrapper = (ev: emitter.GenericEventData<Object>) => {
|
||||
callback(ev.data);
|
||||
};
|
||||
emitter.once(eventId, wrapper);
|
||||
@@ -34,9 +34,9 @@ export class EventBus {
|
||||
};
|
||||
}
|
||||
|
||||
/** 发布事件。 */
|
||||
/** 发布事件(payload 为具名 interface 实例或省略)。 */
|
||||
static emit(eventId: string, payload?: EventPayload): void {
|
||||
const data: emitter.EventData = { data: payload };
|
||||
const data: emitter.GenericEventData<Object> = { data: payload };
|
||||
emitter.emit(eventId, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* 导航事件名 + 载荷(跨模块共享:NavProvider(feature_capabilities) 发 → BridgeGameContainer(entry) 订阅执行)。
|
||||
*
|
||||
* 容器持有 pathStack/WebviewController,能力层不直接导航——经 EventBus 解耦。
|
||||
* 载荷用具名 interface(ArkTS 严格:禁 Record/无类型对象字面量)。
|
||||
*/
|
||||
export class NavEvents {
|
||||
/** 打开通用网页容器。 */
|
||||
static readonly OPEN_GENERIC_WEB: string = 'nav.openGenericWeb';
|
||||
/** 容器内切换子游戏。 */
|
||||
static readonly SWITCH_GAME: string = 'nav.switchGame';
|
||||
/** 子游戏带数据返回大厅。 */
|
||||
static readonly BACK_GAME: string = 'nav.backGame';
|
||||
}
|
||||
|
||||
/** OPEN_GENERIC_WEB 载荷(§11.2)。 */
|
||||
export interface OpenGenericWebPayload {
|
||||
url: string;
|
||||
title: string;
|
||||
data: string;
|
||||
/** "1" 竖屏 / 其他 横屏 */
|
||||
orientation: string;
|
||||
}
|
||||
|
||||
/** SWITCH_GAME 载荷(§11.1)。 */
|
||||
export interface SwitchGamePayload {
|
||||
/** "2" 竖屏 / "3" 横屏 */
|
||||
webtype: string;
|
||||
/** 目标游戏目录名 */
|
||||
dir: string;
|
||||
data: string;
|
||||
}
|
||||
|
||||
/** BACK_GAME 载荷。 */
|
||||
export interface BackGamePayload {
|
||||
data: string;
|
||||
}
|
||||
Reference in New Issue
Block a user