Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
fix: lint

fix: lint
  • Loading branch information
greenhat616 committed Sep 23, 2024
1 parent 38b2512 commit c9ad8fe
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 35 deletions.
7 changes: 4 additions & 3 deletions backend/tauri/src/core/manager.rs
Original file line number Diff line number Diff line change
@@ -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}");

Expand Down
36 changes: 20 additions & 16 deletions backend/tauri/src/core/service/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
10 changes: 6 additions & 4 deletions backend/tauri/src/enhance/advice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,29 @@ 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();
let user = User::from_uid(Uid::from_raw(uid)).ok().flatten();
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!(
Expand Down
9 changes: 0 additions & 9 deletions backend/tauri/src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mapping> {
Expand Down
1 change: 0 additions & 1 deletion backend/tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions backend/tauri/src/utils/dialog.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use rfd::{MessageButtons, MessageDialog, MessageDialogResult, MessageLevel};
use rust_i18n::t;

Expand Down
3 changes: 1 addition & 2 deletions backend/tauri/src/utils/init/mod.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down

0 comments on commit c9ad8fe

Please sign in to comment.