Refactor application structure and simplify implementation
This commit is contained in:
@@ -57,6 +57,7 @@ pub enum ComponentState {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ProfileItemInput {
|
||||
#[serde(rename = "type")]
|
||||
pub item_type: String,
|
||||
@@ -66,6 +67,7 @@ pub struct ProfileItemInput {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ProfileInput {
|
||||
pub id: Option<String>,
|
||||
pub name: String,
|
||||
@@ -98,6 +100,7 @@ pub struct Profile {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TargetInput {
|
||||
pub id: Option<String>,
|
||||
pub name: String,
|
||||
@@ -149,6 +152,8 @@ pub struct LocalSingBoxConfig {
|
||||
pub device_hwid: Option<String>,
|
||||
#[serde(default)]
|
||||
pub selected_server_tag: Option<String>,
|
||||
#[serde(default)]
|
||||
pub selected_server_id: Option<String>,
|
||||
#[serde(default = "default_local_singbox_listen_host")]
|
||||
pub listen_host: String,
|
||||
#[serde(default = "default_local_singbox_listen_port")]
|
||||
@@ -181,6 +186,7 @@ impl Default for LocalSingBoxConfig {
|
||||
subscription_url: None,
|
||||
device_hwid: None,
|
||||
selected_server_tag: None,
|
||||
selected_server_id: None,
|
||||
listen_host: default_local_singbox_listen_host(),
|
||||
listen_port: default_local_singbox_listen_port(),
|
||||
service_name: default_local_singbox_service_name(),
|
||||
@@ -204,6 +210,7 @@ impl SubscriptionCache {
|
||||
pub fn normalize_percent_encoded_tags(&mut self) {
|
||||
for server in &mut self.servers {
|
||||
server.tag = decode_percent_encoded_utf8(&server.tag);
|
||||
server.ensure_id();
|
||||
}
|
||||
|
||||
let Some(outbounds) = self
|
||||
@@ -232,6 +239,8 @@ impl SubscriptionCache {
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct SubscriptionServer {
|
||||
#[serde(default)]
|
||||
pub id: String,
|
||||
pub tag: String,
|
||||
#[serde(rename = "type")]
|
||||
pub server_type: String,
|
||||
@@ -239,6 +248,34 @@ pub struct SubscriptionServer {
|
||||
pub server_port: u16,
|
||||
}
|
||||
|
||||
impl SubscriptionServer {
|
||||
pub fn ensure_id(&mut self) {
|
||||
if self.id.trim().is_empty() {
|
||||
self.id = subscription_server_id(
|
||||
&self.server_type,
|
||||
&self.tag,
|
||||
&self.server,
|
||||
self.server_port,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subscription_server_id(
|
||||
server_type: &str,
|
||||
tag: &str,
|
||||
server: &str,
|
||||
server_port: u16,
|
||||
) -> String {
|
||||
format!(
|
||||
"{}|{}|{}|{}",
|
||||
server_type.trim().to_ascii_lowercase(),
|
||||
tag.trim(),
|
||||
server.trim().to_ascii_lowercase(),
|
||||
server_port
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ActivityEntry {
|
||||
pub id: String,
|
||||
|
||||
Reference in New Issue
Block a user