hmz 8de61173e0 修复应用宝一条龙任务恢复、常亮及公共浏览安装流程
完善惊喜任务逐项执行和存储授权,兼容微信浏览入口及应用推荐下载落点。增加重复运行保护、投影恢复和任务完成复核,并保留原有安装适配。

验证:59项离线回归通过,生成文件一致性、语法及差异空白检查通过。
2026-11-18 16:05:57 +08:00

85 lines
4.1 KiB
JavaScript
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.

// vivo 的跨应用打开确认只处理由应用宝发起的请求,按用户偏好选择“始终打开”。
var yibaoAppJumpBusy = false;
function readYibaoAppJumpPage(root) {
if (!root || String(root.getPackageName() || "") !== "com.vivo.appfilter") return null;
var items = [], title = "", count = 0;
function visit(node, depth) {
if (!node || depth > 24 || ++count > 500) throw new Error("打开确认弹窗节点树不完整");
if (!node.isVisibleToUser()) return;
var text = String(node.getText() || ""), desc = String(node.getContentDescription() || "");
var resourceId = String(node.getViewIdResourceName() || "");
if (resourceId === "com.vivo.appfilter:id/alertTitle") title = text;
if (text || desc) {
var rect = new android.graphics.Rect();
node.getBoundsInScreen(rect);
items.push({text:text,desc:desc,enabled:Boolean(node.isEnabled()),
bounds:{left:rect.left,top:rect.top,right:rect.right,bottom:rect.bottom}});
}
for (var i = 0; i < node.getChildCount(); i += 1) visit(node.getChild(i), depth + 1);
}
visit(root, 0);
return {packageName:"com.vivo.appfilter",title:title,items:items};
}
function planYibaoAppJumpAction(page) {
if (!page || page.packageName !== "com.vivo.appfilter" ||
!/^[“"「『]?应用宝[”"」』]?想要打开.+$/.test(normalizeText(page.title))) return null;
var matches = (page.items || []).filter(function (item) {
var b = item.bounds;
return item.enabled !== false &&
(normalizeText(item.text) === "始终打开" || normalizeText(item.desc) === "始终打开") &&
b && b.left >= 0 && b.top >= 0 && b.right <= device.width && b.bottom <= device.height &&
b.right > b.left && b.bottom > b.top;
});
// 同一个按钮的父控件描述与子控件文字可能重复,按中心位置合并。
var unique = [];
matches.forEach(function (item) {
var b = item.bounds;
if (!unique.some(function (other) {
var a = other.bounds;
return Math.abs(a.left + a.right - b.left - b.right) < 8 &&
Math.abs(a.top + a.bottom - b.top - b.bottom) < 8;
})) unique.push(item);
});
return unique.length === 1 ? unique[0] : null;
}
function handleYibaoAppJumpPrompt(root) {
if (yibaoAppJumpBusy || !root || String(root.getPackageName() || "") !== "com.vivo.appfilter") return false;
yibaoAppJumpBusy = true;
try {
var page = readYibaoAppJumpPage(root), action = planYibaoAppJumpAction(page);
if (!action) return false;
// 点击前重读,避免沿用上一个目标应用弹窗的位置。
var fresh = readYibaoAppJumpPage(auto.rootInActiveWindow);
action = planYibaoAppJumpAction(fresh);
if (!action || fresh.title !== page.title) return false;
var b = action.bounds;
log("应用宝跨应用打开确认:选择始终打开,title=" + fresh.title + " bounds=" + JSON.stringify(b));
if (press(Math.round((b.left + b.right) / 2), Math.round((b.top + b.bottom) / 2), 100) === false) return false;
var deadline = Date.now() + 3000;
while (Date.now() < deadline) {
sleep(200);
var current = auto.rootInActiveWindow;
if (current && String(current.getPackageName() || "") !== "com.vivo.appfilter") {
log("始终打开确认已消失,继续验证目标应用跳转");
return true;
}
}
log("始终打开点击后弹窗尚未消失,交给后续跳转检查复核");
return false;
} catch (error) {
if (error && error.taskInterrupted) throw error;
log("应用宝打开确认读取失败,本帧不操作:" + errorText(error));
return false;
} finally { yibaoAppJumpBusy = false; }
}
function getForegroundAppByAutoJs() {
try {
if (typeof auto !== "undefined" && auto && auto.service) handleYibaoAppJumpPrompt(auto.rootInActiveWindow);
} catch (error) { if (error && error.taskInterrupted) throw error; }
return businessGetForegroundAppByAutoJs();
}