From 9d8c263e9a37a14474db659039c0890b334bc813 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 5 Dec 2023 13:46:02 +0100 Subject: Extend pakjoy to Qt 6.5.0/.1/.2 with dark mode See #7837 --- doc/changelog.asciidoc | 3 ++- qutebrowser/misc/pakjoy.py | 24 +++++++++++++++++++----- tests/unit/misc/test_pakjoy.py | 30 +++++++++++++++++++++--------- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/doc/changelog.asciidoc b/doc/changelog.asciidoc index e3fe5784f..bb424242f 100644 --- a/doc/changelog.asciidoc +++ b/doc/changelog.asciidoc @@ -51,7 +51,8 @@ Fixed - Compatibility with PDF.js v4 - Added an elaborate workaround for a bug in QtWebEngine 6.6.0 causing crashes - on Google Mail/Meet/Chat. + on Google Mail/Meet/Chat, and a bug in QtWebEngine 6.5.0/.1/.2 causing crashes + there with dark mode. - Graphical glitches in Google sheets and PDF.js, again. Removed the version restriction for the default application of `qt.workarounds.disable_accelerated_2d_canvas` as the issue was still diff --git a/qutebrowser/misc/pakjoy.py b/qutebrowser/misc/pakjoy.py index a511034a2..2bcde7ce9 100644 --- a/qutebrowser/misc/pakjoy.py +++ b/qutebrowser/misc/pakjoy.py @@ -32,11 +32,15 @@ import dataclasses import contextlib from typing import ClassVar, IO, Optional, Dict, Tuple, Iterator +from qutebrowser.config import config from qutebrowser.misc import binparsing, objects from qutebrowser.utils import qtutils, standarddir, version, utils, log HANGOUTS_MARKER = b"// Extension ID: nkeimhogjdpnpccoofpliimaahmaaome" -HANGOUTS_ID = 36197 # as found by toofar +HANGOUTS_IDS = [ + 36197, # QtWebEngine 6.5, as found by toofar + 34897, # QtWebEngine 6.4 +] PAK_VERSION = 5 RESOURCES_ENV_VAR = "QTWEBENGINE_RESOURCES_PATH" DISABLE_ENV_VAR = "QUTE_DISABLE_PAKJOY" @@ -136,9 +140,10 @@ class PakParser: def _find_manifest(self, entries: Dict[int, PakEntry]) -> Tuple[PakEntry, bytes]: to_check = list(entries.values()) - if HANGOUTS_ID in entries: - # Most likely candidate, based on previous known ID - to_check.insert(0, entries[HANGOUTS_ID]) + for hangouts_id in HANGOUTS_IDS: + if hangouts_id in entries: + # Most likely candidate, based on previous known ID + to_check.insert(0, entries[hangouts_id]) for entry in to_check: manifest = self._maybe_get_hangouts_manifest(entry) @@ -192,7 +197,16 @@ def copy_webengine_resources() -> Optional[pathlib.Path]: shutil.rmtree(work_dir) versions = version.qtwebengine_versions(avoid_init=True) - if versions.webengine != utils.VersionNumber(6, 6): + if not ( + # https://bugreports.qt.io/browse/QTBUG-118157 + versions.webengine == utils.VersionNumber(6, 6) + # https://bugreports.qt.io/browse/QTBUG-113369 + or ( + versions.webengine >= utils.VersionNumber(6, 5) + and versions.webengine < utils.VersionNumber(6, 5, 3) + and config.val.colors.webpage.darkmode.enabled + ) + ): # No patching needed return None diff --git a/tests/unit/misc/test_pakjoy.py b/tests/unit/misc/test_pakjoy.py index 65d02ec7e..2dcfbd5b1 100644 --- a/tests/unit/misc/test_pakjoy.py +++ b/tests/unit/misc/test_pakjoy.py @@ -43,26 +43,38 @@ def prepare_env(qapp, monkeypatch): monkeypatch.delenv(pakjoy.DISABLE_ENV_VAR, raising=False) -def patch_version(monkeypatch, *args): +def patch_version(monkeypatch: pytest.MonkeyPatch, qtwe_version: utils.VersionNumber): monkeypatch.setattr( pakjoy.version, "qtwebengine_versions", lambda **kwargs: version.WebEngineVersions( - webengine=utils.VersionNumber(*args), + webengine=qtwe_version, chromium=None, source="unittest", ), ) -@pytest.fixture -def unaffected_version(monkeypatch): - patch_version(monkeypatch, 6, 6, 1) +@pytest.fixture(params=[ + utils.VersionNumber(6, 4), + utils.VersionNumber(6, 5, 3), + utils.VersionNumber(6, 6, 1), + utils.VersionNumber(6, 7), +]) +def unaffected_version(monkeypatch: pytest.MonkeyPatch, request: pytest.FixtureRequest, config_stub): + config_stub.val.colors.webpage.darkmode.enabled = True + patch_version(monkeypatch, request.param) -@pytest.fixture -def affected_version(monkeypatch): - patch_version(monkeypatch, 6, 6) +@pytest.fixture(params=[ + utils.VersionNumber(6, 5), + utils.VersionNumber(6, 5, 1), + utils.VersionNumber(6, 5, 2), + utils.VersionNumber(6, 6), +]) +def affected_version(monkeypatch: pytest.MonkeyPatch, request: pytest.FixtureRequest, config_stub): + config_stub.val.colors.webpage.darkmode.enabled = True + patch_version(monkeypatch, request.param) @pytest.mark.parametrize("workdir_exists", [True, False]) @@ -318,7 +330,7 @@ class TestWithConstructedResourcesFile: @pytest.mark.parametrize( "offset", - [0, 42, pakjoy.HANGOUTS_ID], # test both slow search and fast path + [0, 42, *pakjoy.HANGOUTS_IDS], # test both slow search and fast path ) def test_happy_path(self, offset): entries = [b""] * offset + [json_manifest_factory()] -- cgit v1.2.3-54-g00ecf