|
| 1 | +#[allow(unused_imports)] |
1 | 2 | use crate::enhance::{script::runner::ProcessOutput, Logs, LogsExt}; |
2 | 3 | use rust_i18n::t; |
3 | 4 | use serde_yaml::Mapping; |
4 | 5 |
|
5 | 6 | // TODO: add more advice for chain |
6 | 7 | pub fn chain_advice(config: &Mapping) -> ProcessOutput { |
7 | | - // FIXME: its clone is not necessary |
| 8 | + #[allow(unused_mut)] |
8 | 9 | let mut logs = Logs::default(); |
9 | 10 | if config.get("tun").is_some_and(|val| { |
10 | 11 | val.is_mapping() |
@@ -44,34 +45,35 @@ pub fn chain_advice(config: &Mapping) -> ProcessOutput { |
44 | 45 | use nix::unistd::{Gid, Group as NixGroup, Uid, User}; |
45 | 46 | use std::os::unix::fs::MetadataExt; |
46 | 47 | if !service_state.is_connected() { |
47 | | - let core = { |
| 48 | + let core: nyanpasu_utils::core::CoreType = { |
48 | 49 | crate::config::Config::verge() |
49 | 50 | .latest() |
50 | 51 | .clash_core |
51 | 52 | .as_ref() |
52 | 53 | .unwrap_or(&crate::config::nyanpasu::ClashCore::default()) |
| 54 | + .into() |
53 | 55 | }; |
54 | 56 | let core_path = crate::core::clash::core::find_binary_path(&core); |
55 | | - if let Some(core_path) = core_path { |
56 | | - if let Some(metadata) = std::fs::metadata(&core_path).ok() { |
| 57 | + if let Ok(core_path) = core_path { |
| 58 | + if let Ok(metadata) = std::fs::metadata(&core_path) { |
57 | 59 | let uid = metadata.uid(); |
58 | 60 | let gid = metadata.gid(); |
59 | 61 | let user = User::from_uid(Uid::from_raw(uid)).ok().flatten(); |
60 | 62 | let group = NixGroup::from_gid(Gid::from_raw(gid)).ok().flatten(); |
61 | 63 | if let (Some(user), Some(group)) = (user, group) { |
62 | 64 | if !*crate::consts::IS_APPIMAGE |
63 | | - && (user.name() != "root" || group.name() != ROOT_GROUP) |
| 65 | + && (user.name != "root" || group.name != ROOT_GROUP) |
64 | 66 | { |
65 | 67 | tracing::warn!("The core file is not granted the necessary permissions, grant it"); |
66 | 68 | let msg = t!("dialog.info.grant_core_permission"); |
67 | | - if crate::utils::dialog::ask_dialog(&msg) { |
| 69 | + if crate::utils::dialog::ask_dialog(msg.as_ref()) { |
68 | 70 | if let Err(err) = crate::core::manager::grant_permission(&core) |
69 | 71 | { |
70 | 72 | tracing::error!( |
71 | 73 | "Failed to grant permission to the core file: {}", |
72 | 74 | err |
73 | 75 | ); |
74 | | - crate::utils::dialog::error_dialog(&format!( |
| 76 | + crate::utils::dialog::error_dialog(format!( |
75 | 77 | "failed to grant core permission:\n{:#?}", |
76 | 78 | err |
77 | 79 | )); |
|
0 commit comments