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(
|
self.form.searchEdit.lineEdit().setPlaceholderText(
|
||||||
tr.browsing_search_bar_hint()
|
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:
|
if search is not None:
|
||||||
self.search_for_terms(*search)
|
self.search_for_terms(*search)
|
||||||
else:
|
else:
|
||||||
|
@ -451,7 +451,7 @@ class Browser(QMainWindow):
|
||||||
showWarning(str(err))
|
showWarning(str(err))
|
||||||
|
|
||||||
def update_history(self) -> None:
|
def update_history(self) -> None:
|
||||||
sh = self.mw.pm.profile["searchHistory"]
|
sh = self.mw.pm.profile.get("searchHistory")
|
||||||
if self._lastSearchTxt in sh:
|
if self._lastSearchTxt in sh:
|
||||||
sh.remove(self._lastSearchTxt)
|
sh.remove(self._lastSearchTxt)
|
||||||
sh.insert(0, self._lastSearchTxt)
|
sh.insert(0, self._lastSearchTxt)
|
||||||
|
|
|
@ -476,7 +476,7 @@ class AnkiQt(QMainWindow):
|
||||||
self.setup_sound()
|
self.setup_sound()
|
||||||
self.flags = FlagManager(self)
|
self.flags = FlagManager(self)
|
||||||
# show main window
|
# show main window
|
||||||
if self.pm.profile["mainWindowState"]:
|
if self.pm.profile.get("mainWindowState"):
|
||||||
restoreGeom(self, "mainWindow")
|
restoreGeom(self, "mainWindow")
|
||||||
restoreState(self, "mainWindow")
|
restoreState(self, "mainWindow")
|
||||||
# titlebar
|
# titlebar
|
||||||
|
@ -687,7 +687,8 @@ class AnkiQt(QMainWindow):
|
||||||
|
|
||||||
def maybeOptimize(self) -> None:
|
def maybeOptimize(self) -> None:
|
||||||
# have two weeks passed?
|
# have two weeks passed?
|
||||||
if (int_time() - self.pm.profile["lastOptimize"]) < 86400 * 14:
|
if (last_optimize := self.pm.profile.get("lastOptimize")) is not None:
|
||||||
|
if (int_time() - last_optimize) < 86400 * 14:
|
||||||
return
|
return
|
||||||
self.progress.start(label=tr.qt_misc_optimizing())
|
self.progress.start(label=tr.qt_misc_optimizing())
|
||||||
self.col.optimize()
|
self.col.optimize()
|
||||||
|
|
|
@ -632,10 +632,10 @@ create table if not exists profiles
|
||||||
self.profile["hostNum"] = val or 0
|
self.profile["hostNum"] = val or 0
|
||||||
|
|
||||||
def media_syncing_enabled(self) -> bool:
|
def media_syncing_enabled(self) -> bool:
|
||||||
return self.profile["syncMedia"]
|
return self.profile.get("syncMedia")
|
||||||
|
|
||||||
def auto_syncing_enabled(self) -> bool:
|
def auto_syncing_enabled(self) -> bool:
|
||||||
return self.profile["autoSync"]
|
return self.profile.get("autoSync")
|
||||||
|
|
||||||
def sync_auth(self) -> SyncAuth | None:
|
def sync_auth(self) -> SyncAuth | None:
|
||||||
if not (hkey := self.profile.get("syncKey")):
|
if not (hkey := self.profile.get("syncKey")):
|
||||||
|
|
Loading…
Reference in a new issue