diff --git a/src/calibre/utils/rapydscript.py b/src/calibre/utils/rapydscript.py index 06cc1061eb..61c9405d6c 100644 --- a/src/calibre/utils/rapydscript.py +++ b/src/calibre/utils/rapydscript.py @@ -215,7 +215,10 @@ def compile_srv(): base = P('content-server', allow_user_override=False) fname = os.path.join(rapydscript_dir, 'srv.pyj') with lopen(fname, 'rb') as f: - js = compile_fast(f.read(), fname).replace('__RENDER_VERSION__', rv, 1).replace('__MATHJAX_VERSION__', mathjax_version, 1).encode('utf-8') + js = compile_fast(f.read(), fname).replace( + '__RENDER_VERSION__', rv, 1).replace( + '__MATHJAX_VERSION__', mathjax_version, 1).replace( + '__CALIBRE_VERSION__', __version__, 1).encode('utf-8') 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) diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 71342bfda1..446ef5f0da 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -28,10 +28,38 @@ from read_book.touch import create_handlers as create_touch_handlers from utils import debounce FORCE_FLOW_MODE = False +CALIBRE_VERSION = '__CALIBRE_VERSION__' +ERS_SUPPORTED_FEATURES = {'dom-manipulation', 'layout-changes', 'touch-events', 'mouse-events', 'keyboard-events', 'spine-scripting'} + + +class EPUBReadingSystem: + + @property + def name(self): + return 'calibre' + + @property + def version(self): + return CALIBRE_VERSION + + @property + def layoutStyle(self): + return 'scrolling' if current_layout_mode() is 'flow' else 'paginated' + + def hasFeature(self, feature, version): + return feature in ERS_SUPPORTED_FEATURES + + def __repr__(self): + return f'{{name:{self.name}, version:{self.version}, layoutStyle:{self.layoutStyle}}}' + + def __str__(self): + return self.__repr__() + class IframeBoss: def __init__(self): + window.navigator.epubReadingSystem = EPUBReadingSystem() self.ready_sent = False self.last_cfi = None self.replace_history_on_next_cfi_update = True