launcher: a forgotten offline name is gone for good

Forget removed the name from accounts.json but left skins/<name>.png and
skins/<name>.cape.png behind, the skin panel's file pick could still
record a look for a name that no longer existed, and the account rows'
Play as / Play offline / Sign out saved the window's stale account list,
which could write a name forgotten elsewhere (CLI, another window) back.

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
socksprox
2026-10-27 17:41:07 +01:00
parent 42cbbb565e
commit a7e3bcf79f
10 changed files with 90 additions and 18 deletions
+1 -1
View File
@@ -136,7 +136,7 @@ MCP: `account_offline`.
## `horizon-launcher account forget-offline`
Forget one of your offline names.
Forget one of your offline names; its skin and cape go with it.
horizon-launcher account forget-offline <NAME>
+3 -2
View File
@@ -125,8 +125,9 @@ The opening, then Play ([clip](docs/opening.webm)):
- **Accounts and quick switch**: the top bar's account chip opens a menu of everyone who can play:
each signed-in Microsoft account, the offline names the player keeps, and the name the game
made up (`horizon-player.txt`). Picking one plays as it from the next Play. Settings > Account
adds offline names (3 to 16 letters, digits or `_`; the game gets `--name`) and forgets them;
the Console's Share log takes them out of the log too. `horizon-launcher account offline
adds offline names (3 to 16 letters, digits or `_`; the game gets `--name`) and forgets them,
skin and cape files included; the Console's Share log takes the names out of the log too.
`horizon-launcher account offline
[NAME]`, `account select <name>` (an account or an offline name), `account forget-offline
<name>`.
- **Accent and Home background**: on top of Dark, Light or System, Settings > Launcher picks an
+4 -2
View File
@@ -760,14 +760,16 @@ impl Accounts {
Ok(name.to_string())
}
/// Forgets an offline name; if it was playing, the game's own name plays.
pub fn remove_offline(&mut self, name: &str) -> Result<(), String> {
/// Forgets an offline name: its look and its skin and cape files (`skins`) go with it; if
/// it was playing, the game's own name plays.
pub fn remove_offline(&mut self, name: &str, skins_dir: &Path) -> Result<(), String> {
let before = self.offline.len();
self.offline.retain(|n| !n.eq_ignore_ascii_case(name));
self.looks.remove(&name.to_ascii_lowercase());
if self.offline.len() == before {
return Err(format!("No offline name {name}."));
}
crate::skins::forget(skins_dir, name);
if self
.offline_selected
.as_ref()
+19 -2
View File
@@ -452,9 +452,26 @@ fn offline_names_switch_with_accounts() {
assert_eq!(a.name_arg(), None, "an account plays with its own name");
assert!(a.play_as(Player::Microsoft("zzz".into())).is_err());
a.play_as(Player::Offline("Builder_1".into())).unwrap();
a.remove_offline("BUILDER_1").unwrap();
// Forgetting drops the look and the name's skin and cape files too.
let dir = std::env::temp_dir().join(format!("horizon-accounts-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
std::fs::create_dir_all(&dir).unwrap();
let (skin, cape) = crate::skins::files(&dir, "builder_1");
std::fs::write(&skin, b"skin").unwrap();
std::fs::write(&cape, b"cape").unwrap();
a.looks.insert(
"builder_1".into(),
crate::skins::Look {
skin: true,
cape: true,
..crate::skins::Look::default()
},
);
a.remove_offline("BUILDER_1", &dir).unwrap();
assert_eq!(a.player(), Player::GameName);
assert!(a.remove_offline("Builder_1").is_err());
assert!(a.looks.is_empty() && !skin.exists() && !cape.exists());
let _ = std::fs::remove_dir_all(&dir);
assert!(a.remove_offline("Builder_1", &dir).is_err());
// An accounts.json from before offline names reads as it was, and writes nothing new.
let old: Accounts = serde_json::from_str(r#"{"accounts":[],"selected":null}"#).unwrap();
assert_eq!(old.player(), Player::GameName);
+2 -2
View File
@@ -91,7 +91,7 @@ enum AccountCmd {
/// Play offline, without an account: as NAME (kept to switch back to; 3 to 16 letters,
/// digits or _), or as the name the game made up
Offline { name: Option<String> },
/// Forget one of your offline names
/// Forget one of your offline names; its skin and cape go with it
ForgetOffline { name: String },
/// Show or set an offline name's skin and cape: a 64x64 (or 64x32) skin PNG, a 64x32 cape
/// PNG, the model. Kept by the launcher and given to the game when that name plays
@@ -1444,7 +1444,7 @@ fn account_command(action: AccountCmd, as_json: bool) -> Result<(), String> {
}
}
AccountCmd::ForgetOffline { name } => {
accounts.remove_offline(&name)?;
accounts.remove_offline(&name, &horizon_launcher::skins::dir())?;
accounts.save()?;
println!("Forgot the offline name {name}.");
}
+13 -8
View File
@@ -3103,8 +3103,11 @@ impl Launcher {
actions = actions.child(
button(format!("offline-{i}"), "Play offline", Kind::Ghost, &t).on_click(
cx.listener(|this, _: &ClickEvent, _, cx| {
this.accounts.selected = None;
let _ = this.accounts.save();
let mut accounts = Accounts::load();
accounts.selected = None;
if accounts.save().is_ok() {
this.accounts = accounts;
}
cx.notify();
}),
),
@@ -3114,8 +3117,7 @@ impl Launcher {
actions = actions.child(
button(format!("select-{i}"), "Play as", Kind::Secondary, &t).on_click(
cx.listener(move |this, _: &ClickEvent, _, cx| {
this.accounts.selected = Some(uuid.clone());
let _ = this.accounts.save();
this.play_as(account::Player::Microsoft(uuid.clone()));
cx.notify();
}),
),
@@ -3124,11 +3126,14 @@ impl Launcher {
actions = actions.child(
button(format!("sign-out-{i}"), "Sign out", Kind::Ghost, &t).on_click(cx.listener(
move |this, _: &ClickEvent, _, cx| {
let store = account::store();
if let Err(e) = this.accounts.remove(store, &uuid) {
this.sign_in_state = Some(SignInState::Done(Err(e)));
let mut accounts = Accounts::load();
match accounts
.remove(account::store(), &uuid)
.and_then(|()| accounts.save())
{
Ok(()) => this.accounts = accounts,
Err(e) => this.sign_in_state = Some(SignInState::Done(Err(e))),
}
let _ = this.accounts.save();
cx.notify();
},
)),
+16
View File
@@ -38,6 +38,14 @@ impl Launcher {
return Ok(());
};
let mut accounts = Accounts::load();
// The name may have been forgotten while a file dialog was open: keep nothing for it.
if !accounts
.offline
.iter()
.any(|n| n.eq_ignore_ascii_case(&name))
{
return Ok(());
}
let mut look = accounts.look(&name);
change(&mut look);
accounts.looks.insert(name.to_ascii_lowercase(), look);
@@ -75,6 +83,14 @@ impl Launcher {
let Some(name) = self.skin.as_ref().map(|p| p.name.clone()) else {
return;
};
// The name may have been forgotten while the file dialog was open.
if !Accounts::load()
.offline
.iter()
.any(|n| n.eq_ignore_ascii_case(&name))
{
return;
}
let done = skins::keep(&skins::dir(), &name, &path, cape).and_then(|()| {
self.save_look(|l| match cape {
false => l.skin = true,
+7
View File
@@ -157,6 +157,13 @@ pub fn keep(dir: &Path, name: &str, file: &Path, cape: bool) -> Result<(), Strin
std::fs::write(&to, bytes).map_err(|e| format!("{}: {e}", to.display()))
}
/// Drops a forgotten name's files (`Accounts::remove_offline`); missing files are fine.
pub fn forget(dir: &Path, name: &str) {
let (skin, cape) = files(dir, name);
let _ = std::fs::remove_file(skin);
let _ = std::fs::remove_file(cape);
}
/// The variables the game gets for `name`'s look.
pub fn env(dir: &Path, name: &str, look: &Look) -> Vec<(&'static str, String)> {
let (skin, cape) = files(dir, name);
+20
View File
@@ -102,3 +102,23 @@ fn a_kept_look_reaches_the_game_only_with_its_files() {
);
std::fs::remove_dir_all(&root).unwrap();
}
#[test]
fn forgetting_a_name_drops_its_files() {
let root = std::env::temp_dir().join(format!("horizon-skins-forget-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&root);
std::fs::create_dir_all(&root).unwrap();
let (src, cape_src) = (root.join("alex.png"), root.join("cape.png"));
std::fs::write(&src, png(&mapped(64))).unwrap();
std::fs::write(&cape_src, png(&mapped(32))).unwrap();
let dir = root.join("skins");
keep(&dir, "Alex", &src, false).unwrap();
keep(&dir, "Alex", &cape_src, true).unwrap();
let (skin, cape) = files(&dir, "Alex");
assert!(skin.is_file() && cape.is_file());
forget(&dir, "ALEX");
assert!(!skin.exists() && !cape.exists());
// A name that never had files is forgotten all the same.
forget(&dir, "Alex");
std::fs::remove_dir_all(&root).unwrap();
}
+5 -1
View File
@@ -183,7 +183,11 @@ impl Launcher {
button(format!("offline-forget-{i}"), "Forget", Kind::Ghost, &t).on_click(
cx.listener(move |this, _: &ClickEvent, _, cx| {
let mut accounts = Accounts::load();
if accounts.remove_offline(&forget).is_ok() && accounts.save().is_ok() {
if accounts
.remove_offline(&forget, &horizon_launcher::skins::dir())
.is_ok()
&& accounts.save().is_ok()
{
this.accounts = accounts;
}
cx.notify();