@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.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";
@@ -1031,15 +1034,15 @@ async function scrollToTop(ctx, selector, options = {}) {
1031
1034
  async function scrollUntilStable(ctx, selector, direction, options = {}) {
1032
1035
  const maxSwipes = Math.max(1, Number(options.maxSwipes || 20));
1033
1036
  const stableRoundsTarget = Math.max(1, Number(options.stableRounds || 2));
1037
+ const hashSource = String(options.stability || options.hashSource || "view");
1034
1038
  let lastHash = "";
1035
1039
  let stableRounds = 0;
1036
1040
  for (let index = 0; index < maxSwipes; index += 1) {
1037
- const node = await DeviceView.find(ctx, selector, options);
1038
- const currentHash = DeviceView.hashNode(node);
1041
+ const currentHash = await scrollStateHash(ctx, selector, options, hashSource);
1039
1042
  if (currentHash === lastHash) {
1040
1043
  stableRounds += 1;
1041
1044
  if (stableRounds >= stableRoundsTarget) {
1042
- return { swipes: index, stableRounds, hash: currentHash };
1045
+ return { swipes: index, stableRounds, hash: currentHash, hashSource };
1043
1046
  }
1044
1047
  } else {
1045
1048
  stableRounds = 0;
@@ -1047,7 +1050,15 @@ async function scrollUntilStable(ctx, selector, direction, options = {}) {
1047
1050
  }
1048
1051
  await scroll(ctx, selector, direction, options);
1049
1052
  }
1050
- return { swipes: maxSwipes, stableRounds, hash: lastHash };
1053
+ return { swipes: maxSwipes, stableRounds, hash: lastHash, hashSource };
1054
+ }
1055
+ async function scrollStateHash(ctx, selector, options, hashSource) {
1056
+ if (hashSource === "screenshot") {
1057
+ const png = await Device.screenshotPng(ctx);
1058
+ return createHash2("sha256").update(png).digest("hex");
1059
+ }
1060
+ const node = await DeviceView.find(ctx, selector, options);
1061
+ return DeviceView.hashNode(node);
1051
1062
  }
1052
1063
  function nearestClickable(node) {
1053
1064
  let current = node;
@@ -1323,8 +1334,24 @@ async function waitForStable(ctx, selectors, options = {}) {
1323
1334
  let stableSince = 0;
1324
1335
  let mutationCount = 0;
1325
1336
  let wasPaused = false;
1337
+ let snapshotErrorCount = 0;
1338
+ let lastSnapshotError = null;
1326
1339
  while (Date.now() < deadline) {
1327
- const snapshot2 = await captureSnapshot(ctx, selectorList, options);
1340
+ const snapshot2 = await captureSnapshot(ctx, selectorList, options).catch((error) => {
1341
+ snapshotErrorCount += 1;
1342
+ lastSnapshotError = error;
1343
+ if (snapshotErrorCount === 1 || snapshotErrorCount % 5 === 0) {
1344
+ Logger.warn("Mutation.waitForStable snapshot skipped", {
1345
+ snapshotErrorCount,
1346
+ message: error?.message || String(error)
1347
+ });
1348
+ }
1349
+ return null;
1350
+ });
1351
+ if (!snapshot2) {
1352
+ await sleep(pollIntervalMs);
1353
+ continue;
1354
+ }
1328
1355
  if (!foundInitial) {
1329
1356
  if (snapshot2.found || Date.now() >= initialDeadline) {
1330
1357
  foundInitial = true;
@@ -1372,7 +1399,7 @@ async function waitForStable(ctx, selectors, options = {}) {
1372
1399
  }
1373
1400
  await sleep(pollIntervalMs);
1374
1401
  }
1375
- throw new Error(`Mutation.waitForStable \u8D85\u65F6 (${timeout}ms), \u5DF2\u68C0\u6D4B\u5230 ${mutationCount} \u6B21\u53D8\u5316`);
1402
+ throw new Error(`Mutation.waitForStable \u8D85\u65F6 (${timeout}ms), \u5DF2\u68C0\u6D4B\u5230 ${mutationCount} \u6B21\u53D8\u5316, snapshotErrorCount=${snapshotErrorCount}, lastSnapshotError=${lastSnapshotError?.message || ""}`);
1376
1403
  }
1377
1404
  async function waitForStableAcrossRoots(ctx, selectors, options = {}) {
1378
1405
  return waitForStable(ctx, selectors, options);
@@ -1486,7 +1513,7 @@ function selectorLabel2(selector) {
1486
1513
  }
1487
1514
 
1488
1515
  // src/share.js
1489
- import { createHash as createHash2 } from "node:crypto";
1516
+ import { createHash as createHash3 } from "node:crypto";
1490
1517
  import { Jimp as Jimp2, JimpMime as JimpMime2 } from "jimp";
1491
1518
 
1492
1519
  // src/internals/compression.js
@@ -1658,7 +1685,7 @@ async function captureScreen(ctx, options = {}) {
1658
1685
  });
1659
1686
  await sleep(DEFAULT_SETTLE_MS);
1660
1687
  const png = await Device.screenshotPng(ctx);
1661
- const hash = createHash2("sha256").update(png).digest("hex");
1688
+ const hash = createHash3("sha256").update(png).digest("hex");
1662
1689
  if (seen.has(hash)) break;
1663
1690
  seen.add(hash);
1664
1691
  frameBuffers.push(png);