2020-06-08 12:28:11 +02:00
|
|
|
# Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-02-02 14:30:53 +01:00
|
|
|
from concurrent.futures import Future
|
|
|
|
|
2020-06-08 12:28:11 +02:00
|
|
|
import aqt
|
|
|
|
from aqt.qt import *
|
|
|
|
from aqt.utils import showText, tooltip
|
|
|
|
|
|
|
|
|
2021-02-01 14:28:21 +01:00
|
|
|
def on_progress(mw: aqt.main.AnkiQt) -> None:
|
2020-06-08 12:28:11 +02:00
|
|
|
progress = mw.col.latest_progress()
|
2021-02-08 07:40:27 +01:00
|
|
|
if not progress.HasField("database_check"):
|
2020-06-08 12:28:11 +02:00
|
|
|
return
|
2021-02-08 07:40:27 +01:00
|
|
|
dbprogress = progress.database_check
|
2020-06-08 12:28:11 +02:00
|
|
|
mw.progress.update(
|
2020-06-09 06:07:39 +02:00
|
|
|
process=False,
|
2021-02-08 07:40:27 +01:00
|
|
|
label=dbprogress.stage,
|
|
|
|
value=dbprogress.stage_current,
|
|
|
|
max=dbprogress.stage_total,
|
2020-06-08 12:28:11 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def check_db(mw: aqt.AnkiQt) -> None:
|
2021-02-01 14:28:21 +01:00
|
|
|
def on_timer() -> None:
|
2020-06-08 12:28:11 +02:00
|
|
|
on_progress(mw)
|
|
|
|
|
|
|
|
timer = QTimer(mw)
|
|
|
|
qconnect(timer.timeout, on_timer)
|
|
|
|
timer.start(100)
|
|
|
|
|
2021-02-02 14:30:53 +01:00
|
|
|
def on_future_done(fut: Future) -> None:
|
2020-06-08 12:28:11 +02:00
|
|
|
timer.stop()
|
|
|
|
ret, ok = fut.result()
|
|
|
|
|
|
|
|
if not ok:
|
|
|
|
showText(ret)
|
|
|
|
else:
|
|
|
|
tooltip(ret)
|
|
|
|
|
|
|
|
# if an error has directed the user to check the database,
|
|
|
|
# silently clean up any broken reset hooks which distract from
|
|
|
|
# the underlying issue
|
|
|
|
n = 0
|
|
|
|
while n < 10:
|
|
|
|
try:
|
|
|
|
mw.reset()
|
|
|
|
break
|
|
|
|
except Exception as e:
|
|
|
|
print("swallowed exception in reset hook:", e)
|
|
|
|
n += 1
|
|
|
|
continue
|
|
|
|
|
2021-06-27 07:12:22 +02:00
|
|
|
mw.taskman.with_progress(mw.col.fix_integrity, on_future_done)
|