mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Try to always set the default webengine profile's cache path to the calibre cache directory
This commit is contained in:
parent
0e044aa866
commit
a6adb4c1e9
@ -39,6 +39,7 @@ isworker = hasenv('CALIBRE_WORKER') or hasenv('CALIBRE_SIMPLE_WORKER')
|
|||||||
if isworker:
|
if isworker:
|
||||||
os.environ.pop(environ_item('CALIBRE_FORCE_ANSI'), None)
|
os.environ.pop(environ_item('CALIBRE_FORCE_ANSI'), None)
|
||||||
FAKE_PROTOCOL, FAKE_HOST = 'clbr', 'internal.invalid'
|
FAKE_PROTOCOL, FAKE_HOST = 'clbr', 'internal.invalid'
|
||||||
|
SPECIAL_TITLE_FOR_WEBENGINE_COMMS = '__webengine_messages_pending__'
|
||||||
VIEWER_APP_UID = 'com.calibre-ebook.viewer'
|
VIEWER_APP_UID = 'com.calibre-ebook.viewer'
|
||||||
EDITOR_APP_UID = 'com.calibre-ebook.edit-book'
|
EDITOR_APP_UID = 'com.calibre-ebook.edit-book'
|
||||||
MAIN_APP_UID = 'com.calibre-ebook.main-gui'
|
MAIN_APP_UID = 'com.calibre-ebook.main-gui'
|
||||||
|
@ -155,6 +155,8 @@ class PDFOutput(OutputFormatPlugin):
|
|||||||
scheme.setFlags(QWebEngineUrlScheme.Flag.SecureScheme)
|
scheme.setFlags(QWebEngineUrlScheme.Flag.SecureScheme)
|
||||||
QWebEngineUrlScheme.registerScheme(scheme)
|
QWebEngineUrlScheme.registerScheme(scheme)
|
||||||
must_use_qt()
|
must_use_qt()
|
||||||
|
from calibre.utils.webengine import setup_default_profile
|
||||||
|
setup_default_profile()
|
||||||
self.input_fmt = input_fmt
|
self.input_fmt = input_fmt
|
||||||
|
|
||||||
if opts.pdf_use_document_margins:
|
if opts.pdf_use_document_margins:
|
||||||
|
@ -99,6 +99,8 @@ def main(path_to_html, tdir, image_format='jpeg'):
|
|||||||
if image_format not in ('jpeg', 'png'):
|
if image_format not in ('jpeg', 'png'):
|
||||||
raise ValueError('Image format must be either jpeg or png')
|
raise ValueError('Image format must be either jpeg or png')
|
||||||
must_use_qt()
|
must_use_qt()
|
||||||
|
from calibre.utils.webengine import setup_default_profile
|
||||||
|
setup_default_profile()
|
||||||
path_to_html = os.path.abspath(path_to_html)
|
path_to_html = os.path.abspath(path_to_html)
|
||||||
os.chdir(tdir)
|
os.chdir(tdir)
|
||||||
renderer = Render()
|
renderer = Render()
|
||||||
|
@ -1188,6 +1188,8 @@ def main(shm_name=None):
|
|||||||
|
|
||||||
override = 'calibre-gui' if islinux else None
|
override = 'calibre-gui' if islinux else None
|
||||||
app = Application([], override_program_name=override)
|
app = Application([], override_program_name=override)
|
||||||
|
from calibre.utils.webengine import setup_default_profile
|
||||||
|
setup_default_profile()
|
||||||
d = TOCEditor(path, title=title, write_result_to=path + '.result')
|
d = TOCEditor(path, title=title, write_result_to=path + '.result')
|
||||||
d.start()
|
d.start()
|
||||||
ok = 0
|
ok = 0
|
||||||
|
@ -71,6 +71,8 @@ def _run(args, notify=None):
|
|||||||
decouple('edit-book-'), set_gui_prefs(tprefs)
|
decouple('edit-book-'), set_gui_prefs(tprefs)
|
||||||
override = 'calibre-ebook-edit' if islinux else None
|
override = 'calibre-ebook-edit' if islinux else None
|
||||||
app = Application(args, override_program_name=override, color_prefs=tprefs, windows_app_uid=EDITOR_APP_UID)
|
app = Application(args, override_program_name=override, color_prefs=tprefs, windows_app_uid=EDITOR_APP_UID)
|
||||||
|
from calibre.utils.webengine import setup_default_profile
|
||||||
|
setup_default_profile()
|
||||||
app.file_event_hook = EventAccumulator()
|
app.file_event_hook = EventAccumulator()
|
||||||
app.load_builtin_fonts()
|
app.load_builtin_fonts()
|
||||||
app.setWindowIcon(QIcon.ic('tweak.png'))
|
app.setWindowIcon(QIcon.ic('tweak.png'))
|
||||||
|
@ -5,15 +5,15 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from contextlib import closing
|
||||||
from qt.core import QIcon, QObject, Qt, QTimer, pyqtSignal
|
from qt.core import QIcon, QObject, Qt, QTimer, pyqtSignal
|
||||||
from qt.webengine import QWebEngineUrlScheme
|
from qt.webengine import QWebEngineUrlScheme
|
||||||
from contextlib import closing
|
|
||||||
|
|
||||||
from calibre.constants import FAKE_PROTOCOL, VIEWER_APP_UID, islinux
|
from calibre.constants import FAKE_PROTOCOL, VIEWER_APP_UID, islinux
|
||||||
from calibre.gui2 import Application, error_dialog, setup_gui_option_parser
|
from calibre.gui2 import Application, error_dialog, setup_gui_option_parser
|
||||||
|
from calibre.gui2.listener import send_message_in_process
|
||||||
from calibre.gui2.viewer.config import get_session_pref, vprefs
|
from calibre.gui2.viewer.config import get_session_pref, vprefs
|
||||||
from calibre.gui2.viewer.ui import EbookViewer, is_float
|
from calibre.gui2.viewer.ui import EbookViewer, is_float
|
||||||
from calibre.gui2.listener import send_message_in_process
|
|
||||||
from calibre.ptempfile import reset_base_dir
|
from calibre.ptempfile import reset_base_dir
|
||||||
from calibre.utils.config import JSONConfig
|
from calibre.utils.config import JSONConfig
|
||||||
from calibre.utils.ipc import viewer_socket_address
|
from calibre.utils.ipc import viewer_socket_address
|
||||||
@ -194,6 +194,8 @@ def main(args=sys.argv):
|
|||||||
pass
|
pass
|
||||||
args = processed_args
|
args = processed_args
|
||||||
app = Application(args, override_program_name=override, windows_app_uid=VIEWER_APP_UID)
|
app = Application(args, override_program_name=override, windows_app_uid=VIEWER_APP_UID)
|
||||||
|
from calibre.utils.webengine import setup_default_profile
|
||||||
|
setup_default_profile()
|
||||||
|
|
||||||
parser = option_parser()
|
parser = option_parser()
|
||||||
opts, args = parser.parse_args(args)
|
opts, args = parser.parse_args(args)
|
||||||
@ -204,8 +206,8 @@ def main(args=sys.argv):
|
|||||||
raise SystemExit(f'Not a valid --open-at value: {opts.open_at}')
|
raise SystemExit(f'Not a valid --open-at value: {opts.open_at}')
|
||||||
|
|
||||||
if get_session_pref('singleinstance', False):
|
if get_session_pref('singleinstance', False):
|
||||||
from calibre.utils.lock import SingleInstance
|
|
||||||
from calibre.gui2.listener import Listener
|
from calibre.gui2.listener import Listener
|
||||||
|
from calibre.utils.lock import SingleInstance
|
||||||
with SingleInstance(singleinstance_name) as si:
|
with SingleInstance(singleinstance_name) as si:
|
||||||
if si:
|
if si:
|
||||||
try:
|
try:
|
||||||
|
@ -11,15 +11,15 @@ import sys
|
|||||||
|
|
||||||
from calibre import force_unicode
|
from calibre import force_unicode
|
||||||
from calibre.constants import (
|
from calibre.constants import (
|
||||||
FAKE_HOST, FAKE_PROTOCOL, __appname__, __version__, builtin_colors_dark,
|
FAKE_HOST, FAKE_PROTOCOL, SPECIAL_TITLE_FOR_WEBENGINE_COMMS, __appname__,
|
||||||
builtin_colors_light, builtin_decorations, dark_link_color
|
__version__, builtin_colors_dark, builtin_colors_light, builtin_decorations,
|
||||||
|
dark_link_color
|
||||||
)
|
)
|
||||||
from calibre.ptempfile import TemporaryDirectory
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
from calibre.utils.filenames import atomic_rename
|
from calibre.utils.filenames import atomic_rename
|
||||||
from polyglot.builtins import as_bytes, as_unicode, exec_path
|
from polyglot.builtins import as_bytes, as_unicode, exec_path
|
||||||
|
|
||||||
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
COMPILER_PATH = 'rapydscript/compiler.js.xz'
|
||||||
special_title = '__webengine_messages_pending__'
|
|
||||||
|
|
||||||
|
|
||||||
def abspath(x):
|
def abspath(x):
|
||||||
@ -59,8 +59,9 @@ def compiler():
|
|||||||
|
|
||||||
from calibre import walk
|
from calibre import walk
|
||||||
from calibre.gui2 import must_use_qt
|
from calibre.gui2 import must_use_qt
|
||||||
from calibre.utils.webengine import secure_webengine
|
from calibre.utils.webengine import secure_webengine, setup_default_profile
|
||||||
must_use_qt()
|
must_use_qt()
|
||||||
|
setup_default_profile()
|
||||||
|
|
||||||
with lzma.open(P(COMPILER_PATH, allow_user_override=False)) as lzf:
|
with lzma.open(P(COMPILER_PATH, allow_user_override=False)) as lzf:
|
||||||
compiler_script = lzf.read().decode('utf-8')
|
compiler_script = lzf.read().decode('utf-8')
|
||||||
@ -124,7 +125,7 @@ document.title = 'compiler initialized';
|
|||||||
class Compiler(QWebEnginePage):
|
class Compiler(QWebEnginePage):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
QWebEnginePage.__init__(self)
|
super().__init__()
|
||||||
self.errors = []
|
self.errors = []
|
||||||
secure_webengine(self)
|
secure_webengine(self)
|
||||||
script = compiler_script
|
script = compiler_script
|
||||||
@ -330,17 +331,19 @@ def atomic_write(base, name, content):
|
|||||||
|
|
||||||
|
|
||||||
def run_rapydscript_tests():
|
def run_rapydscript_tests():
|
||||||
from urllib.parse import parse_qs
|
|
||||||
from qt.core import QApplication, QByteArray, QEventLoop, QUrl
|
from qt.core import QApplication, QByteArray, QEventLoop, QUrl
|
||||||
from qt.webengine import (
|
from qt.webengine import (
|
||||||
QWebEnginePage, QWebEngineProfile, QWebEngineScript, QWebEngineUrlRequestJob,
|
QWebEnginePage, QWebEngineProfile, QWebEngineScript, QWebEngineUrlRequestJob,
|
||||||
QWebEngineUrlScheme, QWebEngineUrlSchemeHandler
|
QWebEngineUrlScheme, QWebEngineUrlSchemeHandler
|
||||||
)
|
)
|
||||||
|
from urllib.parse import parse_qs
|
||||||
|
|
||||||
from calibre.constants import FAKE_HOST, FAKE_PROTOCOL
|
from calibre.constants import FAKE_HOST, FAKE_PROTOCOL
|
||||||
from calibre.gui2 import must_use_qt
|
from calibre.gui2 import must_use_qt
|
||||||
from calibre.gui2.viewer.web_view import send_reply
|
from calibre.gui2.viewer.web_view import send_reply
|
||||||
from calibre.utils.webengine import secure_webengine, insert_scripts, create_script
|
from calibre.utils.webengine import (
|
||||||
|
create_script, insert_scripts, secure_webengine
|
||||||
|
)
|
||||||
must_use_qt()
|
must_use_qt()
|
||||||
scheme = QWebEngineUrlScheme(FAKE_PROTOCOL.encode('ascii'))
|
scheme = QWebEngineUrlScheme(FAKE_PROTOCOL.encode('ascii'))
|
||||||
scheme.setSyntax(QWebEngineUrlScheme.Syntax.Host)
|
scheme.setSyntax(QWebEngineUrlScheme.Syntax.Host)
|
||||||
@ -418,7 +421,7 @@ def run_rapydscript_tests():
|
|||||||
|
|
||||||
def set_data(src, **kw):
|
def set_data(src, **kw):
|
||||||
for k, v in {
|
for k, v in {
|
||||||
'__SPECIAL_TITLE__': special_title,
|
'__SPECIAL_TITLE__': SPECIAL_TITLE_FOR_WEBENGINE_COMMS,
|
||||||
'__FAKE_PROTOCOL__': FAKE_PROTOCOL,
|
'__FAKE_PROTOCOL__': FAKE_PROTOCOL,
|
||||||
'__FAKE_HOST__': FAKE_HOST,
|
'__FAKE_HOST__': FAKE_HOST,
|
||||||
'__CALIBRE_VERSION__': __version__,
|
'__CALIBRE_VERSION__': __version__,
|
||||||
|
@ -3,11 +3,18 @@
|
|||||||
# License: GPL v3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
import json
|
import json, os
|
||||||
from qt.core import QBuffer, QIODevice, QObject, pyqtSignal, sip
|
from qt.core import QBuffer, QIODevice, QObject, pyqtSignal, sip
|
||||||
from qt.webengine import QWebEngineScript, QWebEngineSettings
|
from qt.webengine import QWebEngineScript, QWebEngineSettings, QWebEngineProfile
|
||||||
|
|
||||||
from calibre.utils.rapydscript import special_title
|
from calibre.constants import cache_dir, SPECIAL_TITLE_FOR_WEBENGINE_COMMS
|
||||||
|
|
||||||
|
|
||||||
|
def setup_default_profile():
|
||||||
|
p = QWebEngineProfile.defaultProfile()
|
||||||
|
q = os.path.join(cache_dir(), 'qt-webeng')
|
||||||
|
if p.cachePath() != q:
|
||||||
|
p.setCachePath(q)
|
||||||
|
|
||||||
|
|
||||||
def send_reply(rq, mime_type, data):
|
def send_reply(rq, mime_type, data):
|
||||||
@ -112,7 +119,7 @@ class Bridge(QObject):
|
|||||||
return self._signals_registered
|
return self._signals_registered
|
||||||
|
|
||||||
def _title_changed(self, title):
|
def _title_changed(self, title):
|
||||||
if title.startswith(special_title):
|
if title.startswith(SPECIAL_TITLE_FOR_WEBENGINE_COMMS):
|
||||||
self._poll_for_messages()
|
self._poll_for_messages()
|
||||||
|
|
||||||
def _register_signals(self):
|
def _register_signals(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user