Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
194 changes: 97 additions & 97 deletions backend/tauri/src/config/core.rs
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
use std::path::PathBuf;
use anyhow::{Result, anyhow};
use nyanpasu_utils::runtime::block_on;
use once_cell::sync::OnceCell;
use crate::{
config::{
chimera::IVerge, clash::IClashTemp, draft::Draft, profile::profiles::Profiles,
runtime::IRuntime,
},
core::state::ManagedState,
enhance,
utils::{dirs, help},
};

use anyhow::{Result, anyhow};
use nyanpasu_utils::runtime::block_on;
use once_cell::sync::OnceCell;

use crate::{
config::{
chimera::IVerge, clash::IClashTemp, draft::Draft, profile::profiles::Profiles,
runtime::IRuntime,
},
core::state::ManagedState,
enhance,
utils::{dirs, help},
};

pub const RUNTIME_CONFIG: &str = "clash-config.yaml";
/// whole config
pub struct Config {
profiles_config: ManagedState<Profiles>,
verge_config: Draft<IVerge>,
/// 3
clash_config: Draft<IClashTemp>,
/// 4
runtime_config: Draft<IRuntime>,
}
impl Config {
pub fn global() -> &'static Config {
static CONFIG: OnceCell<Config> = OnceCell::new();
CONFIG.get_or_init(|| Config {
profiles_config: ManagedState::from(Profiles::new()),
verge_config: Draft::from(IVerge::new()),
clash_config: Draft::from(IClashTemp::new()),
runtime_config: Draft::from(IRuntime::new()),
})
}
pub fn profiles() -> &'static ManagedState<Profiles> {
&Self::global().profiles_config
}
pub fn verge() -> Draft<IVerge> {
Self::global().verge_config.clone()
}
/// 生成配置存好
pub async fn generate() -> Result<()> {
let (config, exists_keys, postprocessing_outputs) = enhance::enhance().await;
*Config::runtime().draft() = IRuntime {
config: Some(config),
};
Ok(())
}
pub fn clash() -> Draft<IClashTemp> {
Self::global().clash_config.clone()
}
pub fn runtime() -> Draft<IRuntime> {
Self::global().runtime_config.clone()
}

/// whole config
pub struct Config {
profiles_config: ManagedState<Profiles>,
verge_config: Draft<IVerge>,
/// 3
clash_config: Draft<IClashTemp>,
/// 4
runtime_config: Draft<IRuntime>,
}

impl Config {
pub fn global() -> &'static Config {
static CONFIG: OnceCell<Config> = OnceCell::new();

CONFIG.get_or_init(|| Config {
profiles_config: ManagedState::from(Profiles::new()),
verge_config: Draft::from(IVerge::new()),
clash_config: Draft::from(IClashTemp::new()),
runtime_config: Draft::from(IRuntime::new()),
})
}

pub fn profiles() -> &'static ManagedState<Profiles> {
&Self::global().profiles_config
}

pub fn verge() -> Draft<IVerge> {
Self::global().verge_config.clone()
}

/// 生成配置存好
pub async fn generate() -> Result<()> {
let (config, _, _) = enhance::enhance().await;

*Config::runtime().draft() = IRuntime {
config: Some(config),
};

Ok(())
}

pub fn clash() -> Draft<IClashTemp> {
Self::global().clash_config.clone()
}

pub fn runtime() -> Draft<IRuntime> {
Self::global().runtime_config.clone()
}

/// 将配置丢到对应的文件中
pub fn generate_file(typ: ConfigType) -> Result<PathBuf> {
let path = match typ {
ConfigType::Run => dirs::app_config_dir()?.join(RUNTIME_CONFIG),
ConfigType::Check => Self::create_check_config_path()?,
};
let runtime = Config::runtime();
let runtime = runtime.latest();
let config = runtime
.config
.as_ref()
.ok_or(anyhow!("failed to get runtime config"))?;

let runtime = Config::runtime();
let runtime = runtime.latest();
let config = runtime
.config
.as_ref()
.ok_or(anyhow!("failed to get runtime config"))?;

help::save_yaml(&path, &config, Some("# Generated by Clash Chimera"))?;
Ok(path)
}
Expand All @@ -94,27 +94,27 @@ impl Config {
}

/// 初始化配置
pub fn init_config() -> Result<()> {
crate::log_err!(block_on(Self::generate()));
if let Err(err) = Self::generate_file(ConfigType::Run) {
log::error!(target: "app", "{err:?}");
let runtime_path = dirs::app_config_dir()?.join(RUNTIME_CONFIG);
// 如果不存在就将默认的clash文件拿过来
if !runtime_path.exists() {
help::save_yaml(
&runtime_path,
&Config::clash().latest().0,
Some("# Clash Chimera Runtime"),
)?;
}
}
Ok(())
}
}
#[derive(Debug)]
pub enum ConfigType {
Run,
Check,
}
pub fn init_config() -> Result<()> {
crate::log_err!(block_on(Self::generate()));
if let Err(err) = Self::generate_file(ConfigType::Run) {
log::error!(target: "app", "{err:?}");

let runtime_path = dirs::app_config_dir()?.join(RUNTIME_CONFIG);
// 如果不存在就将默认的clash文件拿过来
if !runtime_path.exists() {
help::save_yaml(
&runtime_path,
&Config::clash().latest().0,
Some("# Clash Chimera Runtime"),
)?;
}
}
Ok(())
}
}

#[derive(Debug)]
pub enum ConfigType {
Run,
Check,
}
12 changes: 2 additions & 10 deletions backend/tauri/src/enhance/chain.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use serde_yaml::Mapping;

use crate::{
config::profile::{
item::{Profile, ProfileMetaGetter},
item_type::ProfileUid,
},
enhance::utils::Logs,
};
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};

#[derive(Default, Debug, Clone, Serialize, Deserialize, specta::Type)]
/// 后处理输出
Expand All @@ -17,12 +15,6 @@ pub struct PostProcessingOutput {
pub scopes: IndexMap<ProfileUid, IndexMap<ProfileUid, Logs>>,
}

#[derive(Debug, Clone)]
pub enum ChainTypeWrapper {
Merge(Mapping),
// Script(ScriptWrapper),
}

#[derive(Debug, Clone)]
pub struct ChainItem {
pub uid: String,
Expand Down
13 changes: 3 additions & 10 deletions backend/tauri/src/enhance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ use crate::{
mod chain;
/// 3
mod field;
/// 4
mod script;
/// 5
mod tun;
/// 2
Expand All @@ -28,20 +26,17 @@ pub async fn enhance() -> (Mapping, Vec<String>, PostProcessingOutput) {
// config.yaml 的配置
let clash_config = { Config::clash().latest().0.clone() };

let (clash_core, enable_tun, enable_builtin, enable_filter) = {
let (enable_tun, enable_filter) = {
let verge = Config::verge();
let verge = verge.latest();
(
verge.clash_core,
verge.enable_tun_mode.unwrap_or(false),
// todo: will changed to true in the future
verge.enable_builtin_enhanced.unwrap_or(false),
verge.enable_clash_fields.unwrap_or(true),
)
};

// 从profiles里拿东西·
let (profiles, profile_chain, global_chain, valid) = {
let (profiles, profile_chain, valid) = {
let profiles = Config::profiles();
let profiles = profiles.latest();

Expand Down Expand Up @@ -75,11 +70,9 @@ pub async fn enhance() -> (Mapping, Vec<String>, PostProcessingOutput) {
.map(|(k, v)| (k.to_string(), v))
.collect::<IndexMap<_, _>>();

let global_chain = utils::convert_uids_to_scripts(&profiles, &profiles.chain);

let valid = profiles.valid.clone();

(current_mappings, profile_chain_mapping, global_chain, valid)
(current_mappings, profile_chain_mapping, valid)
};

let mut postprocessing_output = PostProcessingOutput::default();
Expand Down
11 changes: 4 additions & 7 deletions backend/tauri/src/enhance/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde_yaml::Mapping;

use crate::{
config::profile::{item_type::ProfileUid, profiles::Profiles},
enhance::{chain::ChainItem, script::runner::RunnerManager},
enhance::chain::ChainItem,
};

pub fn convert_uids_to_scripts(profiles: &Profiles, uids: &[ProfileUid]) -> Vec<ChainItem> {
Expand All @@ -28,14 +28,11 @@ pub type Logs = Vec<(LogSpan, String)>;

/// 处理链
pub async fn process_chain(
mut config: Mapping,
nodes: &[ChainItem],
config: Mapping,
_nodes: &[ChainItem],
) -> (Mapping, IndexMap<ProfileUid, Logs>) {
let mut result_map = IndexMap::new();

let mut script_runner = RunnerManager::new();
log::debug!("todo: impl script_runner");
(config, result_map)
(config, IndexMap::new())
}

/// 合并多个配置
Expand Down
2 changes: 0 additions & 2 deletions backend/tauri/src/features/agent/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub enum AgentHealth {
pub enum AgentCoreState {
Running,
Stopped,
Unknown,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Type)]
Expand All @@ -26,7 +25,6 @@ pub enum AgentRunType {
Normal,
Service,
Elevated,
Unknown,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Type)]
Expand Down
2 changes: 1 addition & 1 deletion frontend/chimera/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"nanoid": "6.0.0",
"postcss": "8.5.20",
"sass-embedded": "1.100.0",
"shiki": "4.3.1",
"shiki": "4.4.1",
"tailwindcss": "4.3.3",
"typescript": "7.0.2",
"unplugin-icons": "23.0.1",
Expand Down
4 changes: 2 additions & 2 deletions frontend/interface/src/ipc/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export type AgentCoreSnapshot = {
applied_consistency: AgentAppliedState;
};

export type AgentCoreState = 'running' | 'stopped' | 'unknown';
export type AgentCoreState = 'running' | 'stopped';

export type AgentFinding = {
code: AgentFindingCode;
Expand Down Expand Up @@ -416,7 +416,7 @@ export type AgentProposal = {

export type AgentRoutingMode = 'rule' | 'global' | 'direct';

export type AgentRunType = 'normal' | 'service' | 'elevated' | 'unknown';
export type AgentRunType = 'normal' | 'service' | 'elevated';

export type AgentServiceSnapshot = {
desired_enabled: boolean;
Expand Down
6 changes: 3 additions & 3 deletions manifest/version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"manifest_version": 1,
"latest": {
"mihomo": "v1.19.29",
"mihomo_alpha": "alpha-7198c9d",
"mihomo_alpha": "alpha-cd05b74",
"clash_rs": "v0.10.8",
"chimera_client": "v0.24.2",
"chimera_client": "v0.24.3",
"clash_premium": "2023-09-05-gdcc8d87",
"clash_rs_alpha": "0.10.8-alpha+sha.2272555"
},
Expand Down Expand Up @@ -82,5 +82,5 @@
"linux-armv7hf": "clash-rs-armv7-unknown-linux-gnueabihf"
}
},
"updated_at": "2026-07-31T23:14:25.581Z"
"updated_at": "2026-08-02T23:08:46.536Z"
}
Loading
Loading