Fix #1968767 [JSONDecode Error when turning pages with space bar in the E-Book Viewer](https://bugs.launchpad.net/calibre/+bug/1968767)

This commit is contained in:
Kovid Goyal 2022-04-13 07:32:15 +05:30
parent 28c9006729
commit 572c34b821
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -38,13 +38,17 @@ def reading_rates_path():
def save_reading_rates(key, rates):
path = reading_rates_path()
existing = {}
try:
with open(path, 'rb') as f:
raw = f.read()
except OSError:
existing = {}
pass
else:
try:
existing = json.loads(raw)
except Exception:
pass
existing.pop(key, None)
existing[key] = rates
while len(existing) > 50: