Ver Fonte

refactor: remove grant logic

MystiPanda há 11 meses atrás
pai
commit
b5556613cf

+ 0 - 9
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<Mapping> {

+ 0 - 48
src-tauri/src/core/manager.rs

@@ -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}");
-    }
-}

+ 0 - 1
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;

+ 0 - 1
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,

+ 1 - 36
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<DialogRef>((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<DialogRef>((props, ref) => {
             onClick={() => onCoreChange(each.core)}
           >
             <ListItemText primary={each.name} secondary={`/${each.core}`} />
-
-            {(OS === "macos" || OS === "linux") && (
-              <Tooltip title={t("Tun mode requires")}>
-                <Button
-                  variant="outlined"
-                  size="small"
-                  onClick={(e) => {
-                    e.preventDefault();
-                    e.stopPropagation();
-                    onGrant(each.core);
-                  }}
-                >
-                  {t("Grant")}
-                </Button>
-              </Tooltip>
-            )}
           </ListItemButton>
         ))}
       </List>

+ 0 - 4
src/services/cmds.ts

@@ -142,10 +142,6 @@ export async function restartSidecar() {
   return invoke<void>("restart_sidecar");
 }
 
-export async function grantPermission(core: string) {
-  return invoke<void>("grant_permission", { core });
-}
-
 export async function getAppDir() {
   return invoke<string>("get_app_dir");
 }