fix: 大 APK 推送到设备时显示实时进度(原来是整段黑箱干等)

问题(用户反馈):从网页点「安装」到设备,包大的时候(抖音 336MB)只显示
一句「正在推送 APK...」,传了两分多钟全程没有任何进度,像卡死了。

根因:推送用的是 `adb push`,它**只在结束时**吐一行汇总
("1 file pushed, 3.0 MB/s"),中间过程什么都不给。

改法:分块写 + 实时进度
- core/apk_manager.py 新增 `_push_with_progress()`:改用 `adb exec-in "cat > 文件"`
  自己按 1MB 分块喂数据,每块更新一次状态(限流 0.8s 一次):
    `推送中 62%(211.0/336.1 MB · 2.6 MB/s · 剩约 48s)`
  传完校验设备上文件大小;中途断流/exec-in 不可用时**退回原来的 adb push**(保证兼容)
- 代价:实测速度 2.6 vs 3.1 MB/s(慢 17%),换来看得见的进度,划算
- 「正在设备上安装...」补上预期时间说明 —— `pm install` 在设备端解包
  (336MB 实测 ~65s),系统没给进度接口,只能给预期值
- static/admin/apps.js:安装进度轮询 3s → 1.5s;表格里再加一条细进度条
  (大包要一两分钟,光有文字不够直观)
- doc/API.md:把安装状态机的两段式进度与耗时参考写进接口说明

实测(抖音 v40.4.0 336.1MB → 192.168.20.100,单台):
  推送 60%→100% 每 2 秒一档,速度稳定 2.6 MB/s,134s 传完;
  设备端安装 65s;端到端 ~200s,全程有进度可看。
全量回归 106 项通过。
This commit is contained in:
2026-09-13 15:38:14 +08:00
parent dad1af8b0b
commit cdf06e1929
3 changed files with 121 additions and 15 deletions
+5 -2
View File
@@ -210,7 +210,7 @@ function showInstallProgress(){
'<button class="btn" onclick="closeInstallModal()" id="install-close-btn" style="display:none">关闭</button>';
pollInstallStatus();
if(_installTimer)clearInterval(_installTimer);
_installTimer=setInterval(pollInstallStatus,3000);
_installTimer=setInterval(pollInstallStatus,1500);
}
async function pollInstallStatus(){
@@ -226,10 +226,13 @@ async function pollInstallStatus(){
const items=st.items||{};
const itemRows=Object.entries(items).map(([serial,info])=>{
const s=SS[info.status]||{t:info.status,c:'default'};
// 推送进度带百分比时补一条细进度条(大包传输要一两分钟,光有文字不够直观)
const m=/推送中 (\d+)%/.exec(info.msg||'');
const bar=m?'<div class="progress" style="height:6px;margin-top:4px;max-width:240px"><div class="progress-bar" style="width:'+m[1]+'%"></div></div>':'';
return '<tr><td>'+esc(info.name||serial)+'</td>'+
'<td style="font-family:monospace;font-size:11px;color:#94a3b8">'+esc(serial)+'</td>'+
'<td><span class="label label-'+s.c+'">'+s.t+'</span></td>'+
'<td style="font-size:12px;color:#64748b">'+esc(info.msg||'')+'</td></tr>';
'<td style="font-size:12px;color:#64748b">'+esc(info.msg||'')+bar+'</td></tr>';
}).join('');
const pct=st.total>0?Math.round((st.success+st.failed+st.skipped)*100/st.total):0;