diff --git a/src-tauri/src/config/clash.rs b/src-tauri/src/config/clash.rs index 142f096..70169ad 100644 --- a/src-tauri/src/config/clash.rs +++ b/src-tauri/src/config/clash.rs @@ -31,7 +31,7 @@ impl IClashTemp { map.insert("external-controller".into(), "127.0.0.1:9090".into()); map.insert("secret".into(), "".into()); - Self(Self::guard(map)) + Self(map) } fn guard(mut config: Mapping) -> Mapping { @@ -57,10 +57,6 @@ impl IClashTemp { ) } - // pub fn get_info(&self) -> ClashInfo { - // self.1.clone() - // } - pub fn get_mixed_port(&self) -> u16 { Self::guard_mixed_port(&self.0) } diff --git a/src-tauri/src/utils/init.rs b/src-tauri/src/utils/init.rs index 5d6e457..6a3c375 100644 --- a/src-tauri/src/utils/init.rs +++ b/src-tauri/src/utils/init.rs @@ -1,4 +1,5 @@ -use crate::utils::dirs; +use crate::config::*; +use crate::utils::{dirs, help}; use anyhow::Result; use chrono::Local; use log::LevelFilter; @@ -60,17 +61,38 @@ pub fn init_config() -> Result<()> { let _ = init_log(); - let _ = dirs::app_home_dir().map(|app_dir| { + crate::log_err!(dirs::app_home_dir().map(|app_dir| { if !app_dir.exists() { let _ = fs::create_dir_all(&app_dir); } - }); + })); - let _ = dirs::app_profiles_dir().map(|profiles_dir| { + crate::log_err!(dirs::app_profiles_dir().map(|profiles_dir| { if !profiles_dir.exists() { let _ = fs::create_dir_all(&profiles_dir); } - }); + })); + + crate::log_err!(dirs::clash_path().map(|path| { + if !path.exists() { + help::save_yaml(&path, &IClashTemp::template().0, Some("# Clash Verge"))?; + } + >::Ok(()) + })); + + crate::log_err!(dirs::verge_path().map(|path| { + if !path.exists() { + help::save_yaml(&path, &IVerge::template(), Some("# Clash Verge"))?; + } + >::Ok(()) + })); + + crate::log_err!(dirs::profiles_path().map(|path| { + if !path.exists() { + help::save_yaml(&path, &IProfiles::template(), Some("# Clash Verge"))?; + } + >::Ok(()) + })); Ok(()) } @@ -80,6 +102,13 @@ pub fn init_resources(package_info: &PackageInfo) -> Result<()> { let app_dir = dirs::app_home_dir()?; let res_dir = dirs::app_resources_dir(package_info)?; + if !app_dir.exists() { + let _ = fs::create_dir_all(&app_dir); + } + if !res_dir.exists() { + let _ = fs::create_dir_all(&res_dir); + } + // copy the resource file for file in ["Country.mmdb", "geoip.dat", "geosite.dat", "wintun.dll"].iter() { let src_path = res_dir.join(file);