@skrillex1224/android-toolkit 1.0.7 → 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 CHANGED
@@ -1037,7 +1037,10 @@ async function pressEnter2(ctx) {
1037
1037
  }
1038
1038
  async function scroll(ctx, selector, direction, options = {}) {
1039
1039
  const node = await DeviceView.find(ctx, selector, options);
1040
- const box = node.bounds;
1040
+ await scrollBounds(ctx, node.bounds, direction, options);
1041
+ }
1042
+ async function scrollBounds(ctx, bounds2, direction, options = {}) {
1043
+ const box = bounds2;
1041
1044
  const ratio = Number(options.swipeRatio || 0.72);
1042
1045
  const durationMs = Number(options.durationMs || 360);
1043
1046
  const x = box.centerX;
@@ -1064,6 +1067,9 @@ async function scrollUntilStable(ctx, selector, direction, options = {}) {
1064
1067
  const maxSwipes = Math.max(1, Number(options.maxSwipes || 20));
1065
1068
  const stableRoundsTarget = Math.max(1, Number(options.stableRounds || 2));
1066
1069
  const hashSource = String(options.stability || options.hashSource || "view");
1070
+ if (hashSource === "screenshot") {
1071
+ return scrollUntilScreenshotStable(ctx, selector, direction, options, maxSwipes, stableRoundsTarget, hashSource);
1072
+ }
1067
1073
  let lastHash = "";
1068
1074
  let stableRounds = 0;
1069
1075
  for (let index = 0; index < maxSwipes; index += 1) {
@@ -1071,7 +1077,7 @@ async function scrollUntilStable(ctx, selector, direction, options = {}) {
1071
1077
  if (currentHash === lastHash) {
1072
1078
  stableRounds += 1;
1073
1079
  if (stableRounds >= stableRoundsTarget) {
1074
- return { swipes: index, stableRounds, hash: currentHash, hashSource };
1080
+ return { swipes: index, stableRounds, hash: currentHash, hashSource, capped: false };
1075
1081
  }
1076
1082
  } else {
1077
1083
  stableRounds = 0;
@@ -1079,7 +1085,27 @@ async function scrollUntilStable(ctx, selector, direction, options = {}) {
1079
1085
  }
1080
1086
  await scroll(ctx, selector, direction, options);
1081
1087
  }
1082
- return { swipes: maxSwipes, stableRounds, hash: lastHash, hashSource };
1088
+ return { swipes: maxSwipes, stableRounds, hash: lastHash, hashSource, capped: true };
1089
+ }
1090
+ async function scrollUntilScreenshotStable(ctx, selector, direction, options, maxSwipes, stableRoundsTarget, hashSource) {
1091
+ const node = await DeviceView.find(ctx, selector, options);
1092
+ const bounds2 = node.bounds;
1093
+ let lastHash = await scrollStateHash(ctx, selector, options, hashSource);
1094
+ let stableRounds = 0;
1095
+ for (let index = 0; index < maxSwipes; index += 1) {
1096
+ await scrollBounds(ctx, bounds2, direction, options);
1097
+ const currentHash = await scrollStateHash(ctx, selector, options, hashSource);
1098
+ if (currentHash === lastHash) {
1099
+ stableRounds += 1;
1100
+ if (stableRounds >= stableRoundsTarget) {
1101
+ return { swipes: index + 1, stableRounds, hash: currentHash, hashSource, capped: false };
1102
+ }
1103
+ } else {
1104
+ stableRounds = 0;
1105
+ lastHash = currentHash;
1106
+ }
1107
+ }
1108
+ return { swipes: maxSwipes, stableRounds, hash: lastHash, hashSource, capped: true };
1083
1109
  }
1084
1110
  async function scrollStateHash(ctx, selector, options, hashSource) {
1085
1111
  if (hashSource === "screenshot") {