feat: retry a page that failed to load on its own

On a Steam machine remus can start before the network is up, so the
first page load fails even though the saved login is fine. An empty
page now retries with backoff (2 s doubling to 30 s) and fills in once
the server is reachable, without anyone pressing a button.
This commit is contained in:
Ansho Rei
2026-11-04 01:17:29 +01:00
parent b1914e4ac1
commit f10c2776aa
+29 -1
View File
@@ -152,6 +152,8 @@ struct Page {
sel: usize,
loading: bool,
error: Option<String>,
/// Automatic retries after a failed load, for the backoff.
retries: u32,
source: Source,
}
@@ -561,6 +563,7 @@ impl App {
sel: 0,
loading: true,
error: None,
retries: 0,
source,
}
}
@@ -942,11 +945,20 @@ impl App {
page.header = data.header;
}
page.loading = !done;
page.retries = 0;
}
Err(e) => {
log::warn!("load failed: {e:#}");
page.error = Some(format!("{e:#}"));
page.loading = false;
// An empty page retries on its own, so a library opened before
// the network is up (right after boot) fills in once it is.
// A partial one does not: reloading would duplicate entries.
if page.entries.is_empty() {
let delay = Duration::from_secs(2u64.saturating_pow(page.retries + 1).min(30));
page.retries += 1;
Timer::single_shot(delay, move || with_app(move |app| app.retry_page(page_id)));
}
}
}
if self.is_current(page_id) {
@@ -954,6 +966,22 @@ impl App {
}
}
fn retry_page(&mut self, page_id: u64) {
let Some(page) = self.find_page_mut(page_id) else {
return;
};
if page.error.is_none() || !page.entries.is_empty() {
return;
}
page.error = None;
page.loading = true;
let source = page.source.clone();
self.load(page_id, source);
if self.is_current(page_id) {
self.render_page();
}
}
// ---------------------------------------------------------------- render
fn render_page(&mut self) {
@@ -963,7 +991,7 @@ impl App {
} else if page.loading {
"Loading…".to_string()
} else if let Some(e) = &page.error {
format!("Could not load this page.\n{e}\n\nPress A to try again.")
format!("Could not reach the server. Retrying on its own, or press A to try now.\n\n{e}")
} else {
match page.source {
Source::Section(Section::Search) => "Search your library by artist, album or song title.".to_string(),