Launcher downloads go through the proxy the player sets

Everything the launcher fetches now goes through one HTTP proxy when there is
one: Horizon's releases and the launcher's own update, Minecraft's files and
Java from Mojang, Modrinth, CurseForge, the mod registry, pictures, Microsoft
sign-in, Tailscale's API, and the jars a modpack import downloads. It is
Settings' Proxy row (`proxy` in settings.json), or `horizon-launcher settings
proxy http://host:port`; without one, HTTPS_PROXY, HTTP_PROXY and ALL_PROXY
apply, with NO_PROXY naming the hosts to reach directly.

A local address never goes through it, and the Servers page's calls to a game
server's API stay direct: they are on loopback and asked every second.

horizon-port-pack builds its own agents, so the launcher hands it the address
(net.rs); run on its own, it reads the same variables.

Co-Authored-By: WorkBuddy AI (DeepSeek-V4.1-Flash) <noreply@workbuddy.cn>
This commit is contained in:
zhykowo
2026-10-26 16:21:24 +08:00
parent 57c5f81299
commit 3e79b22c43
18 changed files with 489 additions and 54 deletions
+14 -2
View File
@@ -295,7 +295,7 @@ enum Cmd {
},
/// Show the launcher's settings, or set one (the Settings page): selected-version TAG,
/// minecraft-dir PATH, server-dir PATH ("default" resets a folder), install-new-versions
/// on|off, opening-animation on|off
/// on|off, opening-animation on|off, proxy http://host:port ("default" removes it)
Settings {
#[arg(value_parser = SETTING_KEYS)]
key: Option<String>,
@@ -397,12 +397,13 @@ pub fn command() -> clap::Command {
pub const AI_COMMANDS: [&str; 2] = ["mcp", "agent-config"];
/// The keys `settings` sets.
const SETTING_KEYS: [&str; 5] = [
const SETTING_KEYS: [&str; 6] = [
"selected-version",
"minecraft-dir",
"server-dir",
"install-new-versions",
"opening-animation",
"proxy",
];
fn on_off(value: &str) -> Result<bool, String> {
@@ -421,6 +422,15 @@ fn set_setting(s: &mut backend::Settings, key: &str, value: &str) -> Result<(),
"server-dir" => s.server_dir = folder(value),
"install-new-versions" => s.install_new_versions = Some(on_off(value)?),
"opening-animation" => s.skip_opening = !on_off(value)?,
"proxy" => {
if value == "default" || value.is_empty() {
s.proxy = None;
} else if let Some(why) = horizon_launcher::proxy::refuse(value) {
return Err(why);
} else {
s.proxy = Some(value.trim().to_string());
}
}
_ => return Err(format!("No setting {key}.")),
}
Ok(())
@@ -435,6 +445,7 @@ fn settings_json(s: &backend::Settings) -> serde_json::Value {
"install_new_versions": s.install_new_versions.unwrap_or(true),
"opening_animation": !s.skip_opening,
"game_args": s.game_args,
"proxy": s.proxy,
"desktop_entry": s.desktop_entry.unwrap_or(true),
"no_ai": backend::no_ai(),
})
@@ -720,6 +731,7 @@ fn execute(command: Cmd, as_json: bool) -> Result<(), String> {
let value = value.ok_or("settings KEY VALUE: the value is missing")?;
set_setting(&mut settings, &key, &value)?;
settings.save();
horizon_launcher::proxy::announce();
}
let all = settings_json(&settings);
if as_json {