Merge pull request #2591 from ludovic111/feat/launcher-instance-version
🤖 Agent: version per instance (item 2 of launcher-features-1), now on main after #2590: verify and launcher CI passed on this head, merges cleanly with main; launcher fmt, clippy -D warnings and lib tests pass locally (pin/unpin test); screenshots in the PR.
This commit is contained in:
@@ -320,6 +320,16 @@ Make Play start this instance.
|
||||
|
||||
MCP: `instance_select`.
|
||||
|
||||
## `horizon-launcher instance version`
|
||||
|
||||
Keep an instance on one installed Horizon version, or "latest" to follow updates again.
|
||||
|
||||
horizon-launcher instance version <INSTANCE> <VERSION>
|
||||
|
||||
- `INSTANCE`
|
||||
|
||||
MCP: `instance_version`.
|
||||
|
||||
## `horizon-launcher modpack list`
|
||||
|
||||
The imported packs and their coverage (the default).
|
||||
|
||||
+4
-1
@@ -78,7 +78,9 @@ The opening, then Play ([clip](docs/opening.webm)):
|
||||
data folder, so renaming moves nothing. Every instance follows the launcher's data collection
|
||||
answer and No AI. In the window, **+** beside Instances makes one, the sidebar lists them by
|
||||
group (click one to play it), and Home's Instance row has Edit (name, group, icon), Copy and
|
||||
Open folder.
|
||||
Open folder. Each instance plays the launcher's version, which follows updates, unless the Play
|
||||
page's version picker keeps it on another installed one (to keep an old world on the version
|
||||
it was made with); picking the version marked "follows updates" lets it follow again.
|
||||
- **Patch notes**: each release's notes, newest first, with a link to GitHub Sponsors. Quiet "Discord" and "Website" links sit in the footer.
|
||||
|
||||
Data lives in the platform's data directory (`~/.local/share/horizon-launcher` on Linux,
|
||||
@@ -178,6 +180,7 @@ and don't set `%ERRORLEVEL%` / `$LASTEXITCODE`. Scripts that need the exit code
|
||||
horizon-launcher instance create <name> [--copy <instance>] empty, or a copy of one's worlds, options and packs
|
||||
horizon-launcher instance rename|icon|group <instance> <value> icon: a block or item name, #rrggbb or none
|
||||
horizon-launcher instance select <instance> make Play start it
|
||||
horizon-launcher instance version <instance> <tag|latest> keep it on one installed version, or follow updates
|
||||
horizon-launcher modpack [list] the imported packs and their coverage
|
||||
horizon-launcher modpack import <pack> a .mrpack, CurseForge zip or instance folder
|
||||
horizon-launcher modpack port <pack> [--from <dir>] [--version <tag>] get the jars and carry them over
|
||||
|
||||
+17
-2
@@ -180,6 +180,8 @@ enum InstanceCmd {
|
||||
},
|
||||
/// Make Play start this instance
|
||||
Select { instance: String },
|
||||
/// Keep an instance on one installed Horizon version, or "latest" to follow updates again
|
||||
Version { instance: String, version: String },
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
@@ -647,11 +649,11 @@ fn execute(command: Cmd, as_json: bool) -> Result<(), String> {
|
||||
join,
|
||||
arg,
|
||||
} => {
|
||||
let mut cmd = backend::client(&backend::resolve_version(version.as_deref())?)?;
|
||||
let instance = match instance {
|
||||
Some(name) => instances::find(&name)?,
|
||||
None => instances::selected(),
|
||||
};
|
||||
let mut cmd = backend::client(&instance.resolve_version(version.as_deref())?)?;
|
||||
instances::apply(&mut cmd, &instance)?;
|
||||
if let Some(code) = join {
|
||||
backend::join_friend(&mut cmd, &code)?;
|
||||
@@ -1385,6 +1387,7 @@ fn instance(action: InstanceCmd, as_json: bool) -> Result<(), String> {
|
||||
serde_json::json!({
|
||||
"id": i.id, "name": i.name, "kind": format!("{:?}", i.kind).to_lowercase(),
|
||||
"home": i.home, "icon": i.icon, "group": i.group, "selected": selected,
|
||||
"version": i.version,
|
||||
})
|
||||
};
|
||||
let line = |i: &instances::Instance, selected: bool| {
|
||||
@@ -1394,8 +1397,13 @@ fn instance(action: InstanceCmd, as_json: bool) -> Result<(), String> {
|
||||
.as_ref()
|
||||
.map(|g| format!(" [{g}]"))
|
||||
.unwrap_or_default();
|
||||
let pinned = i
|
||||
.version
|
||||
.as_ref()
|
||||
.map(|v| format!(" {v}"))
|
||||
.unwrap_or_default();
|
||||
println!(
|
||||
"{mark} {} ({}){group}\n {}",
|
||||
"{mark} {} ({}){pinned}{group}\n {}",
|
||||
i.name,
|
||||
i.id,
|
||||
i.home.display()
|
||||
@@ -1430,6 +1438,13 @@ fn instance(action: InstanceCmd, as_json: bool) -> Result<(), String> {
|
||||
changed(instances::edit(&instance, |m| m.group = group)?)
|
||||
}
|
||||
InstanceCmd::Select { instance } => changed(instances::select(&instance)?),
|
||||
InstanceCmd::Version { instance, version } => {
|
||||
let pin = match version.as_str() {
|
||||
"latest" => None,
|
||||
tag => Some(backend::resolve_version(Some(tag))?),
|
||||
};
|
||||
changed(instances::edit(&instance, |m| m.version = pin)?)
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -86,6 +86,10 @@ pub struct Meta {
|
||||
pub icon: Option<Icon>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub group: Option<String>,
|
||||
/// The Horizon version this instance plays, kept when newer ones are installed. None: the
|
||||
/// launcher's own version, which follows updates.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub version: Option<String>,
|
||||
}
|
||||
|
||||
/// `instances.json`: each instance's choices, by id.
|
||||
@@ -121,6 +125,25 @@ pub struct Instance {
|
||||
pub home: PathBuf,
|
||||
pub icon: Option<Icon>,
|
||||
pub group: Option<String>,
|
||||
/// Its pinned Horizon version, if any (`Meta::version`).
|
||||
pub version: Option<String>,
|
||||
}
|
||||
|
||||
impl Instance {
|
||||
/// The installed version this instance plays: its pinned one, else `requested` (the
|
||||
/// command line's `--version`) or the launcher's (`backend::resolve_version`).
|
||||
pub fn resolve_version(&self, requested: Option<&str>) -> Result<String, String> {
|
||||
match (requested, &self.version) {
|
||||
(None, Some(pinned)) => backend::resolve_version(Some(pinned)).map_err(|_| {
|
||||
format!(
|
||||
"{} plays {pinned}, which is not installed: install it, or horizon-launcher \
|
||||
instance version \"{}\" latest",
|
||||
self.name, self.name
|
||||
)
|
||||
}),
|
||||
_ => backend::resolve_version(requested),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The instances, by the default game home and the launcher's data folder: Horizon first, then
|
||||
@@ -172,6 +195,7 @@ fn list_in(game_home: &Path, data: &Path) -> Vec<Instance> {
|
||||
name: meta.name.unwrap_or(name),
|
||||
icon: meta.icon,
|
||||
group: meta.group,
|
||||
version: meta.version,
|
||||
id,
|
||||
kind,
|
||||
work,
|
||||
|
||||
@@ -201,3 +201,26 @@ fn icons_are_a_texture_name_or_a_colour() {
|
||||
assert_eq!(Icon::Texture("stone".into()).texture(&root), None);
|
||||
fs::remove_dir_all(&root).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_instance_keeps_its_own_version_until_it_follows_updates_again() {
|
||||
let root = scratch("version");
|
||||
let (home, data) = (root.join("horizon"), root.join("launcher"));
|
||||
player_home(&home);
|
||||
create_in(&home, &data, "Old world", None).unwrap();
|
||||
let pinned = edit_in(&home, &data, "Old world", |m| {
|
||||
m.version = Some("v0.1.0".into())
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(pinned.version.as_deref(), Some("v0.1.0"));
|
||||
// Renaming keeps it; the other instances follow the launcher's version.
|
||||
let renamed = edit_in(&home, &data, "old-world", |m| m.name = Some("Older".into())).unwrap();
|
||||
assert_eq!(renamed.version.as_deref(), Some("v0.1.0"));
|
||||
assert!(list_in(&home, &data)
|
||||
.iter()
|
||||
.filter(|i| i.id != "old-world")
|
||||
.all(|i| i.version.is_none()));
|
||||
let follows = edit_in(&home, &data, "Older", |m| m.version = None).unwrap();
|
||||
assert_eq!(follows.version, None);
|
||||
fs::remove_dir_all(&root).unwrap();
|
||||
}
|
||||
|
||||
@@ -77,6 +77,25 @@ impl Launcher {
|
||||
list.iter().find(|i| i.id == id).or(list.first())
|
||||
}
|
||||
|
||||
/// The installed version `instance` plays: its own, else the launcher's.
|
||||
pub(super) fn version_of(&self, instance: &Instance) -> Option<&String> {
|
||||
match &instance.version {
|
||||
Some(own) => self.installed.iter().find(|t| *t == own),
|
||||
None => self.launcher_version(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Keeps the selected instance on `tag`, or lets it follow the launcher's version.
|
||||
pub(super) fn pin_version(&mut self, tag: Option<String>) {
|
||||
let Some(id) = self.selected_instance().map(|i| i.id.clone()) else {
|
||||
return;
|
||||
};
|
||||
match instances::edit(&id, |m| m.version = tag) {
|
||||
Ok(_) => self.reload_instances(),
|
||||
Err(e) => self.client_error = Some(e),
|
||||
}
|
||||
}
|
||||
|
||||
fn select_instance(&mut self, instance: &Instance) {
|
||||
self.settings.instance =
|
||||
(instance.kind != InstanceKind::Default).then(|| instance.id.clone());
|
||||
@@ -154,15 +173,6 @@ impl Launcher {
|
||||
cx: &mut Context<Self>,
|
||||
) -> Vec<AnyElement> {
|
||||
let t = self.theme;
|
||||
let tag = self.selected().cloned();
|
||||
let prepared = tag.as_deref().is_some_and(backend::is_prepared);
|
||||
let status = if tag.is_none() {
|
||||
"No version installed"
|
||||
} else if prepared {
|
||||
"Ready"
|
||||
} else {
|
||||
"Needs preparing"
|
||||
};
|
||||
let selected = self.selected_instance().map(|i| i.id.clone());
|
||||
let on_packs = self.page == Page::Mods && self.mods.on_modpacks();
|
||||
let mut out = Vec::new();
|
||||
@@ -174,10 +184,18 @@ impl Launcher {
|
||||
out.push(heading(g.to_uppercase()).into_any_element());
|
||||
}
|
||||
}
|
||||
let tag = self.version_of(&i).cloned();
|
||||
let prepared = tag.as_deref().is_some_and(backend::is_prepared);
|
||||
let (open, sub) = match i.kind {
|
||||
InstanceKind::Default | InstanceKind::Own => (
|
||||
self.page == Page::Play && selected.as_ref() == Some(&i.id),
|
||||
status.to_string(),
|
||||
match (&tag, &i.version) {
|
||||
(None, Some(own)) => format!("{own} is not installed"),
|
||||
(None, None) => "No version installed".into(),
|
||||
(Some(_), _) if !prepared => "Needs preparing".into(),
|
||||
(Some(tag), Some(_)) => format!("Ready · {tag}"),
|
||||
(Some(_), None) => "Ready".into(),
|
||||
},
|
||||
),
|
||||
InstanceKind::Port => {
|
||||
let slug = &i.id["port:".len()..];
|
||||
|
||||
+26
-6
@@ -764,7 +764,15 @@ impl Launcher {
|
||||
switched
|
||||
}
|
||||
|
||||
/// The version Play starts: the selected instance's own, else the launcher's.
|
||||
fn selected(&self) -> Option<&String> {
|
||||
self.selected_instance()
|
||||
.and_then(|i| self.version_of(i))
|
||||
.or_else(|| self.launcher_version())
|
||||
}
|
||||
|
||||
/// The launcher's version: what instances without one of their own play.
|
||||
fn launcher_version(&self) -> Option<&String> {
|
||||
self.settings
|
||||
.selected
|
||||
.as_ref()
|
||||
@@ -1850,16 +1858,20 @@ impl Launcher {
|
||||
.absolute()
|
||||
.top(px(66.))
|
||||
.right_0()
|
||||
.w(px(240.))
|
||||
.w(px(300.))
|
||||
.p(px(6.))
|
||||
.border_2()
|
||||
.border_color(t.outline)
|
||||
.bg(t.surface)
|
||||
.flex()
|
||||
.flex_col();
|
||||
// Picking a version keeps the selected instance on it; the launcher's own version
|
||||
// (newest unless chosen otherwise on Versions) follows updates.
|
||||
let follows = self.launcher_version().cloned();
|
||||
for tag in &self.installed {
|
||||
let selected = self.selected() == Some(tag);
|
||||
let tag = tag.clone();
|
||||
let latest = follows.as_ref() == Some(&tag);
|
||||
menu = menu.child(
|
||||
div()
|
||||
.id(SharedString::from(format!("pick-{tag}")))
|
||||
@@ -1875,12 +1887,20 @@ impl Launcher {
|
||||
.cursor_pointer()
|
||||
.hover(move |s| s.bg(t.plate_soft))
|
||||
.child(tag.clone())
|
||||
.when(selected, |d| {
|
||||
d.child(div().size(px(6.)).rounded_full().bg(t.accent))
|
||||
})
|
||||
.child(
|
||||
div()
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap(px(8.))
|
||||
.when(latest, |d| {
|
||||
d.child(caps("follows updates").text_color(t.muted))
|
||||
})
|
||||
.when(selected, |d| {
|
||||
d.child(div().size(px(6.)).rounded_full().bg(t.accent))
|
||||
}),
|
||||
)
|
||||
.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
|
||||
this.settings.selected = Some(tag.clone());
|
||||
this.settings.save();
|
||||
this.pin_version((!latest).then(|| tag.clone()));
|
||||
this.picker_open = false;
|
||||
cx.notify();
|
||||
})),
|
||||
|
||||
+3
-3
@@ -25,7 +25,7 @@ struct Session {
|
||||
/// The tools the session runs itself, under their CLI names: they keep a process (the game, a
|
||||
/// server) or a sign-in going between calls. Every other CLI command is generated (cli_tools.rs).
|
||||
fn session_tools() -> Value {
|
||||
let version = json!({ "type": "string", "description": "An installed version tag such as v2026.10.13. Default: the selected version." });
|
||||
let version = json!({ "type": "string", "description": "An installed version tag such as v2026.10.13. Default: the selected version (play: the instance's own first)." });
|
||||
let none = json!({ "type": "object", "properties": {} });
|
||||
json!([
|
||||
{ "name": "play", "description": "Start the Horizon client (a game window on the player's screen) under agent control: the game_* tools then play it. Returns once it has started; game_wait_ready waits for the world. CLI: horizon-launcher play",
|
||||
@@ -68,12 +68,12 @@ impl Session {
|
||||
if self.client.as_ref().is_some_and(|c| c.finished().is_none()) {
|
||||
return Err("The client is already running.".into());
|
||||
}
|
||||
let tag = backend::resolve_version(arg_str(args, "version"))?;
|
||||
let mut cmd = backend::client(&tag)?;
|
||||
let instance = match arg_str(args, "instance") {
|
||||
Some(name) => instances::find(name)?,
|
||||
None => instances::selected(),
|
||||
};
|
||||
let tag = instance.resolve_version(arg_str(args, "version"))?;
|
||||
let mut cmd = backend::client(&tag)?;
|
||||
instances::apply(&mut cmd, &instance)?;
|
||||
cmd.args(game_tools::control_args());
|
||||
if let Some(world) = arg_str(args, "world") {
|
||||
|
||||
@@ -116,7 +116,13 @@ impl Launcher {
|
||||
}
|
||||
|
||||
fn play_pack(&mut self, work: PathBuf) {
|
||||
let Some(tag) = self.selected().cloned() else {
|
||||
// The pack's instance plays its own version, if it has one.
|
||||
let pack = self.instances.list.iter().find(|i| i.work == work);
|
||||
let Some(tag) = pack
|
||||
.and_then(|i| self.version_of(i))
|
||||
.or_else(|| self.launcher_version())
|
||||
.cloned()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
if self.client.is_some() || self.starting_client.is_some() {
|
||||
|
||||
Reference in New Issue
Block a user