Notices hide at their expiry while the launcher runs; tests stay offline; withdrawal documented

This commit is contained in:
Martin Ball committed 2026-11-22 23:16:29 +00:00
1 parent 550147c058
commit e6220e6de2
7 files changed
+32 -8

No files matched your search

+14
View File
@@ -31,6 +31,16 @@ pub struct Notice {
/// Only `https://` links survive parsing.
pub link: Option<String>,
pub created_at: Option<i64>,
/// From then on the notice is hidden, also while the launcher stays open.
pub expires: Option<i64>,
}
impl Notice {
/// Not yet past its `expires` at `now`.
#[must_use]
pub fn current(&self, now: i64) -> bool {
self.expires.is_none_or(|e| now < e)
}
}
/// A verified notices file, with what is not yet published or already expired at `now` left out.
@@ -95,6 +105,7 @@ fn rows(values: Vec<toml::Value>, kind: &str, now: i64) -> Vec<Notice> {
body: truncate(body, MAX_TEXT),
link: r.link.filter(|l| safe_web_link(l)),
created_at: published,
expires,
})
})
.take(MAX_NOTICES)
@@ -150,6 +161,9 @@ mod tests {
// Kinds keep separate ids, so dismissing one never hides the other.
assert_eq!(n.alerts.len(), 1);
assert_ne!(n.alerts[0].id, n.announcements[0].id);
// A notice read before its end date stops being current once the date passes.
let alert = &n.alerts[0];
assert!(alert.current(NOW) && !alert.current(alert.expires.unwrap()));
}
#[test]
+3 -1
View File
@@ -26,7 +26,9 @@ struct Saved {
/// cache. `None` when neither has a valid signed file, so nothing is shown.
pub fn load(http: Option<&Http>, paths: &Paths, now: i64) -> Option<Notices> {
let cache = cache_path(paths);
if let Some(http) = http.filter(|_| due(Instant::now())) {
// Unit tests never reach the website: a slow answer would push the backend tests past
// their deadlines.
if let Some(http) = http.filter(|_| !cfg!(test) && due(Instant::now())) {
match fetch(http, now) {
Ok((notices, saved)) => {
if let Ok(bytes) = serde_json::to_vec(&saved)
+3 -1
View File
@@ -20,8 +20,10 @@ impl LauncherUi {
self.listed().filter(|n| !self.settings.read_notices.contains(&n.id)).count()
}
/// Announcements neither dismissed nor past their end date.
fn listed(&self) -> impl Iterator<Item = &Notice> {
self.announcements.iter().filter(|n| !self.settings.dismissed_notices.contains(&n.id))
let now = self.backend.now();
self.announcements.iter().filter(move |n| n.current(now) && !self.settings.dismissed_notices.contains(&n.id))
}
/// The bell's header cell, its unread count, and the panel it opens.
+3 -2
View File
@@ -67,9 +67,10 @@ impl LauncherUi {
}
}
/// The first alert from the release feed the user hasn't acknowledged, as a popup.
/// The first current alert the user hasn't acknowledged, as a popup.
fn alert_popup(&mut self, ctx: &egui::Context) {
let Some(alert) = self.alerts.iter().find(|a| !self.settings.dismissed_notices.contains(&a.id)).cloned() else { return };
let now = self.backend.now();
let Some(alert) = self.alerts.iter().find(|a| a.current(now) && !self.settings.dismissed_notices.contains(&a.id)).cloned() else { return };
let t = Tokens::get(ctx);
let modal = egui::Modal::new(egui::Id::unique("feed_alert").with(&alert.id)).frame(
egui::Frame::new().fill(t.bg).stroke(egui::Stroke::new(1.0, t.line_strong)).shadow(theme::shadow(&t)).inner_margin(theme::PAD as i8),
+1
View File
@@ -2814,6 +2814,7 @@ fn feed_announcements_and_alerts_show_until_dismissed() {
body: format!("{title} body"),
link: link.map(str::to_string),
created_at: None,
expires: None,
};
let sent = Rc::new(RefCell::new(Vec::new()));
let mut evs = events();
@@ -9,6 +9,6 @@ Announcements and alerts are text that every launcher puts on the user's screen,
## Consequences
- Publishing an announcement means a change to the website and its build signing the file. With no signed file there are no notices; there is no unsigned fallback.
- Publishing an announcement means a change to the website and its build signing the file. There is no unsigned fallback: a launcher that never fetched a valid file shows no notices, and one that did keeps its last verified copy when the file goes missing or its signature fails. Notices are withdrawn by publishing a signed file without them, not by deleting the file.
- A signature proves content, not freshness: an old signed file could be served again. Each notice can carry a signed `expires`, which bounds how long a replayed one is shown.
- The file is fetched at launch and at most every six hours after, from the pinned host, with redirects refused and nothing identifying in the request.
+7 -3
View File
@@ -9,7 +9,10 @@ The launcher shows notices only from a file on the website, signed like the host
(see [hosted-catalog.md](hosted-catalog.md)).
Announcements are listed in the bell in the header; alerts open as a dialog the user must
acknowledge. With no file, or a signature that does not match, nothing is shown.
acknowledge. A launcher that has never fetched a valid file shows nothing. One that has keeps its
verified copy: a missing file or a bad signature leaves the last good notices in place, so deleting
the file does not withdraw them. To withdraw notices, publish a signed file without them (a file
with no rows is valid); launchers drop them at their next successful fetch.
```toml
[[announcements]]
@@ -33,5 +36,6 @@ the rest still show. At most 20 of each kind, 64 KiB in all, 4000 characters of
The launcher fetches the file at launch and at most every six hours after, from the pinned host,
with redirects refused, and caches the verified copy. A signature proves who wrote the file, not
when, so give anything time-limited an `expires`: it bounds how long an old copy served again
could show it. Removing a row removes the notice on the next fetch; the user's read and dismissed
marks for it are then forgotten.
could show it. An `expires` takes effect at that moment, also in a launcher that stays open.
Removing a row from the published, signed file removes the notice at the next successful fetch;
the user's read and dismissed marks for it are then forgotten.