Tighten module organization after second review (#103)
CI / core (pull_request) Successful in 1m35s

This commit is contained in:
nessar committed 2026-11-22 18:06:44 +01:00
1 parent e56da040e5
commit 242ecc4f28
31 files changed
+545 -492

No files matched your search

+13 -82
View File
@@ -1,6 +1,10 @@
//! Keeping the active Account up to date by following the game client.
mod pending;
mod progress;
mod status;
pub use status::{ProgressCheck, Status, UpdateProblem};
use std::sync::{MutexGuard, PoisonError};
use std::thread;
use std::time::Duration;
@@ -8,7 +12,7 @@ use std::time::Duration;
use rusqlite::OptionalExtension;
use crate::client::{ClientEvent, ClientSnapshot, GameClientSource, GamePhase, Gameflow};
use crate::error::{Error, SourceError};
use crate::error::Error;
use crate::model::{Account, FollowedMatch, SyncProgress, SyncReport};
use crate::seasons::Season;
use crate::tracker::{Tracker, account_from_row};
@@ -27,86 +31,6 @@ const WAIT_OTHERWISE: Duration = Duration::from_secs(60);
/// ended before that time, and started longer ago than this: an Arena game lasts longer.
const CLOCK_SLACK_MS: i64 = 5 * 60_000;
/// Why the last update did not (fully) happen.
#[derive(Debug, Clone, PartialEq)]
pub enum UpdateProblem {
MissingKey,
InvalidKey,
Network,
RateLimited,
/// Client absent and no Account known yet.
NoAccount,
/// A finished Arena game is not available from the Riot API yet.
MatchPending,
Other(String),
}
impl UpdateProblem {
/// The French banner text.
pub fn message(&self) -> String {
match self {
UpdateProblem::MissingKey => {
"Aucune clé API Riot n'est configurée : ajoutez-la dans les Paramètres.".into()
}
UpdateProblem::InvalidKey => {
"La clé API Riot est refusée (invalide ou expirée) : renouvelez-la dans les Paramètres."
.into()
}
UpdateProblem::Network => {
"L'API Riot est injoignable : vérifiez votre connexion.".into()
}
UpdateProblem::RateLimited => {
"L'API Riot limite les requêtes : la mise à jour reprendra plus tard.".into()
}
UpdateProblem::NoAccount => {
"Aucun Compte connu : lancez le client de League of Legends et connectez-vous."
.into()
}
UpdateProblem::MatchPending => {
"La dernière Partie n'est pas encore disponible chez Riot : actualisez plus tard pour l'importer."
.into()
}
UpdateProblem::Other(reason) => format!("Mise à jour impossible : {reason}"),
}
}
}
impl From<&Error> for UpdateProblem {
fn from(error: &Error) -> Self {
match error {
Error::Source(SourceError::MissingKey) => UpdateProblem::MissingKey,
Error::Source(SourceError::InvalidKey) => UpdateProblem::InvalidKey,
Error::Source(SourceError::Network(_)) => UpdateProblem::Network,
Error::Source(SourceError::RateLimited { .. }) => UpdateProblem::RateLimited,
other => UpdateProblem::Other(other.to_string()),
}
}
}
/// The game's own count compared with the app's, for the current Season.
#[derive(Debug, Clone, Default, PartialEq)]
pub enum ProgressCheck {
#[default]
Absent,
Agrees(u32),
Differs {
app: usize,
official: u32,
},
}
/// What the interface needs to know besides statistics.
#[derive(Debug, Clone, PartialEq)]
pub struct Status {
/// As of the last `follow_client` round.
pub client_running: bool,
/// The signed-in Account while the client runs, otherwise the last active one.
pub updating: Option<Account>,
/// Outcome of the most recent update attempt; `None` after a success.
pub problem: Option<UpdateProblem>,
pub official_progress: ProgressCheck,
}
/// The Match of a finished Arena game, not stored yet.
struct Pending {
/// The client's id of that game, when it gave one.
@@ -144,7 +68,14 @@ pub fn riot_id(game_name: &str, tag_line: &str) -> String {
format!("{game_name}#{tag_line}")
}
/// Riot IDs differ in case only when they name the same Account.
/// Compare Riot IDs case-insensitively, including the tag line.
///
/// ```
/// use arena_tracker_core::same_riot_id;
///
/// assert!(same_riot_id("Étoile#EUW", "étoile#euw"));
/// assert!(!same_riot_id("Étoile#EUW", "Étoile#NA1"));
/// ```
pub fn same_riot_id(a: &str, b: &str) -> bool {
a.to_lowercase() == b.to_lowercase()
}
+82
View File
@@ -0,0 +1,82 @@
use crate::error::{Error, SourceError};
use crate::model::Account;
/// Why the last update did not (fully) happen.
#[derive(Debug, Clone, PartialEq)]
pub enum UpdateProblem {
MissingKey,
InvalidKey,
Network,
RateLimited,
/// Client absent and no Account known yet.
NoAccount,
/// A finished Arena game is not available from the Riot API yet.
MatchPending,
Other(String),
}
impl UpdateProblem {
/// The French banner text.
pub fn message(&self) -> String {
match self {
UpdateProblem::MissingKey => {
"Aucune clé API Riot n'est configurée : ajoutez-la dans les Paramètres.".into()
}
UpdateProblem::InvalidKey => {
"La clé API Riot est refusée (invalide ou expirée) : renouvelez-la dans les Paramètres."
.into()
}
UpdateProblem::Network => {
"L'API Riot est injoignable : vérifiez votre connexion.".into()
}
UpdateProblem::RateLimited => {
"L'API Riot limite les requêtes : la mise à jour reprendra plus tard.".into()
}
UpdateProblem::NoAccount => {
"Aucun Compte connu : lancez le client de League of Legends et connectez-vous."
.into()
}
UpdateProblem::MatchPending => {
"La dernière Partie n'est pas encore disponible chez Riot : actualisez plus tard pour l'importer."
.into()
}
UpdateProblem::Other(reason) => format!("Mise à jour impossible : {reason}"),
}
}
}
impl From<&Error> for UpdateProblem {
fn from(error: &Error) -> Self {
match error {
Error::Source(SourceError::MissingKey) => UpdateProblem::MissingKey,
Error::Source(SourceError::InvalidKey) => UpdateProblem::InvalidKey,
Error::Source(SourceError::Network(_)) => UpdateProblem::Network,
Error::Source(SourceError::RateLimited { .. }) => UpdateProblem::RateLimited,
other => UpdateProblem::Other(other.to_string()),
}
}
}
/// The game's own count compared with the app's, for the current Season.
#[derive(Debug, Clone, Default, PartialEq)]
pub enum ProgressCheck {
#[default]
Absent,
Agrees(u32),
Differs {
app: usize,
official: u32,
},
}
/// What the interface needs to know besides statistics.
#[derive(Debug, Clone, PartialEq)]
pub struct Status {
/// As of the last `follow_client` round.
pub client_running: bool,
/// The signed-in Account while the client runs, otherwise the last active one.
pub updating: Option<Account>,
/// Outcome of the most recent update attempt; `None` after a success.
pub problem: Option<UpdateProblem>,
pub official_progress: ProgressCheck,
}
+1
View File
@@ -1,4 +1,5 @@
use super::*;
use crate::error::SourceError;
use std::collections::HashSet;
use std::time::Duration;