mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-03-11 20:31:04 -04:00
45 lines
1.8 KiB
Plaintext
45 lines
1.8 KiB
Plaintext
# vim:fileencoding=utf-8
|
|
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
|
from __python__ import hash_literals
|
|
|
|
from gettext import gettext as _
|
|
|
|
import initialize # noqa: unused-import
|
|
from ajax import ajax
|
|
from autoreload import create_auto_reload_watcher
|
|
from book_list.globals import main_js
|
|
from book_list.main import main
|
|
from read_book.iframe import init
|
|
|
|
is_running_in_iframe = False # Changed before script is loaded in the iframe
|
|
|
|
if is_running_in_iframe:
|
|
init()
|
|
else:
|
|
window.applicationCache.addEventListener('updateready', def():
|
|
if window.applicationCache.status is window.applicationCache.UPDATEREADY:
|
|
try:
|
|
window.applicationCache.swapCache()
|
|
if 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 occassionally fails even though status is UPDATEREADY
|
|
print('WARNING: falied to swap applicationCache')
|
|
console.log(e)
|
|
, False)
|
|
script = document.currentScript or document.scripts[0]
|
|
main_js(script.textContent)
|
|
script.parentNode.removeChild(script) # save some memory
|
|
script = undefined
|
|
# We wait for all page elements to load, since this is a single page app
|
|
# with a largely empty starting document, we can use this to preload any resources
|
|
# we know are going to be needed immediately.
|
|
window.addEventListener('load', main)
|
|
|
|
ajax('auto-reload-port', def(end_type, xhr, event):
|
|
if end_type is 'load':
|
|
port = parseInt(xhr.responseText)
|
|
if not isNaN(port) and port > 0:
|
|
create_auto_reload_watcher(port)
|
|
).send() # We must bypass cache as otherwise we could get stale port info
|