diff --git a/src-tauri/src/cmds.rs b/src-tauri/src/cmds.rs index 68b2ac8..dd474e8 100644 --- a/src-tauri/src/cmds.rs +++ b/src-tauri/src/cmds.rs @@ -181,15 +181,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/src-tauri/src/core/manager.rs b/src-tauri/src/core/manager.rs deleted file mode 100644 index de87738..0000000 --- a/src-tauri/src/core/manager.rs +++ /dev/null @@ -1,48 +0,0 @@ -/// 给clash内核的tun模式授权 -#[cfg(any(target_os = "macos", target_os = "linux"))] -pub fn grant_permission(core: String) -> anyhow::Result<()> { - use std::process::Command; - use tauri::utils::platform::current_exe; - - let path = current_exe()?.with_file_name(core).canonicalize()?; - let path = path.display().to_string(); - - log::debug!("grant_permission path: {path}"); - - #[cfg(target_os = "macos")] - let output = { - let path = path.replace(' ', "\\\\ "); - let shell = format!("chown root:admin {path}\nchmod +sx {path}"); - let command = format!(r#"do shell script "{shell}" with administrator privileges"#); - Command::new("osascript") - .args(vec!["-e", &command]) - .output()? - }; - - #[cfg(target_os = "linux")] - let output = { - let path = path.replace(' ', "\\ "); // 避免路径中有空格 - let shell = - format!("setcap cap_net_bind_service,cap_net_admin,cap_dac_override=+ep {path}"); - - let sudo = match Command::new("which").arg("pkexec").output() { - Ok(output) => { - if output.stdout.is_empty() { - "sudo" - } else { - "pkexec" - } - } - Err(_) => "sudo", - }; - - Command::new(sudo).arg("sh").arg("-c").arg(shell).output()? - }; - - if output.status.success() { - Ok(()) - } else { - let stderr = std::str::from_utf8(&output.stderr).unwrap_or(""); - anyhow::bail!("{stderr}"); - } -} diff --git a/src-tauri/src/core/mod.rs b/src-tauri/src/core/mod.rs index 436ac51..52e8f27 100644 --- a/src-tauri/src/core/mod.rs +++ b/src-tauri/src/core/mod.rs @@ -4,7 +4,6 @@ mod core; pub mod handle; pub mod hotkey; pub mod logger; -pub mod manager; pub mod service; pub mod sysopt; pub mod timer; diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 738135c..032f176 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -44,7 +44,6 @@ fn main() -> std::io::Result<()> { cmds::get_portable_flag, // cmds::kill_sidecar, cmds::restart_sidecar, - cmds::grant_permission, // clash cmds::get_clash_info, cmds::get_clash_logs, diff --git a/src/components/setting/mods/clash-core-viewer.tsx b/src/components/setting/mods/clash-core-viewer.tsx index b5f4986..88e89ab 100644 --- a/src/components/setting/mods/clash-core-viewer.tsx +++ b/src/components/setting/mods/clash-core-viewer.tsx @@ -6,17 +6,9 @@ import { useVerge } from "@/hooks/use-verge"; import { useLockFn } from "ahooks"; import { LoadingButton } from "@mui/lab"; import { SwitchAccessShortcut, RestartAlt } from "@mui/icons-material"; -import { - Box, - Button, - Tooltip, - List, - ListItemButton, - ListItemText, -} from "@mui/material"; +import { Box, Button, List, ListItemButton, ListItemText } from "@mui/material"; import { changeClashCore, restartSidecar } from "@/services/cmds"; import { closeAllConnections, upgradeCore } from "@/services/api"; -import { grantPermission } from "@/services/cmds"; import getSystem from "@/utils/get-system"; const VALID_CORE = [ @@ -58,17 +50,6 @@ export const ClashCoreViewer = forwardRef((props, ref) => { } }); - const onGrant = useLockFn(async (core: string) => { - try { - await grantPermission(core); - // 自动重启 - if (core === clash_core) await restartSidecar(); - Notice.success(t("Permissions Granted Successfully for _clash Core", { core: `${core}` }), 1000); - } catch (err: any) { - Notice.error(err?.message || err.toString()); - } - }); - const onRestart = useLockFn(async () => { try { await restartSidecar(); @@ -140,22 +121,6 @@ export const ClashCoreViewer = forwardRef((props, ref) => { onClick={() => onCoreChange(each.core)} > - - {(OS === "macos" || OS === "linux") && ( - - - - )} ))} diff --git a/src/services/cmds.ts b/src/services/cmds.ts index b91ccec..377f374 100644 --- a/src/services/cmds.ts +++ b/src/services/cmds.ts @@ -142,10 +142,6 @@ export async function restartSidecar() { return invoke("restart_sidecar"); } -export async function grantPermission(core: string) { - return invoke("grant_permission", { core }); -} - export async function getAppDir() { return invoke("get_app_dir"); }