Skip to content

Commit

Permalink
Check for QtWebEngine versions for session workaround
Browse files Browse the repository at this point in the history
This means sessions need to be initialized after websettings, because
initializing websettings also initializes QtWebEngine and thus
qutescheme. This needs to happen before sessions.init() calls
version.webengine_versions(). I don't think this should be a problem, as
they are independent to each other.

Fixes #5738
See #5359
Also switches sessions.init() to pathlib, see #176.
  • Loading branch information
The-Compiler committed Feb 16, 2021
1 parent a275308 commit bd152d3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
5 changes: 3 additions & 2 deletions qutebrowser/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,14 @@ def _init_modules(*, args):

log.init.debug("Initializing command history...")
cmdhistory.init()
log.init.debug("Initializing sessions...")
sessions.init(objects.qapp)

log.init.debug("Initializing websettings...")
websettings.init(args)
quitter.instance.shutting_down.connect(websettings.shutdown)

log.init.debug("Initializing sessions...")
sessions.init(objects.qapp)

if not args.no_err_windows:
crashsignal.crash_handler.display_faulthandler()

Expand Down
3 changes: 2 additions & 1 deletion qutebrowser/browser/webengine/webenginetab.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ def _load_items_workaround(self, items):
self._tab.load_url(url)

def load_items(self, items):
if qtutils.version_check('5.15', compiled=False):
webengine_version = version.qtwebengine_versions().webengine
if webengine_version >= utils.VersionNumber(5, 15):
self._load_items_workaround(items)
return

Expand Down
32 changes: 17 additions & 15 deletions qutebrowser/misc/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
import os.path
import itertools
import urllib
import glob
import shutil
import pathlib
from typing import Any, Iterable, MutableMapping, MutableSequence, Optional, Union, cast

from PyQt5.QtCore import Qt, QUrl, QObject, QPoint, QTimer, QDateTime
import yaml

from qutebrowser.utils import (standarddir, objreg, qtutils, log, message,
utils)
utils, usertypes, version)
from qutebrowser.api import cmdutils
from qutebrowser.config import config, configfiles
from qutebrowser.completion.models import miscmodels
Expand Down Expand Up @@ -60,24 +60,26 @@ def init(parent=None):
Args:
parent: The parent to use for the SessionManager.
"""
base_path = os.path.join(standarddir.data(), 'sessions')
base_path = pathlib.Path(standarddir.data()) / 'sessions'

# WORKAROUND for https://github.com/qutebrowser/qutebrowser/issues/5359
backup_path = os.path.join(base_path, 'before-qt-515')
if (os.path.exists(base_path) and
not os.path.exists(backup_path) and
qtutils.version_check('5.15', compiled=False)):
os.mkdir(backup_path)
for filename in glob.glob(os.path.join(base_path, '*.yml')):
shutil.copy(filename, backup_path)
backup_path = base_path / 'before-qt-515'

try:
os.mkdir(base_path)
except FileExistsError:
pass
if objects.backend == usertypes.Backend.QtWebEngine:
webengine_version = version.qtwebengine_versions().webengine
do_backup = webengine_version >= utils.VersionNumber(5, 15)
else:
do_backup = False

if base_path.exists() and not backup_path.exists() and do_backup:
backup_path.mkdir()
for path in base_path.glob('*.yml'):
shutil.copy(path, backup_path)

base_path.mkdir(exist_ok=True)

global session_manager
session_manager = SessionManager(base_path, parent)
session_manager = SessionManager(str(base_path), parent)


def shutdown(session: Optional[ArgType], last_window: bool) -> None:
Expand Down

0 comments on commit bd152d3

Please sign in to comment.