diff --git a/backend/tauri/src/core/manager.rs b/backend/tauri/src/core/manager.rs index ab227e329bb..736ac798cd9 100644 --- a/backend/tauri/src/core/manager.rs +++ b/backend/tauri/src/core/manager.rs @@ -1,13 +1,14 @@ -use crate::{config::nyanpasu::ClashCore, core::find_binary_path}; use std::borrow::Cow; /// 给clash内核的tun模式授权 #[cfg(any(target_os = "macos", target_os = "linux"))] -pub fn grant_permission(core: &ClashCore) -> anyhow::Result<()> { +pub fn grant_permission(core: &nyanpasu_utils::core::CoreType) -> anyhow::Result<()> { use std::process::Command; use tauri::utils::platform::current_exe; - let path = find_binary_path(&core).map_err(|| anyhow::anyhow!("clash core not found"))?; + let path = crate::core::clash::core::find_binary_path(&core) + .map_err(|_| anyhow::anyhow!("clash core not found"))? + .canonicalize()?; log::debug!("grant_permission path: {path}"); diff --git a/backend/tauri/src/core/service/ipc.rs b/backend/tauri/src/core/service/ipc.rs index 12d9674ec9d..ffa778b7afe 100644 --- a/backend/tauri/src/core/service/ipc.rs +++ b/backend/tauri/src/core/service/ipc.rs @@ -37,26 +37,30 @@ pub(super) fn set_ipc_state(state: IpcState) { } fn dispatch_disconnected() { - match IPC_STATE.compare_exchange_weak( - IpcState::Connected, - IpcState::Disconnected, - Ordering::SeqCst, - Ordering::Relaxed, - ) { - Ok(_) => on_ipc_state_changed(IpcState::Disconnected), - Err(_) => {} + if IPC_STATE + .compare_exchange_weak( + IpcState::Connected, + IpcState::Disconnected, + Ordering::SeqCst, + Ordering::Relaxed, + ) + .is_ok() + { + on_ipc_state_changed(IpcState::Disconnected) } } fn dispatch_connected() { - match IPC_STATE.compare_exchange_weak( - IpcState::Disconnected, - IpcState::Connected, - Ordering::SeqCst, - Ordering::Relaxed, - ) { - Ok(_) => on_ipc_state_changed(IpcState::Connected), - Err(_) => {} + if IPC_STATE + .compare_exchange_weak( + IpcState::Disconnected, + IpcState::Connected, + Ordering::SeqCst, + Ordering::Relaxed, + ) + .is_ok() + { + on_ipc_state_changed(IpcState::Connected) } } diff --git a/backend/tauri/src/enhance/advice.rs b/backend/tauri/src/enhance/advice.rs index dd00f66f220..e9869d0185d 100644 --- a/backend/tauri/src/enhance/advice.rs +++ b/backend/tauri/src/enhance/advice.rs @@ -44,15 +44,17 @@ pub fn chain_advice(config: &Mapping) -> ProcessOutput { use nix::unistd::{Gid, Group as NixGroup, Uid, User}; use std::os::unix::fs::MetadataExt; if !service_state.is_connected() { - let core = { + let core: nyanpasu_utils::core::CoreType = { crate::config::Config::verge() .latest() .clash_core .as_ref() .unwrap_or(&crate::config::nyanpasu::ClashCore::default()) + .clone() + .into() }; let core_path = crate::core::clash::core::find_binary_path(&core); - if let Some(core_path) = core_path { + if let Ok(core_path) = core_path { if let Some(metadata) = std::fs::metadata(&core_path).ok() { let uid = metadata.uid(); let gid = metadata.gid(); @@ -60,11 +62,11 @@ pub fn chain_advice(config: &Mapping) -> ProcessOutput { let group = NixGroup::from_gid(Gid::from_raw(gid)).ok().flatten(); if let (Some(user), Some(group)) = (user, group) { if !*crate::consts::IS_APPIMAGE - && (user.name() != "root" || group.name() != ROOT_GROUP) + && (user.name != "root" || group.name != ROOT_GROUP) { tracing::warn!("The core file is not granted the necessary permissions, grant it"); let msg = t!("dialog.info.grant_core_permission"); - if crate::utils::dialog::ask_dialog(&msg) { + if crate::utils::dialog::ask_dialog(msg.as_ref()) { if let Err(err) = crate::core::manager::grant_permission(&core) { tracing::error!( diff --git a/backend/tauri/src/ipc.rs b/backend/tauri/src/ipc.rs index 341e05b9156..28584f07568 100644 --- a/backend/tauri/src/ipc.rs +++ b/backend/tauri/src/ipc.rs @@ -276,15 +276,6 @@ pub async fn restart_sidecar() -> CmdResult { wrap_err!(CoreManager::global().run_core().await) } -// #[tauri::command] -// pub fn grant_permission(_core: String) -> CmdResult { -// #[cfg(any(target_os = "macos", target_os = "linux"))] -// return wrap_err!(manager::grant_permission(_core)); - -// #[cfg(not(any(target_os = "macos", target_os = "linux")))] -// return Err("Unsupported target".into()); -// } - /// get the system proxy #[tauri::command] pub fn get_sys_proxy() -> CmdResult { diff --git a/backend/tauri/src/lib.rs b/backend/tauri/src/lib.rs index 785a9a951b0..e9ac4595488 100644 --- a/backend/tauri/src/lib.rs +++ b/backend/tauri/src/lib.rs @@ -249,7 +249,6 @@ pub fn run() -> std::io::Result<()> { ipc::open_core_dir, // cmds::kill_sidecar, ipc::restart_sidecar, - // ipc::grant_permission, // clash ipc::get_clash_info, ipc::get_clash_logs, diff --git a/backend/tauri/src/utils/dialog.rs b/backend/tauri/src/utils/dialog.rs index ddfc6b20098..e79d821126b 100644 --- a/backend/tauri/src/utils/dialog.rs +++ b/backend/tauri/src/utils/dialog.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + use rfd::{MessageButtons, MessageDialog, MessageDialogResult, MessageLevel}; use rust_i18n::t; diff --git a/backend/tauri/src/utils/init/mod.rs b/backend/tauri/src/utils/init/mod.rs index b416ce732e4..93c923d0763 100644 --- a/backend/tauri/src/utils/init/mod.rs +++ b/backend/tauri/src/utils/init/mod.rs @@ -1,12 +1,11 @@ use crate::{ config::*, - utils::{dialog::migrate_dialog, dirs, help}, + utils::{dirs, help}, }; use anyhow::{anyhow, Context, Result}; use fs_extra::dir::CopyOptions; #[cfg(windows)] use runas::Command as RunasCommand; -use rust_i18n::t; use std::{ fs, io::{BufReader, Write},