diff --git a/.husky/pre-commit b/.husky/pre-commit index b50e8966..412da72a 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -3,14 +3,14 @@ #pnpm pretty-quick --staged # 运行 clippy fmt -#cargo fmt --manifest-path ./src-tauri/Cargo.toml +cargo fmt --manifest-path ./src-tauri/Cargo.toml -# if [ $? -ne 0 ]; then -# echo "rustfmt failed to format the code. Please fix the issues and try again." -# exit 1 -# fi +if [ $? -ne 0 ]; then + echo "rustfmt failed to format the code. Please fix the issues and try again." + exit 1 +fi -#git add . +git add . # 允许提交 exit 0 diff --git a/.husky/pre-push b/.husky/pre-push index 94ab55d3..807ac5fe 100644 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,13 +1,13 @@ #!/bin/bash # 运行 clippy -#cargo clippy --manifest-path ./src-tauri/Cargo.toml --fix +cargo clippy --manifest-path ./src-tauri/Cargo.toml --fix # 如果 clippy 失败,阻止 push -#if [ $? -ne 0 ]; then -# echo "Clippy found issues in sub_crate. Please fix them before pushing." -# exit 1 -#fi +if [ $? -ne 0 ]; then + echo "Clippy found issues in sub_crate. Please fix them before pushing." + exit 1 +fi # 允许 push -exit 0 \ No newline at end of file +exit 0 diff --git a/src-tauri/src/cmd/media_unlock_checker.rs b/src-tauri/src/cmd/media_unlock_checker.rs index 2b44c02c..08b1ad25 100644 --- a/src-tauri/src/cmd/media_unlock_checker.rs +++ b/src-tauri/src/cmd/media_unlock_checker.rs @@ -2,11 +2,9 @@ use chrono::Local; use regex::Regex; use reqwest::Client; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; -use std::sync::Arc; +use std::{collections::HashMap, sync::Arc}; use tauri::command; -use tokio::sync::Mutex; -use tokio::task::JoinSet; +use tokio::{sync::Mutex, task::JoinSet}; // 定义解锁测试项目的结构 #[derive(Debug, Clone, Serialize, Deserialize)] @@ -464,9 +462,11 @@ async fn check_netflix(client: &Client) -> UnlockItem { let url2 = "https://www.netflix.com/title/70143836"; // Breaking Bad // 创建简单的请求(不添加太多头部信息) - let result1 = client.get(url1) + let result1 = client + .get(url1) .timeout(std::time::Duration::from_secs(30)) - .send().await; + .send() + .await; // 检查连接失败情况 if let Err(e) = &result1 { @@ -480,9 +480,11 @@ async fn check_netflix(client: &Client) -> UnlockItem { } // 如果第一个请求成功,尝试第二个请求 - let result2 = client.get(url2) + let result2 = client + .get(url2) .timeout(std::time::Duration::from_secs(30)) - .send().await; + .send() + .await; if let Err(e) = &result2 { eprintln!("Netflix请求错误: {}", e); @@ -521,7 +523,8 @@ async fn check_netflix(client: &Client) -> UnlockItem { // 成功解锁,尝试获取地区信息 // 使用Netflix测试内容获取区域 let test_url = "https://www.netflix.com/title/80018499"; - match client.get(test_url) + match client + .get(test_url) .timeout(std::time::Duration::from_secs(30)) .send() .await @@ -561,7 +564,7 @@ async fn check_netflix(client: &Client) -> UnlockItem { region: None, check_time: Some(get_local_date_string()), } - }, + } } } else { // 其他未知错误状态 @@ -578,11 +581,13 @@ async fn check_netflix(client: &Client) -> UnlockItem { async fn check_netflix_cdn(client: &Client) -> UnlockItem { // Fast.com API URL let url = "https://api.fast.com/netflix/speedtest/v2?https=true&token=YXNkZmFzZGxmbnNkYWZoYXNkZmhrYWxm&urlCount=5"; - - let result = client.get(url) + + let result = client + .get(url) .timeout(std::time::Duration::from_secs(30)) - .send().await; - + .send() + .await; + match result { Ok(response) => { // 检查状态码 @@ -594,7 +599,7 @@ async fn check_netflix_cdn(client: &Client) -> UnlockItem { check_time: Some(get_local_date_string()), }; } - + // 尝试解析响应 match response.json::().await { Ok(data) => { @@ -602,7 +607,9 @@ async fn check_netflix_cdn(client: &Client) -> UnlockItem { if let Some(targets) = data.get("targets").and_then(|t| t.as_array()) { if !targets.is_empty() { if let Some(location) = targets[0].get("location") { - if let Some(country) = location.get("country").and_then(|c| c.as_str()) { + if let Some(country) = + location.get("country").and_then(|c| c.as_str()) + { let emoji = country_code_to_emoji(country); return UnlockItem { name: "Netflix".to_string(), @@ -614,7 +621,7 @@ async fn check_netflix_cdn(client: &Client) -> UnlockItem { } } } - + // 如果无法解析区域信息 return UnlockItem { name: "Netflix".to_string(), diff --git a/src-tauri/src/config/verge.rs b/src-tauri/src/config/verge.rs index 1fb31a2c..2aa8430a 100644 --- a/src-tauri/src/config/verge.rs +++ b/src-tauri/src/config/verge.rs @@ -196,7 +196,7 @@ pub struct IVerge { /// 自动进入轻量模式的延迟(分钟) pub auto_light_weight_minutes: Option, - + /// 服务状态跟踪 pub service_state: Option, } diff --git a/src-tauri/src/core/sysopt.rs b/src-tauri/src/core/sysopt.rs index c6aca452..7e22e3dc 100644 --- a/src-tauri/src/core/sysopt.rs +++ b/src-tauri/src/core/sysopt.rs @@ -220,9 +220,9 @@ impl Sysopt { let enable = enable.unwrap_or(false); let app_handle = Handle::global().app_handle().unwrap(); let autostart_manager = app_handle.autolaunch(); - + log::info!(target: "app", "Setting auto launch to: {}", enable); - + match enable { true => { let result = autostart_manager.enable(); @@ -232,7 +232,7 @@ impl Sysopt { log::info!(target: "app", "Auto launch enabled successfully"); } log_err!(result) - }, + } false => { let result = autostart_manager.disable(); if let Err(ref e) = result { @@ -241,7 +241,7 @@ impl Sysopt { log::info!(target: "app", "Auto launch disabled successfully"); } log_err!(result) - }, + } }; Ok(()) @@ -251,12 +251,12 @@ impl Sysopt { pub fn get_launch_status(&self) -> Result { let app_handle = Handle::global().app_handle().unwrap(); let autostart_manager = app_handle.autolaunch(); - + match autostart_manager.is_enabled() { Ok(status) => { log::info!(target: "app", "Auto launch status: {}", status); Ok(status) - }, + } Err(e) => { log::error!(target: "app", "Failed to get auto launch status: {}", e); Err(anyhow::anyhow!("Failed to get auto launch status: {}", e)) diff --git a/src-tauri/src/module/mod.rs b/src-tauri/src/module/mod.rs index d122a47b..39cb3c83 100644 --- a/src-tauri/src/module/mod.rs +++ b/src-tauri/src/module/mod.rs @@ -1,3 +1,3 @@ +pub mod lightweight; pub mod mihomo; pub mod sysinfo; -pub mod lightweight; \ No newline at end of file