diff --git a/src/pyj/read_book/db.pyj b/src/pyj/read_book/db.pyj index 7025328fe9..a7a1ec7629 100644 --- a/src/pyj/read_book/db.pyj +++ b/src/pyj/read_book/db.pyj @@ -155,15 +155,16 @@ class DB: idb.close() self.show_error(_('Database upgraded!'), _( 'A newer version of calibre is available, please click the Reload button in your browser.')) + + def try_persist(lock): + if not lock: + return # another tab is already requesting persistence + return window.navigator.storage.persisted().then(def(already_persistent): + if not already_persistent: + return window.navigator.storage.persist() + ) if window.navigator.storage?.persist: if window.navigator.locks: - def try_persist(lock): - if not lock: - return # another tab is already requesting persistence - return window.navigator.storage.persisted().then(def(already_persistent): - if not already_persistent: - return window.navigator.storage.persist() - ) window.navigator.locks.request('calibre-storage-persist', {'ifAvailable': True}, try_persist) else: window.navigator.storage.persisted().then(def(already_persistent): @@ -211,7 +212,7 @@ class DB: def get_all_pending_annot_uploads(self, proceed): transaction = self.idb.transaction(['objects']) store = transaction.objectStore('objects') - key_range = IDBKeyRange.bound('pending-annot-upload:', 'pending-annot-upload:\uffff') + key_range = IDBKeyRange.bound('pending-annot-upload:', 'pending-annot-upload:\uffff') # noqa entries = v'[]' req = store.openCursor(key_range) req.onsuccess = def(event): diff --git a/src/pyj/read_book/ui.pyj b/src/pyj/read_book/ui.pyj index 74a99b0ccb..828e7ff3ca 100644 --- a/src/pyj/read_book/ui.pyj +++ b/src/pyj/read_book/ui.pyj @@ -325,21 +325,22 @@ class ReadUI: self._make_annot_upload_done(library_id, book_id, fmt)) def _make_annot_upload_done(self, library_id, book_id, fmt): + def on_cleared(): + if (self.unsynced_amap is not None and self.base_url_data + and self.base_url_data.library_id is library_id + and str(self.base_url_data.book_id) is str(book_id) + and self.base_url_data.fmt is fmt): + self.unsynced_amap = None + if self.unsynced_indicator_timer: + window.clearTimeout(self.unsynced_indicator_timer) + self.unsynced_indicator_timer = None + if self.unsynced_indicator_active: + self.unsynced_indicator_active = False + self.view.show_unsynced_indicator(False) + self._upload_next_from_idb() + def done(end_type, xhr, ev): if end_type is 'load': - def on_cleared(): - if (self.unsynced_amap is not None and self.base_url_data - and self.base_url_data.library_id is library_id - and str(self.base_url_data.book_id) is str(book_id) - and self.base_url_data.fmt is fmt): - self.unsynced_amap = None - if self.unsynced_indicator_timer: - window.clearTimeout(self.unsynced_indicator_timer) - self.unsynced_indicator_timer = None - if self.unsynced_indicator_active: - self.unsynced_indicator_active = False - self.view.show_unsynced_indicator(False) - self._upload_next_from_idb() self.db.clear_pending_annot_upload(library_id, book_id, fmt, on_cleared) return done @@ -379,7 +380,7 @@ class ReadUI: self._make_annot_upload_done(library_id, book_id, fmt)) callback(True) return - # unsynced_amap is None — page may have been killed or this is another book; + # unsynced_amap is None — page may have been killed or this is another book # check IDB for surviving entries self.db.get_all_pending_annot_uploads(def(entries): if not entries.length: