Also implement remembering reading rate for in browser viewer

This commit is contained in:
Kovid Goyal 2022-03-03 20:25:49 +05:30
parent f043ceff0c
commit 6e054fd1b0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 13 additions and 1 deletions

View File

@ -60,6 +60,7 @@ def new_book(key, metadata):
'recent_date': new Date(),
'last_read': {},
'last_read_position': {},
'saved_reading_rates': {},
'annotations_map': {},
}
@ -300,6 +301,10 @@ class DB:
book.metadata[key] = new_metadata[key]
self.do_op(['books'], book, _('Failed to write to the books database'), op='put')
def save_reading_rates(self, book, rates):
book.saved_reading_rates = rates
self.do_op(['books'], book, _('Failed to write to the books database'), op='put')
def update_annotations_data_from_key(self, library_id, book_id, fmt, new_data):
unkey = username_key(get_interface_data().username)
self.get_book(library_id, book_id, fmt, None, def(book):

View File

@ -18,7 +18,7 @@ class Timers:
def start_book(self, book):
self.reset_read_timer()
self.rates = v'[]'
if book.saved_reading_rates?.rates:
if book?.saved_reading_rates?.rates:
self.rates = book.saved_reading_rates.rates.slice(0)
self.calculate()

View File

@ -65,6 +65,7 @@ class ReadUI:
ui_operations.update_url_state = self.update_url_state.bind(self)
ui_operations.update_last_read_time = self.db.update_last_read_time
ui_operations.show_error = self.show_error.bind(self)
ui_operations.update_reading_rates = self.update_reading_rates.bind(self)
ui_operations.redisplay_book = self.redisplay_book.bind(self)
ui_operations.reload_book = self.reload_book.bind(self)
ui_operations.forward_gesture = self.forward_gesture.bind(self)
@ -642,3 +643,9 @@ class ReadUI:
self.tts_client.speak_marked_text(data.marked_text, self.view.read_aloud.handle_tts_event)
else:
getattr(self.tts_client, event)()
def update_reading_rates(self, rates):
if not self.view?.book:
return
book = self.view.book
self.db.save_reading_rates(book, rates)