host: low memory only for parked tabs, not for tabs hidden behind a shell overlay; skip unchanged targets

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
CRTkafa 2026-09-28 19:42:34 +07:00
parent 3ef4a27a6b
commit edf5171435
2 changed files with 23 additions and 8 deletions

View file

@ -189,11 +189,20 @@ pub fn system_menu<R: Runtime>(webview: &Webview<R>, x: f64, y: f64) -> Result<(
/// ([`tabs::memory_target`]): hidden tabs run at `COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_LOW`
/// (ICoreWebView2_19, WebView2 Runtime 114+; older runtimes just skip it). Other platforms only
/// show/hide.
pub fn set_tab_visible<R: Runtime>(webview: &Webview<R>, visible: bool) {
pub fn set_tab_visible<R: Runtime>(webview: &Webview<R>, visible: bool, parked: bool) {
let _ = if visible { webview.show() } else { webview.hide() };
#[cfg(windows)]
{
let target = tabs::memory_target(visible);
use std::collections::HashMap;
use std::sync::{Mutex, OnceLock};
// Last target per webview label: a sync that changes nothing costs no COM call.
static LAST: OnceLock<Mutex<HashMap<String, tabs::MemoryTarget>>> = OnceLock::new();
let target = tabs::memory_target(visible, parked);
let mut last = LAST.get_or_init(Default::default).lock().unwrap_or_else(|poisoned| poisoned.into_inner());
if last.insert(webview.label().to_owned(), target) == Some(target) {
return;
}
drop(last);
let _ = webview.with_webview(move |platform| {
use webview2_com::Microsoft::Web::WebView2::Win32::{
ICoreWebView2_19, COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_LOW, COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_NORMAL,