Use single LAUNCHER_USER_AGENT constant for all user agents
This commit is contained in:
parent
1e934312a4
commit
80e0f84b62
@ -116,7 +116,17 @@ fn main() {
|
|||||||
|
|
||||||
#[cfg(feature = "updater")]
|
#[cfg(feature = "updater")]
|
||||||
{
|
{
|
||||||
builder = builder.plugin(tauri_plugin_updater::Builder::new().build());
|
use tauri_plugin_http::reqwest::header::{HeaderValue, USER_AGENT};
|
||||||
|
use theseus::LAUNCHER_USER_AGENT;
|
||||||
|
builder = builder.plugin(
|
||||||
|
tauri_plugin_updater::Builder::new()
|
||||||
|
.header(
|
||||||
|
USER_AGENT,
|
||||||
|
HeaderValue::from_str(LAUNCHER_USER_AGENT).unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.build(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder = builder
|
builder = builder
|
||||||
|
|||||||
@ -7,12 +7,11 @@ use tauri_plugin_http::reqwest;
|
|||||||
use tauri_plugin_http::reqwest::ClientBuilder;
|
use tauri_plugin_http::reqwest::ClientBuilder;
|
||||||
use tauri_plugin_updater::Error;
|
use tauri_plugin_updater::Error;
|
||||||
use tauri_plugin_updater::Update;
|
use tauri_plugin_updater::Update;
|
||||||
use theseus::{LoadingBarType, emit_loading, init_loading};
|
use theseus::{
|
||||||
|
LAUNCHER_USER_AGENT, LoadingBarType, emit_loading, init_loading,
|
||||||
|
};
|
||||||
use tokio::time::Instant;
|
use tokio::time::Instant;
|
||||||
|
|
||||||
const UPDATER_USER_AGENT: &str =
|
|
||||||
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct PendingUpdateData(pub Mutex<Option<(Arc<Update>, Vec<u8>)>>);
|
pub struct PendingUpdateData(pub Mutex<Option<(Arc<Update>, Vec<u8>)>>);
|
||||||
|
|
||||||
@ -32,7 +31,7 @@ pub async fn get_update_size<R: Runtime>(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut request = ClientBuilder::new().user_agent(UPDATER_USER_AGENT);
|
let mut request = ClientBuilder::new().user_agent(LAUNCHER_USER_AGENT);
|
||||||
if let Some(timeout) = update.timeout {
|
if let Some(timeout) = update.timeout {
|
||||||
request = request.timeout(timeout);
|
request = request.timeout(timeout);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,3 +26,9 @@ pub use event::{
|
|||||||
};
|
};
|
||||||
pub use logger::start_logger;
|
pub use logger::start_logger;
|
||||||
pub use state::State;
|
pub use state::State;
|
||||||
|
|
||||||
|
pub const LAUNCHER_USER_AGENT: &str = concat!(
|
||||||
|
"modrinth/theseus/",
|
||||||
|
env!("CARGO_PKG_VERSION"),
|
||||||
|
" (support@modrinth.com)"
|
||||||
|
);
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
use crate::LAUNCHER_USER_AGENT;
|
||||||
use crate::config::{MODRINTH_API_URL_V3, MODRINTH_SOCKET_URL};
|
use crate::config::{MODRINTH_API_URL_V3, MODRINTH_SOCKET_URL};
|
||||||
use crate::data::ModrinthCredentials;
|
use crate::data::ModrinthCredentials;
|
||||||
use crate::event::FriendPayload;
|
use crate::event::FriendPayload;
|
||||||
@ -82,13 +83,9 @@ impl FriendsSocket {
|
|||||||
)
|
)
|
||||||
.into_client_request()?;
|
.into_client_request()?;
|
||||||
|
|
||||||
let user_agent = format!(
|
|
||||||
"modrinth/theseus/{} (support@modrinth.com)",
|
|
||||||
env!("CARGO_PKG_VERSION")
|
|
||||||
);
|
|
||||||
request.headers_mut().insert(
|
request.headers_mut().insert(
|
||||||
"User-Agent",
|
"User-Agent",
|
||||||
HeaderValue::from_str(&user_agent).unwrap(),
|
HeaderValue::from_str(LAUNCHER_USER_AGENT).unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let res = connect_async(request).await;
|
let res = connect_async(request).await;
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
//! Functions for fetching information from the Internet
|
//! Functions for fetching information from the Internet
|
||||||
use super::io::{self, IOError};
|
use super::io::{self, IOError};
|
||||||
|
use crate::LAUNCHER_USER_AGENT;
|
||||||
use crate::config::{MODRINTH_API_URL, MODRINTH_API_URL_V3};
|
use crate::config::{MODRINTH_API_URL, MODRINTH_API_URL_V3};
|
||||||
use crate::event::LoadingBarId;
|
use crate::event::LoadingBarId;
|
||||||
use crate::event::emit::emit_loading;
|
use crate::event::emit::emit_loading;
|
||||||
@ -20,11 +21,8 @@ pub struct FetchSemaphore(pub Semaphore);
|
|||||||
|
|
||||||
pub static REQWEST_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| {
|
pub static REQWEST_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| {
|
||||||
let mut headers = reqwest::header::HeaderMap::new();
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
let header = reqwest::header::HeaderValue::from_str(&format!(
|
let header =
|
||||||
"modrinth/theseus/{} (support@modrinth.com)",
|
reqwest::header::HeaderValue::from_str(LAUNCHER_USER_AGENT).unwrap();
|
||||||
env!("CARGO_PKG_VERSION")
|
|
||||||
))
|
|
||||||
.unwrap();
|
|
||||||
headers.insert(reqwest::header::USER_AGENT, header);
|
headers.insert(reqwest::header::USER_AGENT, header);
|
||||||
reqwest::Client::builder()
|
reqwest::Client::builder()
|
||||||
.tcp_keepalive(Some(time::Duration::from_secs(10)))
|
.tcp_keepalive(Some(time::Duration::from_secs(10)))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user