Choose the update channel and download authenticated updates (#58)
The settings offer Stable or Bêta. The choice is saved only once made; until then the installed version's channel applies, so the beta installer follows Bêta. Updates never change a saved choice. Each launch, and each channel change, runs one check on a below-normal thread. It lists the channel's Releases through the public Gitea API (betas are pre-releases) and takes the highest version above the installed one. The package is downloaded into %LOCALAPPDATA%\arena-tracker\updates\partial, verified with verify_release, then kept as <channel>-<version>; another channel's package is removed before any network access. Only then does a green title-bar button show « Mise à jour prête » and open the settings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #66.
This commit is contained in:
1 parent
24aca3c93d
commit
8e12abf7f4
11 files changed
+842
-37
No files matched your search
+60
-16
@@ -24,7 +24,7 @@ use gpui_kit::*;
|
||||
|
||||
use settings::{KeyEvent, KeyForm, KeyStore, apply_theme};
|
||||
use stats_page::StatsPage;
|
||||
use title_bar::{MIN_WINDOW_SIZE, refresh_button, settings_button, title_bar};
|
||||
use title_bar::{MIN_WINDOW_SIZE, refresh_button, settings_button, title_bar, update_button};
|
||||
use worker::{Msg, spawn_follower};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
@@ -84,6 +84,8 @@ impl RootView {
|
||||
}
|
||||
KeyEvent::Saved => this.page.update(cx, |page, cx| page.request_refresh(cx)),
|
||||
KeyEvent::Back => {}
|
||||
// Only the title bar changes.
|
||||
KeyEvent::UpdateReady => return cx.notify(),
|
||||
}
|
||||
this.show_page(window, cx);
|
||||
});
|
||||
@@ -127,6 +129,14 @@ impl RootView {
|
||||
self.screen != Screen::Prompt && self.form.read(cx).has_key() && !self.page.read(cx).busy()
|
||||
}
|
||||
|
||||
fn open_settings(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if self.screen == Screen::Page {
|
||||
self.screen = Screen::Settings;
|
||||
self.focus.focus(window, cx);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/// Leaves the key form for the page, discarding half-typed edits.
|
||||
fn show_page(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.form.update(cx, |form, cx| form.reset(window, cx));
|
||||
@@ -144,15 +154,14 @@ impl Render for RootView {
|
||||
this.page.update(cx, |page, cx| page.request_refresh(cx));
|
||||
}
|
||||
}));
|
||||
let settings = settings_button(self.screen == Screen::Page, cx).on_click(cx.listener(
|
||||
|this, _, window, cx| {
|
||||
if this.screen == Screen::Page {
|
||||
this.screen = Screen::Settings;
|
||||
this.focus.focus(window, cx);
|
||||
cx.notify();
|
||||
}
|
||||
},
|
||||
));
|
||||
let on_page = self.screen == Screen::Page;
|
||||
let settings = settings_button(on_page, cx)
|
||||
.on_click(cx.listener(|this, _, window, cx| this.open_settings(window, cx)));
|
||||
// The settings show the ready version; #59 turns this into « Redémarrer ».
|
||||
let update = self.form.read(cx).update_ready().then(|| {
|
||||
update_button(on_page, cx)
|
||||
.on_click(cx.listener(|this, _, window, cx| this.open_settings(window, cx)))
|
||||
});
|
||||
let content = match self.screen {
|
||||
Screen::Page => self.page.clone().into_any_element(),
|
||||
Screen::Prompt | Screen::Settings => self.form.clone().into_any_element(),
|
||||
@@ -162,7 +171,7 @@ impl Render for RootView {
|
||||
.track_focus(&self.focus)
|
||||
.v_flex()
|
||||
.size_full()
|
||||
.child(title_bar(refresh, settings, window, cx))
|
||||
.child(title_bar(refresh, settings, update, window, cx))
|
||||
.child(div().flex_1().min_h_0().child(content))
|
||||
}
|
||||
}
|
||||
@@ -183,6 +192,7 @@ impl Render for Unavailable {
|
||||
.child(title_bar(
|
||||
refresh_button(false, cx),
|
||||
settings_button(false, cx),
|
||||
None,
|
||||
window,
|
||||
cx,
|
||||
))
|
||||
@@ -330,15 +340,16 @@ mod tests {
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use arena_tracker_core::{Config, RiotApi, Tracker};
|
||||
use arena_tracker_core::{Config, RiotApi, Tracker, UpdateChannel};
|
||||
use gpui_kit::component::{Theme, ThemeMode};
|
||||
use gpui_kit::{
|
||||
AppContext as _, FontWeight, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers,
|
||||
AppContext as _, Entity, FontWeight, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers,
|
||||
TestAppContext, VisualTestContext, WindowOptions, font, point, px,
|
||||
};
|
||||
|
||||
use super::{INTER, KeyStore, RootView, Screen, Setup};
|
||||
use crate::title_bar::{BAR_HEIGHT, BUTTON_WIDTH};
|
||||
use crate::worker::UpdateChecked;
|
||||
|
||||
// Not #[gpui::test]: its text system is a no-op, and this checks DirectWrite's real one.
|
||||
#[test]
|
||||
@@ -369,8 +380,8 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn settings_in_the_title_bar_respects_the_initial_key_prompt(cx: &mut TestAppContext) {
|
||||
/// A first launch: no key and nothing stored.
|
||||
fn first_launch(cx: &mut TestAppContext) -> (VisualTestContext, Entity<RootView>) {
|
||||
cx.update(gpui_kit::init);
|
||||
let (window, root) = cx.update(|cx| {
|
||||
let config = Config::load_or_default(Path::new(":memory:")).unwrap();
|
||||
@@ -388,7 +399,40 @@ mod tests {
|
||||
})
|
||||
.unwrap()
|
||||
});
|
||||
let cx = &mut VisualTestContext::from_window(window, cx);
|
||||
(VisualTestContext::from_window(window, cx), root)
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_ready_update_adds_a_title_bar_button_that_opens_the_settings(cx: &mut TestAppContext) {
|
||||
let (mut cx, root) = first_launch(cx);
|
||||
let cx = &mut cx;
|
||||
root.update(cx, |root, cx| {
|
||||
root.screen = Screen::Page;
|
||||
cx.notify();
|
||||
});
|
||||
// Centre of the third action button, title-bar drag area until an update is ready.
|
||||
let update = point(BUTTON_WIDTH * 2.5, BAR_HEIGHT / 2.);
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
cx.simulate_click(update, Modifiers::none());
|
||||
assert!(root.read_with(cx, |root, _| root.screen == Screen::Page));
|
||||
|
||||
let form = root.read_with(cx, |root, _| root.form.clone());
|
||||
form.update(cx, |form, cx| {
|
||||
let checked = UpdateChecked {
|
||||
channel: UpdateChannel::Stable,
|
||||
ready: Some("1.0.1".into()),
|
||||
};
|
||||
form.update_checked(checked, cx);
|
||||
});
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
cx.simulate_click(update, Modifiers::none());
|
||||
assert!(root.read_with(cx, |root, _| root.screen == Screen::Settings));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn settings_in_the_title_bar_respects_the_initial_key_prompt(cx: &mut TestAppContext) {
|
||||
let (mut cx, root) = first_launch(cx);
|
||||
let cx = &mut cx;
|
||||
// Centre of the second action button.
|
||||
let settings = point(BUTTON_WIDTH * 1.5, BAR_HEIGHT / 2.);
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use arena_tracker_core::UpdateChannel;
|
||||
use base64::prelude::{BASE64_STANDARD, Engine};
|
||||
|
||||
/// This executable's release version; `None` for a development build, which never updates.
|
||||
pub const VERSION: Option<&str> = option_env!("ARENA_RELEASE_VERSION");
|
||||
const CHANNEL: Option<&str> = option_env!("ARENA_RELEASE_CHANNEL");
|
||||
const PUBLIC_KEY: Option<&str> = option_env!("ARENA_RELEASE_PUBLIC_KEY");
|
||||
/// Public: read without a Gitea account or token.
|
||||
const RELEASES: &str = "https://gitea.nessar.fr/api/v1/repos/nessar/arena-tracker/releases";
|
||||
|
||||
/// The Windows installer invokes these fast callbacks and waits for the process to exit.
|
||||
/// The SDK's ordinary startup path opens cached packages even with auto-apply disabled.
|
||||
pub fn handle_command() {
|
||||
@@ -31,9 +39,9 @@ pub fn handle_command() {
|
||||
/// Checks a release folder with the identity this executable was built with.
|
||||
fn verify_release(dir: &Path) -> Result<(), String> {
|
||||
let (Some(channel), Some(version), Some(key), Some(commit)) = (
|
||||
option_env!("ARENA_RELEASE_CHANNEL"),
|
||||
option_env!("ARENA_RELEASE_VERSION"),
|
||||
option_env!("ARENA_RELEASE_PUBLIC_KEY"),
|
||||
CHANNEL,
|
||||
VERSION,
|
||||
PUBLIC_KEY,
|
||||
option_env!("ARENA_RELEASE_COMMIT"),
|
||||
) else {
|
||||
return Err("Exécutable construit sans identité de version.".into());
|
||||
@@ -46,3 +54,24 @@ fn verify_release(dir: &Path) -> Result<(), String> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The channel followed until the player chooses one: the installed version's, Stable for a
|
||||
/// development build.
|
||||
pub fn installed_channel() -> UpdateChannel {
|
||||
if CHANNEL == Some("beta") {
|
||||
UpdateChannel::Beta
|
||||
} else {
|
||||
UpdateChannel::Stable
|
||||
}
|
||||
}
|
||||
|
||||
/// Keeps the newest release of `channel` downloaded and authenticated in
|
||||
/// `%LOCALAPPDATA%\arena-tracker\updates`, outside the installation, 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 (version, key) = (VERSION?, BASE64_STANDARD.decode(PUBLIC_KEY?).ok()?);
|
||||
let dir = PathBuf::from(std::env::var_os("LOCALAPPDATA")?).join("arena-tracker/updates");
|
||||
arena_tracker_core::download_update(RELEASES, &dir, &key, channel, version)
|
||||
.ok()
|
||||
.flatten()
|
||||
}
|
||||
+189
-4
@@ -4,7 +4,7 @@ use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use arena_tracker_core::{Config, Error, Preferences, RiotApi, ThemePreference};
|
||||
use arena_tracker_core::{Config, Error, Preferences, RiotApi, ThemePreference, UpdateChannel};
|
||||
use gpui_kit::base::async_util::{Sender, unbounded};
|
||||
use gpui_kit::component::button::{Button, ButtonVariants as _};
|
||||
use gpui_kit::component::input::{Input, InputEvent, InputState};
|
||||
@@ -13,7 +13,9 @@ use gpui_kit::component::switch::Switch;
|
||||
use gpui_kit::component::{ActiveTheme as _, StyledExt as _, Theme, ThemeMode};
|
||||
use gpui_kit::*;
|
||||
|
||||
use crate::release;
|
||||
use crate::tray::{Tray, UNAVAILABLE};
|
||||
use crate::worker::{RefreshGate, UpdateChecked, spawn_update_check};
|
||||
|
||||
const PLACEHOLDER_SAVED: &str = "Clé enregistrée";
|
||||
const PLACEHOLDER_EMPTY: &str = "Clé API Riot";
|
||||
@@ -22,6 +24,12 @@ const THEMES: [(ThemePreference, &str); 3] = [
|
||||
(ThemePreference::Light, "Clair"),
|
||||
(ThemePreference::Dark, "Sombre"),
|
||||
];
|
||||
const CHANNELS: [(UpdateChannel, &str); 2] = [
|
||||
(UpdateChannel::Stable, "Stable"),
|
||||
(UpdateChannel::Beta, "Bêta"),
|
||||
];
|
||||
const STABLE_AFTER_BETA: &str =
|
||||
"La bêta installée reste en place jusqu’à une version stable plus récente.";
|
||||
|
||||
fn theme_mode(preference: ThemePreference, system: ThemeMode) -> ThemeMode {
|
||||
match preference {
|
||||
@@ -84,6 +92,13 @@ impl KeyStore {
|
||||
pub enum KeyEvent {
|
||||
Saved,
|
||||
Back,
|
||||
/// An update became ready or stopped being ready: the title bar shows it.
|
||||
UpdateReady,
|
||||
}
|
||||
|
||||
/// The saved choice, or the installed version's channel until the player chooses.
|
||||
fn channel(preferences: Preferences) -> UpdateChannel {
|
||||
(preferences.update_channel).unwrap_or_else(release::installed_channel)
|
||||
}
|
||||
|
||||
pub struct KeyForm {
|
||||
@@ -96,8 +111,14 @@ pub struct KeyForm {
|
||||
tray: Option<Rc<Tray>>,
|
||||
/// The tray reports here that it showed its one-time notice.
|
||||
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.
|
||||
update_checks: RefreshGate,
|
||||
updates: Sender<UpdateChecked>,
|
||||
_subscriptions: [Subscription; 2],
|
||||
_notice_listener: Task<()>,
|
||||
_update_listener: Task<()>,
|
||||
}
|
||||
|
||||
impl EventEmitter<KeyEvent> for KeyForm {}
|
||||
@@ -126,6 +147,17 @@ impl KeyForm {
|
||||
}
|
||||
}
|
||||
});
|
||||
let (updates, results) = unbounded();
|
||||
let update_listener = cx.spawn(async move |this, cx| {
|
||||
while let Ok(checked) = results.recv().await {
|
||||
if this
|
||||
.update(cx, |form, cx| form.update_checked(checked, cx))
|
||||
.is_err()
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
let notice = (!store.config.tray_notice_shown).then(|| notice_shown.clone());
|
||||
let tray = Tray::install_saved(window, preferences.close_to_tray, notice, cx);
|
||||
let appearance = cx.observe_window_appearance(window, |this, window, cx| {
|
||||
@@ -147,7 +179,7 @@ impl KeyForm {
|
||||
this.save(window, cx);
|
||||
}
|
||||
});
|
||||
KeyForm {
|
||||
let mut form = KeyForm {
|
||||
first_launch,
|
||||
store,
|
||||
input,
|
||||
@@ -155,11 +187,57 @@ impl KeyForm {
|
||||
preference_error: None,
|
||||
tray,
|
||||
notice_shown,
|
||||
ready: None,
|
||||
update_checks: RefreshGate::default(),
|
||||
updates,
|
||||
_subscriptions: [subscription, appearance],
|
||||
_notice_listener: notice_listener,
|
||||
_update_listener: update_listener,
|
||||
};
|
||||
form.check_updates();
|
||||
form
|
||||
}
|
||||
|
||||
pub fn update_ready(&self) -> bool {
|
||||
self.ready.is_some()
|
||||
}
|
||||
|
||||
/// Checks the chosen channel in the background, after the running check if there is one.
|
||||
fn check_updates(&mut self) {
|
||||
if release::VERSION.is_some() && self.update_checks.request() {
|
||||
let channel = channel(self.store.config.preferences);
|
||||
spawn_update_check(channel, self.updates.clone());
|
||||
}
|
||||
}
|
||||
|
||||
/// Only a check of the channel chosen now can make an update ready.
|
||||
pub(crate) fn update_checked(&mut self, checked: UpdateChecked, cx: &mut Context<Self>) {
|
||||
if self.update_checks.finished() {
|
||||
let channel = channel(self.store.config.preferences);
|
||||
spawn_update_check(channel, self.updates.clone());
|
||||
}
|
||||
if checked.channel == channel(self.store.config.preferences) {
|
||||
let ready = (checked.ready)
|
||||
.map(|version| format!("Mise à jour prête : version {version}").into());
|
||||
self.set_ready(ready, cx);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_ready(&mut self, ready: Option<SharedString>, cx: &mut Context<Self>) {
|
||||
if self.ready != ready {
|
||||
self.ready = ready;
|
||||
cx.emit(KeyEvent::UpdateReady);
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/// « Mise à jour prête », or why an installed beta stays on the stable channel.
|
||||
fn update_status(&self) -> Option<SharedString> {
|
||||
let beta = release::VERSION.is_some_and(|version| version.contains("-beta."));
|
||||
let stable = channel(self.store.config.preferences) == UpdateChannel::Stable;
|
||||
(self.ready.clone()).or_else(|| (beta && stable).then_some(STABLE_AFTER_BETA.into()))
|
||||
}
|
||||
|
||||
/// Back to an empty field, as when the form is opened again.
|
||||
pub fn reset(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.error = None;
|
||||
@@ -191,6 +269,11 @@ impl KeyForm {
|
||||
Some("Impossible d’enregistrer les préférences.")
|
||||
} else {
|
||||
apply_theme(preferences.theme, window, cx);
|
||||
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_updates();
|
||||
}
|
||||
None
|
||||
};
|
||||
if !self.store.config.preferences.close_to_tray
|
||||
@@ -203,7 +286,7 @@ impl KeyForm {
|
||||
|
||||
fn preferences(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let preferences = self.store.config.preferences;
|
||||
let danger = cx.theme().danger;
|
||||
let (muted, danger) = (cx.theme().muted_foreground, cx.theme().danger);
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_3()
|
||||
@@ -243,6 +326,35 @@ impl KeyForm {
|
||||
})),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_1()
|
||||
.child("Mises à jour")
|
||||
.child(
|
||||
RadioGroup::horizontal("update-channel")
|
||||
.children(CHANNELS.map(|(_, label)| label))
|
||||
.selected_index(
|
||||
CHANNELS
|
||||
.iter()
|
||||
.position(|(choice, _)| *choice == channel(preferences)),
|
||||
)
|
||||
.on_change(cx.listener(|this, index: &usize, window, cx| {
|
||||
this.set_preferences(
|
||||
Preferences {
|
||||
update_channel: Some(CHANNELS[*index].0),
|
||||
..this.store.config.preferences
|
||||
},
|
||||
window,
|
||||
cx,
|
||||
);
|
||||
})),
|
||||
)
|
||||
.children(
|
||||
self.update_status()
|
||||
.map(|status| div().text_color(muted).child(status)),
|
||||
),
|
||||
)
|
||||
.children(
|
||||
self.preference_error
|
||||
.map(|error| div().text_color(danger).child(error)),
|
||||
@@ -346,7 +458,80 @@ impl Render for KeyForm {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{ThemeMode, ThemePreference, theme_mode};
|
||||
use std::sync::Arc;
|
||||
|
||||
use arena_tracker_core::{Config, Preferences, RiotApi, UpdateChannel};
|
||||
use gpui_kit::{AppContext as _, TestAppContext, VisualTestContext, WindowOptions};
|
||||
|
||||
use super::{KeyForm, KeyStore, ThemeMode, ThemePreference, theme_mode};
|
||||
use crate::worker::UpdateChecked;
|
||||
|
||||
#[gpui::test]
|
||||
fn the_chosen_channel_is_saved_and_only_its_check_makes_an_update_ready(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
cx.update(gpui_kit::init);
|
||||
let dir = std::env::temp_dir().join(format!("arena-channel-{}", std::process::id()));
|
||||
let path = dir.join("config.toml");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
let (window, form) = cx.update(|cx| {
|
||||
let config = Config::load_or_default(&path).unwrap();
|
||||
let api = Arc::new(RiotApi::new(String::new(), &config.region));
|
||||
let store = KeyStore::new(path.clone(), 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 choose = |channel, cx: &mut VisualTestContext| {
|
||||
cx.update(|window, cx| {
|
||||
form.update(cx, |form, cx| {
|
||||
let preferences = Preferences {
|
||||
update_channel: Some(channel),
|
||||
..form.store.config.preferences
|
||||
};
|
||||
form.set_preferences(preferences, window, cx);
|
||||
})
|
||||
})
|
||||
};
|
||||
let saved = |channel| Preferences {
|
||||
update_channel: Some(channel),
|
||||
..Preferences::default()
|
||||
};
|
||||
|
||||
choose(UpdateChannel::Beta, cx);
|
||||
let loaded = Config::load(&path).unwrap().preferences;
|
||||
assert_eq!(loaded, saved(UpdateChannel::Beta));
|
||||
|
||||
form.update(cx, |form, cx| {
|
||||
// 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()),
|
||||
};
|
||||
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()),
|
||||
};
|
||||
form.update_checked(checked, cx);
|
||||
assert!(form.update_ready());
|
||||
assert_eq!(
|
||||
form.update_status().as_deref(),
|
||||
Some("Mise à jour prête : version 1.1.0-beta.3")
|
||||
);
|
||||
});
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
|
||||
choose(UpdateChannel::Stable, cx);
|
||||
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();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn system_tracks_the_current_appearance_and_manual_choices_override_it() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use gpui_kit::base::Button as BaseButton;
|
||||
use gpui_kit::component::tooltip::Tooltip;
|
||||
use gpui_kit::component::{ActiveTheme as _, Icon, IconName, Sizable as _, StyledExt as _};
|
||||
use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::*;
|
||||
use windows::Win32::{
|
||||
Foundation::{LPARAM, WPARAM},
|
||||
@@ -11,7 +12,8 @@ use windows::Win32::{
|
||||
pub(crate) const BUTTON_WIDTH: Pixels = px(46.);
|
||||
pub(crate) const BAR_HEIGHT: Pixels = px(32.);
|
||||
|
||||
// Six button widths plus room for the centered title, in narrow Windows Snap zones.
|
||||
// Six button widths plus room for the centered title, in narrow Windows Snap zones. A ready
|
||||
// update adds a seventh in place of the title's left padding.
|
||||
pub const MIN_WINDOW_SIZE: Size<Pixels> = size(px(380.), px(216.));
|
||||
|
||||
/// A flat button filling the bar's height, so that when the window is maximized the screen
|
||||
@@ -60,13 +62,32 @@ pub fn settings_button(enabled: bool, cx: &App) -> BaseButton {
|
||||
action_button("settings", IconName::Settings, "Paramètres", enabled, cx)
|
||||
}
|
||||
|
||||
/// Shown only while an update is ready, in green so it is noticed.
|
||||
pub fn update_button(enabled: bool, cx: &App) -> BaseButton {
|
||||
let button = action_button(
|
||||
"update",
|
||||
IconName::ArrowUp,
|
||||
"Mise à jour prête",
|
||||
enabled,
|
||||
cx,
|
||||
);
|
||||
if enabled {
|
||||
button.text_color(cx.theme().success)
|
||||
} else {
|
||||
button
|
||||
}
|
||||
}
|
||||
|
||||
/// `update` is the update button, while one is ready.
|
||||
pub fn title_bar(
|
||||
refresh: BaseButton,
|
||||
settings: BaseButton,
|
||||
update: Option<BaseButton>,
|
||||
window: &Window,
|
||||
cx: &App,
|
||||
) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let balanced = update.is_some();
|
||||
let (icon, label) = if window.is_maximized() {
|
||||
(IconName::WindowRestore, "Restaurer")
|
||||
} else {
|
||||
@@ -82,14 +103,15 @@ pub fn title_bar(
|
||||
.border_color(theme.title_bar_border)
|
||||
.child(refresh)
|
||||
.child(settings)
|
||||
.children(update)
|
||||
.child(
|
||||
div()
|
||||
.h_flex()
|
||||
.h_full()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
// The third button on the right is balanced by this padding.
|
||||
.pl(BUTTON_WIDTH)
|
||||
// Without the update button, this padding balances the third button on the right.
|
||||
.when(!balanced, |title| title.pl(BUTTON_WIDTH))
|
||||
.justify_center()
|
||||
.text_xs()
|
||||
.window_control_area(WindowControlArea::Drag)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Background threads: following the game client, refreshing and computing statistics.
|
||||
//! They talk to the page through `Msg`.
|
||||
//! Background threads: following the game client, refreshing, computing statistics and
|
||||
//! downloading updates. They talk to the page through `Msg`, and to the settings through
|
||||
//! `UpdateChecked`.
|
||||
|
||||
use std::panic::{AssertUnwindSafe, catch_unwind};
|
||||
use std::sync::Arc;
|
||||
@@ -7,7 +8,7 @@ use std::thread;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use arena_tracker_core::{
|
||||
ChampSelect, ClientEvent, Scope, Statistics, Status, SyncProgress, Tracker,
|
||||
ChampSelect, ClientEvent, Scope, Statistics, Status, SyncProgress, Tracker, UpdateChannel,
|
||||
};
|
||||
use gpui_kit::base::async_util::Sender;
|
||||
|
||||
@@ -103,7 +104,11 @@ fn lower_priority() {
|
||||
}
|
||||
|
||||
/// Runs `body` on its own thread; a panic is reported instead of leaving the page waiting.
|
||||
fn spawn_guarded(tx: Sender<Msg>, on_panic: Msg, body: impl FnOnce(&Sender<Msg>) + Send + 'static) {
|
||||
fn spawn_guarded<T: Send + 'static>(
|
||||
tx: Sender<T>,
|
||||
on_panic: T,
|
||||
body: impl FnOnce(&Sender<T>) + Send + 'static,
|
||||
) {
|
||||
thread::spawn(move || {
|
||||
lower_priority();
|
||||
if catch_unwind(AssertUnwindSafe(|| body(&tx))).is_err() {
|
||||
@@ -192,6 +197,24 @@ 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.
|
||||
pub struct UpdateChecked {
|
||||
pub channel: UpdateChannel,
|
||||
pub ready: Option<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,
|
||||
};
|
||||
spawn_guarded(tx, crashed, move |tx| {
|
||||
let ready = crate::release::download_update(channel);
|
||||
let _ = tx.try_send(UpdateChecked { channel, ready });
|
||||
});
|
||||
}
|
||||
|
||||
/// The refresh button: one sync of the Account being kept up to date.
|
||||
pub fn spawn_refresh(tracker: Arc<Tracker>, tx: Sender<Msg>) {
|
||||
spawn_guarded(tx, Msg::RefreshCrashed, move |tx| {
|
||||
|
||||
Reference in new issue
Block a user