Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions packages/app-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
" ([email protected])"
);
pub fn launcher_user_agent() -> String {
const LAUNCHER_BASE_USER_AGENT: &str =
concat!("modrinth/theseus/", env!("CARGO_PKG_VERSION"),);

format!(
"{} ({}; [email protected])",
LAUNCHER_BASE_USER_AGENT,
std::env::consts::OS
)
}
3 changes: 1 addition & 2 deletions packages/app-lib/src/state/friends.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions packages/app-lib/src/util/fetch.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,8 +20,10 @@ pub struct FetchSemaphore(pub Semaphore);

pub static REQWEST_CLIENT: LazyLock<reqwest::Client> = 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)))
Expand Down