mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Merge pull request #517 from Arthur-Milchior/backup_is_done
hook backup_is_done
This commit is contained in:
commit
b7c64aaf39
3 changed files with 26 additions and 0 deletions
|
@ -311,6 +311,30 @@ class _AvPlayerWillPlayHook:
|
||||||
av_player_will_play = _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:
|
class _BrowserDidChangeRowHook:
|
||||||
_hooks: List[Callable[["aqt.browser.Browser"], None]] = []
|
_hooks: List[Callable[["aqt.browser.Browser"], None]] = []
|
||||||
|
|
||||||
|
|
|
@ -561,6 +561,7 @@ from the profile screen."
|
||||||
fname = backups.pop(0)
|
fname = backups.pop(0)
|
||||||
path = os.path.join(dir, fname)
|
path = os.path.join(dir, fname)
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
|
gui_hooks.backup_is_done()
|
||||||
|
|
||||||
def maybeOptimize(self) -> None:
|
def maybeOptimize(self) -> None:
|
||||||
# have two weeks passed?
|
# have two weeks passed?
|
||||||
|
|
|
@ -341,6 +341,7 @@ hooks = [
|
||||||
),
|
),
|
||||||
# Main
|
# Main
|
||||||
###################
|
###################
|
||||||
|
Hook(name="backup_is_done"),
|
||||||
Hook(name="profile_did_open", legacy_hook="profileLoaded"),
|
Hook(name="profile_did_open", legacy_hook="profileLoaded"),
|
||||||
Hook(name="profile_will_close", legacy_hook="unloadProfile"),
|
Hook(name="profile_will_close", legacy_hook="unloadProfile"),
|
||||||
Hook(
|
Hook(
|
||||||
|
|
Loading…
Reference in a new issue