From a82a2724ce861ac3efc4e1462d9f8424f3661b37 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 31 Oct 2019 10:50:59 +0530 Subject: [PATCH] Clear history only after first page of book is loaded --- src/calibre/gui2/viewer/web_view.py | 3 ++- src/pyj/read_book/view.pyj | 7 +++++++ src/pyj/viewer-main.pyj | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/viewer/web_view.py b/src/calibre/gui2/viewer/web_view.py index 3721fb8655..73b6b2521d 100644 --- a/src/calibre/gui2/viewer/web_view.py +++ b/src/calibre/gui2/viewer/web_view.py @@ -254,6 +254,7 @@ class ViewerBridge(Bridge): show_error = from_js(object, object, object) export_shortcut_map = from_js(object) print_book = from_js() + clear_history = from_js() create_view = to_js() start_book_load = to_js() @@ -430,6 +431,7 @@ class WebView(RestartingWebEngineView): self.bridge.show_loading_message.connect(self.show_loading_message) self.bridge.show_error.connect(self.show_error) self.bridge.print_book.connect(self.print_book) + self.bridge.clear_history.connect(self.clear_history) self.bridge.export_shortcut_map.connect(self.set_shortcut_map) self.shortcut_map = {} self.bridge.report_cfi.connect(self.call_callback) @@ -504,7 +506,6 @@ class WebView(RestartingWebEngineView): def start_book_load(self, initial_cfi=None, initial_toc_node=None, initial_bookpos=None): key = (set_book_path.path,) - self.clear_history() self.execute_when_ready('start_book_load', key, initial_cfi, initial_toc_node, initial_bookpos, set_book_path.pathtoebook) def execute_when_ready(self, action, *args): diff --git a/src/pyj/read_book/view.pyj b/src/pyj/read_book/view.pyj index 7bc0194a14..5dd27cc0d0 100644 --- a/src/pyj/read_book/view.pyj +++ b/src/pyj/read_book/view.pyj @@ -365,6 +365,8 @@ class View: self.on_next_section({'forward': True}) elif data.name is 'previous_section': self.on_next_section({'forward': False}) + elif data.name is 'open_book': + self.overlay.open_book() def on_selection_change(self, data): self.currently_showing.selected_text = data.text @@ -571,6 +573,7 @@ class View: self.hide_overlays() self.iframe.focus() is_current_book = self.book and self.book.key == book.key + self.book_load_started = True if not is_current_book: self.iframe_wrapper.reset() self.content_popup_overlay.iframe_wrapper.reset() @@ -912,6 +915,10 @@ class View: self.set_progress_frac(data.progress_frac, data.file_progress_frac) self.update_header_footer() window.scrollTo(0, 0) # ensure window is at 0 on mobile where the navbar causes issues + if self.book_load_started: + self.book_load_started = False + if ui_operations.clear_history: + ui_operations.clear_history() def set_progress_frac(self, progress_frac, file_progress_frac): self.current_progress_frac = progress_frac or 0 diff --git a/src/pyj/viewer-main.pyj b/src/pyj/viewer-main.pyj index 159fd89e70..04a3595ffd 100644 --- a/src/pyj/viewer-main.pyj +++ b/src/pyj/viewer-main.pyj @@ -346,6 +346,8 @@ if window is window.top: to_python.export_shortcut_map(smap) ui_operations.print_book = def(): to_python.print_book() + ui_operations.clear_history = def(): + to_python.clear_history() document.body.appendChild(E.div(id='view')) window.onerror = onerror