Use new mathjax location in viewer2

This commit is contained in:
Kovid Goyal 2019-01-04 22:28:16 +05:30
parent 2ccbe705b2
commit 1ccc979081
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -24,7 +24,6 @@ from calibre.gui2.webengine import (
Bridge, RestartingWebEngineView, create_script, from_js, insert_scripts, Bridge, RestartingWebEngineView, create_script, from_js, insert_scripts,
secure_webengine, to_js secure_webengine, to_js
) )
from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.utils.config import JSONConfig from calibre.utils.config import JSONConfig
try: try:
@ -62,7 +61,8 @@ class UrlSchemeHandler(QWebEngineUrlSchemeHandler):
def __init__(self, parent=None): def __init__(self, parent=None):
QWebEngineUrlSchemeHandler.__init__(self, parent) QWebEngineUrlSchemeHandler.__init__(self, parent)
self.mathjax_tdir = self.mathjax_manifest = None self.mathjax_dir = P('mathjax', allow_user_override=False)
self.mathjax_manifest = None
def requestStarted(self, rq): def requestStarted(self, rq):
if bytes(rq.requestMethod()) != b'GET': if bytes(rq.requestMethod()) != b'GET':
@ -101,15 +101,14 @@ class UrlSchemeHandler(QWebEngineUrlSchemeHandler):
elif name.startswith('mathjax/'): elif name.startswith('mathjax/'):
from calibre.gui2.viewer2.mathjax import monkeypatch_mathjax from calibre.gui2.viewer2.mathjax import monkeypatch_mathjax
if name == 'mathjax/manifest.json': if name == 'mathjax/manifest.json':
if self.mathjax_tdir is None: if self.mathjax_manifest is None:
import json import json
from calibre.srv.books import get_mathjax_manifest from calibre.srv.books import get_mathjax_manifest
self.mathjax_tdir = PersistentTemporaryDirectory(prefix='v2mjx-') self.mathjax_manifest = json.dumps(get_mathjax_manifest()['files'])
self.mathjax_manifest = json.dumps(get_mathjax_manifest(self.mathjax_tdir)['files'])
self.send_reply(rq, 'application/json', self.mathjax_manifest) self.send_reply(rq, 'application/json', self.mathjax_manifest)
return return
path = os.path.abspath(os.path.join(self.mathjax_tdir, name)) path = os.path.abspath(os.path.join(self.mathjax_dir, '..', name))
if path.startswith(self.mathjax_tdir): if path.startswith(self.mathjax_dir):
mt = guess_type(name) mt = guess_type(name)
try: try:
with lopen(path, 'rb') as f: with lopen(path, 'rb') as f: