Files
youle_app_ios_v2/ylgamehall/Source/Bridge/Handlers/SwitchOverGameHandler.swift
T
joywayerandClaude Opus 4.7 7a5644053d Phase 6 commit A:AppCoordinator + SubGameViewController 框架 + SwitchOverGameData push
- AppCoordinator:2s 节流 + 栈深 < 2 守门 + .subGameDidReturn 通知名(Design §2.4.3)
- SubGameViewController:复用 BridgedWebView/Splash/16:9 letterbox/ExternalSubscriptions,
  AppDataWriter(.subGame) 写 4 个 app_*.js;H5 未安装时抛错(待 commit B 接入下载)
- SwitchOverGameHandler:解 Gamedirectory/gamedownloadurl/data → AppCoordinator.showSubGame
  (msext NewRootVC.m:541-566 等价,节流与栈深由 Coordinator 守门,cb 字面始终回)
- SceneDelegate:UINavigationController 承载大厅,nav 引用交给 AppCoordinator
- Plan 进度已勾选 §5 / §8(commit B/C 留待 SubGameDownloader 与 backgameData/getWebdata 链路)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-22 20:59:00 +08:00

49 lines
2.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// SwitchOverGameHandler.swift
// ylgamehall
//
// H5 → Native handlerSwitchOverGameData — 切换到子游戏。
// 契约:docs/H5-Native-Contract.md §3.1 17
//
// 与 msext NewRootVC.m:541-566 等价:
// - 解析 Gamedirectory / gamedownloadurl / data
// - 2s 节流(msext one_Time / canbackone;本项目挪到 AppCoordinator.showSubGame
// - 调 AppCoordinator.shared.showSubGame(...) push 子游戏 VC
// - 无论 push 是否成功,都回 callback "SwitchOverGameData"msext 行为)
//
// ⚠️ 入参字段名严格保持字面:
// - "Gamedirectory" G 大写
// - "gamedownloadurl" 全小写
// - "data" 透传给子游戏 H5commit C 通过 .subGameDidReturn 反向 callback getWebdata
//
import Foundation
public enum SwitchOverGameHandler {
public static func register(on bridge: any BridgeProtocol) {
// 【17】SwitchOverGameData
// 入参 type / Gamedirectory / gamedownloadurl / data
// cb: "SwitchOverGameData"(驼峰首字母大写,沿用 msext 字面)
bridge.register("SwitchOverGameData") { data, callback in
await MainActor.run {
let dir = data?["Gamedirectory"]?.asString ?? ""
let url = data?["gamedownloadurl"]?.asString ?? ""
let web = data?["data"]?.asString ?? ""
// msext 行为:gameStart 沿用 Gamedirectory(同名同目录),
// 后续若契约出现独立 gamestart 字段再扩展。
let request = SubGameRequest(
gameDir: dir,
gameStart: dir,
downloadURL: url,
webData: web
)
AppCoordinator.shared.showSubGame(request)
}
// 与 msext 一致:节流命中 / 入参缺失也回 cb,避免 H5 业务期等待
callback?(.string("SwitchOverGameData"))
}
}
}