mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Content server: Remove appcache since it has now been completely removed from both Chrome and Firefox
This commit is contained in:
parent
ecf9f837c8
commit
0b8e39ffef
@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html manifest="calibre.appcache">
|
||||
<html>
|
||||
<head>
|
||||
<title>calibre</title>
|
||||
<meta charset="utf-8">
|
||||
@ -16,7 +16,7 @@
|
||||
<progress>
|
||||
</progress>
|
||||
<div>Loading, please wait…</div>
|
||||
<div>You can also use a simple, non-javascript version of this site: <a href="mobile">here</a></div>
|
||||
<div>You can also use a simple, non-JavaScript version of this site: <a href="mobile">here</a></div>
|
||||
<style type="text/css">
|
||||
#page_load_progress {
|
||||
position:relative;
|
||||
|
@ -39,11 +39,6 @@ def index(ctx, rd):
|
||||
return lopen(P('content-server/index-generated.html'), 'rb')
|
||||
|
||||
|
||||
@endpoint('/calibre.appcache', auth_required=False, cache_control='no-cache')
|
||||
def appcache(ctx, rd):
|
||||
return lopen(P('content-server/calibre.appcache'), 'rb')
|
||||
|
||||
|
||||
@endpoint('/robots.txt', auth_required=False)
|
||||
def robots(ctx, rd):
|
||||
return b'User-agent: *\nDisallow: /'
|
||||
|
@ -17,9 +17,7 @@ from calibre.constants import (
|
||||
)
|
||||
from calibre.ptempfile import TemporaryDirectory
|
||||
from calibre.utils.filenames import atomic_rename
|
||||
from polyglot.builtins import (
|
||||
as_bytes, as_unicode, exec_path, itervalues, unicode_type, zip
|
||||
)
|
||||
from polyglot.builtins import as_bytes, as_unicode, exec_path, unicode_type, zip
|
||||
|
||||
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
||||
special_title = '__webengine_messages_pending__'
|
||||
@ -318,20 +316,6 @@ def compile_fast(
|
||||
return js.decode('utf-8')
|
||||
|
||||
|
||||
def create_manifest(html):
|
||||
import hashlib
|
||||
from calibre.library.field_metadata import category_icon_map
|
||||
h = hashlib.sha256(html)
|
||||
for ci in itervalues(category_icon_map):
|
||||
h.update(I(ci, data=True))
|
||||
icons = {'icon/' + x for x in itervalues(category_icon_map)}
|
||||
icons.add('favicon.png')
|
||||
h.update(I('lt.png', data=True))
|
||||
manifest = '\n'.join(sorted(icons))
|
||||
return 'CACHE MANIFEST\n# {}\n{}\n\nNETWORK:\n*'.format(
|
||||
h.hexdigest(), manifest).encode('utf-8')
|
||||
|
||||
|
||||
def base_dir():
|
||||
d = os.path.dirname
|
||||
return d(d(d(d(os.path.abspath(__file__)))))
|
||||
@ -456,9 +440,7 @@ def compile_srv():
|
||||
with lopen(os.path.join(base, 'index.html'), 'rb') as f:
|
||||
html = f.read().replace(b'RESET_STYLES', reset, 1).replace(b'ICONS', icons, 1).replace(b'MAIN_JS', js, 1)
|
||||
|
||||
manifest = create_manifest(html)
|
||||
atomic_write(base, 'index-generated.html', html)
|
||||
atomic_write(base, 'calibre.appcache', manifest)
|
||||
|
||||
# }}}
|
||||
|
||||
|
@ -52,22 +52,8 @@ class Watcher:
|
||||
self.reload_app()
|
||||
|
||||
def reload_app(self):
|
||||
appcache = window.top.applicationCache
|
||||
if appcache:
|
||||
for which in 'cached error noupdate obsolete updateready'.split(' '):
|
||||
appcache.addEventListener(which, self.cache_update_done, False)
|
||||
try:
|
||||
appcache.update()
|
||||
except: # In chrome with devtools open, appcache is sometimes disabled/fails
|
||||
window.location.reload(True)
|
||||
|
||||
def cache_update_done(self):
|
||||
appcache = window.top.applicationCache
|
||||
if appcache and appcache.status is appcache.UPDATEREADY:
|
||||
appcache.swapCache()
|
||||
window.location.reload(True)
|
||||
|
||||
|
||||
def create_auto_reload_watcher(autoreload_port):
|
||||
if not create_auto_reload_watcher.watcher:
|
||||
create_auto_reload_watcher.watcher = Watcher(autoreload_port)
|
||||
|
@ -6,8 +6,3 @@ from __python__ import hash_literals, bound_methods
|
||||
book_list_container_id = 'book-list-container'
|
||||
read_book_container_id = 'read-book-container'
|
||||
INIT_ENDPOINT = 'interface-data/init'
|
||||
|
||||
def has_offline_support(val):
|
||||
if val is not undefined:
|
||||
has_offline_support.ans = val
|
||||
return has_offline_support.ans
|
||||
|
@ -3,18 +3,14 @@
|
||||
# globals: ρσ_get_module
|
||||
from __python__ import hash_literals
|
||||
|
||||
from gettext import gettext as _
|
||||
|
||||
import initialize # noqa: unused-import
|
||||
from ajax import ajax, console_print, set_default_timeout
|
||||
from autoreload import create_auto_reload_watcher
|
||||
from book_list.globals import main_js
|
||||
from book_list.main import main
|
||||
from book_list.constants import has_offline_support
|
||||
|
||||
is_running_in_iframe = False # Changed before script is loaded in the iframe
|
||||
autoreload_enabled = False
|
||||
asked_appcache_update = False
|
||||
AUTO_UPDATE_THRESHOLD = 1000 # millisecs
|
||||
|
||||
if is_running_in_iframe:
|
||||
@ -30,31 +26,6 @@ if is_running_in_iframe:
|
||||
else:
|
||||
start_time = window.performance.now()
|
||||
|
||||
on_appcache_ready = def ():
|
||||
nonlocal asked_appcache_update
|
||||
if asked_appcache_update:
|
||||
return
|
||||
if window.applicationCache.status is window.applicationCache.UPDATEREADY:
|
||||
asked_appcache_update = True
|
||||
try:
|
||||
window.applicationCache.swapCache()
|
||||
time_since_start = window.performance.now() - start_time
|
||||
if time_since_start <= AUTO_UPDATE_THRESHOLD or autoreload_enabled or window.confirm(_(
|
||||
'The calibre web application has been updated. Do you want reload the site?')):
|
||||
window.location.reload()
|
||||
except Exception as e:
|
||||
# For some reason swapCache occasionally fails even though status is UPDATEREADY
|
||||
print('WARNING: failed to swap applicationCache')
|
||||
console.log(e)
|
||||
|
||||
if window.applicationCache:
|
||||
window.applicationCache.addEventListener('updateready', on_appcache_ready)
|
||||
if window.applicationCache.status is window.applicationCache.UPDATEREADY:
|
||||
on_appcache_ready()
|
||||
has_offline_support(True)
|
||||
else:
|
||||
has_offline_support(False)
|
||||
console.warn("Your browser does not have a working Application Cache, offline access will not work")
|
||||
script = document.currentScript or document.scripts[0]
|
||||
main_js(script.textContent)
|
||||
script.parentNode.removeChild(script) # save some memory
|
||||
|
Loading…
x
Reference in New Issue
Block a user