Skip to content

Commit 86b86e4

Browse files
committed
fix: lint
fix: lint fix: lint fix: lint
1 parent 38b2512 commit 86b86e4

File tree

7 files changed

+39
-41
lines changed

7 files changed

+39
-41
lines changed

backend/tauri/src/core/manager.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
use crate::{config::nyanpasu::ClashCore, core::find_binary_path};
21
use std::borrow::Cow;
32

43
/// 给clash内核的tun模式授权
54
#[cfg(any(target_os = "macos", target_os = "linux"))]
6-
pub fn grant_permission(core: &ClashCore) -> anyhow::Result<()> {
5+
pub fn grant_permission(core: &nyanpasu_utils::core::CoreType) -> anyhow::Result<()> {
76
use std::process::Command;
8-
use tauri::utils::platform::current_exe;
97

10-
let path = find_binary_path(&core).map_err(|| anyhow::anyhow!("clash core not found"))?;
8+
let path = crate::core::clash::core::find_binary_path(&core)
9+
.map_err(|_| anyhow::anyhow!("clash core not found"))?
10+
.canonicalize()?
11+
.to_string_lossy()
12+
.to_string();
1113

12-
log::debug!("grant_permission path: {path}");
14+
log::debug!("grant_permission path: {:?}", path);
1315

1416
#[cfg(target_os = "macos")]
1517
let output = {

backend/tauri/src/core/service/ipc.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,30 @@ pub(super) fn set_ipc_state(state: IpcState) {
3737
}
3838

3939
fn dispatch_disconnected() {
40-
match IPC_STATE.compare_exchange_weak(
41-
IpcState::Connected,
42-
IpcState::Disconnected,
43-
Ordering::SeqCst,
44-
Ordering::Relaxed,
45-
) {
46-
Ok(_) => on_ipc_state_changed(IpcState::Disconnected),
47-
Err(_) => {}
40+
if IPC_STATE
41+
.compare_exchange_weak(
42+
IpcState::Connected,
43+
IpcState::Disconnected,
44+
Ordering::SeqCst,
45+
Ordering::Relaxed,
46+
)
47+
.is_ok()
48+
{
49+
on_ipc_state_changed(IpcState::Disconnected)
4850
}
4951
}
5052

5153
fn dispatch_connected() {
52-
match IPC_STATE.compare_exchange_weak(
53-
IpcState::Disconnected,
54-
IpcState::Connected,
55-
Ordering::SeqCst,
56-
Ordering::Relaxed,
57-
) {
58-
Ok(_) => on_ipc_state_changed(IpcState::Connected),
59-
Err(_) => {}
54+
if IPC_STATE
55+
.compare_exchange_weak(
56+
IpcState::Disconnected,
57+
IpcState::Connected,
58+
Ordering::SeqCst,
59+
Ordering::Relaxed,
60+
)
61+
.is_ok()
62+
{
63+
on_ipc_state_changed(IpcState::Connected)
6064
}
6165
}
6266

backend/tauri/src/enhance/advice.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
#[allow(unused_imports)]
12
use crate::enhance::{script::runner::ProcessOutput, Logs, LogsExt};
23
use rust_i18n::t;
34
use serde_yaml::Mapping;
45

56
// TODO: add more advice for chain
67
pub fn chain_advice(config: &Mapping) -> ProcessOutput {
7-
// FIXME: its clone is not necessary
8+
#[allow(unused_mut)]
89
let mut logs = Logs::default();
910
if config.get("tun").is_some_and(|val| {
1011
val.is_mapping()
@@ -44,34 +45,35 @@ pub fn chain_advice(config: &Mapping) -> ProcessOutput {
4445
use nix::unistd::{Gid, Group as NixGroup, Uid, User};
4546
use std::os::unix::fs::MetadataExt;
4647
if !service_state.is_connected() {
47-
let core = {
48+
let core: nyanpasu_utils::core::CoreType = {
4849
crate::config::Config::verge()
4950
.latest()
5051
.clash_core
5152
.as_ref()
5253
.unwrap_or(&crate::config::nyanpasu::ClashCore::default())
54+
.into()
5355
};
5456
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) {
5759
let uid = metadata.uid();
5860
let gid = metadata.gid();
5961
let user = User::from_uid(Uid::from_raw(uid)).ok().flatten();
6062
let group = NixGroup::from_gid(Gid::from_raw(gid)).ok().flatten();
6163
if let (Some(user), Some(group)) = (user, group) {
6264
if !*crate::consts::IS_APPIMAGE
63-
&& (user.name() != "root" || group.name() != ROOT_GROUP)
65+
&& (user.name != "root" || group.name != ROOT_GROUP)
6466
{
6567
tracing::warn!("The core file is not granted the necessary permissions, grant it");
6668
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()) {
6870
if let Err(err) = crate::core::manager::grant_permission(&core)
6971
{
7072
tracing::error!(
7173
"Failed to grant permission to the core file: {}",
7274
err
7375
);
74-
crate::utils::dialog::error_dialog(&format!(
76+
crate::utils::dialog::error_dialog(format!(
7577
"failed to grant core permission:\n{:#?}",
7678
err
7779
));

backend/tauri/src/ipc.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,6 @@ pub async fn restart_sidecar() -> CmdResult {
276276
wrap_err!(CoreManager::global().run_core().await)
277277
}
278278

279-
// #[tauri::command]
280-
// pub fn grant_permission(_core: String) -> CmdResult {
281-
// #[cfg(any(target_os = "macos", target_os = "linux"))]
282-
// return wrap_err!(manager::grant_permission(_core));
283-
284-
// #[cfg(not(any(target_os = "macos", target_os = "linux")))]
285-
// return Err("Unsupported target".into());
286-
// }
287-
288279
/// get the system proxy
289280
#[tauri::command]
290281
pub fn get_sys_proxy() -> CmdResult<Mapping> {

backend/tauri/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(auto_traits, negative_impls, let_chains)]
2-
#![feature(std_internals)]
32
#![cfg_attr(
43
all(not(debug_assertions), target_os = "windows"),
54
windows_subsystem = "windows"
@@ -249,7 +248,6 @@ pub fn run() -> std::io::Result<()> {
249248
ipc::open_core_dir,
250249
// cmds::kill_sidecar,
251250
ipc::restart_sidecar,
252-
// ipc::grant_permission,
253251
// clash
254252
ipc::get_clash_info,
255253
ipc::get_clash_logs,

backend/tauri/src/utils/dialog.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(dead_code)]
2+
13
use rfd::{MessageButtons, MessageDialog, MessageDialogResult, MessageLevel};
24
use rust_i18n::t;
35

backend/tauri/src/utils/init/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use crate::{
22
config::*,
3-
utils::{dialog::migrate_dialog, dirs, help},
3+
utils::{dirs, help},
44
};
55
use anyhow::{anyhow, Context, Result};
66
use fs_extra::dir::CopyOptions;
77
#[cfg(windows)]
88
use runas::Command as RunasCommand;
9-
use rust_i18n::t;
109
use std::{
1110
fs,
1211
io::{BufReader, Write},

0 commit comments

Comments
 (0)