Launcher: a Native mods switch and Build in Settings, with the warning

Settings → Game → Native mods (experimental), off by default. On, Build names the native mods
turned on in the instance Play starts, warns in red that they run with full access to the
computer, and compiles them only from "I trust these mods: build"; the row shows the step while
it runs, the error if it fails, and the build the instance plays. Ported from native-mixins-1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-28 14:04:35 +01:00
parent 07ab7ccfc1
commit cd7f177104
2 changed files with 180 additions and 0 deletions
+8
View File
@@ -2495,6 +2495,10 @@ pub enum Msg {
NightlyProgress(f32),
/// A nightly check ended: the version installed (None: already up to date), or why not.
Nightly(Result<Option<String>, String>),
/// Where the native-mods build is (`native_mods::Step::label`).
NativeProgress(String),
/// The native-mods build ended: the version built, or why not.
Native(Result<String, String>),
}
/// A running process; its output arrives as `Msg::Line`, its end as `Msg::Exit`.
@@ -2681,6 +2685,10 @@ pub struct Settings {
/// instance. Off by default.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub nightly: bool,
/// The player turned Native mods (experimental) on (`native_mods`): mixin mods compiled into
/// a game of their own. Off by default.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub native_mods: bool,
}
impl Settings {
+172
View File
@@ -53,6 +53,7 @@ use horizon_launcher::account::{self, Accounts, SignIn, SignInState};
use horizon_launcher::backend::{self, Job, Msg, Release, Running, Settings, Updates};
use horizon_launcher::i18n::{self, tr, trf};
use horizon_launcher::instances;
use horizon_launcher::native_mods;
use horizon_launcher::nightly;
use horizon_launcher::telemetry;
use scrollbar::Scrollbar;
@@ -176,6 +177,11 @@ struct Launcher {
nightly_error: Option<String>,
/// Play the Nightly instance once its first install ends: the player just turned Nightly on.
nightly_select: bool,
/// Native mods (`native_mods`): the build's step while it runs, why it failed, and the
/// warning before a build while it is open, with the mods it names.
native_step: Option<String>,
native_error: Option<String>,
native_confirm: Option<Result<Vec<native_mods::Bundle>, String>>,
confirm_remove: Option<String>,
picker_open: bool,
/// The top bar's quick switch of who plays (`switch_page.rs`).
@@ -389,6 +395,9 @@ impl Launcher {
nightly_progress: None,
nightly_error: None,
nightly_select: false,
native_step: None,
native_error: None,
native_confirm: None,
confirm_remove: None,
picker_open: false,
account_menu: false,
@@ -578,6 +587,56 @@ impl Launcher {
/// Turns Nightly on (install it, then play its instance) or off (play the release again; the
/// Nightly instance and its worlds stay).
/// The native mods turned on in the instance Play starts, unpacked and checked, with their
/// bundles: what the warning names and the build compiles.
fn native_mods_to_build(
&self,
) -> Result<(std::path::PathBuf, Vec<native_mods::Bundle>), String> {
let folder = native_mods::installed_mods(&instances::selected().home)?;
let found = native_mods::bundles(&folder)?;
Ok((folder, found))
}
/// Builds the selected instance's native mods, once the player accepted the warning. The
/// build reuses the game files of the version the instance plays, else the newest installed.
fn build_native(&mut self) {
if self.native_step.is_some() {
return;
}
self.native_confirm = None;
self.native_error = None;
let instance = instances::selected();
let base = instance
.version
.clone()
.filter(|v| !native_mods::is_native(v))
.or_else(|| {
self.installed
.iter()
.find(|t| backend::is_game_tag(t) || t.starts_with("nightly-"))
.cloned()
});
let Some(base) = base else {
self.native_error = Some(tr("Install Horizon first.").into());
return;
};
let folder = match self.native_mods_to_build() {
Ok((folder, _)) => folder,
Err(e) => {
self.native_error = Some(e);
return;
}
};
self.native_step = Some(tr("Starting the build").into());
let tx = self.tx.clone();
std::thread::spawn(move || {
let result = native_mods::build(&base, &folder, Some(&instance), |step| {
let _ = tx.send(Msg::NativeProgress(step.label()));
});
let _ = tx.send(Msg::Native(result));
});
}
fn set_nightly(&mut self, on: bool) {
self.settings.nightly = on;
if on {
@@ -776,6 +835,15 @@ impl Launcher {
}
Msg::Updates(Err(e)) => self.update_error = Some(e),
Msg::NightlyProgress(p) => self.nightly_progress = Some(p),
Msg::NativeProgress(step) => self.native_step = Some(step),
Msg::Native(result) => {
self.native_step = None;
self.installed = backend::installed();
self.reload_instances();
if let Err(e) = result {
self.native_error = Some(e);
}
}
Msg::Nightly(result) => {
self.nightly_progress = None;
self.installed = backend::installed();
@@ -2953,6 +3021,7 @@ impl Launcher {
.child(self.proxy_row(n + 4, cx))
.child(group("Game", "gamepad"))
.child(self.game_args_row(n + 5, cx))
.child(self.native_mods_row(n + 5, cx))
.child(group("AI", "terminal"))
.child(self.no_ai_row(n + 6, cx))
.child(group("About", "info-box"))
@@ -3061,6 +3130,109 @@ impl Launcher {
/// Settings' Game arguments row: the extra arguments the game starts with, kept in
/// `settings.json` and appended to the launcher's own (quotes group a word with spaces).
/// Settings' Native mods row (docs/native-mods.md): off by default. On, Build compiles the
/// native mods installed in the instance Play starts, after a warning that names them, and
/// that instance then plays the build.
fn native_mods_row(&self, n: usize, cx: &mut Context<Self>) -> Div {
let t = self.theme;
let on = self.settings.native_mods;
let toggle =
switch("native-mods", on, &t).on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
this.settings.native_mods = !this.settings.native_mods;
this.native_confirm = None;
this.settings.save();
cx.notify();
}));
let mut detail = div().flex().flex_col().gap(px(4.)).child(
tr("Native mods from the Mods page compile into the game with the launcher's own Rust. Not sandboxed: they can do anything you can on this computer.").to_string(),
);
if on {
let status = match (&self.native_step, &self.native_error) {
(Some(step), _) => Some(div().child(step.clone())),
(None, Some(e)) => Some(div().text_color(t.danger).child(e.clone())),
(None, None) => instances::selected()
.version
.filter(|v| native_mods::is_native(v))
.map(|v| {
div().child(trf("{version} plays in this instance.", &[("version", &v)]))
}),
};
detail = detail.children(status);
if self.native_step.is_none() && self.native_confirm.is_none() {
detail = detail.child(div().flex().gap(px(8.)).mt(px(4.)).child(
button("native-build", "Build", Kind::Primary, &t).on_click(cx.listener(
|this, _: &ClickEvent, _, cx| {
this.native_confirm = Some(this.native_mods_to_build().map(|(_, b)| b));
cx.notify();
},
)),
));
}
if let Some(mods) = &self.native_confirm {
detail = detail.child(self.native_warning(mods, cx));
}
}
index_row(
n,
tr("Native mods (experimental)"),
Some(detail.into_any_element()),
Some(toggle.into_any_element()),
&t,
)
}
/// The warning before a native build: what the mods can do and which mods. The build starts
/// only from its button.
fn native_warning(
&self,
mods: &Result<Vec<native_mods::Bundle>, String>,
cx: &mut Context<Self>,
) -> Div {
let t = self.theme;
let list = match mods {
Ok(found) => found
.iter()
.map(|b| format!("{} {}", b.id, b.version))
.collect::<Vec<_>>()
.join(", "),
Err(e) => e.clone(),
};
let panel = div()
.flex()
.flex_col()
.gap(px(6.))
.mt(px(8.))
.p(px(12.))
.bg(t.well)
.child(div().text_color(t.danger).child(tr("These mods will run with full access to your computer").to_string()))
.child(tr("They can read, change or delete your files, and use your accounts and network, like any program you run. Build them only if you trust their authors: the Mods page names them.").to_string())
.child(trf("Mods: {mods}", &[("mods", &list)]))
.child(tr("The build compiles the game: about ten minutes and a few GB of disk the first time, a few minutes after that.").to_string());
let mut buttons = div().flex().gap(px(8.)).mt(px(4.));
if mods.is_ok() {
buttons = buttons.child(
button(
"native-trust",
"I trust these mods: build",
Kind::Primary,
&t,
)
.on_click(cx.listener(|this, _: &ClickEvent, _, cx| {
this.build_native();
cx.notify();
})),
);
}
panel.child(buttons.child(
button("native-cancel", "Cancel", Kind::Secondary, &t).on_click(cx.listener(
|this, _: &ClickEvent, _, cx| {
this.native_confirm = None;
cx.notify();
},
)),
))
}
fn game_args_row(&self, n: usize, cx: &mut Context<Self>) -> Div {
let t = self.theme;
let focused = self.args_focused;