Support disabling a lifecycle state by setting a delay of -1

This is inspired by previous iterations of this feature. Discarding a
page can lose information on the page, for example, if you go to
duckduckgo.com and put some text in the search box, then switch to a
different tab and wait for the ddg tab to be discarded, when you switch
back to the ddg tab the search box will be empty.

Until a point where we have more sophisticated controls of what sites
these transitions apply to, it may be useful for users to disable the
discard state completely. I know that's how I've had the lazier loading
implementation set up for years.

Negative numbers would previously have raised a warning on every state
transition where the time complained that negative numbers weren't
supported.
This commit is contained in:
toofar 2025-05-17 16:57:35 +12:00 committed by owl
parent 0d73ca833a
commit bf9df26538
No known key found for this signature in database
GPG Key ID: C2308C68A80FC991
3 changed files with 25 additions and 0 deletions

View File

@ -1761,6 +1761,9 @@ class WebEngineTab(browsertab.AbstractTab):
if self._widget.page().lifecycleState() == recommended_state:
return
if delay < 0:
return
log.webview.debug(f"Scheduling recommended lifecycle change {delay=} {recommended_state=} tab={self}")
self._lifecycle_timer.timeout.connect(lambda: self._set_lifecycle_state(recommended_state))
self._lifecycle_timer.start(delay)

View File

@ -349,6 +349,7 @@ qt.chromium.use_recommended_page_lifecycle_state:
type: Bool
default: false
backend: QtWebEngine
# yamllint disable rule:line-length
desc: >-
Use recommended page lifecycle state.
@ -361,6 +362,9 @@ qt.chromium.use_recommended_page_lifecycle_state:
Ongoing page activity is taken into account when determining the
recommended lifecycle state, as to not disrupt your browsing.
See the Qt documentation for more details: https://doc.qt.io/qt-6/qtwebengine-features.html#page-lifecycle-api
# yamllint enable rule:line-length
qt.chromium.lifecycle_state_freeze_delay:
type: Int
default: 0
@ -369,6 +373,8 @@ qt.chromium.lifecycle_state_freeze_delay:
The amount of time (in milliseconds) to wait before transitioning a page to
the frozen lifecycle state.
Set to -1 to disable this state (will also disable the discard state).
qt.chromium.lifecycle_state_discard_delay:
type: Int
default: 0
@ -377,6 +383,8 @@ qt.chromium.lifecycle_state_discard_delay:
The amount of time (in milliseconds) to wait before transitioning a page to
the discarded lifecycle state.
Set to -1 to disable this state.
qt.highdpi:
type: Bool
default: false

View File

@ -333,6 +333,20 @@ class TestPageLifecycle:
pass
set_state_spy.assert_called_once_with(new_state)
def test_state_disabled(
self,
webengine_tab: webenginetab.WebEngineTab,
monkeypatch,
config_stub,
):
"""For negative delay values, the timer shouldn't be scheduled."""
self.set_config(
config_stub,
freeze_delay=-1,
)
webengine_tab._on_recommended_state_changed(QWebEnginePage.LifecycleState.Frozen)
assert not webengine_tab._lifecycle_timer.isActive()
def test_timer_interrupted(
self,
webengine_tab: webenginetab.WebEngineTab,