mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-08 19:22:44 +08:00
* refactor: optimize item handling and improve profile management * refactor: update IVerge references to use references instead of owned values * refactor: update patch_verge to use data_ref for improved data handling * refactor: move handle_copy function to improve resource initialization logic * refactor: update profile handling to use references for improved memory efficiency * refactor: simplify get_item method and update profile item retrieval to use string slices * refactor: update profile validation and patching to use references for improved performance * refactor: update profile functions to use references for improved performance and memory efficiency * refactor: update profile patching functions to use references for improved memory efficiency * refactor: simplify merge function in PrfOption to enhance readability * refactor: update change_core function to accept a reference for improved memory efficiency * refactor: update PrfItem and profile functions to use references for improved memory efficiency * refactor: update resolve_scheme function to accept a reference for improved memory efficiency * refactor: update resolve_scheme function to accept a string slice for improved flexibility * refactor: simplify update_profile parameters and logic
86 lines
2.9 KiB
Rust
86 lines
2.9 KiB
Rust
use anyhow::{Result, bail};
|
|
use percent_encoding::percent_decode_str;
|
|
use smartstring::alias::String;
|
|
use tauri::Url;
|
|
|
|
use crate::{
|
|
config::{PrfItem, profiles},
|
|
core::handle,
|
|
logging, logging_error,
|
|
utils::logging::Type,
|
|
};
|
|
|
|
pub(super) async fn resolve_scheme(param: &str) -> Result<()> {
|
|
log::info!(target:"app", "received deep link: {param}");
|
|
|
|
let param_str = if param.starts_with("[") && param.len() > 4 {
|
|
param
|
|
.get(2..param.len() - 2)
|
|
.ok_or_else(|| anyhow::anyhow!("Invalid string slice boundaries"))?
|
|
} else {
|
|
param
|
|
};
|
|
|
|
// 解析 URL
|
|
let link_parsed = match Url::parse(param_str) {
|
|
Ok(url) => url,
|
|
Err(e) => {
|
|
bail!("failed to parse deep link: {:?}, param: {:?}", e, param);
|
|
}
|
|
};
|
|
|
|
if link_parsed.scheme() == "clash" || link_parsed.scheme() == "clash-verge" {
|
|
let name_owned: Option<String> = link_parsed
|
|
.query_pairs()
|
|
.find(|(key, _)| key == "name")
|
|
.map(|(_, value)| value.into_owned().into());
|
|
let name = name_owned.as_ref();
|
|
|
|
let url_param = if let Some(query) = link_parsed.query() {
|
|
let prefix = "url=";
|
|
if let Some(pos) = query.find(prefix) {
|
|
let raw_url = &query[pos + prefix.len()..];
|
|
Some(percent_decode_str(raw_url).decode_utf8_lossy().to_string())
|
|
} else {
|
|
None
|
|
}
|
|
} else {
|
|
None
|
|
};
|
|
|
|
match url_param {
|
|
Some(ref url) => {
|
|
log::info!(target:"app", "decoded subscription url: {url}");
|
|
match PrfItem::from_url(url, name, None, None).await {
|
|
Ok(mut item) => {
|
|
let uid = match item.uid.clone() {
|
|
Some(uid) => uid,
|
|
None => {
|
|
logging!(error, Type::Config, "Profile item missing UID");
|
|
handle::Handle::notice_message(
|
|
"import_sub_url::error",
|
|
"Profile item missing UID".to_string(),
|
|
);
|
|
return Ok(());
|
|
}
|
|
};
|
|
let result = profiles::profiles_append_item_safe(&mut item).await;
|
|
logging_error!(
|
|
Type::Config,
|
|
"failed to import subscription url: {:?}",
|
|
result
|
|
);
|
|
handle::Handle::notice_message("import_sub_url::ok", uid);
|
|
}
|
|
Err(e) => {
|
|
handle::Handle::notice_message("import_sub_url::error", e.to_string());
|
|
}
|
|
}
|
|
}
|
|
None => bail!("failed to get profile url"),
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|