mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 11:42:21 +08:00
Compare commits
4 Commits
a5a849b126
...
9653decfa1
Author | SHA1 | Date | |
---|---|---|---|
|
9653decfa1 | ||
|
a0f9fb90ee | ||
|
1b8c4cb832 | ||
|
cfd50d281b |
3
src-tauri/Cargo.lock
generated
3
src-tauri/Cargo.lock
generated
|
@ -378,7 +378,8 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "auto-launch"
|
name = "auto-launch"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
source = "git+https://github.com/zzzgydi/auto-launch?branch=main#2d94a103ca20652a3baf581ca2c296791c35c09b"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1f012b8cc0c850f34117ec8252a44418f2e34a2cf501de89e29b241ae5f79471"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dirs 4.0.0",
|
"dirs 4.0.0",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
|
|
@ -30,13 +30,13 @@ once_cell = "1.19"
|
||||||
port_scanner = "0.1.5"
|
port_scanner = "0.1.5"
|
||||||
delay_timer = "0.11"
|
delay_timer = "0.11"
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
|
auto-launch = "0.5.0"
|
||||||
percent-encoding = "2.3.1"
|
percent-encoding = "2.3.1"
|
||||||
window-shadows = { version = "0.2" }
|
window-shadows = { version = "0.2" }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
reqwest = { version = "0.12", features = ["json", "rustls-tls"] }
|
reqwest = { version = "0.12", features = ["json", "rustls-tls"] }
|
||||||
sysproxy = { git="https://github.com/zzzgydi/sysproxy-rs", branch = "main" }
|
sysproxy = { git="https://github.com/zzzgydi/sysproxy-rs", branch = "main" }
|
||||||
auto-launch = { git="https://github.com/zzzgydi/auto-launch", branch = "main" }
|
|
||||||
tauri = { git="https://github.com/tauri-apps/tauri",branch = "1.x", features = [ "fs-read-file", "fs-exists", "path-all", "protocol-asset", "dialog-open", "notification-all", "icon-png", "icon-ico", "clipboard-all", "global-shortcut-all", "process-all", "shell-all", "system-tray", "updater", "window-all", "devtools"] }
|
tauri = { git="https://github.com/tauri-apps/tauri",branch = "1.x", features = [ "fs-read-file", "fs-exists", "path-all", "protocol-asset", "dialog-open", "notification-all", "icon-png", "icon-ico", "clipboard-all", "global-shortcut-all", "process-all", "shell-all", "system-tray", "updater", "window-all", "devtools"] }
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
runas = "=1.2.0"
|
runas = "=1.2.0"
|
||||||
|
|
|
@ -88,16 +88,37 @@ pub fn toggle_system_proxy() {
|
||||||
pub fn toggle_tun_mode() {
|
pub fn toggle_tun_mode() {
|
||||||
let enable = Config::verge().data().enable_tun_mode;
|
let enable = Config::verge().data().enable_tun_mode;
|
||||||
let enable = enable.unwrap_or(false);
|
let enable = enable.unwrap_or(false);
|
||||||
|
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
match patch_verge(IVerge {
|
if !enable {
|
||||||
enable_tun_mode: Some(!enable),
|
if let Ok(res) = service::check_service().await {
|
||||||
..IVerge::default()
|
if res.code == 0 {
|
||||||
})
|
match patch_verge(IVerge {
|
||||||
.await
|
enable_tun_mode: Some(!enable),
|
||||||
{
|
..IVerge::default()
|
||||||
Ok(_) => handle::Handle::refresh_verge(),
|
})
|
||||||
Err(err) => log::error!(target: "app", "{err}"),
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => handle::Handle::refresh_verge(),
|
||||||
|
Err(err) => log::error!(target: "app", "{err}"),
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tauri::api::dialog::message(
|
||||||
|
None::<&tauri::Window>,
|
||||||
|
"Please install and enable service mode",
|
||||||
|
"Service mode is required for Tun mode",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
match patch_verge(IVerge {
|
||||||
|
enable_tun_mode: Some(!enable),
|
||||||
|
..IVerge::default()
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => handle::Handle::refresh_verge(),
|
||||||
|
Err(err) => log::error!(target: "app", "{err}"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -403,3 +424,19 @@ pub async fn test_delay(url: String) -> Result<u32> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn check_permission() -> Result<()> {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
let hklm = winreg::RegKey::predef(winreg::enums::HKEY_LOCAL_MACHINE);
|
||||||
|
|
||||||
|
if let Ok(reg) = hklm.open_subkey_with_flags(
|
||||||
|
"SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Run",
|
||||||
|
winreg::enums::KEY_SET_VALUE,
|
||||||
|
) {
|
||||||
|
reg.delete_value("Clash Verge").unwrap_or_default();
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(anyhow::anyhow!("permission denied"))
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,16 @@ fn main() -> std::io::Result<()> {
|
||||||
println!("app exists");
|
println!("app exists");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
// 权限检测
|
||||||
|
if feat::check_permission().is_ok() {
|
||||||
|
println!("please do not run with admin permission");
|
||||||
|
tauri::api::dialog::blocking::message(
|
||||||
|
None::<&tauri::Window>,
|
||||||
|
"Please do not run with admin permission",
|
||||||
|
"If you want to use Tun mode, please enable service mode instead",
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
|
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
|
||||||
|
|
|
@ -1,12 +1,4 @@
|
||||||
import { useTranslation } from "react-i18next";
|
import { Button, ButtonGroup } from "@mui/material";
|
||||||
import { Button, ButtonGroup, Tooltip } from "@mui/material";
|
|
||||||
import { checkService } from "@/services/cmds";
|
|
||||||
import { useVerge } from "@/hooks/use-verge";
|
|
||||||
import getSystem from "@/utils/get-system";
|
|
||||||
import useSWR from "swr";
|
|
||||||
import { useEffect } from "react";
|
|
||||||
|
|
||||||
const isWIN = getSystem() === "windows";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
value?: string;
|
value?: string;
|
||||||
|
@ -15,62 +7,31 @@ interface Props {
|
||||||
|
|
||||||
export const StackModeSwitch = (props: Props) => {
|
export const StackModeSwitch = (props: Props) => {
|
||||||
const { value, onChange } = props;
|
const { value, onChange } = props;
|
||||||
const { verge } = useVerge();
|
|
||||||
const { enable_service_mode } = verge ?? {};
|
|
||||||
// service mode
|
|
||||||
const { data: serviceStatus, mutate: mutateCheck } = useSWR(
|
|
||||||
isWIN ? "checkService" : null,
|
|
||||||
checkService,
|
|
||||||
{
|
|
||||||
revalidateIfStale: false,
|
|
||||||
shouldRetryOnError: false,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
mutateCheck();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<ButtonGroup size="small" sx={{ my: "4px" }}>
|
||||||
title={
|
<Button
|
||||||
isWIN && (serviceStatus !== "active" || !enable_service_mode)
|
variant={value?.toLowerCase() === "system" ? "contained" : "outlined"}
|
||||||
? t("System and Mixed Can Only be Used in Service Mode")
|
onClick={() => onChange?.("system")}
|
||||||
: ""
|
sx={{ textTransform: "capitalize" }}
|
||||||
}
|
>
|
||||||
>
|
System
|
||||||
<ButtonGroup size="small" sx={{ my: "4px" }}>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
variant={value?.toLowerCase() === "system" ? "contained" : "outlined"}
|
variant={value?.toLowerCase() === "gvisor" ? "contained" : "outlined"}
|
||||||
onClick={() => onChange?.("system")}
|
onClick={() => onChange?.("gvisor")}
|
||||||
disabled={
|
sx={{ textTransform: "capitalize" }}
|
||||||
isWIN && (serviceStatus !== "active" || !enable_service_mode)
|
>
|
||||||
}
|
gVisor
|
||||||
sx={{ textTransform: "capitalize" }}
|
</Button>
|
||||||
>
|
|
||||||
System
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant={value?.toLowerCase() === "gvisor" ? "contained" : "outlined"}
|
|
||||||
onClick={() => onChange?.("gvisor")}
|
|
||||||
sx={{ textTransform: "capitalize" }}
|
|
||||||
>
|
|
||||||
gVisor
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
variant={value?.toLowerCase() === "mixed" ? "contained" : "outlined"}
|
variant={value?.toLowerCase() === "mixed" ? "contained" : "outlined"}
|
||||||
onClick={() => onChange?.("mixed")}
|
onClick={() => onChange?.("mixed")}
|
||||||
disabled={
|
sx={{ textTransform: "capitalize" }}
|
||||||
isWIN && (serviceStatus !== "active" || !enable_service_mode)
|
>
|
||||||
}
|
Mixed
|
||||||
sx={{ textTransform: "capitalize" }}
|
</Button>
|
||||||
>
|
</ButtonGroup>
|
||||||
Mixed
|
|
||||||
</Button>
|
|
||||||
</ButtonGroup>
|
|
||||||
</Tooltip>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,10 +29,10 @@ export const SysproxyViewer = forwardRef<DialogRef>((props, ref) => {
|
||||||
let validReg;
|
let validReg;
|
||||||
if (getSystem() === "windows") {
|
if (getSystem() === "windows") {
|
||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local>)(;((\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}|(\d{1,3}\.){1,3}\d{1,3}(\/\d{1,2}|\/3[0-2])?|\d{1,3}\.\d{1,3}\.\d{1,3}\.\*(\/\d{1,2}|\/3[0-2])?|\d{1,3}\.\d{1,3}\.\*(\/\d{1,2}|\/3[0-2])?|\d{1,3}\.\*(\/\d{1,2}|\/3[0-2])?|([a-fA-F0-9:]+:+)+[a-fA-F0-9]+(\/\d{1,3})?|localhost|<local>))*;?$/;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
|
@ -22,11 +22,15 @@ const SettingSystem = ({ onError }: Props) => {
|
||||||
const { verge, mutateVerge, patchVerge } = useVerge();
|
const { verge, mutateVerge, patchVerge } = useVerge();
|
||||||
|
|
||||||
// service mode
|
// service mode
|
||||||
const { data: serviceStatus } = useSWR("checkService", checkService, {
|
const { data: serviceStatus, mutate: mutateCheck } = useSWR(
|
||||||
revalidateIfStale: false,
|
"checkService",
|
||||||
shouldRetryOnError: false,
|
checkService,
|
||||||
focusThrottleInterval: 36e5, // 1 hour
|
{
|
||||||
});
|
revalidateIfStale: false,
|
||||||
|
shouldRetryOnError: false,
|
||||||
|
focusThrottleInterval: 36e5, // 1 hour
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const serviceRef = useRef<DialogRef>(null);
|
const serviceRef = useRef<DialogRef>(null);
|
||||||
const sysproxyRef = useRef<DialogRef>(null);
|
const sysproxyRef = useRef<DialogRef>(null);
|
||||||
|
@ -84,7 +88,7 @@ const SettingSystem = ({ onError }: Props) => {
|
||||||
onChange={(e) => onChangeData({ enable_tun_mode: e })}
|
onChange={(e) => onChangeData({ enable_tun_mode: e })}
|
||||||
onGuard={(e) => patchVerge({ enable_tun_mode: e })}
|
onGuard={(e) => patchVerge({ enable_tun_mode: e })}
|
||||||
>
|
>
|
||||||
<Switch edge="end" />
|
<Switch disabled={serviceStatus !== "active"} edge="end" />
|
||||||
</GuardState>
|
</GuardState>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|
||||||
|
@ -109,7 +113,10 @@ const SettingSystem = ({ onError }: Props) => {
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={onSwitchFormat}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ enable_service_mode: e })}
|
onChange={(e) => onChangeData({ enable_service_mode: e })}
|
||||||
onGuard={(e) => patchVerge({ enable_service_mode: e })}
|
onGuard={(e) => {
|
||||||
|
setTimeout(() => mutateCheck(), 1000);
|
||||||
|
return patchVerge({ enable_service_mode: e });
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Switch
|
<Switch
|
||||||
edge="end"
|
edge="end"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user