mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Add sync_will_start and sync_did_finish hook
This commit is contained in:
parent
340c749d4c
commit
8dcd84e7c0
3 changed files with 58 additions and 0 deletions
|
@ -2721,6 +2721,60 @@ class _StyleDidInitFilter:
|
||||||
style_did_init = _StyleDidInitFilter()
|
style_did_init = _StyleDidInitFilter()
|
||||||
|
|
||||||
|
|
||||||
|
class _SyncDidFinishHook:
|
||||||
|
_hooks: List[Callable[[], None]] = []
|
||||||
|
|
||||||
|
def append(self, cb: Callable[[], None]) -> None:
|
||||||
|
"""()"""
|
||||||
|
self._hooks.append(cb)
|
||||||
|
|
||||||
|
def remove(self, cb: Callable[[], None]) -> None:
|
||||||
|
if cb in self._hooks:
|
||||||
|
self._hooks.remove(cb)
|
||||||
|
|
||||||
|
def count(self) -> int:
|
||||||
|
return len(self._hooks)
|
||||||
|
|
||||||
|
def __call__(self) -> None:
|
||||||
|
for hook in self._hooks:
|
||||||
|
try:
|
||||||
|
hook()
|
||||||
|
except:
|
||||||
|
# if the hook fails, remove it
|
||||||
|
self._hooks.remove(hook)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
sync_did_finish = _SyncDidFinishHook()
|
||||||
|
|
||||||
|
|
||||||
|
class _SyncWillStartHook:
|
||||||
|
_hooks: List[Callable[[], None]] = []
|
||||||
|
|
||||||
|
def append(self, cb: Callable[[], None]) -> None:
|
||||||
|
"""()"""
|
||||||
|
self._hooks.append(cb)
|
||||||
|
|
||||||
|
def remove(self, cb: Callable[[], None]) -> None:
|
||||||
|
if cb in self._hooks:
|
||||||
|
self._hooks.remove(cb)
|
||||||
|
|
||||||
|
def count(self) -> int:
|
||||||
|
return len(self._hooks)
|
||||||
|
|
||||||
|
def __call__(self) -> None:
|
||||||
|
for hook in self._hooks:
|
||||||
|
try:
|
||||||
|
hook()
|
||||||
|
except:
|
||||||
|
# if the hook fails, remove it
|
||||||
|
self._hooks.remove(hook)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
sync_will_start = _SyncWillStartHook()
|
||||||
|
|
||||||
|
|
||||||
class _TagEditorDidProcessKeyHook:
|
class _TagEditorDidProcessKeyHook:
|
||||||
_hooks: List[Callable[[TagEdit, QEvent], None]] = []
|
_hooks: List[Callable[[TagEdit, QEvent], None]] = []
|
||||||
|
|
||||||
|
|
|
@ -910,7 +910,9 @@ title="%s" %s>%s</button>""" % (
|
||||||
self.col.models._clear_cache()
|
self.col.models._clear_cache()
|
||||||
self.reset()
|
self.reset()
|
||||||
after_sync()
|
after_sync()
|
||||||
|
gui_hooks.sync_did_finish()
|
||||||
|
|
||||||
|
gui_hooks.sync_will_start()
|
||||||
sync_collection(self, on_done=on_collection_sync_finished)
|
sync_collection(self, on_done=on_collection_sync_finished)
|
||||||
|
|
||||||
def maybe_auto_sync_on_open_close(self, after_sync: Callable[[], None]) -> None:
|
def maybe_auto_sync_on_open_close(self, after_sync: Callable[[], None]) -> None:
|
||||||
|
|
|
@ -562,6 +562,8 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
|
||||||
args=["diag: aqt.emptycards.EmptyCardsDialog"],
|
args=["diag: aqt.emptycards.EmptyCardsDialog"],
|
||||||
doc="""Allows changing the list of cards to delete.""",
|
doc="""Allows changing the list of cards to delete.""",
|
||||||
),
|
),
|
||||||
|
Hook(name="sync_will_start", args=[]),
|
||||||
|
Hook(name="sync_did_finish", args=[]),
|
||||||
# Adding cards
|
# Adding cards
|
||||||
###################
|
###################
|
||||||
Hook(
|
Hook(
|
||||||
|
|
Loading…
Reference in a new issue