From ac272eadcef5c27d6bfb77adc462ecaf3e7e6647 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Tue, 5 May 2026 12:07:27 +0200 Subject: [PATCH] fix(navigation): detect end of carousel by checking ui delta to prevent blind swiping --- GramAddict/core/behaviors/carousel_browsing.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/GramAddict/core/behaviors/carousel_browsing.py b/GramAddict/core/behaviors/carousel_browsing.py index c38e4d8..bc9ec68 100644 --- a/GramAddict/core/behaviors/carousel_browsing.py +++ b/GramAddict/core/behaviors/carousel_browsing.py @@ -74,13 +74,23 @@ class CarouselBrowsingPlugin(BehaviorPlugin): # ── Curiosity Dwell ── if i == curiosity_slide: dwell = random.uniform(3.0, 7.0) - logger.debug(f"📸 [Carousel] Curiosity Peak hit on slide {i+1}. " f"Gazing for {dwell:.1f}s...") + logger.debug(f"📸 [Carousel] Curiosity Peak hit on slide {i+1}. Gazing for {dwell:.1f}s...") sleep(dwell * ctx.sleep_mod) + xml_before = ctx.device.dump_hierarchy() + # Horizontal swipe: Right to left humanized_horizontal_swipe(ctx.device, start_x=w * 0.8, end_x=w * 0.2, y=h * 0.5, duration_ms=250) - - sleep(random.uniform(1.0, 2.0) * ctx.sleep_mod) + + # Brief wait for transition to complete + sleep(random.uniform(1.5, 2.5) * ctx.sleep_mod) + + xml_after = ctx.device.dump_hierarchy() + xml_delta = abs(len(xml_before) - len(xml_after)) + + if xml_before == xml_after or xml_delta < 50: + logger.info(f"📸 [Carousel] End of carousel detected on slide {i+1} (UI stable). Stopping swipe.") + break return BehaviorResult( executed=True, interactions=count, metadata={"slides_viewed": count, "curiosity_slide": curiosity_slide}