Skip to content

Commit

Permalink
refactor(core): use new core manager from nyanpasu utils to prepare f…
Browse files Browse the repository at this point in the history
…or new nyanpasu service
  • Loading branch information
greenhat616 committed Jul 26, 2024
1 parent 2693450 commit e3e9fee
Show file tree
Hide file tree
Showing 8 changed files with 450 additions and 233 deletions.
90 changes: 45 additions & 45 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions backend/tauri/src/config/nyanpasu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod logging;
pub use self::clash_strategy::{ClashStrategy, ExternalControllerPortStrategy};
pub use logging::LoggingLevel;

// TODO: when support sing-box, remove this struct
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
pub enum ClashCore {
#[serde(rename = "clash", alias = "clash-premium")]
Expand Down Expand Up @@ -52,6 +53,41 @@ impl std::fmt::Display for ClashCore {
}
}

impl From<&ClashCore> for nyanpasu_utils::core::CoreType {
fn from(core: &ClashCore) -> Self {
match core {
ClashCore::ClashPremium => nyanpasu_utils::core::CoreType::Clash(
nyanpasu_utils::core::ClashCoreType::ClashPremium,
),
ClashCore::ClashRs => nyanpasu_utils::core::CoreType::Clash(
nyanpasu_utils::core::ClashCoreType::ClashRust,
),
ClashCore::Mihomo => {
nyanpasu_utils::core::CoreType::Clash(nyanpasu_utils::core::ClashCoreType::Mihomo)
}
ClashCore::MihomoAlpha => nyanpasu_utils::core::CoreType::Clash(
nyanpasu_utils::core::ClashCoreType::MihomoAlpha,
),
}
}
}

impl TryFrom<&nyanpasu_utils::core::CoreType> for ClashCore {
type Error = anyhow::Error;

fn try_from(core: &nyanpasu_utils::core::CoreType) -> Result<Self> {
match core {
nyanpasu_utils::core::CoreType::Clash(clash) => match clash {
nyanpasu_utils::core::ClashCoreType::ClashPremium => Ok(ClashCore::ClashPremium),
nyanpasu_utils::core::ClashCoreType::ClashRust => Ok(ClashCore::ClashRs),
nyanpasu_utils::core::ClashCoreType::Mihomo => Ok(ClashCore::Mihomo),
nyanpasu_utils::core::ClashCoreType::MihomoAlpha => Ok(ClashCore::MihomoAlpha),
},
_ => Err(anyhow::anyhow!("unsupported core type")),
}
}
}

/// ### `verge.yaml` schema
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
pub struct IVerge {
Expand Down
Loading

0 comments on commit e3e9fee

Please sign in to comment.