Count installations that run: the update check goes through the site
The programs (desktop, Android) ask https://chess.vrubel.xyz/api/update for the latest release instead of GitHub, with a random id of the installation (made once, kept in the settings), the version and the platform; the site passes GitHub's answer on and keeps one row per installation and day (no IP; the country of the address). Without the site the programs ask GitHub, uncounted; with the update check off nothing is sent. /stats shows installations that ran today, in 7 and 30 days, in all and new ones, by platform and version. The texts about the update check and the site's privacy line say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
04bd7c08a1
commit
1edbbda368
30 changed files with 284 additions and 44 deletions
|
|
@ -5,7 +5,7 @@
|
|||
//! The check talks to GitHub (or to a test server in a debug build) and blocks: call it
|
||||
//! off the main thread.
|
||||
|
||||
use releases::{Release, VERSION, fetch_latest, fetch_sums, sum_in};
|
||||
use releases::{Release, VERSION, check_latest, fetch_latest, fetch_sums, sum_in};
|
||||
|
||||
/// GitHub's answer for the latest release (a debug build may ask a test server).
|
||||
#[uniffi::export]
|
||||
|
|
@ -59,11 +59,24 @@ pub enum ReleaseCheck {
|
|||
const LIGHT: &str = "-android-noengine.apk";
|
||||
const FULL: &str = "-android.apk";
|
||||
|
||||
/// Asks `api` for the latest release; a newer one comes with its APKs.
|
||||
/// Asks `api` (a test server) for the latest release; a newer one comes with its APKs.
|
||||
#[uniffi::export]
|
||||
pub fn check_release(api: String) -> ReleaseCheck {
|
||||
let client = format!("ChessPenguin/{VERSION} (Android)");
|
||||
let release = match fetch_latest(&api, &client) {
|
||||
checked(fetch_latest(&api, &client), &client)
|
||||
}
|
||||
|
||||
/// Asks the site for the latest release, counting this installation for the day (its
|
||||
/// random `install` id and `platform`: "android" or "android-noengine"); without the
|
||||
/// site, GitHub. A newer release comes with its APKs.
|
||||
#[uniffi::export]
|
||||
pub fn check_release_counted(install: String, platform: String) -> ReleaseCheck {
|
||||
let client = format!("ChessPenguin/{VERSION} (Android)");
|
||||
checked(check_latest(&install, &platform, &client), &client)
|
||||
}
|
||||
|
||||
fn checked(found: Result<Release, String>, client: &str) -> ReleaseCheck {
|
||||
let release = match found {
|
||||
Ok(r) => r,
|
||||
Err(detail) => return ReleaseCheck::Failed { detail },
|
||||
};
|
||||
|
|
@ -73,7 +86,7 @@ pub fn check_release(api: String) -> ReleaseCheck {
|
|||
};
|
||||
}
|
||||
let sums = if release.sums().is_some() {
|
||||
match fetch_sums(&release, &client) {
|
||||
match fetch_sums(&release, client) {
|
||||
Ok(s) => s,
|
||||
Err(detail) => return ReleaseCheck::Failed { detail },
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ use serde_json::Value;
|
|||
/// GitHub's answer for the latest release.
|
||||
pub const API: &str = "https://api.github.com/repos/vrubelroman/chessPenguin/releases/latest";
|
||||
|
||||
/// The site's update check: GitHub's answer passed on, and this installation counted for
|
||||
/// the day (website/README.md, "Installations").
|
||||
pub const CHECK: &str = "https://chess.vrubel.xyz/api/update";
|
||||
|
||||
/// Where people download ChessPenguin.
|
||||
pub const DOWNLOAD_PAGE: &str = "https://chess.vrubel.xyz/";
|
||||
|
||||
|
|
@ -130,6 +134,16 @@ pub fn fetch_latest(api: &str, client: &str) -> Result<Release, String> {
|
|||
parse_release(&v).ok_or_else(|| "unexpected answer".to_owned())
|
||||
}
|
||||
|
||||
/// Asks the site for the latest release, counting this installation once a day: only its
|
||||
/// random id (`install`, made up by the program), this version and `platform` ("windows",
|
||||
/// "deb", "android"…) are sent. Without an answer from the site, GitHub is asked.
|
||||
pub fn check_latest(install: &str, platform: &str, client: &str) -> Result<Release, String> {
|
||||
// `CP_UPDATE_CHECK`: another site (a local one, to try it).
|
||||
let site = std::env::var("CP_UPDATE_CHECK").unwrap_or_else(|_| CHECK.to_owned());
|
||||
let url = format!("{site}?install={install}&version={VERSION}&platform={platform}");
|
||||
fetch_latest(&url, client).or_else(|_| fetch_latest(API, client))
|
||||
}
|
||||
|
||||
/// Opens a file of the release for reading; a whole download has half an hour.
|
||||
pub fn open(asset: &Asset, client: &str) -> Result<Box<dyn Read + Send>, String> {
|
||||
let resp = agent(client, Duration::from_secs(1800))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue