完善惊喜任务逐项执行和存储授权,兼容微信浏览入口及应用推荐下载落点。增加重复运行保护、投影恢复和任务完成复核,并保留原有安装适配。 验证:59项离线回归通过,生成文件一致性、语法及差异空白检查通过。
41 lines
2.2 KiB
JavaScript
41 lines
2.2 KiB
JavaScript
// 相同位置存在原生控件时使用原生点击,避免坐标被系统无障碍悬浮按钮截获。
|
||
function tryNativeYibaoOcrClick(match, x, y) {
|
||
if (typeof text !== "function") return false;
|
||
try {
|
||
var foreground = getForegroundApp();
|
||
if (!foreground || (foreground.packageName !== CONFIG.yibaoPackage && !isInstallerForeground(foreground))) return false;
|
||
var label = String(match.item.text || "");
|
||
if (!label) return false;
|
||
var node = text(label).packageName(foreground.packageName).findOnce();
|
||
if (!node || !node.enabled() || !node.visibleToUser()) return false;
|
||
var rect = node.bounds();
|
||
// 同名但位于别处的控件不能替代 OCR 刚确认的目标。
|
||
if (x < rect.left - 16 || x > rect.right + 16 || y < rect.top - 16 || y > rect.bottom + 16) return false;
|
||
for (var depth = 0; node && depth < 4; depth += 1) {
|
||
rect = node.bounds();
|
||
if (rect.height() > device.height * .30 || rect.width() <= 0 || rect.height() <= 0 ||
|
||
!node.enabled() || !node.visibleToUser()) return false;
|
||
if (node.clickable() && node.click()) {
|
||
log("相同位置原生控件点击成功:" + label + " bounds=" + rect);
|
||
return true;
|
||
}
|
||
node = node.parent();
|
||
}
|
||
} catch (error) { log("原生文字点击不可用,沿用已确认的 OCR 位置:" + errorText(error)); }
|
||
return false;
|
||
}
|
||
function clickOcrMatch(match, offsetYRatio) {
|
||
var offset = offsetYRatio || 0;
|
||
var x = Math.max(1, Math.min(device.width - 1, Math.round(match.item.centerX)));
|
||
var y = Math.max(1, Math.min(device.height - 1, Math.round(match.item.centerY + device.height * offset)));
|
||
log("点击 text=" + match.item.text + " target=" + match.target + " bounds=" + JSON.stringify(match.item.bounds));
|
||
var before = logForegroundApp("点击前");
|
||
if (offset !== 0 || !tryNativeYibaoOcrClick(match, x, y)) {
|
||
// 部分OPPO系统确认弹窗会丢弃瞬时click;使用完整的短按手势。
|
||
if (isInstallerForeground(before)) press(x, y, 120);
|
||
else click(x, y);
|
||
}
|
||
observeAfterAction("点击 " + match.target, before);
|
||
return true;
|
||
}
|