 joywayerandClaude Opus 4.7
|
522087f398
|
修复下载进度瞬间跳 100%:换手动 downloadTask + 续作
async 版 await session.download(from:) 内部走 completion-handler 路径,
session 级 delegate 的 didWriteData 全部被跳过,结果只有兜底 onProgress(1.0)
在下载完成后才触发——用户看到的"瞬间 100%"就是这个唯一一次回调。
换成手动 session.downloadTask(with:).resume() + CheckedContinuation:
- didWriteData 正常按 URLSession 节奏在 opQueue 上派发,进度真实推进
- didFinishDownloadingTo 内同步把临时文件 move 到沙盒 Caches 的已知位置
(否则 delegate 返回后系统立即清掉那个临时位置)
- didCompleteWithError 里 resume 续作
- continuation/moveError 跨线程(actor → opQueue)用 NSLock 保护
LobbyZipUpgrader / SubGameDownloader 同款修复(大厅 zip 下载 + 子游戏 zip 下载)。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
2026-06-24 22:40:59 +08:00 |
|
 joywayerandClaude Opus 4.7
|
fd9976c4b9
|
下载进度回调改 session-level delegate(ad-hoc 不触发 didWriteData)
LobbyZipUpgrader 和 SubGameDownloader 之前用 `session.download(from:delegate:)`
的 iOS 15+ async API,把 DownloadProgressDelegate 作为 ad-hoc delegate 传入。
该 API 的 delegate 参数实际只收 URLSessionTaskDelegate 回调,**不会**触发
URLSessionDownloadDelegate.didWriteData,所以 0…1 进度从未上报,splash 进度条
一直停在 0,只有末尾兜底的 onProgress(1.0) 跑一下,看起来"一出现就 100%"。
改为每次下载临时新建一个 URLSession,把 progressDelegate 在 init 时绑到
session 级别(带独立 OperationQueue),下载结束 defer invalidateAndCancel
释放。delegate 现在能收到 didWriteData,真实字节比例上报,进度条 0→1 平滑。
副作用:删除 actor 字段 `session` 与可注入的 `init(session:)`,改用静态
`defaultConfig: URLSessionConfiguration` 复用超时配置(无外部调用方使用过自定义
session init)。
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
2026-06-23 21:34:38 +08:00 |
|
 joywayerandClaude Opus 4.7
|
f3c66b670d
|
Phase 1.14.c:LobbyZipUpgrader 加 0…1 progress 回调
- upgradeIfNeeded 新增 onProgress: @escaping @Sendable (Double) -> Void 参数,
默认 no-op 兼容仅做版本对比的烟雾测试
- 新增文件内私有 DownloadProgressDelegate(URLSessionDownloadDelegate
+ @unchecked Sendable),在 didWriteData 回调里把 totalBytesWritten /
totalBytesExpectedToWrite 换算成 0…1 上报,clamp 到 [0,1]
- 通过 session.download(from:delegate:) 注入;下载完成后兜底报 1.0
(部分 server 不发 Content-Length 或末尾片段晚到,避免进度条停在 99%)
- RootViewController 烟雾测试用 ProgressTicker 把回调节流到 10% 阶梯打印,
避免几百行刷屏(NSLock 保护单 Int 状态,@unchecked Sendable)
- BuildProject 通过
Plan 进度已勾选(§5 Phase 1.14.c + §8)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
2026-06-22 02:46:11 +08:00 |
|
joywayer
|
0887088bb8
|
Phase 1.13:LobbyZipUpgrader 完成 H5 zip 升级端到端链路
Phase 1 远程配置链路(1.10-1.13)最后一环:把 VersionResolver 解出的
gameZip URL 下载 + 解压 + 原子 rename 到 lobbyRoot,触发条件是远端
gameVersion > 本地 version.xml /game/version@value。
- 新增 ylgamehall/Source/Resource/LobbyZipUpgrader.swift
- public actor,单例 LobbyZipUpgrader.shared
- upgradeIfNeeded(resolved:) async throws -> Outcome
- .noop:远端版本 ≤ 本地,或 gameZip nil / 非法 URL,直接返回
- .upgraded(from:to:):完成升级,附前后版本号
- URLSession.download(from:) 异步下载(60s 请求 / 300s 资源超时),
HTTP 状态码非 2xx 抛 .httpStatus
- 解压到 caches/lobby-staging-{UUID}/ 隔离目录(不直接覆盖 lobbyRoot,
msext "removeItem + ZipArchive overWrite:YES" 半途崩溃会留半残;
我们 staging 完整解压成功后才 rename)
- 原子 rename:fm.removeItem(lobbyRoot) → fm.moveItem(staging,
to: lobbyRoot);任一步失败抛 .stagingMoveFailed,调用方决定回退
- 类型化 UpgradeError 5 种:badGameZipURL / downloadFailed /
httpStatus / unzipFailed / stagingMoveFailed
- 实现照搬 msext NewRootVC.m:1789-1869 downFileFromServer + unzip
+ unzipDone 的语义,但用现代 async + 原子 rename 替代 ASIHTTPRequest
+ detachNewThreadSelector + ZipArchive overWrite:YES
- RootViewController 烟雾测试串接 LobbyZipUpgrader:
调 upgradeIfNeeded → switch outcome → 升级后重新读 version.xml 验证
- 真机实测端到端链路:
第一次:本地 260 vs 远端 261 → 升级完成 261,耗时 2.007s
(下载 11.5 MB HTTP zip + ZIPFoundation 解压 + 原子 rename)
重新读 version.xml = 261 ✓ lobbyIndex 仍存在 ✓
第二次:本地 261 vs 远端 261 → .noop,耗时 0.001s(幂等验证)
Phase 1 远程配置链路(1.10-1.13)完整闭环。下一步 Phase 1.14
WebContainer 把这条链路插到 viewDidLoad 之前 + 16:9 letterbox 加载
lobbyIndex,第一次让真实大厅 H5 渲染出来。
|
2026-06-22 02:27:48 +08:00 |
|