Skip to content

Commit

Permalink
Add stop-gap measure for sessions with Qt 5.15
Browse files Browse the repository at this point in the history
See #5359
  • Loading branch information
The-Compiler committed Apr 27, 2020
1 parent 485708f commit 63ade39
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion doc/changelog.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Added
Changed
~~~~~~~

- First adaptions to Qt 5.15, including a stop-gap measure for session loading
not working properly with it.
- Searching now wraps around the page by default with QtWebKit (where it didn't
before). Set `search.wrap` to `false` to restore the old behavior.
- The `{}` placeholder for search engines (the `url.searchengines` setting) now
Expand All @@ -58,7 +60,6 @@ Changed
data.
- The `dictcli.py` script now shows better error messages.
- Various improvements to the `mkvenv.py` script (mainly useful for development).
- First adoptions to Qt 5.15.
- Minor performance improvements.
Deprecated
Expand Down
4 changes: 4 additions & 0 deletions qutebrowser/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ def _open_special_pages(args):
('old-qt-warning-shown',
not qtutils.version_check('5.11'),
'qute://warning/old-qt'),

('session-warning-shown',
qtutils.version_check('5.15', compiled=False),
'qute://warning/sessions'),
]

for state, condition, url in pages:
Expand Down
7 changes: 6 additions & 1 deletion qutebrowser/browser/qutescheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from qutebrowser.browser import pdfjs, downloads, history
from qutebrowser.config import config, configdata, configexc, configdiff
from qutebrowser.utils import (version, utils, jinja, log, message, docutils,
objreg, urlutils)
objreg, urlutils, standarddir)
from qutebrowser.qt import sip


Expand Down Expand Up @@ -576,6 +576,11 @@ def qute_warning(url):
elif path == '/webkit':
src = jinja.render('warning-webkit.html',
title='QtWebKit backend warning')
elif path == '/sessions':
src = jinja.render('warning-sessions.html',
title='Qt 5.15 sessions warning',
datadir=standarddir.data(),
sep=os.sep)
else:
raise NotFoundError("Invalid warning page {}".format(path))
return 'text/html', src
6 changes: 6 additions & 0 deletions qutebrowser/browser/webengine/webenginetab.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,12 @@ def deserialize(self, data):
qtutils.deserialize(data, self._history)

def load_items(self, items):
if qtutils.version_check('5.15', compiled=False):
# WORKAROUND for https://github.com/qutebrowser/qutebrowser/issues/5359
if items:
self._tab.load_url(items[-1].url)
return

if items:
self._tab.before_load_started.emit(items[-1].url)

Expand Down
21 changes: 21 additions & 0 deletions qutebrowser/html/warning-sessions.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% extends "styled.html" %}

{% block content %}
<h1>{{ title }}</h1>
<span class="note">Note this warning will only appear once. Use <span class="mono">:open
qute://warning/sessions</span> to show it again at a later time.</span>

<p>You're using qutebrowser with Qt 5.15.</p>

<p>Since Qt doesn't provide an API to load the history of a tab, qutebrowser relies on a reverse-engineered binary serialization format to load tab history from session files. With Qt 5.15, unfortunately that format changed (due to the underlying Chromium upgrade), in a way which makes it impossible for qutebrowser to load tab history from existing session data.</p>

<p>At the time of writing (April 2020), a new session format which stores part of the needed binary data in saved sessions is <a href="https://github.com/qutebrowser/qutebrowser/issues/5359">in development</a> and will be released with qutebrowser v1.12.0.</p>

<p>As a stop-gap measure:</p>

<ul>
<li>Loading a session with this release will <b>only load the most recently opened page</b> for every tab. As a result, the back/forward-history of every tab <b>will be lost</b> as soon as the session is saved again.</li>
<li>A one-time backup of the session folder has been created at <span class="mono">{{ datadir }}{{ sep }}sessions{{ sep }}before-qt-515</span>.</li>
</ul>

{% endblock %}
12 changes: 12 additions & 0 deletions qutebrowser/misc/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import itertools
import urllib
import typing
import glob
import shutil

from PyQt5.QtCore import QUrl, QObject, QPoint, QTimer, pyqtSlot
from PyQt5.QtWidgets import QApplication
Expand Down Expand Up @@ -59,6 +61,16 @@ def init(parent=None):
parent: The parent to use for the SessionManager.
"""
base_path = os.path.join(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)

try:
os.mkdir(base_path)
except FileExistsError:
Expand Down

0 comments on commit 63ade39

Please sign in to comment.