@skrillex1224/android-toolkit 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +35 -8
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +35 -8
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -757,6 +757,9 @@ function sanitizeData(value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
757
757
|
return out;
|
|
758
758
|
}
|
|
759
759
|
|
|
760
|
+
// src/device-input.js
|
|
761
|
+
var import_node_crypto2 = require("node:crypto");
|
|
762
|
+
|
|
760
763
|
// src/device-view.js
|
|
761
764
|
var import_node_crypto = require("node:crypto");
|
|
762
765
|
var import_fast_xml_parser = require("fast-xml-parser");
|
|
@@ -1060,15 +1063,15 @@ async function scrollToTop(ctx, selector, options = {}) {
|
|
|
1060
1063
|
async function scrollUntilStable(ctx, selector, direction, options = {}) {
|
|
1061
1064
|
const maxSwipes = Math.max(1, Number(options.maxSwipes || 20));
|
|
1062
1065
|
const stableRoundsTarget = Math.max(1, Number(options.stableRounds || 2));
|
|
1066
|
+
const hashSource = String(options.stability || options.hashSource || "view");
|
|
1063
1067
|
let lastHash = "";
|
|
1064
1068
|
let stableRounds = 0;
|
|
1065
1069
|
for (let index = 0; index < maxSwipes; index += 1) {
|
|
1066
|
-
const
|
|
1067
|
-
const currentHash = DeviceView.hashNode(node);
|
|
1070
|
+
const currentHash = await scrollStateHash(ctx, selector, options, hashSource);
|
|
1068
1071
|
if (currentHash === lastHash) {
|
|
1069
1072
|
stableRounds += 1;
|
|
1070
1073
|
if (stableRounds >= stableRoundsTarget) {
|
|
1071
|
-
return { swipes: index, stableRounds, hash: currentHash };
|
|
1074
|
+
return { swipes: index, stableRounds, hash: currentHash, hashSource };
|
|
1072
1075
|
}
|
|
1073
1076
|
} else {
|
|
1074
1077
|
stableRounds = 0;
|
|
@@ -1076,7 +1079,15 @@ async function scrollUntilStable(ctx, selector, direction, options = {}) {
|
|
|
1076
1079
|
}
|
|
1077
1080
|
await scroll(ctx, selector, direction, options);
|
|
1078
1081
|
}
|
|
1079
|
-
return { swipes: maxSwipes, stableRounds, hash: lastHash };
|
|
1082
|
+
return { swipes: maxSwipes, stableRounds, hash: lastHash, hashSource };
|
|
1083
|
+
}
|
|
1084
|
+
async function scrollStateHash(ctx, selector, options, hashSource) {
|
|
1085
|
+
if (hashSource === "screenshot") {
|
|
1086
|
+
const png = await Device.screenshotPng(ctx);
|
|
1087
|
+
return (0, import_node_crypto2.createHash)("sha256").update(png).digest("hex");
|
|
1088
|
+
}
|
|
1089
|
+
const node = await DeviceView.find(ctx, selector, options);
|
|
1090
|
+
return DeviceView.hashNode(node);
|
|
1080
1091
|
}
|
|
1081
1092
|
function nearestClickable(node) {
|
|
1082
1093
|
let current = node;
|
|
@@ -1352,8 +1363,24 @@ async function waitForStable(ctx, selectors, options = {}) {
|
|
|
1352
1363
|
let stableSince = 0;
|
|
1353
1364
|
let mutationCount = 0;
|
|
1354
1365
|
let wasPaused = false;
|
|
1366
|
+
let snapshotErrorCount = 0;
|
|
1367
|
+
let lastSnapshotError = null;
|
|
1355
1368
|
while (Date.now() < deadline) {
|
|
1356
|
-
const snapshot2 = await captureSnapshot(ctx, selectorList, options)
|
|
1369
|
+
const snapshot2 = await captureSnapshot(ctx, selectorList, options).catch((error) => {
|
|
1370
|
+
snapshotErrorCount += 1;
|
|
1371
|
+
lastSnapshotError = error;
|
|
1372
|
+
if (snapshotErrorCount === 1 || snapshotErrorCount % 5 === 0) {
|
|
1373
|
+
Logger.warn("Mutation.waitForStable snapshot skipped", {
|
|
1374
|
+
snapshotErrorCount,
|
|
1375
|
+
message: error?.message || String(error)
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
return null;
|
|
1379
|
+
});
|
|
1380
|
+
if (!snapshot2) {
|
|
1381
|
+
await sleep(pollIntervalMs);
|
|
1382
|
+
continue;
|
|
1383
|
+
}
|
|
1357
1384
|
if (!foundInitial) {
|
|
1358
1385
|
if (snapshot2.found || Date.now() >= initialDeadline) {
|
|
1359
1386
|
foundInitial = true;
|
|
@@ -1401,7 +1428,7 @@ async function waitForStable(ctx, selectors, options = {}) {
|
|
|
1401
1428
|
}
|
|
1402
1429
|
await sleep(pollIntervalMs);
|
|
1403
1430
|
}
|
|
1404
|
-
throw new Error(`Mutation.waitForStable \u8D85\u65F6 (${timeout}ms), \u5DF2\u68C0\u6D4B\u5230 ${mutationCount} \u6B21\u53D8\u5316`);
|
|
1431
|
+
throw new Error(`Mutation.waitForStable \u8D85\u65F6 (${timeout}ms), \u5DF2\u68C0\u6D4B\u5230 ${mutationCount} \u6B21\u53D8\u5316, snapshotErrorCount=${snapshotErrorCount}, lastSnapshotError=${lastSnapshotError?.message || ""}`);
|
|
1405
1432
|
}
|
|
1406
1433
|
async function waitForStableAcrossRoots(ctx, selectors, options = {}) {
|
|
1407
1434
|
return waitForStable(ctx, selectors, options);
|
|
@@ -1515,7 +1542,7 @@ function selectorLabel2(selector) {
|
|
|
1515
1542
|
}
|
|
1516
1543
|
|
|
1517
1544
|
// src/share.js
|
|
1518
|
-
var
|
|
1545
|
+
var import_node_crypto3 = require("node:crypto");
|
|
1519
1546
|
var import_jimp2 = require("jimp");
|
|
1520
1547
|
|
|
1521
1548
|
// src/internals/compression.js
|
|
@@ -1687,7 +1714,7 @@ async function captureScreen(ctx, options = {}) {
|
|
|
1687
1714
|
});
|
|
1688
1715
|
await sleep(DEFAULT_SETTLE_MS);
|
|
1689
1716
|
const png = await Device.screenshotPng(ctx);
|
|
1690
|
-
const hash = (0,
|
|
1717
|
+
const hash = (0, import_node_crypto3.createHash)("sha256").update(png).digest("hex");
|
|
1691
1718
|
if (seen.has(hash)) break;
|
|
1692
1719
|
seen.add(hash);
|
|
1693
1720
|
frameBuffers.push(png);
|