From 17db55a0bcb6c836a3677347ecb7bfc47c2d255f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Talbot?= <108630700+fetchfern@users.noreply.github.com> Date: Wed, 7 Jan 2026 21:11:18 -0500 Subject: [PATCH] Include OS in theseus User-Agent (#5046) --- packages/app-lib/src/lib.rs | 15 ++++++++++----- packages/app-lib/src/state/friends.rs | 3 +-- packages/app-lib/src/util/fetch.rs | 5 +++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/app-lib/src/lib.rs b/packages/app-lib/src/lib.rs index 45da6fbc..6f62495e 100644 --- a/packages/app-lib/src/lib.rs +++ b/packages/app-lib/src/lib.rs @@ -26,8 +26,13 @@ pub use event::{ pub use logger::start_logger; pub use state::State; -pub const LAUNCHER_USER_AGENT: &str = concat!( - "modrinth/theseus/", - env!("CARGO_PKG_VERSION"), - " (support@modrinth.com)" -); +pub fn launcher_user_agent() -> String { + const LAUNCHER_BASE_USER_AGENT: &str = + concat!("modrinth/theseus/", env!("CARGO_PKG_VERSION"),); + + format!( + "{} ({}; support@modrinth.com)", + LAUNCHER_BASE_USER_AGENT, + std::env::consts::OS + ) +} diff --git a/packages/app-lib/src/state/friends.rs b/packages/app-lib/src/state/friends.rs index ad28ffeb..41487df8 100644 --- a/packages/app-lib/src/state/friends.rs +++ b/packages/app-lib/src/state/friends.rs @@ -1,5 +1,4 @@ use crate::ErrorKind; -use crate::LAUNCHER_USER_AGENT; use crate::data::ModrinthCredentials; use crate::event::FriendPayload; use crate::event::emit::emit_friend; @@ -85,7 +84,7 @@ impl FriendsSocket { request.headers_mut().insert( "User-Agent", - HeaderValue::from_str(LAUNCHER_USER_AGENT).unwrap(), + HeaderValue::from_str(&crate::launcher_user_agent()).unwrap(), ); let res = connect_async(request).await; diff --git a/packages/app-lib/src/util/fetch.rs b/packages/app-lib/src/util/fetch.rs index fafba221..3ed23896 100644 --- a/packages/app-lib/src/util/fetch.rs +++ b/packages/app-lib/src/util/fetch.rs @@ -1,7 +1,6 @@ //! Functions for fetching information from the Internet use super::io::{self, IOError}; use crate::ErrorKind; -use crate::LAUNCHER_USER_AGENT; use crate::event::LoadingBarId; use crate::event::emit::emit_loading; use bytes::Bytes; @@ -21,8 +20,10 @@ pub struct FetchSemaphore(pub Semaphore); pub static REQWEST_CLIENT: LazyLock = LazyLock::new(|| { let mut headers = reqwest::header::HeaderMap::new(); + let header = - reqwest::header::HeaderValue::from_str(LAUNCHER_USER_AGENT).unwrap(); + reqwest::header::HeaderValue::from_str(&crate::launcher_user_agent()) + .unwrap(); headers.insert(reqwest::header::USER_AGENT, header); reqwest::Client::builder() .tcp_keepalive(Some(time::Duration::from_secs(10)))