From e073592af96c77c4b23976eb5a4a8af889b1fa91 Mon Sep 17 00:00:00 2001 From: vrubelroman Date: Wed, 28 Oct 2026 03:28:16 +0300 Subject: [PATCH] Online databases update on their own; release 2.0.0 At the start and on coming back after ten minutes or more, every database downloaded from Lichess and Chess.com fetches the games played since, one after another (the sites ask for one export at a time), on the desktop and on Android. Only new games are told. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 12 +++-- Cargo.lock | 22 ++++----- Cargo.toml | 2 +- .../vrubelroman/chesspenguin/MainActivity.kt | 2 + .../chesspenguin/data/OnlineDownloads.kt | 39 +++++++++++++--- .../chesspenguin/ui/DatabasesScreen.kt | 2 + apps/desktop/src/app.rs | 37 ++++++++++++++- apps/desktop/src/online_ui.rs | 46 +++++++++++++++++-- ...thub.vrubelroman.chessPenguin.metainfo.xml | 5 ++ 9 files changed, 139 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cfb9ee4..e1e9df2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,17 +4,21 @@ All notable changes are listed here. Versions follow [Semantic Versioning](https ## [Unreleased] +## [2.0.0] — 2026-10-28 + +- The databases downloaded from Lichess and Chess.com get the games played since on their + own: at the start of the program and when one comes back to it after ten minutes or + more, one database after another, on the desktop and on Android. Only new games are + told («+N»); no message when there are none or the network is off. - Desktop: the notation no longer jumps on every move with the engine on. Between two positions the old lines go at once and the new ones come a frame later; the engine panel now keeps their room, so what is below it stays still. - - The moves of the notation and the signs after them are bold (Ubuntu Bold on the desktop, - the bold system font on Android), and so are the marks in the circles on the board. In Russian the report's rows read «Блестящий» and «Замечательный». - + the bold system font on Android), and so are the marks in the circles on the board. In + Russian the report's rows read «Блестящий» and «Замечательный». - Android: the dark theme by default (it was the system's); a theme chosen before stays. Android is told the app's own theme, so the window and the splash screen before the app draws match it (no white flash before a dark app on a light phone). - - Game review marks brilliant moves (!!, a sound piece sacrifice) and great moves (!, the only good move that turns the game), next to inaccuracies, mistakes and blunders: in the report, the notation, the graph and on the board; written to the game as $3 and $1. The diff --git a/Cargo.lock b/Cargo.lock index 3592731..7856ae4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -768,7 +768,7 @@ dependencies = [ [[package]] name = "chess-core" -version = "1.9.4" +version = "2.0.0" dependencies = [ "encoding_rs", "pgn-reader", @@ -778,7 +778,7 @@ dependencies = [ [[package]] name = "chess-import" -version = "1.9.4" +version = "2.0.0" dependencies = [ "chess-core", "encoding_rs", @@ -791,7 +791,7 @@ dependencies = [ [[package]] name = "chesspenguin" -version = "1.9.4" +version = "2.0.0" dependencies = [ "arboard", "base64 0.22.1", @@ -1668,7 +1668,7 @@ dependencies = [ [[package]] name = "game-review" -version = "1.9.4" +version = "2.0.0" dependencies = [ "chess-core", "serde", @@ -2385,7 +2385,7 @@ dependencies = [ [[package]] name = "maia" -version = "1.9.4" +version = "2.0.0" dependencies = [ "serde_json", "shakmaty", @@ -2462,7 +2462,7 @@ dependencies = [ [[package]] name = "mobile-api" -version = "1.9.4" +version = "2.0.0" dependencies = [ "chess-core", "chess-import", @@ -3061,7 +3061,7 @@ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" [[package]] name = "online-games" -version = "1.9.4" +version = "2.0.0" dependencies = [ "chess-core", "serde", @@ -3328,7 +3328,7 @@ checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" [[package]] name = "play" -version = "1.9.4" +version = "2.0.0" dependencies = [ "chess-core", "getrandom 0.3.4", @@ -3615,7 +3615,7 @@ dependencies = [ [[package]] name = "releases" -version = "1.9.4" +version = "2.0.0" dependencies = [ "serde_json", "ureq", @@ -4610,7 +4610,7 @@ dependencies = [ [[package]] name = "trainer" -version = "1.9.4" +version = "2.0.0" dependencies = [ "chess-core", "chrono", @@ -4652,7 +4652,7 @@ checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "uci" -version = "1.9.4" +version = "2.0.0" dependencies = [ "libc", "thiserror 2.0.21", diff --git a/Cargo.toml b/Cargo.toml index 5cd6485..ede3ac0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ members = [ ] [workspace.package] -version = "1.9.4" +version = "2.0.0" edition = "2024" rust-version = "1.97" license = "GPL-3.0-or-later" diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/MainActivity.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/MainActivity.kt index 500f4fd..ea75c9a 100644 --- a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/MainActivity.kt +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/MainActivity.kt @@ -111,6 +111,8 @@ class MainActivity : ComponentActivity() { val updates = (application as ChessPenguinApp).updates updates.foreground = true updates.checkIfDue() + // The downloaded databases get their new games (at most every ten minutes). + (application as ChessPenguinApp).downloads.updateAllQuietly() } override fun onResume() { diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/OnlineDownloads.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/OnlineDownloads.kt index 02f139e..a0e5b4a 100644 --- a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/OnlineDownloads.kt +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/data/OnlineDownloads.kt @@ -2,6 +2,7 @@ package io.github.vrubelroman.chesspenguin.data import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow @@ -22,8 +23,9 @@ import java.util.concurrent.ConcurrentHashMap /// database did not exist before it (its first download). data class DownloadView(val accounts: List, val state: DownloadState, val fresh: Boolean = false) -/// A download that has ended, for the snackbar of the screen that is shown then. -data class Finished(val id: String, val name: String, val view: DownloadView, val games: Int) +/// A download that has ended, for the snackbar of the screen that is shown then; +/// `quiet` when the app started it on its own (said only when it added games). +data class Finished(val id: String, val name: String, val view: DownloadView, val games: Int, val quiet: Boolean = false) /// The downloads of games from Lichess and Chess.com (android-ui.md §23). They belong to /// the app, not to a screen: leaving the screen does not stop them, and the list of @@ -44,13 +46,15 @@ class OnlineDownloads(private val library: Library, private val scope: Coroutine /// Starts fetching the new games of `accounts` into the database file `path` (put on /// the list at once); one download per database. Returns the database's entry. - fun start(accounts: List, path: String): DbEntry { + fun start(accounts: List, path: String): DbEntry = run(accounts, path, false).first + + private fun run(accounts: List, path: String, quiet: Boolean): Pair { val fresh = !File(path).exists() val entry = library.addOnline(File(path)) - if (running.containsKey(entry.id)) return entry + if (running.containsKey(entry.id)) return entry to null val d = OnlineDownload.start(accounts, path) running[entry.id] = d - scope.launch(Dispatchers.IO) { + val job = scope.launch(Dispatchers.IO) { while (true) { val s = d.state() _views.update { it + (entry.id to DownloadView(accounts, s, fresh)) } @@ -64,9 +68,9 @@ class OnlineDownloads(private val library: Library, private val scope: Coroutine // No game at all (no standard chess there, or it failed at once): not a database. val name = library.entry(entry.id)?.name ?: entry.name if (games == 0) library.dropEmpty(entry.id) else library.downloaded(entry.id, games, info?.updated) - _views.value[entry.id]?.let { _finished.tryEmit(Finished(entry.id, name, it, games)) } + _views.value[entry.id]?.let { _finished.tryEmit(Finished(entry.id, name, it, games, quiet)) } } - return entry + return entry to job } /// Fetches the games played since the last download of a database. @@ -76,6 +80,26 @@ class OnlineDownloads(private val library: Library, private val scope: Coroutine start(info.accounts, path) } + /// Every downloaded database gets the games played since, one after another (the + /// sites ask for one export at a time): at the app's start and when it comes back to + /// the screen, at most every [AUTO_EVERY_MS]. + fun updateAllQuietly() { + val now = System.currentTimeMillis() + if (auto?.isActive == true || now - lastAuto < AUTO_EVERY_MS) return + lastAuto = now + auto = scope.launch(Dispatchers.IO) { + for (e in library.entries.value.filter { it.source == Source.Online }) { + if (isRunning(e.id)) continue + val path = library.onlineFile(e).path + val info = onlineDatabase(path) ?: continue + run(info.accounts, path, true).second?.join() + } + } + } + + private var lastAuto = 0L + private var auto: Job? = null + /// Stops a download; what it fetched stays. fun cancel(id: String) { running[id]?.cancel() @@ -85,5 +109,6 @@ class OnlineDownloads(private val library: Library, private val scope: Coroutine private companion object { const val POLL_MS = 400L + const val AUTO_EVERY_MS = 10 * 60 * 1000L } } diff --git a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/DatabasesScreen.kt b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/DatabasesScreen.kt index 156cf6e..efb52a8 100644 --- a/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/DatabasesScreen.kt +++ b/androidApp/app/src/main/java/io/github/vrubelroman/chesspenguin/ui/DatabasesScreen.kt @@ -815,6 +815,8 @@ private fun pastedName(db: Database, dated: String): String { fun finishedText(res: android.content.res.Resources, f: Finished): String? { val s = f.view.state val games = res.getQuantityString(R.plurals.games_count, f.games, groupDigits(f.games)) + // An update of its own speaks only of new games. + if (f.quiet && (s.failure != null || s.added == 0UL)) return null s.failure?.let { return res.getString(R.string.online_snack_failed, f.name, problemShort(res, it)) } return when { s.cancelled || f.games == 0 -> null diff --git a/apps/desktop/src/app.rs b/apps/desktop/src/app.rs index a7a7026..1a60d7b 100644 --- a/apps/desktop/src/app.rs +++ b/apps/desktop/src/app.rs @@ -181,6 +181,9 @@ pub enum CloseIntent { ReturnToPrevious, } +/// The online databases are updated on their own at most this often (s). +const ONLINE_EVERY: f64 = 600.0; + pub struct App { settings: Settings, settings_dirty: bool, @@ -219,6 +222,10 @@ pub struct App { offer_hook_done: bool, /// Lichess / Chess.com: which answered at start, and the download window. online_probe: crate::online::Probe, + /// When the online databases were last updated on their own (egui time, s), and + /// whether the window had the focus in the last frame. + online_updated_at: f64, + was_focused: bool, online: crate::online_ui::OnlineDialog, /// Translating comments: the setup and consent windows, the ChatGPT sign-in. translation: crate::translate_ui::Hub, @@ -357,6 +364,12 @@ impl App { if !args.is_empty() { let _ = settings.save(); } + let online_dbs: Vec = settings + .databases + .iter() + .filter(|p| crate::online::is_online(p)) + .cloned() + .collect(); let (tx, rx) = channel(); let mut library = Library::new(ctx); // Read in the background: a missing file says so there (a lost network drive @@ -400,7 +413,14 @@ impl App { engine_offer: crate::engine_offer::EngineOffer::new(), offer_hook_done: false, online_probe: crate::online::Probe::start(ctx), - online: crate::online_ui::OnlineDialog::from_env(), + online_updated_at: 0.0, + was_focused: true, + online: { + // Every downloaded database gets the games played since, at each start. + let mut d = crate::online_ui::OnlineDialog::from_env(); + d.update_quietly(online_dbs); + d + }, translation: Default::default(), allow_quit: false, applied_dark: None, @@ -2976,6 +2996,21 @@ impl eframe::App for App { } } + // Back to the window after a while: the downloaded databases get the games + // played since (at the start they did already). + let now = ctx.input(|i| i.time); + let focused = ctx.input(|i| i.viewport().focused).unwrap_or(true); + if focused && !self.was_focused && now - self.online_updated_at > ONLINE_EVERY { + self.online_updated_at = now; + self.online.update_quietly( + self.settings + .databases + .iter() + .filter(|p| crate::online::is_online(p)) + .cloned(), + ); + } + self.was_focused = focused; let events = self.online.show(&ctx, &self.online_probe); for e in events { match e { diff --git a/apps/desktop/src/online_ui.rs b/apps/desktop/src/online_ui.rs index 853cbb9..249cf18 100644 --- a/apps/desktop/src/online_ui.rs +++ b/apps/desktop/src/online_ui.rs @@ -38,6 +38,9 @@ struct Job { /// When Stop was pressed: a download that does not stop soon (a stalled /// connection) leaves the list; its database stays claimed until it ends. stopped: Option, + /// Started on its own at the program's start: says something only when it added + /// games (no "no new games" on every start, no error over a network that is off). + quiet: bool, } /// A finished download. @@ -71,6 +74,9 @@ pub struct OnlineDialog { auto_download: bool, /// Put the cursor into the nickname field (the window was just opened). focus: bool, + /// Online databases to update on their own (at the start), one after another: the + /// sites ask for one export at a time. + queued: std::collections::VecDeque, } /// Where the found accounts go (see [`online_games::targets`]). @@ -208,6 +214,32 @@ impl OnlineDialog { self.start(state.accounts(), path.to_owned(), true, ctx); } + /// Updates these online databases on their own, one after another, once a site + /// answers (the program's start: every downloaded database gets its new games). + pub fn update_quietly(&mut self, paths: impl IntoIterator) { + for p in paths { + if !self.queued.contains(&p) { + self.queued.push_back(p); + } + } + } + + /// The next queued update, when nothing else is being downloaded. + fn next_queued(&mut self, probe: &Probe, ctx: &egui::Context) { + if !self.jobs.is_empty() || !probe.any() { + return; + } + while let Some(path) = self.queued.pop_front() { + if let Some(state) = online::State::load(&path) { + self.start(state.accounts(), path, true, ctx); + if let Some(j) = self.jobs.last_mut() { + j.quiet = true; + } + return; + } + } + } + fn start(&mut self, accounts: Vec, path: PathBuf, update: bool, ctx: &egui::Context) { if self.jobs.iter().any(|j| j.path == path) { return; @@ -229,6 +261,7 @@ impl OnlineDialog { status, work, stopped: None, + quiet: false, }); } } @@ -281,10 +314,14 @@ impl OnlineDialog { platform, result, }; - if !self.open { - events.push(OnlineEvent::Message(outcome_text(&outcome))); + // An update of its own speaks only of new games. + let worth = !job.quiet || outcome.result.as_ref().is_ok_and(|d| d.added > 0); + if worth { + if !self.open { + events.push(OnlineEvent::Message(outcome_text(&outcome))); + } + self.results.push(outcome); } - self.results.push(outcome); } else if self.jobs[i] .stopped .is_some_and(|t| t.elapsed() > std::time::Duration::from_secs(10)) @@ -294,7 +331,8 @@ impl OnlineDialog { i += 1; } } - if !self.jobs.is_empty() || self.lookup.is_some() { + self.next_queued(probe, ctx); + if !self.jobs.is_empty() || self.lookup.is_some() || !self.queued.is_empty() { ctx.request_repaint_after(std::time::Duration::from_millis(250)); } if !self.open { diff --git a/packaging/io.github.vrubelroman.chessPenguin.metainfo.xml b/packaging/io.github.vrubelroman.chessPenguin.metainfo.xml index c606c76..02af45b 100644 --- a/packaging/io.github.vrubelroman.chessPenguin.metainfo.xml +++ b/packaging/io.github.vrubelroman.chessPenguin.metainfo.xml @@ -43,6 +43,11 @@ BoardGame + + +

The game review marks brilliant (!!) and great (!) moves, calibrated on chess.com, in the notation, the report and on the board, now also on Android; move marks in a clearer palette, bold moves in the notation. Downloaded Lichess and Chess.com databases get new games on their own. The notation no longer jumps with the engine on; Android starts in the dark theme.

+
+

Database cards show how many games each holds, the strength in the play dialog follows the slider's handle, the game buttons are even, and translation of annotations is faster.