mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Tolerate missing keys in profile DB
https://forums.ankiweb.net/t/crash-with-error-keyerror-mainwindowstate/29689
This commit is contained in:
parent
c12689160f
commit
e6f970e969
3 changed files with 8 additions and 7 deletions
|
@ -406,7 +406,7 @@ class Browser(QMainWindow):
|
|||
self.form.searchEdit.lineEdit().setPlaceholderText(
|
||||
tr.browsing_search_bar_hint()
|
||||
)
|
||||
self.form.searchEdit.addItems([""] + self.mw.pm.profile["searchHistory"])
|
||||
self.form.searchEdit.addItems([""] + self.mw.pm.profile.get("searchHistory"))
|
||||
if search is not None:
|
||||
self.search_for_terms(*search)
|
||||
else:
|
||||
|
@ -451,7 +451,7 @@ class Browser(QMainWindow):
|
|||
showWarning(str(err))
|
||||
|
||||
def update_history(self) -> None:
|
||||
sh = self.mw.pm.profile["searchHistory"]
|
||||
sh = self.mw.pm.profile.get("searchHistory")
|
||||
if self._lastSearchTxt in sh:
|
||||
sh.remove(self._lastSearchTxt)
|
||||
sh.insert(0, self._lastSearchTxt)
|
||||
|
|
|
@ -476,7 +476,7 @@ class AnkiQt(QMainWindow):
|
|||
self.setup_sound()
|
||||
self.flags = FlagManager(self)
|
||||
# show main window
|
||||
if self.pm.profile["mainWindowState"]:
|
||||
if self.pm.profile.get("mainWindowState"):
|
||||
restoreGeom(self, "mainWindow")
|
||||
restoreState(self, "mainWindow")
|
||||
# titlebar
|
||||
|
@ -687,8 +687,9 @@ class AnkiQt(QMainWindow):
|
|||
|
||||
def maybeOptimize(self) -> None:
|
||||
# have two weeks passed?
|
||||
if (int_time() - self.pm.profile["lastOptimize"]) < 86400 * 14:
|
||||
return
|
||||
if (last_optimize := self.pm.profile.get("lastOptimize")) is not None:
|
||||
if (int_time() - last_optimize) < 86400 * 14:
|
||||
return
|
||||
self.progress.start(label=tr.qt_misc_optimizing())
|
||||
self.col.optimize()
|
||||
self.pm.profile["lastOptimize"] = int_time()
|
||||
|
|
|
@ -632,10 +632,10 @@ create table if not exists profiles
|
|||
self.profile["hostNum"] = val or 0
|
||||
|
||||
def media_syncing_enabled(self) -> bool:
|
||||
return self.profile["syncMedia"]
|
||||
return self.profile.get("syncMedia")
|
||||
|
||||
def auto_syncing_enabled(self) -> bool:
|
||||
return self.profile["autoSync"]
|
||||
return self.profile.get("autoSync")
|
||||
|
||||
def sync_auth(self) -> SyncAuth | None:
|
||||
if not (hkey := self.profile.get("syncKey")):
|
||||
|
|
Loading…
Reference in a new issue