host: hidden tab webviews use the WebView2 low memory target
set_tab_visible shows/hides a tab webview and sets ICoreWebView2_19::SetMemoryUsageTargetLevel (LOW when hidden, NORMAL when shown). Hidden tabs keep running; the browser trims their working set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
99aa9bebf6
commit
3ef4a27a6b
4 changed files with 58 additions and 1 deletions
|
|
@ -159,6 +159,23 @@ impl TabAction {
|
|||
}
|
||||
}
|
||||
|
||||
/// WebView2 memory target for a tab webview. A hidden tab (background tab of a group, or a pane
|
||||
/// clamped away) asks the browser to drop caches, decoded images and GPU tiles it can rebuild;
|
||||
/// its page keeps running (timers, sockets, notifications). Shown tabs go back to normal.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum MemoryTarget {
|
||||
Normal,
|
||||
Low,
|
||||
}
|
||||
|
||||
pub fn memory_target(visible: bool) -> MemoryTarget {
|
||||
if visible {
|
||||
MemoryTarget::Normal
|
||||
} else {
|
||||
MemoryTarget::Low
|
||||
}
|
||||
}
|
||||
|
||||
/// Hands a JSON value to a member of the page runtime: `window.<global>.<member>.<method>(value)`
|
||||
/// when the runtime exists, else parked in `window.<queue>` for the runtime to pick up at start.
|
||||
/// `json` must be serialized JSON (never page-supplied text).
|
||||
|
|
@ -221,6 +238,12 @@ mod tests {
|
|||
assert_eq!(TabState::reported("tab-1".into(), None, None, Some(long_url), None).favicon, None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hidden_tabs_target_low_memory() {
|
||||
assert_eq!(memory_target(false), MemoryTarget::Low);
|
||||
assert_eq!(memory_target(true), MemoryTarget::Normal);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layouts_default_to_the_default_profile() {
|
||||
let layout: TabLayout = serde_json::from_str(r#"{"id":"a","url":"https://a.test/","x":0,"y":0,"width":1,"height":1,"visible":true}"#).unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue