Bump version and auto-generate sing-box HWIDs
This commit is contained in:
+18
-65
@@ -232,8 +232,6 @@ pub struct LocalSingBoxStatusResponse {
|
||||
pub struct LocalSingBoxConfigDto {
|
||||
pub subscription_display_url: Option<String>,
|
||||
pub has_subscription: bool,
|
||||
pub device_hwid_display: Option<String>,
|
||||
pub has_device_hwid: bool,
|
||||
pub selected_server_tag: Option<String>,
|
||||
pub listen_host: String,
|
||||
pub listen_port: u16,
|
||||
@@ -264,15 +262,6 @@ pub struct SubscriptionServerDto {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SaveSingBoxSubscriptionInputDto {
|
||||
pub subscription_url: String,
|
||||
#[serde(default)]
|
||||
pub device_hwid: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SaveSingBoxDeviceHwidInputDto {
|
||||
#[serde(default)]
|
||||
pub device_hwid: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -684,14 +673,6 @@ pub fn save_singbox_subscription(
|
||||
save_singbox_subscription_to_storage(&state.storage(), input, &SystemClock)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn save_singbox_device_hwid(
|
||||
state: tauri::State<'_, CommandState>,
|
||||
input: SaveSingBoxDeviceHwidInputDto,
|
||||
) -> Result<LocalSingBoxStatusResponse, CommandError> {
|
||||
save_singbox_device_hwid_to_storage(&state.storage(), input, &SystemClock)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn fetch_singbox_subscription(
|
||||
state: tauri::State<'_, CommandState>,
|
||||
@@ -1432,9 +1413,7 @@ pub fn save_singbox_subscription_to_storage(
|
||||
|
||||
let mut config = storage.read_local_singbox_config().map_err(storage_error)?;
|
||||
config.subscription_url = Some(subscription_url);
|
||||
if let Some(device_hwid) = input.device_hwid {
|
||||
config.device_hwid = normalize_device_hwid(&device_hwid)?;
|
||||
}
|
||||
ensure_device_hwid(&mut config);
|
||||
config.updated_at = Some(clock.now());
|
||||
storage
|
||||
.write_local_singbox_config(&config)
|
||||
@@ -1462,6 +1441,14 @@ pub fn fetch_singbox_subscription_with_fetcher(
|
||||
)
|
||||
})?;
|
||||
|
||||
let device_hwid_created = ensure_device_hwid(&mut config);
|
||||
if device_hwid_created {
|
||||
config.updated_at = Some(clock.now());
|
||||
storage
|
||||
.write_local_singbox_config(&config)
|
||||
.map_err(storage_error)?;
|
||||
}
|
||||
|
||||
let identity =
|
||||
subscription::SubscriptionFetchIdentity::with_device_hwid(config.device_hwid.as_deref());
|
||||
let cache = fetcher
|
||||
@@ -1501,7 +1488,6 @@ pub fn forget_singbox_subscription_in_storage(
|
||||
) -> Result<LocalSingBoxStatusResponse, CommandError> {
|
||||
let mut config = storage.read_local_singbox_config().map_err(storage_error)?;
|
||||
config.subscription_url = None;
|
||||
config.device_hwid = None;
|
||||
config.selected_server_tag = None;
|
||||
config.updated_at = Some(clock.now());
|
||||
storage
|
||||
@@ -1514,24 +1500,6 @@ pub fn forget_singbox_subscription_in_storage(
|
||||
read_singbox_status(storage)
|
||||
}
|
||||
|
||||
pub fn save_singbox_device_hwid_to_storage(
|
||||
storage: &JsonStorage,
|
||||
input: SaveSingBoxDeviceHwidInputDto,
|
||||
clock: &impl Clock,
|
||||
) -> Result<LocalSingBoxStatusResponse, CommandError> {
|
||||
let mut config = storage.read_local_singbox_config().map_err(storage_error)?;
|
||||
config.device_hwid = match input.device_hwid {
|
||||
Some(device_hwid) => normalize_device_hwid(&device_hwid)?,
|
||||
None => None,
|
||||
};
|
||||
config.updated_at = Some(clock.now());
|
||||
storage
|
||||
.write_local_singbox_config(&config)
|
||||
.map_err(storage_error)?;
|
||||
|
||||
read_singbox_status(storage)
|
||||
}
|
||||
|
||||
pub fn select_singbox_server_in_storage(
|
||||
storage: &JsonStorage,
|
||||
input: SelectSingBoxServerInputDto,
|
||||
@@ -1734,27 +1702,17 @@ fn validate_subscription_url(subscription_url: &str) -> Result<(), CommandError>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn normalize_device_hwid(raw_hwid: &str) -> Result<Option<String>, CommandError> {
|
||||
let device_hwid = raw_hwid.trim();
|
||||
if device_hwid.is_empty() {
|
||||
return Ok(None);
|
||||
fn ensure_device_hwid(config: &mut LocalSingBoxConfig) -> bool {
|
||||
if config
|
||||
.device_hwid
|
||||
.as_deref()
|
||||
.is_some_and(|value| !value.trim().is_empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if device_hwid.chars().count() > 256 {
|
||||
return Err(CommandError::new(
|
||||
"singbox_device_hwid_invalid",
|
||||
"HWID устройства должен быть не длиннее 256 символов.",
|
||||
));
|
||||
}
|
||||
|
||||
if !device_hwid.chars().all(|ch| ch.is_ascii_graphic()) {
|
||||
return Err(CommandError::new(
|
||||
"singbox_device_hwid_invalid",
|
||||
"HWID устройства может содержать только печатные ASCII-символы без пробелов.",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(Some(device_hwid.to_string()))
|
||||
config.device_hwid = Some(uuid::Uuid::new_v4().hyphenated().to_string().to_uppercase());
|
||||
true
|
||||
}
|
||||
|
||||
fn ping_subscription_server(server: &SubscriptionServer) -> PingServerResponse {
|
||||
@@ -4234,11 +4192,6 @@ impl From<&LocalSingBoxConfig> for LocalSingBoxConfigDto {
|
||||
.subscription_url
|
||||
.as_deref()
|
||||
.is_some_and(|value| !value.trim().is_empty()),
|
||||
device_hwid_display: config.device_hwid_display(),
|
||||
has_device_hwid: config
|
||||
.device_hwid
|
||||
.as_deref()
|
||||
.is_some_and(|value| !value.trim().is_empty()),
|
||||
selected_server_tag: config.selected_server_tag.clone(),
|
||||
listen_host: config.listen_host.clone(),
|
||||
listen_port: config.listen_port,
|
||||
|
||||
Reference in New Issue
Block a user