From db6d0dd2cb75575d82c6c8981dcacf065935e2ce Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 Sep 2018 15:15:06 +0530 Subject: [PATCH] Add a warning about missing Application Cache support to the server home page --- src/pyj/book_list/constants.pyj | 5 +++++ src/pyj/book_list/home.pyj | 10 +++++++++- src/pyj/srv.pyj | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/pyj/book_list/constants.pyj b/src/pyj/book_list/constants.pyj index ad40262112..da10384f78 100644 --- a/src/pyj/book_list/constants.pyj +++ b/src/pyj/book_list/constants.pyj @@ -6,3 +6,8 @@ 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 diff --git a/src/pyj/book_list/home.pyj b/src/pyj/book_list/home.pyj index f81a212b79..1f49471de8 100644 --- a/src/pyj/book_list/home.pyj +++ b/src/pyj/book_list/home.pyj @@ -6,13 +6,14 @@ from elementmaker import E from gettext import gettext as _ from ajax import ajax_send +from book_list.constants import has_offline_support from book_list.cover_grid import BORDER_RADIUS from book_list.globals import get_db from book_list.library_data import last_virtual_library_for, sync_library_books from book_list.router import open_book, update_window_title from book_list.top_bar import add_button, create_top_bar from book_list.ui import set_default_panel_handler, show_panel -from dom import add_extra_css, build_rule, clear, ensure_id, unique_id, set_css +from dom import add_extra_css, build_rule, clear, ensure_id, set_css, unique_id from modals import create_custom_dialog from session import get_device_uuid, get_interface_data from utils import conditional_timeout, safe_set_inner_html, username_key @@ -256,5 +257,12 @@ def init(container_id): cl.lastChild.style.margin = '1ex 1rem' cl.lastChild.dataset.lid = library_id + if not has_offline_support(): + container.appendChild(E.div( + style='margin-top: 1rem; padding: 1rem; border-top: solid 1px currentColor', + _('WARNING: This browser does not support Application Cache so offline access' + ' to calibre will not work. Some browsers only enable Application Cache over HTTPS' + ' connections, so you may have to setup HTTPS for your calibre server.'))) + set_default_panel_handler(init) diff --git a/src/pyj/srv.pyj b/src/pyj/srv.pyj index 31fcb5373d..04893d8e08 100644 --- a/src/pyj/srv.pyj +++ b/src/pyj/srv.pyj @@ -10,6 +10,7 @@ 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 @@ -50,7 +51,9 @@ else: 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)