diff --git a/crates/horizon-mods/src/index.rs b/crates/horizon-mods/src/index.rs index 544c52980..4ef292a23 100644 --- a/crates/horizon-mods/src/index.rs +++ b/crates/horizon-mods/src/index.rs @@ -122,6 +122,14 @@ pub struct Project { pub key: Option, /// Newest first. pub versions: Vec, + /// Its files' downloads from their releases, all versions together: + /// GitHub's counts, added by the registry's publish job (hourly). + #[serde(default, skip_serializing_if = "is_zero")] + pub downloads: u64, +} + +fn is_zero(n: &u64) -> bool { + *n == 0 } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] diff --git a/crates/horizon-mods/src/index/registry.rs b/crates/horizon-mods/src/index/registry.rs index 90453c621..05fff7f14 100644 --- a/crates/horizon-mods/src/index/registry.rs +++ b/crates/horizon-mods/src/index/registry.rs @@ -231,6 +231,7 @@ pub fn project(entry: &Entry, src: &Sources) -> Result> { icon, key: entry.key.as_ref().map(|k| k.trim().to_owned()), versions, + downloads: 0, }) } diff --git a/crates/horizon-mods/src/index/tests.rs b/crates/horizon-mods/src/index/tests.rs index ef0299ad9..486704b7d 100644 --- a/crates/horizon-mods/src/index/tests.rs +++ b/crates/horizon-mods/src/index/tests.rs @@ -34,8 +34,14 @@ fn reads_the_sample_and_keeps_unknown_kinds() { [Capability::GameRead, Capability::Hud, Capability::Chat] ); // What CI writes reads back the same. - let again = Index::parse(&serde_json::to_string(&index).unwrap()).unwrap(); + let text = serde_json::to_string(&index).unwrap(); + let again = Index::parse(&text).unwrap(); assert_eq!(again, index); + // Download counts: the publish job adds them; none is left out. + assert_eq!(hud.downloads, 0); + assert!(!text.contains("downloads")); + let counted = text.replacen("\"versions\"", "\"downloads\":12345,\"versions\"", 1); + assert_eq!(Index::parse(&counted).unwrap().projects[0].downloads, 12345); } #[test] diff --git a/docs/api/mod-index.md b/docs/api/mod-index.md index e8476cdf0..ea605fbc7 100644 --- a/docs/api/mod-index.md +++ b/docs/api/mod-index.md @@ -18,7 +18,7 @@ Level: preview ([stability.md](stability.md)). Schema 1. "projects": [{ "id": "coords_hud", "kind": "mod", "name": "Coordinates HUD", "summary": "One line.", "description": "Markdown.", "authors": ["Horizon"], "owners": ["ludovic111"], - "license": "MIT", "source": "https://github.com/...", "icon": "https://...png", "key": "RWT...", + "license": "MIT", "source": "https://github.com/...", "icon": "https://...png", "key": "RWT...", "downloads": 1234, "versions": [{ "version": "0.1.0", "published": "2026-10-24", "changelog": "", "api": "0.1", "side": "client", "capabilities": ["game-read", "hud", "chat"], "api_level": 0, "game": "26.3", @@ -41,6 +41,7 @@ Level: preview ([stability.md](stability.md)). Schema 1. | `icon` | `https://`, optional. | | `key` | The author's [minisign](https://jedisct1.github.io/minisign/) public key. When set, every version must be signed with it; an update signed with another key is refused. Absent: the project is unsigned and the launcher says so. | | `versions` | Newest first, at least one. | +| `downloads` | How many times its files were downloaded, every version together: GitHub's count of each release asset, summed by the publish job, which runs every hour. Absent until a file is downloaded. Read-only: never in an entry. | | `api` | A mod's API line (its manifest's `api`); a modpack's manifest format (`1`). | | `side`, `capabilities` | A mod's, read from its manifest by CI, never typed by hand. | | `api_level` | The mod API level a mod's code needs ([stability.md](stability.md#mod-api-levels)): its newest imported function's, read from the file by CI. Absent for content-only mods and in indexes built before levels. Installers take the newest version whose level the running game serves. | @@ -167,6 +168,7 @@ opens. ## Changelog +- 2026-10-26: `projects[].downloads`, GitHub's download counts of a project's files, refreshed every hour. - 2026-10-26: the launcher installs `shader` files into `shaderpacks/`; the sample index lists one (`glow`). - 2026-10-25: `shader` opens, checked by `horizon_shader_api::check`; its files are `.hshader`. - Schema 1 (2026-10-24): kinds `mod`, `modpack`, `resourcepack`, `shader`; `.hpack` format 1. diff --git a/launcher/src/browser/horizon.rs b/launcher/src/browser/horizon.rs index 3bf465faf..4799e7716 100644 --- a/launcher/src/browser/horizon.rs +++ b/launcher/src/browser/horizon.rs @@ -158,7 +158,7 @@ fn project_of(p: &index::Project) -> Option { title: p.name.clone(), summary: p.summary.clone(), author: p.authors.join(", "), - downloads: 0, + downloads: p.downloads, page: format!("{SITE}/{}", p.id), icon: p.icon.clone(), license: p.license.clone(), @@ -218,14 +218,19 @@ fn matches(p: &index::Project, text: &str) -> bool { .all(|word| hay.contains(&word.to_lowercase())) } -/// The projects of the query's kind whose words match, for this game unless `everything`. +/// The projects of the query's kind whose words match, for this game unless `everything`: the +/// most downloaded first. fn search(index: &Index, query: &Query) -> Vec { - index + let mut found: Vec = index .projects .iter() .filter(|p| kind_of(&p.kind) == Some(query.kind) && matches(p, &query.text)) .filter(|p| query.everything || p.versions.iter().any(|v| v.game == GAME)) .filter_map(project_of) + .collect(); + found.sort_by_key(|p| std::cmp::Reverse(p.downloads)); + found + .into_iter() .skip(query.offset) .take(query.limit) .collect() diff --git a/launcher/src/browser/horizon/tests.rs b/launcher/src/browser/horizon/tests.rs index 7e1b8f585..bed79562f 100644 --- a/launcher/src/browser/horizon/tests.rs +++ b/launcher/src/browser/horizon/tests.rs @@ -49,6 +49,18 @@ fn searches_by_kind_and_words() { assert_eq!(found("", Kind::Modpack), ["cozy"]); assert!(found("skyblock", Kind::ResourcePack).is_empty()); assert_eq!(found("", Kind::Shader), ["glow"]); + // The index's download counts, most downloaded first. + let mut counted = index.clone(); + counted.projects.push(index::Project { + id: "zoom".into(), + name: "Zoom".into(), + downloads: 12_345, + ..index.project("coords_hud").unwrap().clone() + }); + counted.projects[0].downloads = 80; + let first = search(&counted, &Query::new("", Kind::Mod)); + let order: Vec<(&str, u64)> = first.iter().map(|p| (p.id.as_str(), p.downloads)).collect(); + assert_eq!(order, [("zoom", 12_345), ("coords_hud", 80)]); let p = hud(&index); assert_eq!(p.support(), super::super::Support::Works); assert_eq!(p.page, "https://playhorizon.dev/mods/coords_hud"); diff --git a/launcher/src/mods_page.rs b/launcher/src/mods_page.rs index e6ebedc5b..44f899854 100644 --- a/launcher/src/mods_page.rs +++ b/launcher/src/mods_page.rs @@ -968,9 +968,7 @@ impl Launcher { if !p.author.is_empty() { by.push(format!("by {}", p.author)); } - if p.source != SourceId::Horizon { - by.push(format!("{} downloads", count(p.downloads))); - } + by.push(format!("{} downloads", count(p.downloads))); by.push(format!("from {}", p.source.label())); if !p.license.is_empty() { by.push(p.license.clone());