Merge branch 'cosminadrianpopescu-session-autosave'

This commit is contained in:
Florian Bruhin 2017-02-20 06:46:26 +01:00
commit 2c03ad34ad
5 changed files with 20 additions and 5 deletions

View File

@ -32,6 +32,7 @@ Added
- Support for the `general -> print-element-backgrounds` option with QtWebEngine on Qt >= 5.8
- Support for `:download --mhtml` with QtWebEngine
- New `qute:history` URL and `:history` command to show the browsing history.
- Open tabs are now auto-saved on each successful load and restored in case of a crash.
Changed
~~~~~~~

View File

@ -211,6 +211,7 @@ Contributors, sorted by the number of commits in descending order:
* Michael Ilsaas
* Martin Zimmermann
* Jussi Timperi
* Cosmin Popescu
* Brian Jackson
* thuck
* sbinix

View File

@ -214,14 +214,17 @@ def _load_session(name):
name: The name of the session to load, or None to read state file.
"""
state_config = objreg.get('state-config')
if name is None:
session_manager = objreg.get('session-manager')
if name is None and session_manager.exists('_autosave'):
name = '_autosave'
elif name is None:
try:
name = state_config['general']['session']
except KeyError:
# No session given as argument and none in the session file ->
# start without loading a session
return
session_manager = objreg.get('session-manager')
try:
session_manager.load(name)
except sessions.SessionNotFoundError:
@ -720,6 +723,11 @@ class Quitter:
# Now we can hopefully quit without segfaults
log.destroy.debug("Deferring QApplication::exit...")
objreg.get('signal-handler').deactivate()
try:
objreg.get('session-manager').delete('_autosave')
except sessions.SessionError as e:
log.sessions.error("Failed to delete autosave session: {}"
.format(e))
# We use a singleshot timer to exit here to minimize the likelihood of
# segfaults.
QTimer.singleShot(0, functools.partial(qApp.exit, status))

View File

@ -28,7 +28,7 @@ from PyQt5.QtWidgets import QWidget, QApplication
from qutebrowser.keyinput import modeman
from qutebrowser.config import config
from qutebrowser.utils import utils, objreg, usertypes, log, qtutils
from qutebrowser.misc import miscwidgets, objects
from qutebrowser.misc import miscwidgets, objects, sessions
from qutebrowser.browser import mouse, hints
@ -684,12 +684,17 @@ class AbstractTab(QWidget):
@pyqtSlot(bool)
def _on_load_finished(self, ok):
sess_manager = objreg.get('session-manager')
try:
sess_manager.save('_autosave')
except sessions.SessionError as e:
log.sessions.error("Failed to save autosave session: {}".format(e))
if ok and not self._has_ssl_errors:
if self.url().scheme() == 'https':
self._set_load_status(usertypes.LoadStatus.success_https)
else:
self._set_load_status(usertypes.LoadStatus.success)
elif ok:
self._set_load_status(usertypes.LoadStatus.warn)
else:

View File

@ -34,7 +34,6 @@ except ImportError: # pragma: no cover
from qutebrowser.utils import (standarddir, objreg, qtutils, log, usertypes,
message, utils)
from qutebrowser.commands import cmdexc, cmdutils
from qutebrowser.mainwindow import mainwindow
from qutebrowser.config import config
@ -346,6 +345,7 @@ class SessionManager(QObject):
name: The name of the session to load.
temp: If given, don't set the current session.
"""
from qutebrowser.mainwindow import mainwindow
path = self._get_session_path(name, check_exists=True)
try:
with open(path, encoding='utf-8') as f: