Merge pull request #1638 from ludovic111/feat/launcher-horizon-tab

🤖 Agent: merged after verify passed; mod-registry-land-1's combined check (pr_ready --quick on all seven, launcher tests 125, website 25/25, no harness affected) and live end-to-end on horizon-mods.
This commit is contained in:
Ludovic Marie
2026-10-25 15:51:16 +01:00
committed by GitHub
4 changed files with 184 additions and 22 deletions
+9
View File
@@ -45,6 +45,15 @@ pub fn local() -> bool {
static LOADED: Mutex<Option<(Instant, Arc<Index>)>> = Mutex::new(None);
/// The index read last in this run, without asking the network: for what must not wait.
pub fn known_index() -> Option<Arc<Index>> {
LOADED
.lock()
.unwrap()
.as_ref()
.map(|(_, index)| index.clone())
}
/// The index: the one fetched in the last ten minutes, else fetched again (and kept in the game
/// folder), else the copy kept last time.
pub fn index() -> Result<Arc<Index>, String> {
+3 -1
View File
@@ -9,10 +9,12 @@ use std::io::Read;
use std::path::{Path, PathBuf};
/// Hosts images may come from.
const HOSTS: [&str; 3] = [
const HOSTS: [&str; 4] = [
"https://cdn.modrinth.com/",
"https://media.forgecdn.net/",
"https://edge.forgecdn.net/",
// Horizon's registry's icons (its GitHub Pages).
"https://ludovic111.github.io/horizon-mods/",
];
/// The most an image may weigh before decoding.
pub const MAX_DOWNLOAD: u64 = 8 << 20;
+171 -21
View File
@@ -1,11 +1,13 @@
//! The Mods page: search Modrinth (CurseForge: coming soon) for Java mods, modpacks and resource
//! packs, see where each comes from and how well it runs (a Java mod's jar is
//! checked first), install it with its checksum checked, and update or remove what was installed
//! (`horizon_launcher::browser`). Imported modpacks are listed on its Modpacks tab.
//! The Mods page: search Horizon's own registry for mods made for Horizon, or Modrinth
//! (CurseForge: coming soon) for Java mods, modpacks and resource packs, see where each comes
//! from and how well it runs (a Java mod's jar is checked first; a Horizon mod says whether it is
//! signed and what it may do), install it with its checksum checked, turn Horizon mods on and
//! off, and update or remove what was installed (`horizon_launcher::browser`). Imported modpacks
//! are listed on its Modpacks tab.
use super::servers_page::{type_key, Key};
use super::*;
use horizon_launcher::browser::{
self, installed, java, Kind as PackKind, Project, Query, SourceId, Support,
self, horizon, installed, java, Kind as PackKind, Project, Query, SourceId, Support,
};
use horizon_launcher::modpacks;
use horizon_port_pack::check::Check;
@@ -20,7 +22,10 @@ const KINDS: [(PackKind, &str, &str); 3] = [
/// Java mods checked at once.
const CHECKING: usize = 2;
/// The sources to pick from; CurseForge is shown beside them as coming soon.
const SOURCES: [(SourceId, &str); 1] = [(SourceId::Modrinth, "Modrinth")];
const SOURCES: [(SourceId, &str); 2] = [
(SourceId::Modrinth, "Modrinth"),
(SourceId::Horizon, "Horizon"),
];
const PAGE: usize = 20;
pub(super) enum Event {
@@ -31,6 +36,10 @@ pub(super) enum Event {
Updates(HashMap<(SourceId, String), String>),
/// A Java mod's check: its jar read, or why it couldn't be.
Checked((SourceId, String), Result<Box<Check>, String>),
/// What a Horizon registry project says before install: signed or not, what it may do.
About(HashMap<String, Vec<String>>),
/// Registry files taken down that the launcher turned off.
TakenDown(Vec<String>),
/// A project page's part, an image or a filter's values (`mods_project`).
Loaded(super::mods_project::Loaded),
}
@@ -68,6 +77,8 @@ pub(super) struct Mods {
confirm_remove: Option<String>,
/// Java mods' checks, by source and project.
pub(super) checks: HashMap<(SourceId, String), Checking>,
/// Horizon registry projects' trust and capabilities, by id ([`horizon::trust_and_capabilities`]).
pub(super) about: HashMap<String, Vec<String>>,
/// The project page, filters and images.
pub(super) browse: super::mods_project::Browse,
pub(super) tx: Sender<Event>,
@@ -94,7 +105,11 @@ impl Mods {
} else {
PackKind::Mod
},
source: SourceId::Modrinth,
// `HORIZON_LAUNCHER_SOURCE=horizon` opens on Horizon's registry, for screenshots.
source: match std::env::var("HORIZON_LAUNCHER_SOURCE").as_deref() {
Ok("horizon") => SourceId::Horizon,
_ => SourceId::Modrinth,
},
text: String::new(),
focus: cx.focus_handle().tab_index(0).tab_stop(true),
focused: false,
@@ -115,6 +130,7 @@ impl Mods {
updates: HashMap::new(),
confirm_remove: None,
checks: HashMap::new(),
about: HashMap::new(),
browse: Default::default(),
tx,
rx,
@@ -134,7 +150,7 @@ impl Mods {
/// How well a result runs: a Java mod's from its check once it has one.
pub(super) fn support(&self, p: &Project) -> Support {
let metadata = p.support();
if p.kind != PackKind::Mod || !metadata.installable() {
if p.kind != PackKind::Mod || p.source == SourceId::Horizon || !metadata.installable() {
return metadata;
}
match self.checks.get(&(p.source, p.id.clone())) {
@@ -231,6 +247,16 @@ impl Launcher {
m.checks.insert(key, state);
}
Event::Loaded(l) => loaded.push(l),
Event::About(about) => {
// Rows grow by a line: measure them again (`cull`).
m.about.extend(about);
m.results_list.reset();
}
Event::TakenDown(lines) => {
m.message = Some(Ok(lines.join("\n")));
m.installed = installed::Installed::load(&backend::game_home()).entries;
m.installed_list.reset();
}
}
}
// `HORIZON_LAUNCHER_PROJECT=<slug>` (with `HORIZON_LAUNCHER_PAGE=mods`): opens that
@@ -278,7 +304,63 @@ impl Launcher {
let result = browser::source(source)
.ok_or_else(|| format!("{} isn't set up.", source.label()))
.and_then(|s| s.search(&query));
let about: HashMap<String, Vec<String>> = match (&result, source) {
(Ok(found), SourceId::Horizon) => found
.iter()
.map(|p| (p.id.clone(), horizon::trust_and_capabilities(&p.id)))
.collect(),
_ => HashMap::new(),
};
let _ = tx.send(Event::Found(search, offset, result));
if !about.is_empty() {
let _ = tx.send(Event::About(about));
}
});
}
/// Reads the registry's index again when something installed came from it, and turns off
/// what it took down since (`horizon::turn_off_revoked`).
fn mods_taken_down(&mut self) {
if !self
.mods
.installed
.iter()
.any(|e| e.source == SourceId::Horizon)
{
return;
}
let tx = self.mods.tx.clone();
std::thread::spawn(move || {
let Ok(index) = horizon::index() else {
return;
};
let lines = horizon::turn_off_revoked(&index, &backend::game_home());
if !lines.is_empty() {
let _ = tx.send(Event::TakenDown(lines));
}
});
}
/// Turns a Horizon mod the browser installed on or off, as the game's Options > Mods does.
fn mods_switch(&mut self, e: &installed::Entry) {
let home = backend::game_home();
let Some(id) = horizon::mod_id(e) else {
return;
};
let on = !java::is_enabled(&home, id);
let revoked = horizon::known_index().and_then(|index| {
let hash = e.checksum.trim_start_matches("SHA-256:");
index.revoked(&e.project, hash).map(|r| r.reason.clone())
});
self.mods.message = Some(match revoked.filter(|_| on) {
Some(reason) => Err(format!("{} was taken down: {reason}", e.title)),
None => java::set_enabled(&home, id, on).map(|()| {
format!(
"{} is {}. The game reads this when it starts.",
e.title,
if on { "on" } else { "off" }
)
}),
});
}
@@ -288,7 +370,8 @@ impl Launcher {
let m = &mut self.mods;
let todo: Vec<Project> = found
.into_iter()
.filter(|p| p.kind == PackKind::Mod && p.support().installable())
.filter(|p| p.kind == PackKind::Mod && p.source != SourceId::Horizon)
.filter(|p| p.support().installable())
.filter(|p| !m.checks.contains_key(&(p.source, p.id.clone())))
.collect();
if todo.is_empty() {
@@ -403,6 +486,13 @@ impl Launcher {
.iter()
.map(|e| format!("{} {}", e.title, e.number))
.collect();
if p.source == SourceId::Horizon && p.kind == PackKind::Mod {
return Ok(format!(
"Installed {} into horizon-mods and turned it on, checksum checked \
(Options > Mods in the game).",
names.join(", ")
));
}
if p.kind == PackKind::Mod {
let skipped = done.last().map_or(0, |e| e.skipped.len());
return Ok(format!(
@@ -497,14 +587,15 @@ impl Launcher {
self.mods.loaded = true;
self.mods.installed = installed::Installed::load(&backend::game_home()).entries;
self.mods_check_updates();
self.mods_taken_down();
self.mods_search(0);
}
let header = page_header(
"Mods",
"Java mods, modpacks and resource packs. Horizon ports what a Java mod \
carries (blocks, items, recipes, worldgen) and says before you install what runs. \
Each file is checked against its source's checksum before it reaches your game \
folder.",
"Mods made for Horizon from its own reviewed registry, and Java mods, modpacks and \
resource packs from Modrinth: Horizon ports what a Java mod carries (blocks, items, \
recipes, worldgen) and says before you install what runs. Each file is checked \
against its source's checksum before it reaches your game folder.",
&t,
);
let this = cx.entity().downgrade();
@@ -543,7 +634,10 @@ impl Launcher {
}));
// CurseForge support is coming soon: shown, inert, never searched (like the Microsoft
// account's "Coming soon").
let source_note = div().flex().child(source_switch(&t));
let source_note = div().flex().child(self.mods_source_switch(cx));
// The registry lists only what was made for Horizon: no "everything", no Modrinth filters.
let registry = self.mods.source == SourceId::Horizon;
let filters = (!registry).then(|| self.mods_filters(cx));
let controls = div()
.flex()
.flex_col()
@@ -555,10 +649,10 @@ impl Launcher {
.items_center()
.gap(px(12.))
.child(self.mods_field(cx))
.child(toggle),
.when(!registry, |d| d.child(toggle)),
)
.child(source_note)
.child(self.mods_filters(cx));
.children(filters);
// The kinds are inventory tabs on the panel that holds the open one.
let body = blocks::panel(&t).flex().flex_col().gap(px(24.)).p(px(20.));
let page = |body: Div| {
@@ -687,6 +781,30 @@ impl Launcher {
}
cx.notify();
}));
if e.source == SourceId::Horizon && e.kind == PackKind::Mod {
let on = horizon::mod_id(e)
.is_some_and(|id| java::is_enabled(&backend::game_home(), id));
let entry = e.clone();
right = right.child(
div()
.id(SharedString::from(format!("mods-switch-{}", e.project)))
.flex()
.items_center()
.gap(px(8.))
.cursor_pointer()
// Its id sits under the row's own, so one name serves every row.
.child(switch("mods-switch-knob", on, &t))
.child(text(theme::LABEL).text_color(t.ink_soft).child(if on {
"On"
} else {
"Off"
}))
.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
this.mods_switch(&entry);
cx.notify();
})),
);
}
right = right.child(remove);
let detail = div()
.flex()
@@ -750,6 +868,8 @@ impl Launcher {
if m.results.is_empty() {
let line = if m.searching || !m.searched {
"Searching…"
} else if m.source == SourceId::Horizon {
"Nothing in Horizon's registry matches yet."
} else if m.everything {
"Nothing found."
} else {
@@ -768,6 +888,7 @@ impl Launcher {
let busy = m.busy.as_ref().map(|b| b.0.as_str());
let support = m.support(p);
let checking = p.kind == PackKind::Mod
&& p.source != SourceId::Horizon
&& matches!(
m.checks.get(&(p.source, p.id.clone())),
None | Some(Checking::Running)
@@ -828,7 +949,9 @@ impl Launcher {
if !p.author.is_empty() {
by.push(format!("by {}", p.author));
}
by.push(format!("{} downloads", count(p.downloads)));
if p.source != SourceId::Horizon {
by.push(format!("{} downloads", count(p.downloads)));
}
by.push(format!("from {}", p.source.label()));
if !p.license.is_empty() {
by.push(p.license.clone());
@@ -842,6 +965,12 @@ impl Launcher {
support
.reason()
.map(|r| div().text_color(t.ink_soft).child(r.to_string())),
)
.children(
m.about
.get(&p.id)
.filter(|_| p.source == SourceId::Horizon)
.map(|lines| div().text_color(t.ink_soft).child(lines.join(" · "))),
);
let open = p.clone();
let name = div()
@@ -884,9 +1013,30 @@ impl Launcher {
}
}
/// The source switch while Modrinth is the only source: Modrinth chosen, CurseForge shown as
/// coming soon and not clickable, like the Microsoft account's "Coming soon".
fn source_switch(t: &Theme) -> Stateful<Div> {
impl Launcher {
/// The source switch: Modrinth or Horizon's registry, CurseForge shown as coming soon and not
/// clickable, like the Microsoft account's "Coming soon".
fn mods_source_switch(&self, cx: &mut Context<Self>) -> Stateful<Div> {
let this = cx.entity().downgrade();
source_switch(&self.theme, self.mods.source, move |source, _, cx| {
let _ = this.update(cx, |this, cx| {
if this.mods.source != source {
this.mods.source = source;
this.mods.browse.filters = Default::default();
this.mods.browse.open = None;
this.mods_search(0);
}
cx.notify();
});
})
}
}
fn source_switch(
t: &Theme,
current: SourceId,
on_pick: impl Fn(SourceId, &mut Window, &mut App) + Clone + 'static,
) -> Stateful<Div> {
let soon = div()
.flex()
.items_center()
@@ -899,7 +1049,7 @@ fn source_switch(t: &Theme) -> Stateful<Div> {
.text_color(t.muted)
.child("CurseForge (coming soon)"),
);
segments("mods-source", &SOURCES, SourceId::Modrinth, t, |_, _, _| {}).child(soon)
segments("mods-source", &SOURCES, current, t, on_pick).child(soon)
}
#[cfg(test)]
+1
View File
@@ -423,6 +423,7 @@ impl Launcher {
self.mods.checks.get(&(p.source, p.id.clone())),
None | Some(Checking::Running)
) && p.kind == PackKind::Mod
&& p.source != SourceId::Horizon
&& p.support().installable();
let mut action = div().flex().items_center().gap(px(8.)).child(
caps(if checking {