From 95f8c07d7fbd8e45b244e3d5d9d381fb58ea411a Mon Sep 17 00:00:00 2001 From: "mhm@mhm.com" Date: Sat, 18 Nov 2017 00:31:53 +0100 Subject: [PATCH] lazy sessions --- qutebrowser/browser/qutescheme.py | 7 +++++++ qutebrowser/config/configdata.yml | 8 ++++++++ qutebrowser/misc/sessions.py | 17 ++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/qutescheme.py b/qutebrowser/browser/qutescheme.py index 11dcfe004..f943fcba4 100644 --- a/qutebrowser/browser/qutescheme.py +++ b/qutebrowser/browser/qutescheme.py @@ -424,6 +424,13 @@ def qute_settings(url): confget=config.instance.get_str) return 'text/html', html +@add_handler('back') +def qute_back(url): + """Handler for qute://back. Simple page to free ram / lazy load a site, + goes back on focusing the tab.""" + + html = jinja.render('back.html', title='Suspended') + return 'text/html', html @add_handler('configdiff') def qute_configdiff(url): diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index ba8c36857..7284d98d5 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -88,6 +88,14 @@ session_default_name: If this is set to null, the session which was last loaded is saved. +session_lazy_restore: + type: + name: Bool + none_ok: true + default: false + desc: >- + Load a restored tab as soon as it takes focus. + backend: type: name: String diff --git a/qutebrowser/misc/sessions.py b/qutebrowser/misc/sessions.py index 064d8c9e9..471805da9 100644 --- a/qutebrowser/misc/sessions.py +++ b/qutebrowser/misc/sessions.py @@ -347,7 +347,9 @@ class SessionManager(QObject): if 'pinned' in histentry: new_tab.data.pinned = histentry['pinned'] - active = histentry.get('active', False) + active = (histentry.get('active', False) and + (not config.val.session_lazy_restore or + histentry['url'].startswith('qute://'))) url = QUrl.fromEncoded(histentry['url'].encode('ascii')) if 'original-url' in histentry: orig_url = QUrl.fromEncoded( @@ -360,6 +362,19 @@ class SessionManager(QObject): entries.append(entry) if active: new_tab.title_changed.emit(histentry['title']) + + if config.val.session_lazy_restore and data['history']: + last = data['history'][-1] + title = last['title'] + url = 'qute://back#' + title + active = last.get('active', False) + + if not last['url'].startswith('qute://'): + entries.append(TabHistoryItem(url=QUrl.fromEncoded(url.encode('ascii')), + title=title, active=active, user_data={})) + if active: + new_tab.title_changed.emit(title) + try: new_tab.history.load_items(entries) except ValueError as e: