diff --git a/src-tauri/src/config/prfitem.rs b/src-tauri/src/config/prfitem.rs index 455cc3b..9b28e05 100644 --- a/src-tauri/src/config/prfitem.rs +++ b/src-tauri/src/config/prfitem.rs @@ -1,4 +1,4 @@ -use crate::utils::{dirs, help, tmpl}; +use crate::utils::{dirs, help, resolve::VERSION, tmpl}; use anyhow::{bail, Context, Result}; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; @@ -231,7 +231,11 @@ impl PrfItem { }; } - let version = format!("clash-verge-rev"); + let version = match VERSION.get() { + Some(v) => format!("clash-verge/v{}", v), + None => format!("clash-verge/unknown"), + }; + builder = builder.user_agent(user_agent.unwrap_or(version)); let resp = builder.build()?.get(url).send().await?; diff --git a/src-tauri/src/utils/resolve.rs b/src-tauri/src/utils/resolve.rs index 4e8a57d..1cacc90 100644 --- a/src-tauri/src/utils/resolve.rs +++ b/src-tauri/src/utils/resolve.rs @@ -2,10 +2,13 @@ use crate::config::IVerge; use crate::{config::Config, core::*, utils::init, utils::server}; use crate::{log_err, trace_err}; use anyhow::Result; +use once_cell::sync::OnceCell; use serde_yaml::Mapping; use std::net::TcpListener; use tauri::{App, AppHandle, Manager}; +pub static VERSION: OnceCell = OnceCell::new(); + pub fn find_unused_port() -> Result { match TcpListener::bind("127.0.0.1:0") { Ok(listener) => { @@ -27,8 +30,9 @@ pub fn find_unused_port() -> Result { pub fn resolve_setup(app: &mut App) { #[cfg(target_os = "macos")] app.set_activation_policy(tauri::ActivationPolicy::Accessory); - + let version = app.package_info().version.to_string(); handle::Handle::global().init(app.app_handle()); + VERSION.get_or_init(|| version.clone()); log_err!(init::init_resources()); #[cfg(target_os = "windows")] diff --git a/src/components/profile/profile-viewer.tsx b/src/components/profile/profile-viewer.tsx index 40700f5..cdb190e 100644 --- a/src/components/profile/profile-viewer.tsx +++ b/src/components/profile/profile-viewer.tsx @@ -209,7 +209,7 @@ export const ProfileViewer = forwardRef( )}