@@ -405,6 +405,9 @@ struct Splash {
405405 products: usize,
406406 /// When the window opened, so [`SPLASH_FLOOR`] can be honoured.
407407 opened: Instant,
408+ /// Whether the cache has been read and the splash knows if it waits for
409+ /// the network. Decided once, on the first cache-only pass.
410+ decided: bool,
408411}
409412
410413#[derive(Debug, Clone)]
@@ -1900,22 +1903,15 @@ impl Lightforge {
19001903 /// Open the splash and start the fetch it is waiting on.
19011904 fn open_splash(&mut self) -> Task<Message> {
19021905 let codes: Vec<ProductCode> = self.choices.iter().map(|c| c.code.clone()).collect();
1903- self.splash = Some(Splash { products: codes.len(), opened: Instant::now() });
1906+ self.splash = Some(Splash { products: codes.len(), opened: Instant::now(), decided: false });
1907+ // Nothing is fetched yet: the cache-only pass `reload` starts beside
1908+ // this decides whether anything needs to be. See `splash_decide`.
19041909 Task::batch([
19051910 // The window is the launcher's size but only the card is painted,
19061911 // so the rest of it is a transparent rectangle that would still
19071912 // swallow every click landing on whatever is behind it. On
19081913 // Wayland this sets a real empty input region, not a hint.
19091914 iced::window::oldest().and_then(iced::window::enable_mouse_passthrough),
1910- Task::perform(
1911- tasks::prefetch_within(
1912- SPLASH_BUDGET,
1913- self.http.clone(),
1914- self.pipeline.clone(),
1915- codes,
1916- ),
1917- Message::SplashDone,
1918- ),
19191915 // Beside the artwork rather than before it: this is the one moment
19201916 // a start is already waiting on the network, and nothing on screen
19211917 // depends on the answer, so it never holds the splash open.
@@ -1926,6 +1922,51 @@ impl Lightforge {
19261922 ])
19271923 }
19281924
1925+ /// The splash's one decision, made when the selected game's cache-only
1926+ /// pass lands: close, or wait for the network.
1927+ ///
1928+ /// The splash exists so nobody sees a grey launcher, so it closes early
1929+ /// only when the cache already holds everything the first screen draws,
1930+ /// decoded and in state by now. The revalidation `reload` started runs
1931+ /// on behind the launcher and swaps in whatever changed, exactly as on a
1932+ /// product switch. Anything missing, or a first run, whose wizard counts
1933+ /// off the prefetch, waits for the full fetch as it always has.
1934+ fn splash_decide(&mut self, warm: bool) -> Task<Message> {
1935+ let Some(splash) = self.splash.as_mut().filter(|s| !s.decided) else {
1936+ return Task::none();
1937+ };
1938+ splash.decided = true;
1939+ if warm && self.wizard.is_none() {
1940+ trace::mark("splash: cache is warm, not waiting on the network");
1941+ return self.close_splash_after_floor();
1942+ }
1943+ Task::perform(
1944+ tasks::prefetch_within(
1945+ SPLASH_BUDGET,
1946+ self.http.clone(),
1947+ self.pipeline.clone(),
1948+ self.choices.iter().map(|c| c.code.clone()).collect(),
1949+ ),
1950+ Message::SplashDone,
1951+ )
1952+ }
1953+
1954+ /// Close the splash once it has been up for [`SPLASH_FLOOR`].
1955+ fn close_splash_after_floor(&mut self) -> Task<Message> {
1956+ let waited = self.splash.as_ref().map(|s| s.opened.elapsed()).unwrap_or_default();
1957+ match SPLASH_FLOOR.checked_sub(waited) {
1958+ Some(left) if !left.is_zero() => {
1959+ Task::perform(tasks::after(left), |()| Message::FinishSplash)
1960+ }
1961+ // Both ways out go through `finish_splash` and nothing else. An
1962+ // earlier version did the work in two places, and the two copies
1963+ // drifted: the one taken whenever the fetch outlasts the floor,
1964+ // which is every start with anything to fetch, missed a step the
1965+ // other had.
1966+ _ => self.finish_splash(),
1967+ }
1968+ }
1969+
19291970 /// Put the release notes up, if this start is the first one on this
19301971 /// version.
19311972 ///
@@ -2651,10 +2692,14 @@ impl Lightforge {
26512692 if self.icons.is_empty() {
26522693 self.icons = themed.icons;
26532694 }
2654- if code == self.selected.code && self.branding.is_none() {
2695+ let selected = code == self.selected.code;
2696+ if selected && self.branding.is_none() {
26552697 self.branding = themed.branding;
26562698 }
2657- Task::none()
2699+ match selected {
2700+ true => self.splash_decide(themed.warm),
2701+ false => Task::none(),
2702+ }
26582703 }
26592704
26602705 Message::Themed(code, themed) => {
@@ -3164,19 +3209,9 @@ impl Lightforge {
31643209 if let Some(wizard) = self.wizard.as_mut() {
31653210 wizard.prefetched = Some(count);
31663211 }
3167- let waited =
3168- self.splash.as_ref().map(|s| s.opened.elapsed()).unwrap_or_default();
3169- match SPLASH_FLOOR.checked_sub(waited) {
3170- Some(left) if !left.is_zero() => {
3171- Task::perform(tasks::after(left), |()| Message::FinishSplash)
3172- }
3173- // Both ways out go through `finish_splash` and nothing
3174- // else. An earlier version did the work here directly as
3175- // well, and the two copies drifted: the one taken
3176- // whenever the fetch outlasts the floor, which is every
3177- // start with anything to fetch, missed a step the other
3178- // had.
3179- _ => self.finish_splash(),
3212+ match self.splash.is_some() {
3213+ true => self.close_splash_after_floor(),
3214+ false => Task::none(),
31803215 }
31813216 }
31823217
0 commit comments