feat: default user agent same with app version

This commit is contained in:
GyDi 2022-10-12 11:28:47 +08:00
parent 30ef3057ac
commit f68378041f
No known key found for this signature in database
GPG Key ID: 58B15242BA8277A6
3 changed files with 11 additions and 2 deletions

View File

@ -204,7 +204,9 @@ impl PrfItem {
builder = builder.no_proxy();
}
builder = builder.user_agent(user_agent.unwrap_or("clash-verge/v1.0.0".into()));
let version = unsafe { dirs::APP_VERSION };
let version = format!("clash-verge/{version}");
builder = builder.user_agent(user_agent.unwrap_or(version));
let resp = builder.build()?.get(url).send().await?;
let header = resp.headers();

View File

@ -21,6 +21,8 @@ static mut RESOURCE_DIR: Option<PathBuf> = None;
#[allow(unused)]
static mut PORTABLE_FLAG: bool = false;
pub static mut APP_VERSION: &str = "v1.1.1";
/// initialize portable flag
#[allow(unused)]
pub unsafe fn init_portable_flag() {
@ -66,6 +68,10 @@ pub fn app_resources_dir(package_info: &PackageInfo) -> PathBuf {
unsafe {
RESOURCE_DIR = Some(res_dir.clone());
let ver = &package_info.version;
let ver_str = format!("v{}.{}.{}", ver.major, ver.minor, ver.patch);
APP_VERSION = Box::leak(Box::new(ver_str));
}
res_dir

View File

@ -13,6 +13,7 @@ import {
} from "@mui/material";
import { Settings } from "@mui/icons-material";
import { patchProfile } from "@/services/cmds";
import { version } from "@root/package.json";
import Notice from "../base/base-notice";
interface Props {
@ -119,7 +120,7 @@ const InfoEditor = (props: Props) => {
{...textFieldProps}
label="User Agent"
value={option.user_agent}
placeholder="clash-verge/v1.0.0"
placeholder={`clash-verge/v${version}`}
onChange={(e) => setOption({ user_agent: e.target.value })}
onKeyDown={(e) => e.key === "Enter" && onUpdate()}
/>