From 33343546a588963ff2a34e25d569600d480b55b9 Mon Sep 17 00:00:00 2001
From: Nessar
Date: Tue, 17 Nov 2026 19:29:50 +0100
Subject: [PATCH] Draw and reload nothing for a window nobody sees (#29)
A follower round that changes nothing shown no longer rebuilds the page.
With the game client closed one arrives every 5 s, and each redrew the
whole page, also while the window was covered by another window.
Worker-driven reloads wait while GPUI reports the window hidden
(minimised or not shown) and run as soon as it is shown again, so a
restored window shows the Matches imported meanwhile at once.
Co-Authored-By: Claude Opus 5.5
---
crates/app/src/stats_page.rs | 37 ++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/crates/app/src/stats_page.rs b/crates/app/src/stats_page.rs
index 529e108..d8671c4 100644
--- a/crates/app/src/stats_page.rs
+++ b/crates/app/src/stats_page.rs
@@ -70,6 +70,7 @@ pub struct StatsPage {
pending_round: bool,
crashed: bool,
last_reload: Instant,
+ reload_when_shown: bool,
current_season: Option,
season: SeasonScope,
format: Option,
@@ -145,6 +146,13 @@ impl StatsPage {
cx.new(|cx| TableState::new(ChampionTable::new(), window, cx).col_movable(false));
let subscriptions = vec![
+ cx.observe_window_visibility(window, |this, visibility, window, cx| {
+ if visibility.is_visible() && this.reload_when_shown {
+ this.reload_when_shown = false;
+ this.reload(window, cx);
+ cx.notify();
+ }
+ }),
cx.subscribe_in(
&account_select,
window,
@@ -217,6 +225,7 @@ impl StatsPage {
pending_round: following,
crashed: false,
last_reload: Instant::now(),
+ reload_when_shown: false,
current_season,
season,
format: None,
@@ -290,24 +299,33 @@ impl StatsPage {
Msg::Progress(progress) => {
self.progress = Some(progress);
if self.last_reload.elapsed() >= RELOAD_EVERY {
- self.reload(window, cx);
+ self.reload_if_shown(window, cx);
}
}
- Msg::Champions => self.reload(window, cx),
+ Msg::Champions => self.reload_if_shown(window, cx),
Msg::Round { status, reload } => {
+ // A follower round that changes nothing shown must not rebuild the page (they keep coming).
+ let unchanged = status == self.status
+ && !reload
+ && !self.pending_round
+ && self.progress.is_none()
+ && !self.crashed;
+ if unchanged {
+ return;
+ }
self.status = status;
self.pending_round = false;
self.progress = None;
self.crashed = false;
if reload {
- self.reload(window, cx);
+ self.reload_if_shown(window, cx);
}
}
Msg::Refreshed(status) => {
self.status = status;
self.progress = None;
self.crashed = false;
- self.reload(window, cx);
+ self.reload_if_shown(window, cx);
// A request made while this one ran (a key saved meanwhile) is served now.
if self.refresh.finished() {
spawn_refresh(self.tracker.clone(), self.tx.clone());
@@ -323,6 +341,17 @@ impl StatsPage {
cx.notify();
}
+ /// A worker's reload, deferred while GPUI reports the window hidden (minimised or not shown;
+ /// on Windows a covered window still counts as visible), then run as soon as it is shown again
+ /// (rule #1, budget 3).
+ fn reload_if_shown(&mut self, window: &mut Window, cx: &mut Context) {
+ if window.is_visible() {
+ self.reload(window, cx);
+ } else {
+ self.reload_when_shown = true;
+ }
+ }
+
/// Re-reads the Accounts, then the statistics of the one shown.
fn reload(&mut self, window: &mut Window, cx: &mut Context) {
self.accounts = self.tracker.accounts().unwrap_or_default();