-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: compatiable with mihomo icon
field
#562
Conversation
there is a CommonOptions
|
Oh, I missed this opts. I think I could do it later. Additionaly, I think the handler opts could be merged into a share opts too. |
some handlers has that too. they are pretty much the same which we can just pass down. however on groups the connect_via is unsupported, but should be fine |
Yes. It chould be a huge refactor tweak to cleanup or redesign if possible. Besides that, The
|
Signed-off-by: Yuwei Ba <contact@yba.dev>
yeah i agree. will look into it later, thanks! re the enumflags2, I haven't thought much about it and I'm not so familia with the crate either - how would that change how the code looks like? do you have an example? |
The behavior is similar to the crate It impl the equivalence of the const (
VERBOSE MyConf = 1 << iota
CONFIG_FROM_DISK
DATABASE_REQUIRED
LOGGER_ACTIVATED
DEBUG
FLOAT_SUPPORT
RECOVERY_MODE
REBOOT_ON_FAILURE
) The equivalence logic in use enumflags2::{bitflags, make_bitflags, BitFlags};
#[bitflags]
#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq)]
enum Test {
VERBOSE,
CONFIG_FROM_DISK,
DATABASE_REQUIRED,
LOGGER_ACTIVATED,
DEBUG,
FLOAT_SUPPORT,
RECOVERY_MODE,
REBOOT_ON_FAILURE,
} And you can use it do the Here is a usage in Nyanpasu: use enumflags2::{bitflags, BitFlag, BitFlags};
#[bitflags]
#[repr(u8)]
#[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)]
pub enum ClashCore {
#[serde(rename = "clash", alias = "clash-premium")]
ClashPremium = 0b0001,
#[serde(rename = "clash-rs")]
ClashRs,
#[serde(rename = "mihomo", alias = "clash-meta")]
Mihomo,
#[serde(rename = "mihomo-alpha")]
MihomoAlpha,
}
/// a function return result:
pub fn builtin() -> Vec<(BitFlags<ClashCore>, ChainItem)> {
// ...
vec![
(ClashCore::Mihomo | ClashCore::MihomoAlpha, hy_alpn),
(ClashCore::Mihomo | ClashCore::MihomoAlpha, meta_guard),
(ClashCore::all(), config_fixer),
(ClashCore::ClashRs.into(), clash_rs_comp),
]
}
/// the final usage
for item in ChainItem::builtin()
.into_iter()
.filter(|(s, _)| s.contains(*clash_core.as_ref().unwrap_or(&ClashCore::default()))) // This line is the bitflags judgement
.map(|(_, c)| c)
{
// ...
} Ref: https://github.com/libnyanpasu/clash-nyanpasu/blob/f910c600878c281fd40c59c75f84fe6e32f4d968/backend/tauri/src/enhance/chain.rs#L133-L138, https://github.com/libnyanpasu/clash-nyanpasu/blob/f910c600878c281fd40c59c75f84fe6e32f4d968/backend/tauri/src/enhance/mod.rs#L118C8-L121C29 |
i see. thanks for the example. i think it has limited use case here and tbh I think it also adds extra costs to the readability thoughts? @litcc @VendettaReborn |
yeah, i agree, the benefit of enumflags2 is rather limited |
🤔 This is a ...
🔗 Related issue link
Nope
💡 Background and solution
Mihomo introduce the
icon
field for showing a custom icon processed by GUI.Doc link: https://wiki.metacubex.one/config/proxy-groups/?h=icon#icon
What's more, it seems that:
serde(flatten)
. The behavior should be similar to the anonymous field of golang. Doc ref: https://serde.rs/attr-flatten.html📝 Changelog
☑️ Self-Check before Merge