Ensure multiple loads are not running

This commit is contained in:
Kovid Goyal 2016-04-07 15:33:51 +05:30
parent 04929a943d
commit 7b8a045ee4

View File

@ -43,7 +43,7 @@ class View:
self.overlay = Overlay(self) self.overlay = Overlay(self)
self.src_doc = None self.src_doc = None
self.iframe_ready = False self.iframe_ready = False
self.pending_spine_load = None self.pending_load = None
self.encrypted_communications = False self.encrypted_communications = False
self.create_src_doc() self.create_src_doc()
window.addEventListener('message', self.handle_message, False) window.addEventListener('message', self.handle_message, False)
@ -97,9 +97,9 @@ class View:
messenger.reset() messenger.reset()
self.send_message('initialize', 'secret'=messenger.secret, 'translations'=self.ui.interface_data.translations) self.send_message('initialize', 'secret'=messenger.secret, 'translations'=self.ui.interface_data.translations)
self.iframe_ready = True self.iframe_ready = True
if self.pending_spine_load: if self.pending_load:
data = self.pending_spine_load data = self.pending_load
self.pending_spine_load = None self.pending_load = None
self.show_spine_item_stage2(data) self.show_spine_item_stage2(data)
def on_iframe_error(self, data): def on_iframe_error(self, data):
@ -119,7 +119,9 @@ class View:
self.show_name(book.manifest.spine[1]) self.show_name(book.manifest.spine[1])
def show_name(self, name, initial_scroll_fraction=None, cfi=None): def show_name(self, name, initial_scroll_fraction=None, cfi=None):
self.currently_showing = {'name':name, 'cfi':cfi, 'initial_scroll_fraction':initial_scroll_fraction} if self.currently_showing.loading:
return
self.currently_showing = {'name':name, 'cfi':cfi, 'initial_scroll_fraction':initial_scroll_fraction, 'loading':True}
load_resources(self.ui.db, self.book, name, self.loaded_resources, self.show_spine_item) load_resources(self.ui.db, self.book, name, self.loaded_resources, self.show_spine_item)
def goto_doc_boundary(self, data): def goto_doc_boundary(self, data):
@ -144,10 +146,11 @@ class View:
self.loaded_resources = resource_data self.loaded_resources = resource_data
# Re-init the iframe to ensure any changes made to the environment by the last spine item are lost # Re-init the iframe to ensure any changes made to the environment by the last spine item are lost
self.init_iframe() self.init_iframe()
# Now wait for frame to message that it is ready # Now wait for iframe to message that it is ready
self.pending_spine_load = resource_data self.pending_load = resource_data
def show_spine_item_stage2(self, resource_data): def show_spine_item_stage2(self, resource_data):
self.currently_showing.loading = False
self.send_message('display', resource_data=resource_data, book=self.book, name=self.currently_showing.name, self.send_message('display', resource_data=resource_data, book=self.book, name=self.currently_showing.name,
initial_scroll_fraction=self.currently_showing.initial_scroll_fraction) initial_scroll_fraction=self.currently_showing.initial_scroll_fraction)
self.encrypted_communications = True self.encrypted_communications = True