From 49971d0235c76383e077f849271e80dd0fd17fc1 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 31 May 2020 18:51:05 +1000 Subject: [PATCH] fix media sync progress not updating, and issues closing profile --- qt/aqt/main.py | 6 ++++-- qt/aqt/mediasync.py | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/qt/aqt/main.py b/qt/aqt/main.py index fc43345cd..87a734fe5 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -514,11 +514,13 @@ close the profile or restart Anki.""" self.col.reopen() def unloadCollection(self, onsuccess: Callable) -> None: - def after_sync(): - self.media_syncer.show_diag_until_finished() + def after_media_sync(): self._unloadCollection() onsuccess() + def after_sync(): + self.media_syncer.show_diag_until_finished(after_media_sync) + def before_sync(): self.setEnabled(False) self.maybe_auto_sync_on_open_close(after_sync) diff --git a/qt/aqt/mediasync.py b/qt/aqt/mediasync.py index 4d9ca3c1a..2ef984996 100644 --- a/qt/aqt/mediasync.py +++ b/qt/aqt/mediasync.py @@ -6,7 +6,7 @@ from __future__ import annotations import time from concurrent.futures import Future from dataclasses import dataclass -from typing import List, Optional, Union +from typing import Callable, List, Optional, Union import aqt from anki.rsbackend import ( @@ -62,7 +62,9 @@ class MediaSyncer: self._log_and_notify(tr(TR.SYNC_MEDIA_STARTING)) self._syncing = True - self._progress_timer = self.mw.progress.timer(1000, self._on_progress, False) + self._progress_timer = self.mw.progress.timer( + 1000, self._on_progress, True, False + ) gui_hooks.media_sync_did_start_or_stop(True) def run() -> None: @@ -121,13 +123,22 @@ class MediaSyncer: def show_sync_log(self): aqt.dialogs.open("sync_log", self.mw, self) - def show_diag_until_finished(self): + def show_diag_until_finished(self, on_finished: Callable[[], None]): # nothing to do if not syncing if not self.is_syncing(): - return + return on_finished() diag: MediaSyncDialog = aqt.dialogs.open("sync_log", self.mw, self, True) - diag.exec_() + diag.show() + + timer: Optional[QTimer] = None + + def check_finished(): + if not self.is_syncing(): + timer.stop() + on_finished() + + timer = self.mw.progress.timer(150, check_finished, True, False) def seconds_since_last_sync(self) -> int: if self.is_syncing():