mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
hook backup_is_done
I expect to use this hook in add-on 529955533. It'll serve me to create long term backup at the same time than your backup
This commit is contained in:
parent
e3a57a4193
commit
bfc305fa26
3 changed files with 26 additions and 0 deletions
|
@ -272,6 +272,30 @@ class _AvPlayerWillPlayHook:
|
|||
av_player_will_play = _AvPlayerWillPlayHook()
|
||||
|
||||
|
||||
class _BackupIsDoneHook:
|
||||
_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 __call__(self) -> None:
|
||||
for hook in self._hooks:
|
||||
try:
|
||||
hook()
|
||||
except:
|
||||
# if the hook fails, remove it
|
||||
self._hooks.remove(hook)
|
||||
raise
|
||||
|
||||
|
||||
backup_is_done = _BackupIsDoneHook()
|
||||
|
||||
|
||||
class _BrowserDidChangeRowHook:
|
||||
_hooks: List[Callable[["aqt.browser.Browser"], None]] = []
|
||||
|
||||
|
|
|
@ -561,6 +561,7 @@ from the profile screen."
|
|||
fname = backups.pop(0)
|
||||
path = os.path.join(dir, fname)
|
||||
os.unlink(path)
|
||||
gui_hooks.backup_is_done()
|
||||
|
||||
def maybeOptimize(self) -> None:
|
||||
# have two weeks passed?
|
||||
|
|
|
@ -341,6 +341,7 @@ hooks = [
|
|||
),
|
||||
# Main
|
||||
###################
|
||||
Hook(name="backup_is_done"),
|
||||
Hook(name="profile_did_open", legacy_hook="profileLoaded"),
|
||||
Hook(name="profile_will_close", legacy_hook="unloadProfile"),
|
||||
Hook(
|
||||
|
|
Loading…
Reference in a new issue