Merge pull request #517 from Arthur-Milchior/backup_is_done

hook backup_is_done
This commit is contained in:
Damien Elmes 2020-03-20 20:56:33 +10:00 committed by GitHub
commit b7c64aaf39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

View file

@ -311,6 +311,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]] = []

View file

@ -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?

View file

@ -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(