chore: update

This commit is contained in:
huzibaca 2024-09-04 07:53:16 +08:00
parent 7b11e157c4
commit ae1c6d4617
No known key found for this signature in database
GPG Key ID: D4364EE4851DC302
3 changed files with 19 additions and 7 deletions

View File

@ -313,7 +313,10 @@ pub async fn startup_script(app_handle: &AppHandle) -> Result<()> {
} else if script_path.ends_with(".ps1") || script_path.ends_with(".bat") { } else if script_path.ends_with(".ps1") || script_path.ends_with(".bat") {
"powershell" "powershell"
} else { } else {
return Err(anyhow::anyhow!("unsupported script extension: {}", script_path)); return Err(anyhow::anyhow!(
"unsupported script extension: {}",
script_path
));
}; };
let script_dir = PathBuf::from(&script_path); let script_dir = PathBuf::from(&script_path);
@ -329,7 +332,8 @@ pub async fn startup_script(app_handle: &AppHandle) -> Result<()> {
.command(shell_type) .command(shell_type)
.current_dir(working_dir.to_path_buf()) .current_dir(working_dir.to_path_buf())
.args(&[script_path]) .args(&[script_path])
.output().await?; .output()
.await?;
Ok(()) Ok(())
} }

View File

@ -243,7 +243,7 @@ pub async fn resolve_scheme(param: String) -> Result<()> {
.trim_start_matches("clash://install-config?url="); .trim_start_matches("clash://install-config?url=");
let handle = handle::Handle::global(); let handle = handle::Handle::global();
let app_handle = handle.app_handle.lock(); let app_handle = handle.app_handle.lock().clone();
if let Some(app_handle) = app_handle.as_ref() { if let Some(app_handle) = app_handle.as_ref() {
match import_profile(url.to_string(), None).await { match import_profile(url.to_string(), None).await {
Ok(_) => { Ok(_) => {

View File

@ -10,7 +10,9 @@ use warp::http::StatusCode;
use warp::Filter; use warp::Filter;
#[derive(serde::Deserialize, Debug)] #[derive(serde::Deserialize, Debug)]
struct QueryParam {} struct QueryParam {
param: String,
}
/// check whether there is already exists /// check whether there is already exists
pub async fn check_singleton() -> Result<()> { pub async fn check_singleton() -> Result<()> {
@ -84,10 +86,16 @@ pub fn embed_server(app_handle: &AppHandle) {
.and(warp::query::<QueryParam>()) .and(warp::query::<QueryParam>())
.and_then(scheme_handler); .and_then(scheme_handler);
async fn scheme_handler(_: QueryParam) -> Result<impl warp::Reply, Infallible> { async fn scheme_handler(query: QueryParam) -> Result<impl warp::Reply, Infallible> {
//let _ = resolve::resolve_scheme(query.param).await; let result = resolve::resolve_scheme(query.param).await;
Ok(warp::reply::with_status("Ok", StatusCode::OK)) Ok(match result {
Ok(_) => warp::reply::with_status("Ok", StatusCode::OK),
Err(_) => {
warp::reply::with_status("Internal Error", StatusCode::INTERNAL_SERVER_ERROR)
}
})
} }
let commands = ping.or(visible).or(pac).or(scheme); let commands = ping.or(visible).or(pac).or(scheme);
warp::serve(commands).run(([127, 0, 0, 1], port)).await; warp::serve(commands).run(([127, 0, 0, 1], port)).await;
}); });