Add a button to check for an update from the settings
CI / core (pull_request) Successful in 1m40s
CI / core (push) Successful in 1m42s

The check ran only at launch and on a channel change, so an app left
open never saw a release published since. « Rechercher une mise à jour »
runs the same check on demand, through the same gate, and the settings
now say how the last check ended: running, up to date, or why it failed.
A failed check leaves a ready update ready.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit was merged in pull request #105.
This commit is contained in:
nessarandClaude Sonnet 5.5 committed 2026-11-23 08:40:24 +01:00
1 parent 2c9ca4552c
commit 1ad36bdd5a
6 files changed
+142 -21

No files matched your search

+6 -6
View File
@@ -94,13 +94,13 @@ fn update_context() -> Option<(PathBuf, Vec<u8>, &'static str)> {
}
/// Keeps the newest release of `channel` downloaded and authenticated in the updates folder and
/// returns its version. A failed check only means no update is ready; the next launch checks
/// again.
pub fn download_update(channel: UpdateChannel) -> Option<String> {
let (dir, key, version) = update_context()?;
/// returns its version, or `None` when there is no newer one. A failed check changes nothing on
/// disk: the kept package stays, and the next check (launch, channel change or the settings'
/// button) tries again.
pub fn download_update(channel: UpdateChannel) -> Result<Option<String>, String> {
let (dir, key, version) = update_context().ok_or("Cette version ne se met pas à jour.")?;
arena_tracker_core::download_update(RELEASES, &dir, &key, channel, version)
.ok()
.flatten()
.map_err(|e| e.to_string())
}
/// Before the app loads, in the single instance only: hands the kept update of the chosen
+48 -5
View File
@@ -52,7 +52,10 @@ pub struct KeyForm {
notice_shown: Sender<()>,
/// « Mise à jour prête » with the version downloaded and authenticated for the chosen channel.
ready: Option<SharedString>,
/// One update check at a time: once per launch, then once per channel change.
/// How the last check of the chosen channel ended, besides a ready update: up to date, or
/// why it failed. Cleared when the settings are left, as it ages while the app runs.
check_outcome: Option<SharedString>,
/// One update check at a time: at launch, on a channel change and on « Rechercher une mise à jour ».
update_checks: RefreshGate,
updates: Sender<UpdateChecked>,
_subscriptions: [Subscription; 2],
@@ -130,6 +133,7 @@ impl KeyForm {
logon_launch,
notice_shown,
ready: None,
check_outcome: None,
update_checks: RefreshGate::default(),
updates,
_subscriptions: [subscription, appearance],
@@ -157,21 +161,58 @@ impl KeyForm {
}
}
/// Only a check of the channel chosen now can make an update ready.
/// « Rechercher une mise à jour ».
fn check_updates_now(&mut self, cx: &mut Context<Self>) {
self.check_outcome = None;
self.check_updates();
cx.notify();
}
/// Only a check of the channel chosen now can make an update ready or change what is said
/// about the last check. A failure leaves a ready update ready: its package is still kept.
pub(crate) fn update_checked(&mut self, checked: UpdateChecked, cx: &mut Context<Self>) {
if self.update_checks.finished() {
let channel = channel(self.store.preferences());
spawn_update_check(channel, self.updates.clone());
}
if checked.channel == channel(self.store.preferences()) {
let ready = (checked.ready)
.map(|version| format!("Mise à jour prête : version {version}").into());
self.set_ready(ready, cx);
match checked.result {
Ok(Some(version)) => {
self.check_outcome = None;
self.set_ready(
Some(format!("Mise à jour prête : version {version}").into()),
cx,
);
}
Ok(None) => {
let version = release::VERSION.map(|version| format!(" ({version})"));
self.check_outcome = Some(
format!(
"Vous avez la dernière version{}",
version.unwrap_or_default()
)
.into(),
);
self.set_ready(None, cx);
}
Err(error) => {
self.check_outcome =
Some(format!("Impossible de vérifier les mises à jour : {error}").into());
}
}
}
// « Redémarrer » waits for the end of the check.
cx.notify();
}
/// « Recherche en cours… » while a check runs, then how the last one ended.
fn check_status(&self) -> Option<SharedString> {
if self.update_checks.running() {
return Some("Recherche en cours…".into());
}
self.check_outcome.clone()
}
fn set_ready(&mut self, ready: Option<SharedString>, cx: &mut Context<Self>) {
if self.ready != ready {
self.ready = ready;
@@ -191,6 +232,7 @@ impl KeyForm {
pub fn reset(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.error = None;
self.preference_error = None;
self.check_outcome = None;
self.clear(window, cx);
cx.notify();
}
@@ -221,6 +263,7 @@ impl KeyForm {
if channel(preferences) != channel(previous) {
// The other channel's update must not show as ready, even if its check ends late.
self.set_ready(None, cx);
self.check_outcome = None;
self.check_updates();
}
None
+12 -2
View File
@@ -6,7 +6,7 @@ use gpui_kit::component::{ActiveTheme as _, Disableable as _, StyledExt as _};
use gpui_kit::*;
use super::KeyForm;
use crate::release::channel;
use crate::release::{self, channel};
const THEMES: [(ThemePreference, &str); 3] = [
(ThemePreference::System, "Système"),
@@ -107,8 +107,18 @@ impl KeyForm {
);
})),
)
.children(release::VERSION.is_some().then(|| {
div().h_flex().child(
Button::new("check-update")
.label("Rechercher une mise à jour")
.disabled(self.update_checks.running())
.on_click(cx.listener(|this, _, _, cx| this.check_updates_now(cx))),
)
}))
.children(
self.update_status()
[self.check_status(), self.update_status()]
.into_iter()
.flatten()
.map(|status| div().text_color(muted).child(status)),
)
.children(self.can_restart().then(|| {
+69 -2
View File
@@ -48,14 +48,14 @@ fn the_chosen_channel_is_saved_and_only_its_check_offers_a_restart(cx: &mut Test
// A stable check that ends after the change to Bêta stays out of sight.
let late = UpdateChecked {
channel: UpdateChannel::Stable,
ready: Some("1.0.1".into()),
result: Ok(Some("1.0.1".into())),
};
form.update_checked(late, cx);
assert!(!form.update_ready());
assert_eq!(form.update_status(), None);
let checked = UpdateChecked {
channel: UpdateChannel::Beta,
ready: Some("1.1.0-beta.3".into()),
result: Ok(Some("1.1.0-beta.3".into())),
};
form.update_checked(checked, cx);
assert!(form.update_ready());
@@ -73,13 +73,80 @@ fn the_chosen_channel_is_saved_and_only_its_check_offers_a_restart(cx: &mut Test
assert_eq!(error, Some("Cette version ne se met pas à jour."));
});
form.update(cx, |form, cx| {
let checked = UpdateChecked {
channel: UpdateChannel::Beta,
result: Ok(None),
};
form.update_checked(checked, cx);
assert!(form.check_status().is_some());
});
choose(UpdateChannel::Stable, cx);
assert_eq!(form.read_with(cx, |form, _| form.check_status()), None);
assert!(!form.read_with(cx, |form, _| form.update_ready()));
let loaded = Config::load(&path).unwrap().preferences;
assert_eq!(loaded, saved(UpdateChannel::Stable));
std::fs::remove_dir_all(&dir).unwrap();
}
#[gpui::test]
fn the_last_check_is_told_until_the_settings_are_shown_again(cx: &mut TestAppContext) {
cx.update(gpui_kit::init);
let (window, form) = cx.update(|cx| {
let config = Config::load_or_default(std::path::Path::new(":memory:")).unwrap();
let api = Arc::new(RiotApi::new(String::new(), &config.region));
let store = KeyStore::new("unused.toml".into(), config, api);
gpui_kit::open_window(WindowOptions::default(), cx, |window, cx| {
cx.new(|cx| KeyForm::new(store, false, window, cx))
})
.unwrap()
});
let cx = &mut VisualTestContext::from_window(window, cx);
let checked = |result| UpdateChecked {
channel: UpdateChannel::Stable,
result,
};
form.update(cx, |form, cx| {
assert_eq!(form.check_status(), None);
assert!(form.update_checks.request());
assert_eq!(form.check_status().as_deref(), Some("Recherche en cours…"));
form.update_checked(checked(Ok(Some("1.0.1".into()))), cx);
assert!(form.update_ready());
assert_eq!(form.check_status(), None);
// A failed check leaves the kept package ready and says why.
form.update_checked(checked(Err("réseau".into())), cx);
assert!(form.update_ready());
assert_eq!(
form.check_status().as_deref(),
Some("Impossible de vérifier les mises à jour : réseau")
);
// A check of the other channel that ends late says nothing about this one.
let other = UpdateChecked {
channel: UpdateChannel::Beta,
result: Err("autre canal".into()),
};
form.update_checked(other, cx);
assert!(form.check_status().as_deref().unwrap().ends_with("réseau"));
// Nothing newer: the kept package is gone and the settings say so.
form.update_checked(checked(Ok(None)), cx);
assert!(!form.update_ready());
assert_eq!(
form.check_status().as_deref(),
Some("Vous avez la dernière version")
);
});
cx.update(|window, cx| {
form.update(cx, |form, cx| {
form.reset(window, cx);
assert_eq!(form.check_status(), None);
})
});
}
#[gpui::test]
fn the_logon_switch_shows_what_windows_holds(cx: &mut TestAppContext) {
cx.update(gpui_kit::init);
+1 -1
View File
@@ -50,7 +50,7 @@ fn a_ready_update_adds_a_title_bar_button_that_opens_the_settings(cx: &mut TestA
form.update(cx, |form, cx| {
let checked = UpdateChecked {
channel: UpdateChannel::Stable,
ready: Some("1.0.1".into()),
result: Ok(Some("1.0.1".into())),
};
form.update_checked(checked, cx);
});
+6 -5
View File
@@ -290,21 +290,22 @@ pub fn spawn_follower(tracker: Arc<Tracker>, fallback_riot_id: String, tx: Sende
});
}
/// What an update check for `channel` kept ready: the version, if any.
/// What an update check for `channel` ended with: the version kept ready, `None` when there is
/// no newer one, or why the check failed.
pub struct UpdateChecked {
pub channel: UpdateChannel,
pub ready: Option<String>,
pub result: Result<Option<String>, String>,
}
/// Downloads and authenticates the newest release of `channel`, as one below-normal thread.
pub fn spawn_update_check(channel: UpdateChannel, tx: Sender<UpdateChecked>) {
let crashed = UpdateChecked {
channel,
ready: None,
result: Err("la vérification s’est interrompue".into()),
};
spawn_guarded(tx, crashed, move |tx| {
let ready = crate::release::download_update(channel);
let _ = tx.try_send(UpdateChecked { channel, ready });
let result = crate::release::download_update(channel);
let _ = tx.try_send(UpdateChecked { channel, result });
});
}