fix media sync progress not updating, and issues closing profile

This commit is contained in:
Damien Elmes 2020-05-31 18:51:05 +10:00
parent 00138c6ba0
commit 49971d0235
2 changed files with 20 additions and 7 deletions

View File

@ -514,11 +514,13 @@ close the profile or restart Anki."""
self.col.reopen() self.col.reopen()
def unloadCollection(self, onsuccess: Callable) -> None: def unloadCollection(self, onsuccess: Callable) -> None:
def after_sync(): def after_media_sync():
self.media_syncer.show_diag_until_finished()
self._unloadCollection() self._unloadCollection()
onsuccess() onsuccess()
def after_sync():
self.media_syncer.show_diag_until_finished(after_media_sync)
def before_sync(): def before_sync():
self.setEnabled(False) self.setEnabled(False)
self.maybe_auto_sync_on_open_close(after_sync) self.maybe_auto_sync_on_open_close(after_sync)

View File

@ -6,7 +6,7 @@ from __future__ import annotations
import time import time
from concurrent.futures import Future from concurrent.futures import Future
from dataclasses import dataclass from dataclasses import dataclass
from typing import List, Optional, Union from typing import Callable, List, Optional, Union
import aqt import aqt
from anki.rsbackend import ( from anki.rsbackend import (
@ -62,7 +62,9 @@ class MediaSyncer:
self._log_and_notify(tr(TR.SYNC_MEDIA_STARTING)) self._log_and_notify(tr(TR.SYNC_MEDIA_STARTING))
self._syncing = True 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) gui_hooks.media_sync_did_start_or_stop(True)
def run() -> None: def run() -> None:
@ -121,13 +123,22 @@ class MediaSyncer:
def show_sync_log(self): def show_sync_log(self):
aqt.dialogs.open("sync_log", self.mw, 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 # nothing to do if not syncing
if not self.is_syncing(): if not self.is_syncing():
return return on_finished()
diag: MediaSyncDialog = aqt.dialogs.open("sync_log", self.mw, self, True) 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: def seconds_since_last_sync(self) -> int:
if self.is_syncing(): if self.is_syncing():