@skrillex1224/android-toolkit 1.0.6 → 1.0.8
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 +44 -7
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +44 -7
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -728,6 +728,9 @@ function sanitizeData(value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
728
728
|
return out;
|
|
729
729
|
}
|
|
730
730
|
|
|
731
|
+
// src/device-input.js
|
|
732
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
733
|
+
|
|
731
734
|
// src/device-view.js
|
|
732
735
|
import { createHash } from "node:crypto";
|
|
733
736
|
import { XMLParser } from "fast-xml-parser";
|
|
@@ -1005,7 +1008,10 @@ async function pressEnter2(ctx) {
|
|
|
1005
1008
|
}
|
|
1006
1009
|
async function scroll(ctx, selector, direction, options = {}) {
|
|
1007
1010
|
const node = await DeviceView.find(ctx, selector, options);
|
|
1008
|
-
|
|
1011
|
+
await scrollBounds(ctx, node.bounds, direction, options);
|
|
1012
|
+
}
|
|
1013
|
+
async function scrollBounds(ctx, bounds2, direction, options = {}) {
|
|
1014
|
+
const box = bounds2;
|
|
1009
1015
|
const ratio = Number(options.swipeRatio || 0.72);
|
|
1010
1016
|
const durationMs = Number(options.durationMs || 360);
|
|
1011
1017
|
const x = box.centerX;
|
|
@@ -1031,15 +1037,18 @@ async function scrollToTop(ctx, selector, options = {}) {
|
|
|
1031
1037
|
async function scrollUntilStable(ctx, selector, direction, options = {}) {
|
|
1032
1038
|
const maxSwipes = Math.max(1, Number(options.maxSwipes || 20));
|
|
1033
1039
|
const stableRoundsTarget = Math.max(1, Number(options.stableRounds || 2));
|
|
1040
|
+
const hashSource = String(options.stability || options.hashSource || "view");
|
|
1041
|
+
if (hashSource === "screenshot") {
|
|
1042
|
+
return scrollUntilScreenshotStable(ctx, selector, direction, options, maxSwipes, stableRoundsTarget, hashSource);
|
|
1043
|
+
}
|
|
1034
1044
|
let lastHash = "";
|
|
1035
1045
|
let stableRounds = 0;
|
|
1036
1046
|
for (let index = 0; index < maxSwipes; index += 1) {
|
|
1037
|
-
const
|
|
1038
|
-
const currentHash = DeviceView.hashNode(node);
|
|
1047
|
+
const currentHash = await scrollStateHash(ctx, selector, options, hashSource);
|
|
1039
1048
|
if (currentHash === lastHash) {
|
|
1040
1049
|
stableRounds += 1;
|
|
1041
1050
|
if (stableRounds >= stableRoundsTarget) {
|
|
1042
|
-
return { swipes: index, stableRounds, hash: currentHash };
|
|
1051
|
+
return { swipes: index, stableRounds, hash: currentHash, hashSource, capped: false };
|
|
1043
1052
|
}
|
|
1044
1053
|
} else {
|
|
1045
1054
|
stableRounds = 0;
|
|
@@ -1047,7 +1056,35 @@ async function scrollUntilStable(ctx, selector, direction, options = {}) {
|
|
|
1047
1056
|
}
|
|
1048
1057
|
await scroll(ctx, selector, direction, options);
|
|
1049
1058
|
}
|
|
1050
|
-
return { swipes: maxSwipes, stableRounds, hash: lastHash };
|
|
1059
|
+
return { swipes: maxSwipes, stableRounds, hash: lastHash, hashSource, capped: true };
|
|
1060
|
+
}
|
|
1061
|
+
async function scrollUntilScreenshotStable(ctx, selector, direction, options, maxSwipes, stableRoundsTarget, hashSource) {
|
|
1062
|
+
const node = await DeviceView.find(ctx, selector, options);
|
|
1063
|
+
const bounds2 = node.bounds;
|
|
1064
|
+
let lastHash = await scrollStateHash(ctx, selector, options, hashSource);
|
|
1065
|
+
let stableRounds = 0;
|
|
1066
|
+
for (let index = 0; index < maxSwipes; index += 1) {
|
|
1067
|
+
await scrollBounds(ctx, bounds2, direction, options);
|
|
1068
|
+
const currentHash = await scrollStateHash(ctx, selector, options, hashSource);
|
|
1069
|
+
if (currentHash === lastHash) {
|
|
1070
|
+
stableRounds += 1;
|
|
1071
|
+
if (stableRounds >= stableRoundsTarget) {
|
|
1072
|
+
return { swipes: index + 1, stableRounds, hash: currentHash, hashSource, capped: false };
|
|
1073
|
+
}
|
|
1074
|
+
} else {
|
|
1075
|
+
stableRounds = 0;
|
|
1076
|
+
lastHash = currentHash;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return { swipes: maxSwipes, stableRounds, hash: lastHash, hashSource, capped: true };
|
|
1080
|
+
}
|
|
1081
|
+
async function scrollStateHash(ctx, selector, options, hashSource) {
|
|
1082
|
+
if (hashSource === "screenshot") {
|
|
1083
|
+
const png = await Device.screenshotPng(ctx);
|
|
1084
|
+
return createHash2("sha256").update(png).digest("hex");
|
|
1085
|
+
}
|
|
1086
|
+
const node = await DeviceView.find(ctx, selector, options);
|
|
1087
|
+
return DeviceView.hashNode(node);
|
|
1051
1088
|
}
|
|
1052
1089
|
function nearestClickable(node) {
|
|
1053
1090
|
let current = node;
|
|
@@ -1502,7 +1539,7 @@ function selectorLabel2(selector) {
|
|
|
1502
1539
|
}
|
|
1503
1540
|
|
|
1504
1541
|
// src/share.js
|
|
1505
|
-
import { createHash as
|
|
1542
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
1506
1543
|
import { Jimp as Jimp2, JimpMime as JimpMime2 } from "jimp";
|
|
1507
1544
|
|
|
1508
1545
|
// src/internals/compression.js
|
|
@@ -1674,7 +1711,7 @@ async function captureScreen(ctx, options = {}) {
|
|
|
1674
1711
|
});
|
|
1675
1712
|
await sleep(DEFAULT_SETTLE_MS);
|
|
1676
1713
|
const png = await Device.screenshotPng(ctx);
|
|
1677
|
-
const hash =
|
|
1714
|
+
const hash = createHash3("sha256").update(png).digest("hex");
|
|
1678
1715
|
if (seen.has(hash)) break;
|
|
1679
1716
|
seen.add(hash);
|
|
1680
1717
|
frameBuffers.push(png);
|