BlueGit

ict rusty-teams

fix(webview): a tab a call holds loaded runs at the low memory target

- a call keeps the Teams tab from parking; its renderer now gets the low memory target and a pressure notification, also when it loads while held

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-10 · 3 weeks ago

Hash
4af5e7abc87711fdc1b925b84bc3ab4c276780c1
Parent
a9c98143
2 files changed +22 −2
crates/webview/src/host.rs +17 −1
@@ -291,6 +291,10 @@ fn watch_loads(webview: &ICoreWebView2, app: App) -> windows::core::Result<()> {
291 291 let url = current_url(&shared, app);
292 292 if is_running_app(app, &url) {
293 293 unsafe { SetTimer(Some(shared.windows[&app]), PARK_TIMER, PARK_DELAY_MS, None) };
294 if shared.park_gate.borrow().held(app) {
295 set_memory_level(&sender, COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_LOW);
296 release_memory(&sender);
297 }
294 298 } else if app.is_park_url(&url) {
295 299 release_memory(&sender);
296 300 }
@@ -314,6 +318,18 @@ fn park(shared: &Shared, app: App) {
314 318 }
315 319 }
316 320
321 /// A held tab stays loaded for the whole call, so its renderer is told to shrink instead of being parked.
322 fn hold(shared: &Shared, app: App, held: bool) {
323 shared.park_gate.borrow_mut().hold(app, held);
324 if held
325 && let Some(webview) = webview_of(shared, app)
326 && is_running_app(app, &current_url(shared, app))
327 {
328 set_memory_level(&webview, COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_LOW);
329 release_memory(&webview);
330 }
331 }
332
317 333 fn set_memory_level(webview: &ICoreWebView2, level: COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL) {
318 334 if let Ok(webview) = webview.cast::<ICoreWebView2_19>() {
319 335 unsafe {
@@ -430,7 +446,7 @@ fn drain(shared: &Rc<Shared>) {
430 446 UiRequest::Call { app, command } => call(shared, app, command),
431 447 UiRequest::Subscribe { app, sink } => shared.subscribers.borrow_mut().add(app, sink),
432 448 UiRequest::Wake { app } => wake(shared, app),
433 UiRequest::Hold { app, held } => shared.park_gate.borrow_mut().hold(app, held),
449 UiRequest::Hold { app, held } => hold(shared, app, held),
434 450 UiRequest::Retry => {
435 451 if !shared.state.borrow().ready && !shared.restarting.replace(true) {
436 452 restart(shared);
@@ -291,6 +291,10 @@ fn watch_loads(webview: &ICoreWebView2, app: App) -> windows::core::Result<()> {
291 let url = current_url(&shared, app);
291 let url = current_url(&shared, app);
292 if is_running_app(app, &url) {
292 if is_running_app(app, &url) {
293 unsafe { SetTimer(Some(shared.windows[&app]), PARK_TIMER, PARK_DELAY_MS, None) };
293 unsafe { SetTimer(Some(shared.windows[&app]), PARK_TIMER, PARK_DELAY_MS, None) };
294 if shared.park_gate.borrow().held(app) {
295 set_memory_level(&sender, COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_LOW);
296 release_memory(&sender);
297 }
294 } else if app.is_park_url(&url) {
298 } else if app.is_park_url(&url) {
295 release_memory(&sender);
299 release_memory(&sender);
296 }
300 }
@@ -314,6 +318,18 @@ fn park(shared: &Shared, app: App) {
314 }
318 }
315}
319}
316
320
321/// A held tab stays loaded for the whole call, so its renderer is told to shrink instead of being parked.
322fn hold(shared: &Shared, app: App, held: bool) {
323 shared.park_gate.borrow_mut().hold(app, held);
324 if held
325 && let Some(webview) = webview_of(shared, app)
326 && is_running_app(app, &current_url(shared, app))
327 {
328 set_memory_level(&webview, COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_LOW);
329 release_memory(&webview);
330 }
331}
332
317fn set_memory_level(webview: &ICoreWebView2, level: COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL) {
333fn set_memory_level(webview: &ICoreWebView2, level: COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL) {
318 if let Ok(webview) = webview.cast::<ICoreWebView2_19>() {
334 if let Ok(webview) = webview.cast::<ICoreWebView2_19>() {
319 unsafe {
335 unsafe {
@@ -430,7 +446,7 @@ fn drain(shared: &Rc<Shared>) {
430 UiRequest::Call { app, command } => call(shared, app, command),
446 UiRequest::Call { app, command } => call(shared, app, command),
431 UiRequest::Subscribe { app, sink } => shared.subscribers.borrow_mut().add(app, sink),
447 UiRequest::Subscribe { app, sink } => shared.subscribers.borrow_mut().add(app, sink),
432 UiRequest::Wake { app } => wake(shared, app),
448 UiRequest::Wake { app } => wake(shared, app),
433 UiRequest::Hold { app, held } => shared.park_gate.borrow_mut().hold(app, held),
449 UiRequest::Hold { app, held } => hold(shared, app, held),
434 UiRequest::Retry => {
450 UiRequest::Retry => {
435 if !shared.state.borrow().ready && !shared.restarting.replace(true) {
451 if !shared.state.borrow().ready && !shared.restarting.replace(true) {
436 restart(shared);
452 restart(shared);
crates/webview/src/park.rs +5 −1
@@ -24,6 +24,10 @@ impl ParkGate {
24 24 adjust(&mut self.holds, app, held);
25 25 }
26 26
27 pub(crate) fn held(&self, app: App) -> bool {
28 self.holds.get(&app).copied().unwrap_or(0) > 0
29 }
30
27 31 pub(crate) fn command_started(&mut self, app: App) {
28 32 adjust(&mut self.in_flight, app, true);
29 33 }
@@ -42,7 +46,7 @@ impl ParkGate {
42 46
43 47 /// A protocol call whose page promise never settles stays in flight; after a few waits it no longer blocks the park.
44 48 pub(crate) fn decide(&mut self, app: App) -> ParkDecision {
45 if self.holds.get(&app).copied().unwrap_or(0) > 0 {
49 if self.held(app) {
46 50 return ParkDecision::Wait;
47 51 }
48 52 let waits = self.command_waits.entry(app).or_default();
@@ -24,6 +24,10 @@ impl ParkGate {
24 adjust(&mut self.holds, app, held);
24 adjust(&mut self.holds, app, held);
25 }
25 }
26
26
27 pub(crate) fn held(&self, app: App) -> bool {
28 self.holds.get(&app).copied().unwrap_or(0) > 0
29 }
30
27 pub(crate) fn command_started(&mut self, app: App) {
31 pub(crate) fn command_started(&mut self, app: App) {
28 adjust(&mut self.in_flight, app, true);
32 adjust(&mut self.in_flight, app, true);
29 }
33 }
@@ -42,7 +46,7 @@ impl ParkGate {
42
46
43 /// A protocol call whose page promise never settles stays in flight; after a few waits it no longer blocks the park.
47 /// A protocol call whose page promise never settles stays in flight; after a few waits it no longer blocks the park.
44 pub(crate) fn decide(&mut self, app: App) -> ParkDecision {
48 pub(crate) fn decide(&mut self, app: App) -> ParkDecision {
45 if self.holds.get(&app).copied().unwrap_or(0) > 0 {
49 if self.held(app) {
46 return ParkDecision::Wait;
50 return ParkDecision::Wait;
47 }
51 }
48 let waits = self.command_waits.entry(app).or_default();
52 let waits = self.command_waits.entry(app).or_default();