mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Remove edge special case and allow connecting to IDB in workers
This commit is contained in:
parent
486413f267
commit
e158c41ce3
@ -67,6 +67,14 @@ def new_book(key, metadata):
|
|||||||
DB_NAME = 'calibre'
|
DB_NAME = 'calibre'
|
||||||
DB_VERSION = 1
|
DB_VERSION = 1
|
||||||
|
|
||||||
|
|
||||||
|
def indexed_db_api():
|
||||||
|
if window?:
|
||||||
|
return window.indexedDB
|
||||||
|
if self?:
|
||||||
|
return self.indexedDB
|
||||||
|
|
||||||
|
|
||||||
class DB:
|
class DB:
|
||||||
|
|
||||||
def __init__(self, callback, show_read_book_error):
|
def __init__(self, callback, show_read_book_error):
|
||||||
@ -84,16 +92,17 @@ class DB:
|
|||||||
error_dialog(title, msg, det_msg)
|
error_dialog(title, msg, det_msg)
|
||||||
|
|
||||||
def initialize_stage1(self):
|
def initialize_stage1(self):
|
||||||
if not window.indexedDB:
|
idb = indexed_db_api()
|
||||||
|
if not idb:
|
||||||
self.initialize_error_msg = _('Your browser does not support IndexedDB. Cannot read books. Consider using a modern browser, such as Chrome or Firefox.')
|
self.initialize_error_msg = _('Your browser does not support IndexedDB. Cannot read books. Consider using a modern browser, such as Chrome or Firefox.')
|
||||||
self.initialized = True
|
self.initialized = True
|
||||||
# Callers assume __init__ has finished before the callback is
|
# Callers assume __init__ has finished before the callback is
|
||||||
# called, since we are called in __init__, only callback after
|
# called, since we are called in __init__, only callback after
|
||||||
# event loop ticks over
|
# event loop ticks over
|
||||||
window.setTimeout(self.callback, 0)
|
setTimeout(self.callback, 0)
|
||||||
return
|
return
|
||||||
|
|
||||||
request = window.indexedDB.open(DB_NAME, DB_VERSION)
|
request = idb.open(DB_NAME, DB_VERSION)
|
||||||
|
|
||||||
request.onupgradeneeded = def(event):
|
request.onupgradeneeded = def(event):
|
||||||
upgrade_schema(event.target.result, event.oldVersion, event.newVersion, event.target.transaction)
|
upgrade_schema(event.target.result, event.oldVersion, event.newVersion, event.target.transaction)
|
||||||
@ -160,19 +169,7 @@ class DB:
|
|||||||
store = store or stores[0]
|
store = store or stores[0]
|
||||||
if op is 'get':
|
if op is 'get':
|
||||||
transaction = self.idb.transaction(stores)
|
transaction = self.idb.transaction(stores)
|
||||||
# Microsoft Edge currently does not support complex keys so the
|
req = transaction.objectStore(store).get(data)
|
||||||
# next line will throw a DataError in Edge when data is an
|
|
||||||
# object key like an array.
|
|
||||||
# https://gist.github.com/nolanlawson/a841ee23436410f37168
|
|
||||||
try:
|
|
||||||
req = transaction.objectStore(store).get(data)
|
|
||||||
except:
|
|
||||||
if /Edge\/\d+/.test(window.navigator.userAgent):
|
|
||||||
self.show_error(_('Cannot read book'), _(
|
|
||||||
'Reading of books is not supported on Microsoft Edge. Use a better'
|
|
||||||
' browser such as Google Chrome or Mozilla Firefox'))
|
|
||||||
return
|
|
||||||
raise
|
|
||||||
req.onsuccess = def(event):
|
req.onsuccess = def(event):
|
||||||
proceed(req.result)
|
proceed(req.result)
|
||||||
elif op is 'put':
|
elif op is 'put':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user