b2e9fafbe0
The official launcher crashes on some Linux systems (rdbt's Arch), and Horizon only read its layout. Preparing now finds the pinned version in the chosen folder (or a folder above it, so an instance folder works), then in every launcher's default folder on Linux (Flatpak included), macOS and Windows: - the official launcher: versions/<v>/<v>.jar - Prism Launcher, MultiMC: the jar their meta/net.minecraft/<v>.json names (a Maven name in libraries/), libraries/com/mojang/minecraft/<v>/... - the Modrinth App: meta/versions/<v>/<v>.jar, meta/libraries - ATLauncher, GDLauncher (data/, Next's datastore/): libraries/net/minecraft/client/<v>/client-<v>.jar The client jar is checked against the lock's sha1. horizon-prepare reads the official layout and pins the version JSON's own sha1, so files found elsewhere are linked into that layout in the data folder (linked-minecraft/), with the pinned version JSON from piston-meta (by its sha1, checked) when the launcher keeps only its own format or a rewrite. Nothing else is copied or downloaded. Every preparer, old Python ones included, reads the linked folder as an official one. When nothing is found, the error lists the chosen folder and every installed launcher's, with what each lacks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
594 lines
21 KiB
Rust
594 lines
21 KiB
Rust
//! `horizon-launcher <subcommand>`: the same steps as the window, from a terminal. Every
|
|
//! command goes through `backend`; this file only parses arguments and prints.
|
|
use clap::{Parser, Subcommand};
|
|
use horizon_launcher::account::{self, Accounts};
|
|
use horizon_launcher::backend::{self, Release};
|
|
use std::io::{IsTerminal, Write};
|
|
use std::path::PathBuf;
|
|
use std::process::Command;
|
|
|
|
#[derive(Parser)]
|
|
#[command(
|
|
name = "horizon-launcher",
|
|
version = backend::VERSION,
|
|
about = "Installs, prepares and starts Horizon. Without a subcommand, opens the window."
|
|
)]
|
|
struct Cli {
|
|
/// Print JSON instead of text, where a command has something to report
|
|
#[arg(long, global = true)]
|
|
json: bool,
|
|
#[command(subcommand)]
|
|
command: Option<Cmd>,
|
|
}
|
|
|
|
#[derive(Subcommand)]
|
|
enum AccountCmd {
|
|
/// The signed-in accounts and which one plays
|
|
List,
|
|
/// Sign in with a Microsoft account in your browser (device code)
|
|
SignIn,
|
|
/// Sign out: the account's tokens leave the keychain
|
|
SignOut {
|
|
/// Its name or UUID
|
|
who: String,
|
|
},
|
|
/// Play as this account
|
|
Select { who: String },
|
|
/// Play offline, without an account
|
|
Offline,
|
|
}
|
|
|
|
#[derive(Subcommand)]
|
|
enum DataCmd {
|
|
/// What is allowed, the install ID and how many items wait (the default)
|
|
Status,
|
|
/// Turn kinds on: performance, crashes, bugs, benchmarks, or all
|
|
Allow {
|
|
#[arg(required = true)]
|
|
kinds: Vec<String>,
|
|
},
|
|
/// Turn kinds off: performance, crashes, bugs, benchmarks, or all
|
|
Deny {
|
|
#[arg(required = true)]
|
|
kinds: Vec<String>,
|
|
},
|
|
/// Print exactly what would be sent
|
|
Show,
|
|
/// Delete everything sent from here, and what waits, and take a new install ID
|
|
Delete,
|
|
/// Send what is waiting now
|
|
Send,
|
|
/// Send a bug report you write; it is printed first, as it would leave
|
|
Bug {
|
|
text: String,
|
|
/// Add the end of the game's log (scrubbed, without chat)
|
|
#[arg(long)]
|
|
log: bool,
|
|
/// Send without asking
|
|
#[arg(long)]
|
|
yes: bool,
|
|
},
|
|
/// Upload a benchmark report (docs/benchmark-report.md); it is printed first
|
|
Benchmark {
|
|
file: PathBuf,
|
|
#[arg(long)]
|
|
yes: bool,
|
|
},
|
|
}
|
|
|
|
#[derive(Subcommand)]
|
|
enum Cmd {
|
|
/// List Horizon releases, or the installed versions
|
|
Versions {
|
|
/// Only the versions installed here (no network)
|
|
#[arg(long)]
|
|
installed: bool,
|
|
},
|
|
/// Download and install a release (a tag such as v2026.10.13, or "latest")
|
|
Install { tag: String },
|
|
/// Remove an installed version
|
|
Remove { tag: String },
|
|
/// Prepare a version's resources from your own Minecraft install
|
|
Prepare {
|
|
/// The game folder of the official launcher, Prism Launcher, MultiMC, the Modrinth App,
|
|
/// ATLauncher or GDLauncher (default: the launcher's, then every launcher's default)
|
|
#[arg(long)]
|
|
minecraft: Option<PathBuf>,
|
|
/// The installed version (default: the selected one)
|
|
#[arg(long)]
|
|
version: Option<String>,
|
|
},
|
|
/// Start the client
|
|
Play {
|
|
#[arg(long)]
|
|
version: Option<String>,
|
|
/// Join a friend's world with its invite code
|
|
#[arg(long)]
|
|
join: Option<String>,
|
|
},
|
|
/// Run a dedicated server here; type commands into its console
|
|
Server {
|
|
/// The server's folder (default: the one the launcher uses)
|
|
#[arg(long)]
|
|
dir: Option<PathBuf>,
|
|
#[arg(long)]
|
|
version: Option<String>,
|
|
/// Agree to the Minecraft EULA (https://aka.ms/MinecraftEULA)
|
|
#[arg(long)]
|
|
accept_eula: bool,
|
|
},
|
|
/// Show a release's patch notes (default: the newest)
|
|
Notes { tag: Option<String> },
|
|
/// Show the Discord, sponsor and website links
|
|
Links,
|
|
/// Microsoft accounts: list them (the default), sign in, sign out, or pick the one that plays
|
|
Account {
|
|
#[command(subcommand)]
|
|
action: Option<AccountCmd>,
|
|
},
|
|
/// Show or set the game's menu style (classic is vanilla's own screens)
|
|
MenuStyle {
|
|
/// Omit to show the current style
|
|
#[arg(value_parser = ["horizon", "classic"])]
|
|
style: Option<String>,
|
|
},
|
|
/// Print the end of the game's log (logs/latest.log in the game folder), or its newest crash
|
|
/// report
|
|
Logs {
|
|
/// How many lines of latest.log
|
|
#[arg(long, default_value_t = 100)]
|
|
lines: usize,
|
|
/// The newest crash report instead
|
|
#[arg(long)]
|
|
crash: bool,
|
|
},
|
|
/// Look for a newer Horizon release and launcher, and install them
|
|
Update {
|
|
/// Only report what is available
|
|
#[arg(long)]
|
|
check: bool,
|
|
},
|
|
/// Linux: put Horizon in the applications menu (an entry and the icon, under
|
|
/// $XDG_DATA_HOME), or take it out with --remove
|
|
DesktopEntry {
|
|
/// Remove the entry and the icon, and stop adding them back
|
|
#[arg(long)]
|
|
remove: bool,
|
|
},
|
|
/// Opt-in data collection (docs/telemetry.md): what is allowed, what would be sent, and
|
|
/// deleting it; all off until you allow a kind
|
|
Data {
|
|
#[command(subcommand)]
|
|
action: Option<DataCmd>,
|
|
},
|
|
/// Serve the Model Context Protocol on stdin and stdout, for AI agents
|
|
Mcp,
|
|
/// Measure the launcher: starts (the first is the cold one), page switching, idle CPU and
|
|
/// memory, the release list fetch; writes a benchmark report to benchmarks/ in its data folder
|
|
Benchmark {
|
|
/// How many times to start it
|
|
#[arg(long, default_value_t = 5)]
|
|
repeats: usize,
|
|
},
|
|
}
|
|
|
|
/// Runs a subcommand and returns the exit code, or None when the window should open.
|
|
pub fn run() -> Option<i32> {
|
|
let cli = Cli::parse();
|
|
let command = cli.command?;
|
|
let result = match command {
|
|
Cmd::Mcp => crate::mcp::serve(),
|
|
command => execute(command, cli.json),
|
|
};
|
|
Some(match result {
|
|
Ok(()) => 0,
|
|
Err(e) => {
|
|
eprintln!("error: {e}");
|
|
1
|
|
}
|
|
})
|
|
}
|
|
|
|
/// Download progress on one terminal line, only when stderr is a terminal and the percentage moves.
|
|
fn progress(label: String) -> impl Fn(f32) {
|
|
let last = std::cell::Cell::new(-1);
|
|
let tty = std::io::stderr().is_terminal();
|
|
move |p| {
|
|
let pct = (p * 100.) as i32;
|
|
if !tty || pct == last.replace(pct) {
|
|
return;
|
|
}
|
|
eprint!("\r{label} {pct:>3}%");
|
|
let _ = std::io::stderr().flush();
|
|
if p >= 1.0 {
|
|
eprintln!();
|
|
}
|
|
}
|
|
}
|
|
|
|
fn json(value: serde_json::Value) {
|
|
println!("{}", serde_json::to_string_pretty(&value).unwrap());
|
|
}
|
|
|
|
/// Runs a game process in this terminal and reports how it ended.
|
|
fn attached(mut cmd: Command) -> Result<(), String> {
|
|
let status = cmd
|
|
.status()
|
|
.map_err(|e| format!("Could not start {:?}: {e}", cmd.get_program()))?;
|
|
if status.success() {
|
|
Ok(())
|
|
} else {
|
|
Err(format!("Exited with {status}"))
|
|
}
|
|
}
|
|
|
|
fn release_json(r: &Release) -> serde_json::Value {
|
|
serde_json::json!({
|
|
"tag": r.tag, "name": r.name, "date": r.date,
|
|
"available_here": r.asset.is_some(), "installed": backend::installed().contains(&r.tag),
|
|
})
|
|
}
|
|
|
|
fn execute(command: Cmd, as_json: bool) -> Result<(), String> {
|
|
if matches!(command, Cmd::Versions { .. } | Cmd::Update { .. }) {
|
|
for (tag, from) in backend::reuse_prepared_everywhere() {
|
|
if !as_json {
|
|
eprintln!("Prepared {tag} with the resources of {from}.");
|
|
}
|
|
}
|
|
}
|
|
match command {
|
|
Cmd::Versions { installed: true } => {
|
|
let installed = backend::installed();
|
|
let selected = backend::resolve_version(None).ok();
|
|
if as_json {
|
|
json(serde_json::json!({ "installed": installed, "selected": selected }));
|
|
} else if installed.is_empty() {
|
|
println!("No version is installed.");
|
|
}
|
|
for tag in installed.iter().filter(|_| !as_json) {
|
|
let mark = if selected.as_ref() == Some(tag) {
|
|
"*"
|
|
} else {
|
|
" "
|
|
};
|
|
let state = if backend::is_prepared(tag) {
|
|
"prepared"
|
|
} else {
|
|
"not prepared"
|
|
};
|
|
println!("{mark} {tag} {state}");
|
|
}
|
|
}
|
|
Cmd::Versions { installed: false } => {
|
|
let releases = backend::releases()?;
|
|
if as_json {
|
|
json(releases.iter().map(release_json).collect());
|
|
return Ok(());
|
|
}
|
|
let installed = backend::installed();
|
|
for r in &releases {
|
|
let state = match (installed.contains(&r.tag), r.asset.is_some()) {
|
|
(true, _) => "installed",
|
|
(false, true) => "",
|
|
(false, false) => "no build for this platform",
|
|
};
|
|
println!("{:<14} {} {}", r.tag, r.date, state);
|
|
}
|
|
}
|
|
Cmd::Install { tag } => {
|
|
let label = format!("Installing {tag}");
|
|
let tag = backend::install_tag(&tag, false, progress(label))?;
|
|
if as_json {
|
|
json(
|
|
serde_json::json!({ "installed": tag, "prepared": backend::is_prepared(&tag) }),
|
|
);
|
|
} else if backend::is_prepared(&tag) {
|
|
println!(
|
|
"Installed {tag}. It is prepared already, from another installed version."
|
|
);
|
|
} else {
|
|
println!(
|
|
"Installed {tag}. Prepare it next: horizon-launcher prepare --version {tag}"
|
|
);
|
|
}
|
|
}
|
|
Cmd::Remove { tag } => {
|
|
backend::remove_version(&tag)?;
|
|
println!("Removed {tag}.");
|
|
}
|
|
Cmd::Prepare { minecraft, version } => {
|
|
let tag = backend::resolve_version(version.as_deref())?;
|
|
let minecraft = backend::minecraft_dir(minecraft)?;
|
|
let (preparer, minecraft) =
|
|
backend::preparer(&tag, &minecraft, &|line| eprintln!("{line}"))?;
|
|
backend::sounds(&tag, &minecraft, &|line| println!("{line}"));
|
|
match preparer {
|
|
backend::Preparer::Process(cmd) => attached(cmd)?,
|
|
backend::Preparer::InProcess(options) => {
|
|
backend::prepare_in_process(&options, &|line| println!("{line}"))?
|
|
}
|
|
}
|
|
println!("{tag} is prepared.");
|
|
}
|
|
Cmd::Play { version, join } => {
|
|
let mut cmd = backend::client(&backend::resolve_version(version.as_deref())?)?;
|
|
if let Some(code) = join {
|
|
backend::join_friend(&mut cmd, &code)?;
|
|
}
|
|
attached(cmd)?
|
|
}
|
|
Cmd::Server {
|
|
dir,
|
|
version,
|
|
accept_eula,
|
|
} => {
|
|
let tag = backend::resolve_version(version.as_deref())?;
|
|
let dir = backend::server_dir(dir);
|
|
// The server inherits this terminal, so typed lines reach its console.
|
|
attached(backend::server(&tag, &dir, accept_eula)?)?
|
|
}
|
|
Cmd::Notes { tag } => {
|
|
let r = backend::release_notes(tag.as_deref())?;
|
|
if as_json {
|
|
json(
|
|
serde_json::json!({ "tag": r.tag, "name": r.name, "date": r.date, "notes": r.body }),
|
|
);
|
|
} else {
|
|
let title = if r.name.is_empty() { &r.tag } else { &r.name };
|
|
println!(
|
|
"{title}\n{} {}\n\n{}",
|
|
r.tag,
|
|
r.date,
|
|
backend::markdown_to_text(&r.body)
|
|
);
|
|
}
|
|
}
|
|
Cmd::Account { action } => account_command(action.unwrap_or(AccountCmd::List), as_json)?,
|
|
Cmd::Benchmark { repeats } => {
|
|
let path = crate::perf::benchmark(repeats.max(1))?;
|
|
if as_json {
|
|
json(serde_json::json!({ "report": path }));
|
|
} else {
|
|
println!("{}", path.display());
|
|
}
|
|
}
|
|
Cmd::Links => {
|
|
let links = backend::links();
|
|
if as_json {
|
|
json(serde_json::to_value(&links).unwrap());
|
|
} else {
|
|
for (name, url) in [
|
|
("Discord", &links.discord),
|
|
("Sponsor", &links.sponsor),
|
|
("Website", &links.website),
|
|
] {
|
|
println!("{name:<8} {}", if url.is_empty() { "(none)" } else { url });
|
|
}
|
|
}
|
|
}
|
|
Cmd::MenuStyle { style } => {
|
|
if let Some(style) = style.as_deref().and_then(backend::MenuStyle::parse) {
|
|
backend::set_menu_style(style)?;
|
|
}
|
|
let style = backend::menu_style().name();
|
|
if as_json {
|
|
json(serde_json::json!({ "menu_style": style }));
|
|
} else {
|
|
println!("Menu style: {style}");
|
|
}
|
|
}
|
|
Cmd::Logs { lines, crash } => {
|
|
let (path, text) = backend::read_logs(lines, crash)?;
|
|
if as_json {
|
|
json(serde_json::json!({ "path": path, "text": text }));
|
|
} else {
|
|
print!("{text}");
|
|
}
|
|
}
|
|
Cmd::Update { check } => update(check, as_json)?,
|
|
Cmd::Data { action } => data(action.unwrap_or(DataCmd::Status), as_json)?,
|
|
Cmd::DesktopEntry { remove } => {
|
|
let mut settings = backend::Settings::load();
|
|
settings.desktop_entry = Some(!remove);
|
|
settings.save();
|
|
if remove {
|
|
horizon_launcher::desktop::remove()?;
|
|
println!("Removed Horizon from the applications menu.");
|
|
} else {
|
|
horizon_launcher::desktop::install(backend::exe_path())?;
|
|
println!("Horizon is in the applications menu.");
|
|
}
|
|
}
|
|
Cmd::Mcp => unreachable!(),
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
fn update(check: bool, as_json: bool) -> Result<(), String> {
|
|
let updates = backend::check_updates()?;
|
|
if as_json && check {
|
|
json(serde_json::json!({
|
|
"horizon": updates.horizon.as_ref().map(|r| &r.tag),
|
|
"launcher": updates.launcher.as_ref().and_then(|r| backend::launcher_version(&r.tag)),
|
|
"launcher_current": backend::VERSION,
|
|
}));
|
|
return Ok(());
|
|
}
|
|
match &updates.horizon {
|
|
None => println!("Horizon: up to date."),
|
|
Some(r) if check => println!("Horizon: {} is available.", r.tag),
|
|
Some(r) => {
|
|
let tag =
|
|
backend::install_tag(&r.tag, true, progress(format!("Installing {}", r.tag)))?;
|
|
println!("Horizon: installed {tag}.");
|
|
}
|
|
}
|
|
match &updates.launcher {
|
|
None => println!("Launcher: {} is up to date.", backend::VERSION),
|
|
Some(r) => {
|
|
let version = backend::launcher_version(&r.tag).unwrap_or_default();
|
|
if check {
|
|
println!(
|
|
"Launcher: {version} is available (this is {}).",
|
|
backend::VERSION
|
|
);
|
|
} else if !backend::self_update_allowed() {
|
|
println!("Launcher: {version} is available; this build does not replace itself.");
|
|
} else {
|
|
backend::self_update(r, progress(format!("Updating the launcher to {version}")))?;
|
|
println!("Launcher: updated to {version}. Restart the launcher to use it.");
|
|
}
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
/// `account …`: names and UUIDs only; tokens are never printed.
|
|
fn account_command(action: AccountCmd, as_json: bool) -> Result<(), String> {
|
|
let mut accounts = Accounts::load();
|
|
let find = |accounts: &Accounts, who: &str| {
|
|
accounts
|
|
.find(who)
|
|
.cloned()
|
|
.ok_or_else(|| format!("No signed-in account {who}. See `horizon-launcher account`."))
|
|
};
|
|
match action {
|
|
AccountCmd::List => {
|
|
if as_json {
|
|
json(serde_json::json!({
|
|
"accounts": accounts.accounts.iter().map(|a| serde_json::json!({
|
|
"name": a.name, "uuid": a.uuid,
|
|
"selected": accounts.selected.as_ref() == Some(&a.uuid),
|
|
})).collect::<Vec<_>>(),
|
|
"sign_in_configured": account::client_id().is_some(),
|
|
}));
|
|
} else if accounts.accounts.is_empty() {
|
|
println!("No Microsoft account signed in: the game plays offline.");
|
|
} else {
|
|
for a in &accounts.accounts {
|
|
let mark = if accounts.selected.as_ref() == Some(&a.uuid) {
|
|
"*"
|
|
} else {
|
|
" "
|
|
};
|
|
println!("{mark} {} {}", a.name, a.uuid);
|
|
}
|
|
if accounts.selected().is_none() {
|
|
println!("Playing offline (`account select NAME` to play as one).");
|
|
}
|
|
}
|
|
}
|
|
AccountCmd::SignIn => {
|
|
let client_id = account::client_id().ok_or(account::NOT_CONFIGURED)?;
|
|
let ep = account::Endpoints::live();
|
|
let code = account::device_code(&ep, &client_id)?;
|
|
eprintln!(
|
|
"To sign in, open {} in a browser and enter the code {}",
|
|
code.verification_uri, code.user_code
|
|
);
|
|
let ms = account::wait_for_sign_in(&ep, &client_id, &code, &|| false)?;
|
|
let (signed_in, secrets) = account::finish_sign_in(&ep, ms)?;
|
|
accounts.add(account::store(), signed_in.clone(), &secrets)?;
|
|
accounts.save()?;
|
|
println!("Signed in as {}.", signed_in.name);
|
|
if !account::store().persistent() {
|
|
eprintln!("{}", account::NO_KEYCHAIN);
|
|
}
|
|
}
|
|
AccountCmd::SignOut { who } => {
|
|
let a = find(&accounts, &who)?;
|
|
accounts.remove(account::store(), &a.uuid)?;
|
|
accounts.save()?;
|
|
println!("Signed out {}.", a.name);
|
|
}
|
|
AccountCmd::Select { who } => {
|
|
let a = find(&accounts, &who)?;
|
|
accounts.selected = Some(a.uuid);
|
|
accounts.save()?;
|
|
println!("The game plays as {}.", a.name);
|
|
}
|
|
AccountCmd::Offline => {
|
|
accounts.selected = None;
|
|
accounts.save()?;
|
|
println!("The game plays offline.");
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
/// `data`: the same consent as Settings → Data collection.
|
|
fn data(action: DataCmd, as_json: bool) -> Result<(), String> {
|
|
use horizon_launcher::telemetry;
|
|
let review = |item: &horizon_telemetry::Item, yes: bool| -> Result<bool, String> {
|
|
println!(
|
|
"{}",
|
|
serde_json::to_string_pretty(item).map_err(|e| e.to_string())?
|
|
);
|
|
if yes {
|
|
return Ok(true);
|
|
}
|
|
if !std::io::stdin().is_terminal() {
|
|
return Err("Add --yes to send it without asking.".into());
|
|
}
|
|
eprint!("Send this? [y/N] ");
|
|
let mut line = String::new();
|
|
std::io::stdin()
|
|
.read_line(&mut line)
|
|
.map_err(|e| e.to_string())?;
|
|
Ok(line.trim().eq_ignore_ascii_case("y"))
|
|
};
|
|
match action {
|
|
DataCmd::Status => {
|
|
let status = telemetry::status_json();
|
|
if as_json {
|
|
json(status);
|
|
return Ok(());
|
|
}
|
|
let consent = telemetry::consent();
|
|
if consent.needs_asking() {
|
|
println!("Not answered yet: nothing is collected.");
|
|
}
|
|
for (kind, name, _) in telemetry::SWITCHES {
|
|
let on = consent.allows(kind);
|
|
println!("{name}: {}", if on { "on" } else { "off" });
|
|
}
|
|
println!("Waiting to be sent: {}", status["waiting"]);
|
|
match horizon_telemetry::endpoint() {
|
|
Some(url) => println!("Server: {url}"),
|
|
None => println!("Server: none yet, nothing is sent"),
|
|
}
|
|
}
|
|
DataCmd::Allow { kinds } => {
|
|
telemetry::set(&telemetry::parse_kinds(&kinds)?, true)?;
|
|
return data(DataCmd::Status, as_json);
|
|
}
|
|
DataCmd::Deny { kinds } => {
|
|
telemetry::set(&telemetry::parse_kinds(&kinds)?, false)?;
|
|
return data(DataCmd::Status, as_json);
|
|
}
|
|
DataCmd::Show => {
|
|
let (what, text) = telemetry::preview();
|
|
eprintln!("{what}");
|
|
println!("{text}");
|
|
}
|
|
DataCmd::Delete => println!("{}", telemetry::delete_my_data()?),
|
|
DataCmd::Send => println!("{:?}", telemetry::send()),
|
|
DataCmd::Bug { text, log, yes } => {
|
|
telemetry::ensure_allowed(horizon_telemetry::Kind::Bug)?;
|
|
let item = telemetry::bug_report(&text, log)?;
|
|
if review(&item, yes)? {
|
|
println!("{}", telemetry::submit(&item)?);
|
|
}
|
|
}
|
|
DataCmd::Benchmark { file, yes } => {
|
|
telemetry::ensure_allowed(horizon_telemetry::Kind::Benchmark)?;
|
|
let item = telemetry::benchmark_report(&file)?;
|
|
if review(&item, yes)? {
|
|
println!("{}", telemetry::submit(&item)?);
|
|
}
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|