完善惊喜任务逐项执行和存储授权,兼容微信浏览入口及应用推荐下载落点。增加重复运行保护、投影恢复和任务完成复核,并保留原有安装适配。 验证:59项离线回归通过,生成文件一致性、语法及差异空白检查通过。
55 lines
3.3 KiB
JavaScript
55 lines
3.3 KiB
JavaScript
// 下载中断恢复:仅在应用宝详情页确认进度消失、按钮退回下载时重试。
|
||
function waitDownloadComplete(timeoutMs) {
|
||
var deadline = Date.now() + timeoutMs, lastProgress = "", idleFrames = 0;
|
||
var retries = 0, lastRetryAt = 0;
|
||
while (Date.now() < deadline) {
|
||
var foreground = getForegroundApp();
|
||
if (isInstallerForeground(foreground) || isThirdPartyForeground(foreground)) return true;
|
||
var items = recognizeScreenSafe();
|
||
if (items && foreground && foreground.packageName === CONFIG.yibaoPackage) {
|
||
if (filterShortTextMatches(findMatches(items, ["下一步", "继续安装", "安装"]), 8).length > 0) return true;
|
||
var progress = items.filter(function (item) { return /已下载|下载中|正在下载/.test(String(item.text)); });
|
||
if (progress.length) {
|
||
idleFrames = 0;
|
||
var label = String(progress[0].text);
|
||
if (label !== lastProgress) { lastProgress = label; log("下载进度: " + label); }
|
||
} else {
|
||
var downloads = findMatches(items, ["立即下载", "立即下載", "重新下载"]);
|
||
if (filterShortTextMatches(findMatches(items, ["打开"]), 6).length && !downloads.length) return true;
|
||
var corpus = items.map(function (item) { return normalizeText(item.text); }).join("");
|
||
var detail = /应用名称|应用版本/.test(corpus) && /开发者|权限详情|隐私协议/.test(corpus);
|
||
idleFrames = detail && downloads.length ? idleFrames + 1 : 0;
|
||
if (idleFrames >= 2 && Date.now() - lastRetryAt >= 8000) {
|
||
if (retries >= 3) { log("下载按钮持续恢复原状,已重试3次,退出额外任务"); return false; }
|
||
retries += 1;
|
||
lastRetryAt = Date.now();
|
||
idleFrames = 0;
|
||
// 原生节点可能接受事件但未触发下载;交替使用已识别按钮的完整短按。
|
||
var match = downloads[retries % downloads.length];
|
||
log("下载进度消失且详情页恢复下载按钮,重试 " + retries + "/3");
|
||
if (retries % 2 === 1) clickOcrMatch(match, 0);
|
||
else press(Math.round(match.item.centerX), Math.round(match.item.centerY), 120);
|
||
}
|
||
}
|
||
} else idleFrames = 0;
|
||
sleep(2000);
|
||
}
|
||
log("下载等待超时,不将未完成下载当作安装成功");
|
||
return false;
|
||
}
|
||
|
||
function finishYibaoOptionalDownload() {
|
||
if (runExtraDownloadTask()) return true;
|
||
log("额外下载未完成,尝试退出该页,继续原视频任务");
|
||
if (!backToYibao(15000)) return false;
|
||
var items = recognizeScreenSafe();
|
||
var corpus = (items || []).map(function (item) { return normalizeText(item.text); }).join("");
|
||
if (/应用名称|应用版本/.test(corpus) && !isAdView1ExtraDownloadOffer(items)) {
|
||
back(); sleep(1200); items = recognizeScreenSafe();
|
||
}
|
||
if (findAdView1CloseNode("点击退出关闭视频")) {
|
||
return clickByAccessibilityDesc("点击退出关闭视频", "额外下载失败后退出奖励页", items);
|
||
}
|
||
return items && isYibaoTaskCenter(items) || closeYibaoTaskPage("额外下载失败后收尾");
|
||
}
|