From 1966b790d2211225920d4c79740c8d99b7a3ebb1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 4 Dec 2020 06:01:24 +0530 Subject: [PATCH] Read aloud: Keep going when reaching end of internal file --- src/pyj/read_book/read_aloud.pyj | 4 +++- src/pyj/read_book/view.pyj | 15 ++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/pyj/read_book/read_aloud.pyj b/src/pyj/read_book/read_aloud.pyj index 4fda819cff..2c087869f3 100644 --- a/src/pyj/read_book/read_aloud.pyj +++ b/src/pyj/read_book/read_aloud.pyj @@ -174,7 +174,9 @@ class ReadAloud: elif which is 'begin': self.state = PLAYING elif which is 'end': - pass + self.state = STOPPED + if not self.view.show_next_spine_item(): + self.hide() def send_message(self, type, **kw): self.view.iframe_wrapper.send_message('tts', type=type, **kw) diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 747442f1c1..ff3a7bbb72 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -1107,19 +1107,23 @@ class View: self.selection_bar.notes_edited(uuid) self.selection_bar.update_position() - def on_next_spine_item(self, data): + def show_next_spine_item(self, previous): spine = self.book.manifest.spine idx = spine.indexOf(self.currently_showing.name) - if data.previous: + if previous: if idx is 0: - return + return False idx = min(spine.length - 1, max(idx - 1, 0)) self.show_name(spine[idx], initial_position={'type':'frac', 'frac':1, 'replace_history':True}) else: if idx is spine.length - 1: - return + return False idx = max(0, min(spine.length - 1, idx + 1)) self.show_name(spine[idx], initial_position={'type':'frac', 'frac':0, 'replace_history':True}) + return True + + def on_next_spine_item(self, data): + self.show_next_spine_item(data.previous) def on_next_section(self, data): toc_node = get_next_section(data.forward) @@ -1272,7 +1276,6 @@ class View: def on_content_loaded(self, data): self.selection_bar.hide() - self.read_aloud.hide() self.processing_spine_item_display = False self.currently_showing.loading = False self.hide_loading() @@ -1286,6 +1289,8 @@ class View: ui_operations.clear_history() if ui_operations.content_file_changed: ui_operations.content_file_changed(self.currently_showing.name) + if self.read_aloud.is_visible: + self.read_aloud.play() def set_progress_frac(self, progress_frac, file_progress_frac, page_counts): self.current_progress_frac = progress_frac or 0