From 66026623eb5eecb4a41bd0712388880288f2d18c Mon Sep 17 00:00:00 2001 From: junlu592 Date: Mon, 3 Nov 2025 15:17:30 +0100 Subject: [PATCH] added active window check for sync success --- CONTRIBUTORS | 1 + ftl/core-repo | 2 +- ftl/qt-repo | 2 +- qt/aqt/sync.py | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index d90b7dbcc..d19044034 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -254,6 +254,7 @@ nav1s Ranjit Odedra Eltaurus jariji +Junia Mannervik ******************** diff --git a/ftl/core-repo b/ftl/core-repo index ec5e4cad6..5897ef3a4 160000 --- a/ftl/core-repo +++ b/ftl/core-repo @@ -1 +1 @@ -Subproject commit ec5e4cad6242e538cacf52265243668f0de5da80 +Subproject commit 5897ef3a4589c123b7fa4c7fbd67f84d0b7ee13e diff --git a/ftl/qt-repo b/ftl/qt-repo index 0b7c53023..dad4e2736 160000 --- a/ftl/qt-repo +++ b/ftl/qt-repo @@ -1 +1 @@ -Subproject commit 0b7c530233390d73b706f012bbe7489539925c7d +Subproject commit dad4e2736a2b53dcdb52d79b5703dd464c05d666 diff --git a/qt/aqt/sync.py b/qt/aqt/sync.py index 75bdeca89..ce54b82ca 100644 --- a/qt/aqt/sync.py +++ b/qt/aqt/sync.py @@ -121,6 +121,24 @@ def sync_collection(mw: aqt.main.AnkiQt, on_done: Callable[[], None]) -> None: showText(out.server_message, parent=mw) if out.required == out.NO_CHANGES: tooltip(parent=mw, msg=tr.sync_collection_complete()) + + # Monitor window focus and close tooltip if window loses focus + def check_focus() -> None: + from aqt.utils import closeTooltip + # Close tooltip if window loses focus, becomes invisible, or is minimized + if not mw.isActiveWindow() or not mw.isVisible() or (mw.windowState() & Qt.WindowState.WindowMinimized): + closeTooltip() + focus_timer.stop() + + focus_timer = QTimer(mw) + qconnect(focus_timer.timeout, check_focus) + focus_timer.start(100) # Check every 100ms + + # Stop monitoring after tooltip's natural expiry time + def stop_monitoring() -> None: + focus_timer.stop() + + QTimer.singleShot(3000, stop_monitoring) # all done; track media progress mw.media_syncer.start_monitoring() return on_done()