[PR #1788] [MERGED] Discord Rich Presence: Playing Horizon on the player's Discord profile, with a switch #3761

Closed
opened 2026-11-03 04:12:08 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1788
Author: @ludovic111
Created: 10/25/2026
Status: ✅ Merged
Merged: 10/25/2026
Merged by: @ludovic111

Base: main ← Head: feat/discord-presence


📝 Commits (3)

  • 15e4611 Discord Rich Presence: show what the player does, with a switch in Horizon Settings
  • 3063d87 docs: Discord Rich Presence is live with the Horizon application
  • 47d1b06 Discord presence: test where the game looks for Discord on macOS, Linux, Flatpak and Snap

📊 Changes

8 files changed (+449 additions, -7 deletions)

View changed files

📝 crates/horizon-client/src/discord_presence.rs (+58 -3)
📝 crates/horizon-client/src/extras.rs (+19 -3)
📝 crates/horizon-client/src/game.rs (+12 -0)
➕ crates/horizon-client/src/game/discord.rs (+43 -0)
📝 crates/horizon-client/src/game/remote.rs (+4 -0)
📝 crates/horizon-client/src/options_ui.rs (+4 -1)
📝 docs/native-client.md (+22 -0)
➕ tools/discord_presence_e2e.py (+287 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Stacked on #1787: merge that one first.

What players get

While Discord runs, the player's profile shows Playing Horizon with the Horizon logo and what they are doing:

Where Details State Extra
Title screen, menus In the menus none none
Single player (server thread or in-frame) Singleplayer In the Overworld / Nether / End time since entering the world
A server, someone's LAN world, a friend's world Multiplayer the dimension time; never the address or the server's name
Open to LAN / Play with Friends Hosting a world the dimension time + party "N of 8"

Horizon Settings gets a Discord Rich Presence: On/Off switch next to Controller Settings. It is on by default and saved as discordPresence in horizon-extras.txt. Its tooltip says what is shared. Turning it off clears the activity at once. HORIZON_NO_DISCORD=1 turns it off for one run. Dedicated servers (--dedicated) never start it. The launcher's "In the launcher" (optional in the brief) is not part of this PR.

How

  • game/discord.rs reads the window's own state each frame: title, lan (in-frame host: 1 + guests), integrated.published() (server-thread host: the player list's count through the new Remote::player_count), remote without integrated (multiplayer), dim and mode. It hands the result to discord_presence::set, which wakes the thread only on a change. The frame does no new work beyond one uncontended mutex lock.
  • run() starts the thread for every non-dedicated launch (automated runs only with a fake Discord). Both event-loop exits call stop().
  • tools/discord_presence_e2e.py gives each real game a fake Discord IPC server and drives the game with horizon-ctl.
  • docs/native-client.md has a "Discord Rich Presence" section.

How tested (Mac mini, Metal, offscreen, fake Discord)

python3 tools/discord_presence_e2e.py passes all six checks: {"single": true, "in-frame": true, "lan": true, "lan-in-frame": true, "setting": true, "late": true}.

  • single (server thread, the default): title "In the menus" → world "Singleplayer / In the Overworld" with a start time → /execute in minecraft:the_nether run tp gives "In the Nether" with the same start time → quit clears the activity (null). The world's name never reaches Discord.
  • in-frame (--in-frame, confirmed by the log having no Server thread): the same sequence.
  • lan (host on its server thread): the host shows "Hosting a world" with party [1, 8], and [2, 8] once the guest joins. The guest goes from "In the menus" to "Multiplayer / In the Overworld", and 127.0.0.1 never reaches Discord. Both clear on quit.
  • lan-in-frame: the same with the host in-frame (the LanHost path).
  • setting: with discordPresence:false, Discord receives no handshake at all. Switching it on in Horizon Settings shows "In the menus", switching it off clears it, and the file keeps it off.
  • late: Discord starts after the game and is found at the next retry (11 s).
  • By hand: a dedicated server given a fake Discord ran for 40 s without connecting. A windowed game with no Discord running wrote no Discord lines to its logs.
  • Not run: a dedicated server's client (it takes the same Multiplayer path as the LAN guest), and Linux/Windows end to end (the e2e tool fakes Unix sockets: Linux CI runs the unit tests; Windows was only clippy-checked in #1787).

Self-check

Run once on the stack's head (3063d87, both PRs together).

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 574d54e6e, 13 min 7 s)

Check Result
Scope ⚠️ 10 files, +964 −5; 947 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅ (1 s)
Python tests ❌ 267 run, FAILED (errors=2) (1 min 40 s)
rustfmt ✅ (13 s)
clippy ✅ (1 min 32 s)
tests: horizon-client ✅ 1218 passed (9 min 6 s)
doc tests ✅ 0 passed (4 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 331 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 319 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)
  • Python tests: the 2 errors are test_parity_runner.OracleReuseTests.test_reuses_until_an_input_or_output_changes and test_rust_parity.ParityRunnerTests.test_report_rejects_sources_changed_during_a_run. They are not this branch's: both fail the same way on main on macOS (/var vs /private/var temp paths, and a java shim exiting 127).
  • Parity: left to CI. The Mac mini was running three full parity runs, so the orchestrator stopped the local one.

Needs Ludovic

One look with a real Discord: no Discord client is installed on the Mac mini, and the agent did not install one or log in to one. Start Horizon with Discord running and check the profile card. Also, later, whether to upload the game-mode small images (survival, creative, adventure, spectator). The code is ready for them behind MODE_IMAGES.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/1788 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/25/2026 **Status:** ✅ Merged **Merged:** 10/25/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/discord-presence` --- ### 📝 Commits (3) - [`15e4611`](https://github.com/horizon-rust/horizon/commit/15e46114a6ae71986aac13052c724526130bca93) Discord Rich Presence: show what the player does, with a switch in Horizon Settings - [`3063d87`](https://github.com/horizon-rust/horizon/commit/3063d87199fd45ff72edfac36f71b191d865702c) docs: Discord Rich Presence is live with the Horizon application - [`47d1b06`](https://github.com/horizon-rust/horizon/commit/47d1b060b24af9e816f42893c695fa5705c1e92f) Discord presence: test where the game looks for Discord on macOS, Linux, Flatpak and Snap ### 📊 Changes **8 files changed** (+449 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/discord_presence.rs` (+58 -3) 📝 `crates/horizon-client/src/extras.rs` (+19 -3) 📝 `crates/horizon-client/src/game.rs` (+12 -0) ➕ `crates/horizon-client/src/game/discord.rs` (+43 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+4 -0) 📝 `crates/horizon-client/src/options_ui.rs` (+4 -1) 📝 `docs/native-client.md` (+22 -0) ➕ `tools/discord_presence_e2e.py` (+287 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Stacked on #1787: merge that one first. ## What players get While Discord runs, the player's profile shows **Playing Horizon** with the Horizon logo and what they are doing: | Where | Details | State | Extra | |---|---|---|---| | Title screen, menus | In the menus | none | none | | Single player (server thread or in-frame) | Singleplayer | In the Overworld / Nether / End | time since entering the world | | A server, someone's LAN world, a friend's world | Multiplayer | the dimension | time; never the address or the server's name | | Open to LAN / Play with Friends | Hosting a world | the dimension | time + party "N of 8" | **Horizon Settings** gets a **Discord Rich Presence: On/Off** switch next to Controller Settings. It is on by default and saved as `discordPresence` in `horizon-extras.txt`. Its tooltip says what is shared. Turning it off clears the activity at once. `HORIZON_NO_DISCORD=1` turns it off for one run. Dedicated servers (`--dedicated`) never start it. The launcher's "In the launcher" (optional in the brief) is not part of this PR. ## How - `game/discord.rs` reads the window's own state each frame: `title`, `lan` (in-frame host: 1 + guests), `integrated.published()` (server-thread host: the player list's count through the new `Remote::player_count`), `remote` without `integrated` (multiplayer), `dim` and `mode`. It hands the result to `discord_presence::set`, which wakes the thread only on a change. The frame does no new work beyond one uncontended mutex lock. - `run()` starts the thread for every non-dedicated launch (automated runs only with a fake Discord). Both event-loop exits call `stop()`. - `tools/discord_presence_e2e.py` gives each real game a fake Discord IPC server and drives the game with horizon-ctl. - docs/native-client.md has a "Discord Rich Presence" section. ## How tested (Mac mini, Metal, offscreen, fake Discord) `python3 tools/discord_presence_e2e.py` passes all six checks: `{"single": true, "in-frame": true, "lan": true, "lan-in-frame": true, "setting": true, "late": true}`. - **single** (server thread, the default): title "In the menus" → world "Singleplayer / In the Overworld" with a start time → `/execute in minecraft:the_nether run tp` gives "In the Nether" with the same start time → quit clears the activity (null). The world's name never reaches Discord. - **in-frame** (`--in-frame`, confirmed by the log having no Server thread): the same sequence. - **lan** (host on its server thread): the host shows "Hosting a world" with party [1, 8], and [2, 8] once the guest joins. The guest goes from "In the menus" to "Multiplayer / In the Overworld", and 127.0.0.1 never reaches Discord. Both clear on quit. - **lan-in-frame**: the same with the host in-frame (the `LanHost` path). - **setting**: with `discordPresence:false`, Discord receives no handshake at all. Switching it on in Horizon Settings shows "In the menus", switching it off clears it, and the file keeps it off. - **late**: Discord starts after the game and is found at the next retry (11 s). - By hand: a dedicated server given a fake Discord ran for 40 s without connecting. A windowed game with no Discord running wrote no Discord lines to its logs. - Not run: a dedicated server's client (it takes the same `Multiplayer` path as the LAN guest), and Linux/Windows end to end (the e2e tool fakes Unix sockets: Linux CI runs the unit tests; Windows was only clippy-checked in #1787). ## Self-check Run once on the stack's head (3063d87, both PRs together). **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 574d54e6e, 13 min 7 s) | Check | Result | | --- | --- | | Scope | ⚠️ 10 files, +964 −5; 947 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ (1 s) | | Python tests | ❌ 267 run, FAILED (errors=2) (1 min 40 s) | | rustfmt | ✅ (13 s) | | clippy | ✅ (1 min 32 s) | | tests: horizon-client | ✅ 1218 passed (9 min 6 s) | | doc tests | ✅ 0 passed (4 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 331 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 319 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | - **Python tests:** the 2 errors are `test_parity_runner.OracleReuseTests.test_reuses_until_an_input_or_output_changes` and `test_rust_parity.ParityRunnerTests.test_report_rejects_sources_changed_during_a_run`. They are not this branch's: both fail the same way on main on macOS (`/var` vs `/private/var` temp paths, and a `java` shim exiting 127). - **Parity:** left to CI. The Mac mini was running three full parity runs, so the orchestrator stopped the local one. ## Needs Ludovic One look with a real Discord: no Discord client is installed on the Mac mini, and the agent did not install one or log in to one. Start Horizon with Discord running and check the profile card. Also, later, whether to upload the game-mode small images (`survival`, `creative`, `adventure`, `spectator`). The code is ready for them behind `MODE_IMAGES`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:12:08 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#3761
No description provided.