Compare commits

..
Author SHA1 Message Date
TungliesandCopilot a236ee61b0 feat(windows): reinstall an existing Service during NSIS upgrades
The reinstall page runs the previous uninstaller, which removes the
Service, and the new installer only tried to start one. Record whether
clash_verge_service exists, with its start type and running state, in
.onInit before that uninstaller can run. When it existed, Section Install
reinstalls it with the bundled cores and their hashes through the
installer's own elevation, then restores a non-automatic start type and
the stopped state. A first install still never adds a Service.

A failed reinstall or restore is logged, shown in a warning dialog that is
auto-confirmed under /S, and sets exit code 2, so the installer does not
report success.

Validated only by compiling the macros with makensis -WX against the real
SimpleSC plugin; not run on Windows.

Refs #8553

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-09 21:22:48 +08:00
21 changed files with 448 additions and 315 deletions
-21
View File
@@ -34,24 +34,3 @@ jobs:
uses: github/gh-aw-actions/setup-cli@406c7719e31d7fe354224d4bb8fe3d4aeb47da1c # v1.2.1
with:
version: v1.0.1
- name: Install Rust Stable
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- name: Install Linux build dependencies
run: |
sudo apt-get update
sudo apt-get install -y libxslt1.1 libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf
- name: Install pnpm
uses: pnpm/action-setup@v6
with:
run_install: false
- name: Install Node.js
uses: actions/setup-node@v7
with:
node-version: '26.13.0'
cache: 'pnpm'
- name: Install frontend dependencies
env:
HUSKY: 0
run: pnpm install --frozen-lockfile
Generated
+14 -70
View File
@@ -159,9 +159,9 @@ dependencies = [
[[package]]
name = "arc-swap"
version = "1.9.4"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db4c94f57a570fce5d381be3289b3f79aef6332d72948fe82ab5772e423ccf92"
checksum = "380962b3d93b99642e50b9febf72c071e97e8b32d86eae9cf4ef582bb960ae6e"
dependencies = [
"rustversion",
]
@@ -1120,7 +1120,7 @@ dependencies = [
"percent-encoding",
"reqwest 0.13.5",
"reqwest_dav",
"rfd 0.18.0",
"rfd",
"runas",
"rustls",
"scopeguard",
@@ -2404,9 +2404,9 @@ checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99"
[[package]]
name = "flate2"
version = "1.1.11"
version = "1.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4"
checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb"
dependencies = [
"crc32fast",
"miniz_oxide 0.9.1",
@@ -3241,9 +3241,9 @@ dependencies = [
[[package]]
name = "http-body-util"
version = "0.1.5"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c"
checksum = "e9f41fd6a08e4d4ec69df65976da761afd5ad5e58a9d4acb46bd1c953a9e3ff2"
dependencies = [
"bytes",
"futures-core",
@@ -4070,9 +4070,9 @@ checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
[[package]]
name = "lzma-rust2"
version = "0.25.0"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef1d73c59a56771343712b22ea5615092c612c16ba291c0979e3105dfeec4890"
checksum = "490750560fa7851fbbf5d3ab1a8750f09350ed361ed8aed85b1e1e40587812ee"
dependencies = [
"sha2 0.11.1",
]
@@ -4538,7 +4538,6 @@ dependencies = [
"objc2-core-video",
"objc2-foundation",
"objc2-quartz-core",
"objc2-uniform-type-identifiers",
]
[[package]]
@@ -4760,16 +4759,6 @@ dependencies = [
"objc2-user-notifications",
]
[[package]]
name = "objc2-uniform-type-identifiers"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7902ac02859fc1f7045f8b598c63f1ae0cc7efeaa06a9bc9f3d9a3c955974fa4"
dependencies = [
"objc2",
"objc2-foundation",
]
[[package]]
name = "objc2-user-notifications"
version = "0.3.2"
@@ -5313,12 +5302,6 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "pollster"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc6355899e1c9462875b6757c79f3caa011a1fdae12bbb1a2e72dd1f234f8336"
[[package]]
name = "polonius-the-crab"
version = "0.5.0"
@@ -5951,31 +5934,6 @@ dependencies = [
"windows-sys 0.61.2",
]
[[package]]
name = "rfd"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4b9d4857b10297ffb0f64cae711e983a7aeaee561848d56d429d3858bd8ed93"
dependencies = [
"block2",
"dispatch2",
"js-sys",
"libc",
"log",
"objc2",
"objc2-app-kit",
"objc2-core-foundation",
"objc2-foundation",
"objc2-uniform-type-identifiers",
"percent-encoding",
"pollster",
"raw-window-handle",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"windows-sys 0.61.2",
]
[[package]]
name = "ring"
version = "0.17.14"
@@ -7469,7 +7427,7 @@ checksum = "ce0fb9c2b6d34a9720627ed930ebc8af26f61e648695aecaeb03d5c33c5896f5"
dependencies = [
"log",
"raw-window-handle",
"rfd 0.17.2",
"rfd",
"serde",
"serde_json",
"tauri",
@@ -10074,20 +10032,6 @@ name = "zeroize"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e"
dependencies = [
"zeroize_derive",
]
[[package]]
name = "zeroize_derive"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
name = "zerotrie"
@@ -10126,9 +10070,9 @@ dependencies = [
[[package]]
name = "zip"
version = "9.4.2"
version = "9.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3845f734baabdd02de353a20580e30ceccd03897def44a4eb8e9654992e294"
checksum = "eaeb7f16d2605b49aef586996ded29e65642fab7259a3077e537351df6d80426"
dependencies = [
"aes",
"bzip2",
@@ -10156,9 +10100,9 @@ dependencies = [
[[package]]
name = "zlib-rs"
version = "0.6.8"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
checksum = "b142a20ec14a91d5bc708c1dc21b080c550113d8aa77afa29635673a65dd02c5"
[[package]]
name = "zmij"
+4 -1
View File
@@ -28,7 +28,6 @@
- 修复订阅响应过大导致内存占用过高,限制单次下载为 4 MiB
- 修复全局模式默认停在 `DIRECT` 或 `REJECT` 导致流量未经代理,现自动切换到第一个策略组
- 修复订阅中未加引号的 REALITY `short-id`(如 `1234e123`)被误读为数字,导致订阅无法启用
- 修复订阅中唯一的代理组名为 `GLOBAL` 或没有代理组时,规则模式下代理页面显示「未获取到代理信息」
**🍎 macOS**
@@ -49,6 +48,10 @@
- 优化连接、规则和日志筛选:切换页面后保留过滤条件
- 优化全局模式代理列表:仅显示 `GLOBAL` 节点,选中其中的策略组时才显示该组
**🖥️ Windows**
- 优化 Windows 升级安装时自动重装已安装的服务并保留启停设置,重装失败时提示
**🍎 macOS**
- 优化 macOS TUN 模式的系统 DNS,增加阿里和 Cloudflare 地址
+2 -2
View File
@@ -121,7 +121,7 @@
"https-proxy-agent": "^9.1.0",
"husky": "^9.1.7",
"jiti": "^2.7.0",
"knip": "6.44.2",
"knip": "6.44.1",
"lint-staged": "^17.5.1",
"sass": "^1.104.1",
"tar": "^7.5.22",
@@ -133,7 +133,7 @@
"vite-plugin-svgr": "^5.2.0",
"vitest": "^5.0.1",
"webdriverio": "10.2.0",
"ws": "8.22.2"
"ws": "8.22.1"
},
"lint-staged": {
"*.{ts,tsx,js,mjs}": [
+97 -92
View File
@@ -396,8 +396,8 @@ importers:
specifier: ^2.7.0
version: 2.7.0
knip:
specifier: 6.44.2
version: 6.44.2
specifier: 6.44.1
version: 6.44.1
lint-staged:
specifier: ^17.5.1
version: 17.5.1
@@ -432,8 +432,8 @@ importers:
specifier: 10.2.0
version: 10.2.0(supports-color@7.2.0)(yauzl@2.10.0)
ws:
specifier: 8.22.2
version: 8.22.2
specifier: 8.22.1
version: 8.22.1
packages:
@@ -1595,128 +1595,131 @@ packages:
'@octokit/types@18.0.0':
resolution: {integrity: sha512-l6bAF43PNxkJp6g+W4PjoUSSkxHomXw2nOum5CTftJz1NlV3vu93NImgOYtLf6CbBUb5j+fiuzW0PPQ5JTSvZA==}
'@oxc-parser/binding-android-arm-eabi@0.156.0':
resolution: {integrity: sha512-RMq7DKNzEp1T51QKNLTn0NryNEt2IYfh7mZBlIdi2Ju52ltOEDMeIXv0XBpA6dL7j7ChjlcovtGcc1Jv4qMipg==}
'@oxc-parser/binding-android-arm-eabi@0.155.0':
resolution: {integrity: sha512-A6xv7hDtnTm+xlZ7utn6rRQpRMJHRhVr3gjRGqlx0RUX84mNk0pAsy6YN/wWhuOTkaZhRrrzaLxf0NfbH77j2w==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm]
os: [android]
'@oxc-parser/binding-android-arm64@0.156.0':
resolution: {integrity: sha512-mwkWKhOBpmh8fWc3m4MiLsmEAtx0YuHmvyo9ff557cnb3QZ2kt2eauSz75wCGIpiZG3gUsJ4WwzEjm4R4/BHig==}
'@oxc-parser/binding-android-arm64@0.155.0':
resolution: {integrity: sha512-T1wWwH9/JI5g7Z4kEQwDOwhToxdDhRyOTklH+uuNpJ16m3MZFmGl+l2rKc0NHQdbVRG2LTOBsNjpW3h1BWytPA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [android]
'@oxc-parser/binding-darwin-arm64@0.156.0':
resolution: {integrity: sha512-6pGR5fUszM9M4eBBapqpGjCRJolFwuCldx8bRQjqXyM09cQysBTWVF2Ttg4UNJVxYSaw5RRINbveCOOCrsuGvA==}
'@oxc-parser/binding-darwin-arm64@0.155.0':
resolution: {integrity: sha512-ZoRB3qJxJ8DWA41jHja+YeB0lLfjBy4T+Kr15vnN1k65X3zbJt3rPZftEwN4Ju4tmA4K/T9dWWD7Z8ewQLnrVA==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [darwin]
'@oxc-parser/binding-darwin-x64@0.156.0':
resolution: {integrity: sha512-M9QghL7uCAqMKjYJv1rDGblfEvkeQu3QzTPd7Uwo16gG3uO7m9ikVQ9OL8FZTnKzU4vbCEby6kTlEkqN+JeEMA==}
'@oxc-parser/binding-darwin-x64@0.155.0':
resolution: {integrity: sha512-vxtL86BtM+IgrpejA86nbTk5j0HKTIMeuaJ1fQciw6p9RfavPtIPjI7gN34owap0yG9txXBaAWpGdxokNwdqIw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [darwin]
'@oxc-parser/binding-freebsd-x64@0.156.0':
resolution: {integrity: sha512-lX0ANxSwAOrpOT7NHB+YsrBqDJ8sOVon5m7GS9eQtkuUeNzQMMGpFsJLsStawTbrdwOF5KDVxgPWcKmt/DIZUQ==}
'@oxc-parser/binding-freebsd-x64@0.155.0':
resolution: {integrity: sha512-tN6Ru5e0UVnWaIuiH8jEwnvxuxg7FvhWwSd3oe5oDhOD4ObsSr9/N6WfHLjilUWlPPj65ptwrSDH0Y7lzwTzmw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [freebsd]
'@oxc-parser/binding-linux-arm-gnueabihf@0.156.0':
resolution: {integrity: sha512-iPgYpasRcqk7X3TGncQg7B+6RotDvG8weug0UrgF+FXLf4KmaNDyT91BKONlqbHcNgK9Nryp7AEZGuQn32fP6g==}
'@oxc-parser/binding-linux-arm-gnueabihf@0.155.0':
resolution: {integrity: sha512-h4ozA5n6L6lwolsz9iwunEhKWnIVbmFRots5QxEix0H6nJ5ICpuDa7PuShuhfpIDFe3+Qvyscioyiv+9g+4Syg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm]
os: [linux]
'@oxc-parser/binding-linux-arm-musleabihf@0.156.0':
resolution: {integrity: sha512-sJqJDEZevtkEfoxrXfaRTkSt6Itckr549cIfBbs11UgXv8bFyqQsXTQa6iKm8mTiWYmCDDFJf7TLnqxcbqzPOw==}
'@oxc-parser/binding-linux-arm-musleabihf@0.155.0':
resolution: {integrity: sha512-058/+LardpfuUlsKIvBGk/CYoakEVcMgqYx8GgyUZeOxFWTojYLlCc1Gb60/y21v3esDhHidgiY/Zbq9LpBhaQ==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm]
os: [linux]
'@oxc-parser/binding-linux-arm64-gnu@0.156.0':
resolution: {integrity: sha512-mrQs5OdRiqKskRuWEORPKT6YGIFhrpVvCvL9hqVaIh60EzgR4qjPvSsV6hWZcOfyWHBTbdEvfnDJPh/eQlxPRQ==}
'@oxc-parser/binding-linux-arm64-gnu@0.155.0':
resolution: {integrity: sha512-nrOt2Y3xIAzu+lSPzH0864ieO+iCCXgoo9qFlGANE8Xh0cQ+RP8Wstfp+/wXN2YCyb98cAGzX0VruKYw7it/jw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [linux]
libc: [glibc]
'@oxc-parser/binding-linux-arm64-musl@0.156.0':
resolution: {integrity: sha512-ZtPqgCU3+wpU7dvX7YbaEiw71r0UdguzuPhcx4PIEZSs4XFqc6F5wXCtNdb6M7m3DMErlxrwosryoXrzYOY/Gg==}
'@oxc-parser/binding-linux-arm64-musl@0.155.0':
resolution: {integrity: sha512-KYAayyN5hQbJPtGKtRxlyc8XYmyntOplyXSQzTDrmbz7l/GCrzQbSswvyJFBTH1LGtsZrbXOAfN52i/Kz6kLKg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [linux]
libc: [musl]
'@oxc-parser/binding-linux-ppc64-gnu@0.156.0':
resolution: {integrity: sha512-ZuGRT/adReZZJn3PYNneb1HQIOH0iIZ2fzFgC1/XJYpMQ5KsRKmWIEzy3wEFsUwIOTomCmnmTZ/zbFYo9z9VeA==}
'@oxc-parser/binding-linux-ppc64-gnu@0.155.0':
resolution: {integrity: sha512-CSuSY5hfjtsBnHXydOj8jiNfS1qHbdPZuPz1YL1cSgK7VmNYP+QlZIbG0BBYYBgX/vYEgZwbG9mBdW4YairZ5w==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [ppc64]
os: [linux]
libc: [glibc]
'@oxc-parser/binding-linux-riscv64-gnu@0.156.0':
resolution: {integrity: sha512-T+iWCeAOoEAJpHqr6/pogHIv98g9p8Ctccysm/h962hG4ayX5OL2c0Ih4oYe+JuFndLXy/OASvwMlTPe76sIiw==}
'@oxc-parser/binding-linux-riscv64-gnu@0.155.0':
resolution: {integrity: sha512-7KCfOQm+Nz2N8trAXbQkal4TQ5756WVEmhm35y816YHvyFnEfVsICsiV5k0pEszNf/fRm4cm2i6i18SJ6/iCWg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [riscv64]
os: [linux]
libc: [glibc]
'@oxc-parser/binding-linux-riscv64-musl@0.156.0':
resolution: {integrity: sha512-wL55bI2kVKfwdxScbw60zVgzAqbQbmE5zpSPWPZoZ9RSG8egm6ITE/UWE5mDWlglxz1QElJCcUbpaJCtHD11BQ==}
'@oxc-parser/binding-linux-riscv64-musl@0.155.0':
resolution: {integrity: sha512-JSlhgoK+/g1TGJI5NuADx2+6syhxnQNLCWLXyO5QLFyetomcr/vIxSdiNlmyAv963YXUzCuwAwRG6npZ5xyJ1A==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [riscv64]
os: [linux]
libc: [musl]
'@oxc-parser/binding-linux-s390x-gnu@0.156.0':
resolution: {integrity: sha512-+D+JilhLqwrDLODYEl4qtovVwgxKALb23FkAWBiPvgmUWYgjCV83KKuwwxZJM8GCdKlNA1vt3iKtow8HUFjXtg==}
'@oxc-parser/binding-linux-s390x-gnu@0.155.0':
resolution: {integrity: sha512-WFIX+dPokWp64mi434Md3U3lJaTwNxAphvGjpltoyQjGUsdXavOIRrnp9dOS34Hd75HOAwDxAI+YwWOwqmJbtg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [s390x]
os: [linux]
libc: [glibc]
'@oxc-parser/binding-linux-x64-gnu@0.156.0':
resolution: {integrity: sha512-jRfwpN4xKrsEpC+SgrUPY5k0mINYZn7aLrt22I3uQFoumiSgHgsLYgS9f84ntbkvSydH4HiwGuDa2b1XCHaJzw==}
'@oxc-parser/binding-linux-x64-gnu@0.155.0':
resolution: {integrity: sha512-g6xSDC/JpbnVOz5uafMGyK3txBVRFMQTx8opv/yHXGxqV3ZMVl3bf7W8XrSnF68dmy3gM4dgReNryuE53+WkeQ==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [linux]
libc: [glibc]
'@oxc-parser/binding-linux-x64-musl@0.156.0':
resolution: {integrity: sha512-P/ajnypgLmxmuRRyCIZcp2o4lOwmCaXYH5+eqDTcCW+MCTI+csKSw/Zc6GB67jZoVa4ey3q1jXEt7S60adBEMQ==}
'@oxc-parser/binding-linux-x64-musl@0.155.0':
resolution: {integrity: sha512-6/4xlxKlZJWrQ0uwDFPc0H9+xLu7068CKhX3vIDW3SbvP/lVgnVuT5v6dyugeWskWpuxqF/WJ4WKwhxjU3pG2w==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [linux]
libc: [musl]
'@oxc-parser/binding-openharmony-arm64@0.156.0':
resolution: {integrity: sha512-WSN6rQZZc9KqgZ4lMfjVDvqKhVOCjey/YEZIPisGXmwBqwgWOzru207dyiH50LHcf1n9LO2oceGk/id6RL9v0g==}
'@oxc-parser/binding-openharmony-arm64@0.155.0':
resolution: {integrity: sha512-tltklL0J0XjDxIRTBXWOBhvc2mitcmES45pIxhwDWfxRyqz7Vkeu0NekTZEIxGE4f/lXgq3vZcjjffteQOVorg==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [openharmony]
'@oxc-parser/binding-win32-arm64-msvc@0.156.0':
resolution: {integrity: sha512-l21Tz6tjraGBC3JefVeJZ9pojD0fCiB62PydAv+i9nrqJX7z/pDmyDNYLamDr/PRcQ4UQbFwkSnz7NKBB9UMLw==}
'@oxc-parser/binding-win32-arm64-msvc@0.155.0':
resolution: {integrity: sha512-alAb9TzjatUEsOeoncAziUnfdTDxfyswhalFZ9sC6plUgATIUx2NIZ0+bMn6aJ28AduS1OpG/OAisr/YISn4Ig==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [arm64]
os: [win32]
'@oxc-parser/binding-win32-ia32-msvc@0.156.0':
resolution: {integrity: sha512-CUq0ZFl/RODqPiIgfNNSamkpTj5x8AjBTkR/y1DNVIQiTGnmWqjHcn3o08ZW3q/LgkI4g9G9g6UirmmQFvuOZw==}
'@oxc-parser/binding-win32-ia32-msvc@0.155.0':
resolution: {integrity: sha512-yc5cbSfcGmRv/KpxDFuyk8adEBaWd/9HilWvBbQ4bFbus1V2PUh2mGB2Cfq9rqZTqLeiMT8x0skV+LKp9hOMgQ==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [ia32]
os: [win32]
'@oxc-parser/binding-win32-x64-msvc@0.156.0':
resolution: {integrity: sha512-dcpx5Y1x2v/cs7U/q3SZMvmxfyXjVvqC86jMuw2ZZUbHDd7W2cW7uSMQfg3GLVaE68Su3H9xd/Pc4v6QNyeSRg==}
'@oxc-parser/binding-win32-x64-msvc@0.155.0':
resolution: {integrity: sha512-8heq6jGq+rfpTDRDjoQiBHw0maQZf3IXkS99pdHQZPoTL5kyF5qyPS0RidUlSdnWDIqxXb5nux7GBD9cT+imUw==}
engines: {node: ^20.19.0 || >=22.12.0}
cpu: [x64]
os: [win32]
'@oxc-project/types@0.155.0':
resolution: {integrity: sha512-SeE8JPwW1xs1tHeNycjUtUBdhorRa8o4jlvjwk49R7/Z291i+4DQa7JJIgOm/TaYQZx+QrPQbVJ/9c8dMIZN8Q==}
'@oxc-project/types@0.156.0':
resolution: {integrity: sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw==}
@@ -3855,8 +3858,8 @@ packages:
keyv@5.6.0:
resolution: {integrity: sha512-CYDD3SOtsHtyXeEORYRx2qBtpDJFjRTGXUtmNEMGyzYOKj1TE3tycdlho7kA1Ufx9OYWZzg52QFBGALTirzDSw==}
knip@6.44.2:
resolution: {integrity: sha512-6URO7pnqtOnyvSsXfW6+8C9j1lfcicxUCysXO0RgMtHTZ96HqCXh29op8iabeQW5JeIc8dJWwzSdJVWDokeScQ==}
knip@6.44.1:
resolution: {integrity: sha512-Hbd8nvkIsNgFfXgC7Jsb5LHv7jj6VwA3tmfHd53XPX2z9Vc9RnAZqV0BIiP4OrtYqKwCoLseFHQZerb1bNlbSw==}
engines: {node: ^20.19.0 || >=22.12.0}
hasBin: true
@@ -4227,8 +4230,8 @@ packages:
resolution: {integrity: sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==}
engines: {node: '>= 0.8.0'}
oxc-parser@0.156.0:
resolution: {integrity: sha512-7JhjgOfZjrIFJH5TlHrpRua864Si5GvwrPr5+eIRCY2sszhKXo6pyhP0HQKOGTtfO4UowwZ72XTGba0+lZphOQ==}
oxc-parser@0.155.0:
resolution: {integrity: sha512-C/ReSf1JUFukK/zvk6jhcNibSssvas5+ktIzK7fbKVd3CedWe59C3QwHEOrEZj/4Rt9+xg0Jeis/Jv1F/KM1mw==}
engines: {node: ^20.19.0 || >=22.12.0}
oxc-resolver@11.24.2:
@@ -5064,8 +5067,8 @@ packages:
resolution: {integrity: sha512-42AtmgqjV+X1VpdOfyTGOYRi0/zsoLqtXQckTmqTeybT+BDIbM/Guxo7x3pE2vtpr1ok6xRqM9OpBe+Jyoqyww==}
engines: {node: '>=18'}
ws@8.22.2:
resolution: {integrity: sha512-/rEZ2ejown2N5gxVTHUu9bVVC7ttu0/Tgzf5hbTOixR3Fs7mbbXgn2DbdbcKgJOmpQMtrIUWivtYuVMnp/W/yA==}
ws@8.22.1:
resolution: {integrity: sha512-oyL6OPYme/CmiFvNuGzeoxCJ4nOrZE2O1FwM9MWM1AsGri6nLXB2pg+lNA8aLeXMSav0J6eIVS1j6vUPzUtK9g==}
engines: {node: '>=10.0.0'}
peerDependencies:
bufferutil: ^4.0.1
@@ -6483,63 +6486,65 @@ snapshots:
dependencies:
'@octokit/openapi-types': 29.0.1
'@oxc-parser/binding-android-arm-eabi@0.156.0':
'@oxc-parser/binding-android-arm-eabi@0.155.0':
optional: true
'@oxc-parser/binding-android-arm64@0.156.0':
'@oxc-parser/binding-android-arm64@0.155.0':
optional: true
'@oxc-parser/binding-darwin-arm64@0.156.0':
'@oxc-parser/binding-darwin-arm64@0.155.0':
optional: true
'@oxc-parser/binding-darwin-x64@0.156.0':
'@oxc-parser/binding-darwin-x64@0.155.0':
optional: true
'@oxc-parser/binding-freebsd-x64@0.156.0':
'@oxc-parser/binding-freebsd-x64@0.155.0':
optional: true
'@oxc-parser/binding-linux-arm-gnueabihf@0.156.0':
'@oxc-parser/binding-linux-arm-gnueabihf@0.155.0':
optional: true
'@oxc-parser/binding-linux-arm-musleabihf@0.156.0':
'@oxc-parser/binding-linux-arm-musleabihf@0.155.0':
optional: true
'@oxc-parser/binding-linux-arm64-gnu@0.156.0':
'@oxc-parser/binding-linux-arm64-gnu@0.155.0':
optional: true
'@oxc-parser/binding-linux-arm64-musl@0.156.0':
'@oxc-parser/binding-linux-arm64-musl@0.155.0':
optional: true
'@oxc-parser/binding-linux-ppc64-gnu@0.156.0':
'@oxc-parser/binding-linux-ppc64-gnu@0.155.0':
optional: true
'@oxc-parser/binding-linux-riscv64-gnu@0.156.0':
'@oxc-parser/binding-linux-riscv64-gnu@0.155.0':
optional: true
'@oxc-parser/binding-linux-riscv64-musl@0.156.0':
'@oxc-parser/binding-linux-riscv64-musl@0.155.0':
optional: true
'@oxc-parser/binding-linux-s390x-gnu@0.156.0':
'@oxc-parser/binding-linux-s390x-gnu@0.155.0':
optional: true
'@oxc-parser/binding-linux-x64-gnu@0.156.0':
'@oxc-parser/binding-linux-x64-gnu@0.155.0':
optional: true
'@oxc-parser/binding-linux-x64-musl@0.156.0':
'@oxc-parser/binding-linux-x64-musl@0.155.0':
optional: true
'@oxc-parser/binding-openharmony-arm64@0.156.0':
'@oxc-parser/binding-openharmony-arm64@0.155.0':
optional: true
'@oxc-parser/binding-win32-arm64-msvc@0.156.0':
'@oxc-parser/binding-win32-arm64-msvc@0.155.0':
optional: true
'@oxc-parser/binding-win32-ia32-msvc@0.156.0':
'@oxc-parser/binding-win32-ia32-msvc@0.155.0':
optional: true
'@oxc-parser/binding-win32-x64-msvc@0.156.0':
'@oxc-parser/binding-win32-x64-msvc@0.155.0':
optional: true
'@oxc-project/types@0.155.0': {}
'@oxc-project/types@0.156.0': {}
'@oxc-resolver/binding-android-arm-eabi@11.24.2':
@@ -8685,12 +8690,12 @@ snapshots:
dependencies:
'@keyv/serialize': 1.1.1
knip@6.44.2:
knip@6.44.1:
dependencies:
formatly: 0.11.4
get-tsconfig: 4.14.3
jiti: 2.7.0
oxc-parser: 0.156.0
oxc-parser: 0.155.0
oxc-resolver: 11.24.2
picomatch: 4.0.7
smol-toml: 1.9.1
@@ -9171,29 +9176,29 @@ snapshots:
type-check: 0.4.0
word-wrap: 1.2.5
oxc-parser@0.156.0:
oxc-parser@0.155.0:
dependencies:
'@oxc-project/types': 0.156.0
'@oxc-project/types': 0.155.0
optionalDependencies:
'@oxc-parser/binding-android-arm-eabi': 0.156.0
'@oxc-parser/binding-android-arm64': 0.156.0
'@oxc-parser/binding-darwin-arm64': 0.156.0
'@oxc-parser/binding-darwin-x64': 0.156.0
'@oxc-parser/binding-freebsd-x64': 0.156.0
'@oxc-parser/binding-linux-arm-gnueabihf': 0.156.0
'@oxc-parser/binding-linux-arm-musleabihf': 0.156.0
'@oxc-parser/binding-linux-arm64-gnu': 0.156.0
'@oxc-parser/binding-linux-arm64-musl': 0.156.0
'@oxc-parser/binding-linux-ppc64-gnu': 0.156.0
'@oxc-parser/binding-linux-riscv64-gnu': 0.156.0
'@oxc-parser/binding-linux-riscv64-musl': 0.156.0
'@oxc-parser/binding-linux-s390x-gnu': 0.156.0
'@oxc-parser/binding-linux-x64-gnu': 0.156.0
'@oxc-parser/binding-linux-x64-musl': 0.156.0
'@oxc-parser/binding-openharmony-arm64': 0.156.0
'@oxc-parser/binding-win32-arm64-msvc': 0.156.0
'@oxc-parser/binding-win32-ia32-msvc': 0.156.0
'@oxc-parser/binding-win32-x64-msvc': 0.156.0
'@oxc-parser/binding-android-arm-eabi': 0.155.0
'@oxc-parser/binding-android-arm64': 0.155.0
'@oxc-parser/binding-darwin-arm64': 0.155.0
'@oxc-parser/binding-darwin-x64': 0.155.0
'@oxc-parser/binding-freebsd-x64': 0.155.0
'@oxc-parser/binding-linux-arm-gnueabihf': 0.155.0
'@oxc-parser/binding-linux-arm-musleabihf': 0.155.0
'@oxc-parser/binding-linux-arm64-gnu': 0.155.0
'@oxc-parser/binding-linux-arm64-musl': 0.155.0
'@oxc-parser/binding-linux-ppc64-gnu': 0.155.0
'@oxc-parser/binding-linux-riscv64-gnu': 0.155.0
'@oxc-parser/binding-linux-riscv64-musl': 0.155.0
'@oxc-parser/binding-linux-s390x-gnu': 0.155.0
'@oxc-parser/binding-linux-x64-gnu': 0.155.0
'@oxc-parser/binding-linux-x64-musl': 0.155.0
'@oxc-parser/binding-openharmony-arm64': 0.155.0
'@oxc-parser/binding-win32-arm64-msvc': 0.155.0
'@oxc-parser/binding-win32-ia32-msvc': 0.155.0
'@oxc-parser/binding-win32-x64-msvc': 0.155.0
oxc-resolver@11.24.2:
optionalDependencies:
@@ -10002,7 +10007,7 @@ snapshots:
deepmerge-ts: 8.0.2
https-proxy-agent: 9.1.0(supports-color@7.2.0)
undici: 8.12.3
ws: 8.22.2
ws: 8.22.1
transitivePeerDependencies:
- bufferutil
- kerberos
@@ -10070,7 +10075,7 @@ snapshots:
string-width: 7.2.0
strip-ansi: 7.2.0
ws@8.22.2: {}
ws@8.22.1: {}
y18n@5.0.8: {}
+1 -1
View File
@@ -1,7 +1,7 @@
import { createHash } from 'node:crypto'
const reviewer = 'renovate-minor-review.lock.yml'
const agents = ['Copilot', 'copilot-swe-agent', 'copilot-swe-agent[bot]']
const agents = ['copilot-swe-agent', 'copilot-swe-agent[bot]']
const checks = {
'.github/workflows/frontend-check.yml': [
'Run Prettier check',
+5 -5
View File
@@ -58,13 +58,13 @@ smartstring = { workspace = true, features = ["serde"] }
socket2 = { workspace = true }
warp = { version = "0.4.3", features = ["server"] }
open = "5.4.5"
rfd = { version = "0.18.0", default-features = false, features = ["common-controls-v6", "xdg-portal"] }
rfd = { version = "0.17.2", default-features = false, features = ["common-controls-v6"] }
dirs = "7.0.0"
dunce = "1.0.5"
nanoid = "0.5"
chrono = { workspace = true }
boa_engine = "0.22.0"
http-body-util = "0.1.5"
http-body-util = "0.1.4"
percent-encoding = "2.3.2"
reqwest = { workspace = true }
sysproxy = { git = "https://github.com/clash-verge-rev/sysproxy-rs.git", branch = "main", features = [
@@ -77,8 +77,8 @@ tauri-plugin-dialog = "2.8.4"
tauri-plugin-fs = "2.7.1"
tauri-plugin-deep-link = "2.6.3"
tauri-plugin-window-state = "2.5.0"
zip = "9.4.2"
flate2 = "1.1.11"
zip = "9.3.0"
flate2 = "1.1.10"
reqwest_dav = "0.3.3"
aes-gcm = { version = "0.11.1" }
base64 = "0.23.1"
@@ -97,7 +97,7 @@ async-trait = "0.1.92"
clash_verge_service_ipc = { git = "https://github.com/clash-verge-rev/clash-verge-service-ipc.git", tag = "v2.7.7", version = "2.7.7", features = [
"client",
] }
arc-swap = "1.9.4"
arc-swap = "1.9.3"
tokio-rustls = "0.26.6"
rustls = { version = "0.23.46", features = ["ring"] }
webpki-roots = "1.0.11"
+69 -1
View File
@@ -77,6 +77,9 @@ Var VC_REDIST_URL
Var VC_REDIST_EXE
Var VC_RUNTIME_READY
Var VC_RUNTIME_NEEDED
Var ServiceExisted
Var ServiceStartType
Var ServiceWasRunning
Name "${PRODUCTNAME}"
BrandingText "${COPYRIGHT}"
@@ -466,6 +469,34 @@ FunctionEnd
{{#each language_files}}
!include "{{this}}"
{{/each}}
!ifdef LANG_ENGLISH
LangString serviceReinstallFailed ${LANG_ENGLISH} "The ${PRODUCTNAME} Service could not be reinstalled (code $0). Open ${PRODUCTNAME} and reinstall the Service to restore Service mode."
!endif
!ifdef LANG_SIMPCHINESE
LangString serviceReinstallFailed ${LANG_SIMPCHINESE} "${PRODUCTNAME} 服务重装失败(代码 $0)。请打开 ${PRODUCTNAME} 重新安装服务以恢复服务模式。"
!endif
!ifdef LANG_RUSSIAN
LangString serviceReinstallFailed ${LANG_RUSSIAN} "Не удалось переустановить службу ${PRODUCTNAME} (код $0). Откройте ${PRODUCTNAME} и переустановите службу, чтобы восстановить режим службы."
!endif
!macro RecordVergeService
StrCpy $ServiceExisted 0
StrCpy $ServiceStartType ""
StrCpy $ServiceWasRunning 1
SimpleSC::ExistsService "clash_verge_service"
Pop $0
${If} $0 == 0
StrCpy $ServiceExisted 1
SimpleSC::GetServiceStartType "clash_verge_service"
Pop $0
Pop $1
${IfThen} $0 == 0 ${|} StrCpy $ServiceStartType $1 ${|}
SimpleSC::ServiceIsRunning "clash_verge_service"
Pop $0
Pop $1
${IfThen} $0 == 0 ${|} StrCpy $ServiceWasRunning $1 ${|}
${EndIf}
!macroend
Function .onInit
${GetOptions} $CMDLINE "/P" $PassiveMode
@@ -483,6 +514,9 @@ Function .onInit
StrCpy $UpdateMode 1
${EndIf}
; Recorded before the reinstall page can run the previous uninstaller, which removes the Service.
!insertmacro RecordVergeService
!if "${DISPLAYLANGUAGESELECTOR}" == "true"
; Auto-update forwards the app's UI language as `/LANG=<NSIS-lang-id>` so
; the installer uses it directly and skips the interactive language
@@ -663,6 +697,36 @@ FunctionEnd
${EndIf}
!macroend
; Reinstalls the Service with the bundled cores, then restores the recorded start type and stopped state.
!macro ReinstallVergeService
StrCpy $R0 '"$INSTDIR\resources\clash-verge-service-install.exe" --install-service'
!ifdef MIHOMO_SHA256
StrCpy $R0 '$R0 --install-core "$INSTDIR\verge-mihomo.exe" --sha256 "${MIHOMO_SHA256}"'
!endif
!ifdef MIHOMO_ALPHA_SHA256
StrCpy $R0 '$R0 --install-core "$INSTDIR\verge-mihomo-alpha.exe" --sha256 "${MIHOMO_ALPHA_SHA256}"'
!endif
DetailPrint "Reinstalling ${PRODUCTNAME} Service..."
nsExec::ExecToLog $R0
Pop $0
${If} $0 == 0
${AndIf} $ServiceStartType != ""
${AndIf} $ServiceStartType != 2
SimpleSC::SetServiceStartType "clash_verge_service" $ServiceStartType
Pop $0
${EndIf}
${If} $0 == 0
${AndIf} $ServiceWasRunning == 0
SimpleSC::StopService "clash_verge_service" 1 30
Pop $0
${EndIf}
${If} $0 != 0
DetailPrint "Reinstalling ${PRODUCTNAME} Service failed ($0)"
MessageBox MB_OK|MB_ICONEXCLAMATION "$(serviceReinstallFailed)" /SD IDOK
SetErrorLevel 2
${EndIf}
!macroend
!macro RemoveVergeService
; Check if the service exists
SimpleSC::ExistsService "clash_verge_service"
@@ -985,7 +1049,11 @@ Section Install
${IfThen} $0 != 0 ${|} DetailPrint "Staging verge-mihomo-alpha returned $0" ${|}
!endif
!insertmacro StartVergeService
${If} $ServiceExisted = 1
!insertmacro ReinstallVergeService
${Else}
!insertmacro StartVergeService
${EndIf}
; Create file associations
{{#each file_associations as |association| ~}}
+57 -3
View File
@@ -5,10 +5,16 @@ use crate::{
core::{
handle::Handle,
proxy_view::{GroupScope, ProxyViewBuilder, ProxyViewInput, ProxyViewV1},
tray::Tray,
},
process::AsyncHandler,
};
use clash_verge_logging::{Type, logging};
use serde_yaml_ng::Mapping;
use std::collections::{BTreeMap, HashSet};
use std::{
collections::{BTreeMap, HashSet},
sync::atomic::{AtomicBool, Ordering},
};
/// Merges one selection pair into fresh backend state to avoid stale-list overwrites.
#[tauri::command]
@@ -21,12 +27,15 @@ pub async fn record_selected_node(group_name: String, node: String) -> CmdResult
#[tauri::command]
#[specta::specta]
pub async fn switch_proxy_node(group_name: String, proxy_name: String, unfix: bool) -> CmdResult<()> {
crate::feat::switch_proxy_node(&group_name, &proxy_name, unfix)
pub async fn forget_selected_node(group_name: String) -> CmdResult<()> {
crate::config::profiles::forget_selected_node(&group_name)
.await
.stringify_err()
}
static TRAY_SYNC_RUNNING: AtomicBool = AtomicBool::new(false);
static TRAY_SYNC_PENDING: AtomicBool = AtomicBool::new(false);
fn runtime_group_order(config: Option<&Mapping>) -> Vec<String> {
let mut seen = HashSet::new();
@@ -115,3 +124,48 @@ pub async fn get_proxy_view() -> CmdResult<ProxyViewV1> {
providers: providers.ok(),
}))
}
#[tauri::command]
#[specta::specta]
pub async fn sync_tray_proxy_selection() -> CmdResult<()> {
if TRAY_SYNC_RUNNING
.compare_exchange(false, true, Ordering::AcqRel, Ordering::Acquire)
.is_ok()
{
AsyncHandler::spawn(move || async move {
run_tray_sync_loop().await;
});
} else {
TRAY_SYNC_PENDING.store(true, Ordering::Release);
}
Ok(())
}
async fn run_tray_sync_loop() {
// Permanent watcher: keeps syncing until a pass finds no pending sync request.
loop {
match Tray::global().update_menu().await {
Ok(_) => {
logging!(debug, Type::Cmd, "Tray proxy selection synced successfully");
}
Err(e) => {
logging!(error, Type::Cmd, "Failed to sync tray proxy selection: {e:#}");
}
}
if !TRAY_SYNC_PENDING.swap(false, Ordering::AcqRel) {
TRAY_SYNC_RUNNING.store(false, Ordering::Release);
if TRAY_SYNC_PENDING.swap(false, Ordering::AcqRel)
&& TRAY_SYNC_RUNNING
.compare_exchange(false, true, Ordering::AcqRel, Ordering::Acquire)
.is_ok()
{
continue;
}
break;
}
}
}
+1 -3
View File
@@ -1000,9 +1000,7 @@ fn on_menu_event(_: &AppHandle, event: MenuEvent) {
Some((g, p)) => (g, p),
None => return,
};
if let Err(err) = feat::switch_proxy_node(group_name, proxy_name, false).await {
logging!(error, Type::Tray, "Failed to switch proxy: {err:#}");
}
feat::switch_proxy_node(group_name, proxy_name).await;
}
_ => {
logging!(debug, Type::Tray, "Unhandled tray menu event: {:?}", event.id);
+24 -73
View File
@@ -4,7 +4,6 @@ use crate::{
cmd,
config::{Config, PrfItem, PrfOption, profiles::profiles_update_item_safe},
core::{CoreManager, handle, tray, validate::ValidationOutcome},
process::AsyncHandler,
utils::help::{mask_err, mask_url},
};
use anyhow::{Result, bail};
@@ -22,85 +21,37 @@ pub async fn toggle_proxy_profile(profile_index: String) {
}
}
pub async fn switch_proxy_node(group_name: &str, proxy_name: &str, unfix: bool) -> Result<()> {
let mihomo = handle::Handle::mihomo();
let previous_proxy = if Config::verge().await.data_arc().auto_close_connection.unwrap_or(false) {
match mihomo.get_proxy_by_name(group_name).await {
Ok(group) => group.now.filter(|name| !name.is_empty()),
Err(err) => {
logging!(
warn,
Type::Core,
"Failed to read previous proxy selection for {group_name}: {err}"
);
None
}
}
} else {
None
};
if unfix {
mihomo.unfixed_proxy(group_name).await?;
} else {
mihomo.select_node_for_group(group_name, proxy_name).await?;
}
let save_result = if unfix {
crate::config::profiles::forget_selected_node(group_name).await
} else {
crate::config::profiles::record_selected_node(group_name, proxy_name).await
};
// The core selection is already applied; persistence failure must not report it as failed.
if let Err(error) = save_result {
/// Tell the profile which node this group is on now.
///
/// The core is already switched by the time this runs, so failing to record is not a reason to
/// report the switch as failed — but it is worth a log line, because what the profile holds is
/// what gets re-applied the next time a core starts.
async fn record_switched_node(group_name: &str, proxy_name: &str) {
if let Err(error) = crate::config::profiles::record_selected_node(group_name, proxy_name).await {
logging!(
warn,
Type::Config,
"Failed to persist proxy selection for {group_name}: {error:#}"
"切换代理成功但未能记录到配置: {} -> {}, 错误: {error:#}",
group_name,
proxy_name
);
}
announce(Refresh::Proxies);
}
if let Some(previous_proxy) = previous_proxy {
AsyncHandler::spawn(move || async move {
let connections = match mihomo.get_connections().await {
Ok(connections) => connections,
Err(err) => {
logging!(
warn,
Type::Core,
"Failed to read connections after switching proxy: {err}"
);
return;
}
};
futures::future::join_all(
connections
.connections
.unwrap_or_default()
.into_iter()
.filter(|connection| connection.chains.contains(&previous_proxy))
.map(|connection| async move {
if let Err(err) = mihomo.close_connection(&connection.id).await {
logging!(
warn,
Type::Core,
"Failed to close connection {} after switching proxy: {err}",
connection.id
);
}
}),
)
.await;
});
pub async fn switch_proxy_node(group_name: &str, proxy_name: &str) {
match handle::Handle::mihomo()
.select_node_for_group(group_name, proxy_name)
.await
{
Ok(_) => {
record_switched_node(group_name, proxy_name).await;
announce(Refresh::Proxies);
let _ = tray::Tray::global().update_menu().await;
}
Err(err) => {
logging!(error, Type::Tray, "切换代理失败: {err:?}");
}
}
if let Err(err) = tray::Tray::global().update_menu().await {
logging!(
warn,
Type::Tray,
"Failed to refresh tray after switching proxy: {err:#}"
);
}
Ok(())
}
async fn should_update_profile(uid: &String, ignore_auto_update: bool) -> Result<Option<(String, Option<PrfOption>)>> {
+2 -1
View File
@@ -45,8 +45,9 @@ pub fn builder() -> tauri_specta::Builder<tauri::Wry> {
cmd::update_proxy_chain_config_in_runtime,
cmd::invoke_uwp_tool,
cmd::copy_clash_env,
cmd::sync_tray_proxy_selection,
cmd::record_selected_node,
cmd::switch_proxy_node,
cmd::forget_selected_node,
cmd::save_dns_config,
cmd::apply_dns_config,
cmd::set_dns_override,
+5 -1
View File
@@ -606,6 +606,9 @@ export const CurrentProxyCard = () => {
)
const { select } = useProxySelection({
onSuccess: () => {
refreshProxy()
},
onError: (error) => {
console.error('代理切换失败', error)
refreshProxy()
@@ -752,9 +755,10 @@ export const CurrentProxyCard = () => {
if (!selectedGroup || !option || !isInteractableMember(option.member)) {
return
}
const previousProxy = selectedGroup.now
const nextName = option.member.ref.name
// The profile selection is the durable source across core restarts and run modes.
select(selectedGroup.name, nextName, selectedGroup.fixed!)
select(selectedGroup.name, nextName, previousProxy!, selectedGroup.fixed!)
},
[isDirectMode, select, selectedGroup, unsortedProxyOptions],
)
+5 -2
View File
@@ -470,6 +470,9 @@ function NormalProxyGroups(props: { mode: string }) {
}, [handleScroll])
const { select } = useProxySelection({
onSuccess: () => {
onProxies()
},
onError: (error) => {
console.error('代理切换失败', error)
onProxies()
@@ -484,12 +487,12 @@ function NormalProxyGroups(props: { mode: string }) {
if (group.name === globalGroupName) {
pendingRevealRef.current =
member.kind === 'group' ? member.ref.name : null
// The backend selection event refreshes the view.
// The selection refetches the view, so skip onHeadState's refetch.
if (member.kind === 'group') {
setHeadState(member.ref.name, { open: true })
}
}
select(group.name, member.ref.name, group.fixed!)
select(group.name, member.ref.name, group.now!, group.fixed!)
},
[globalGroupName, select, setHeadState],
)
+1 -7
View File
@@ -209,13 +209,7 @@ export const useRenderList = (
const renderGroups = useMemo(() => {
if (!proxyView) return []
// A profile whose only group is GLOBAL (mihomo then skips its built-in one)
// or that has no proxy-groups has nothing else to show in rule mode.
if (mode === 'rule') {
return proxyView.groups.length || !proxyView.global
? proxyView.groups
: [proxyView.global]
}
if (mode === 'rule') return proxyView.groups
const { global } = proxyView
if (!global) return []
const current = findCurrentGroupMember(proxyView, global)?.member
+29 -13
View File
@@ -1,35 +1,51 @@
import { selectNodeForGroup } from 'tauri-plugin-mihomo-api'
import { expect, it, vi } from 'vitest'
import { switchProxyNode } from '@/services/cmds'
import { useProxySelection } from './use-proxy-selection'
const record = vi.hoisted(() => vi.fn())
vi.mock('react', () => ({
useCallback: (callback: unknown) => callback,
useRef: (current: unknown) => ({ current }),
}))
vi.mock('@/services/cmds', () => ({ switchProxyNode: vi.fn() }))
vi.mock('@/hooks/use-record-selection', () => ({
useRecordSelection: () => record,
useForgetSelection: () => vi.fn(),
}))
vi.mock('@/hooks/use-verge', () => ({ useVerge: () => ({ verge: {} }) }))
vi.mock('tauri-plugin-mihomo-api', () => ({
selectNodeForGroup: vi.fn(),
unfixedProxy: vi.fn(),
}))
vi.mock('@/services/cmds', () => ({ syncTrayProxySelection: vi.fn() }))
vi.mock('@/services/notice-service', () => ({ showNotice: { error: vi.fn() } }))
vi.mock('@/services/query-client', () => ({ revalidateQueries: vi.fn() }))
it('requests independent group selections while another group is pending', async () => {
it('applies and records independent group selections while another group is pending', async () => {
let finishFirst!: () => void
vi.mocked(switchProxyNode)
vi.mocked(selectNodeForGroup)
.mockImplementationOnce(
() =>
new Promise((resolve) => {
finishFirst = () => resolve(null)
finishFirst = resolve
}),
)
.mockResolvedValueOnce(null)
const first = useProxySelection()
const second = useProxySelection()
.mockResolvedValueOnce(undefined)
const firstSuccess = vi.fn()
const secondSuccess = vi.fn()
const first = useProxySelection({ onSuccess: firstSuccess })
const second = useProxySelection({ onSuccess: secondSuccess })
first.select('Group A', 'Node A')
second.select('Group B', 'Node B', 'Node B')
second.select('Group B', 'Node B')
await vi.waitFor(() =>
expect(switchProxyNode).toHaveBeenCalledWith('Group B', 'Node B', true),
expect(record).toHaveBeenCalledWith('Group B', 'Node B'),
)
expect(switchProxyNode).toHaveBeenCalledWith('Group A', 'Node A', false)
expect(switchProxyNode).toHaveBeenCalledTimes(2)
expect(selectNodeForGroup).toHaveBeenCalledTimes(2)
expect(firstSuccess).not.toHaveBeenCalled()
expect(secondSuccess).toHaveBeenCalledOnce()
finishFirst()
await vi.waitFor(() =>
expect(record).toHaveBeenCalledWith('Group A', 'Node A'),
)
expect(firstSuccess).toHaveBeenCalledOnce()
})
+96 -8
View File
@@ -1,44 +1,132 @@
import { useCallback } from 'react'
import {
closeConnection,
getConnections,
selectNodeForGroup,
unfixedProxy,
} from 'tauri-plugin-mihomo-api'
import { switchProxyNode } from '@/services/cmds'
import {
useForgetSelection,
useRecordSelection,
} from '@/hooks/use-record-selection'
import { useVerge } from '@/hooks/use-verge'
import { syncTrayProxySelection } from '@/services/cmds'
import { mutate } from '@/services/mutate'
import { debugLog } from '@/utils/debug'
// 缓存连接清理
const cleanupConnections = async (previousProxy: string) => {
try {
const { connections } = await getConnections()
const cleanupPromises = (connections ?? [])
.filter((conn) => conn.chains.includes(previousProxy))
.map((conn) => closeConnection(conn.id))
if (cleanupPromises.length > 0) {
await Promise.allSettled(cleanupPromises)
debugLog(`[ProxySelection] 清理了 ${cleanupPromises.length} 个连接`)
}
} catch (error) {
console.warn('[ProxySelection] 连接清理失败:', error)
}
}
interface ProxySelectionOptions {
onSuccess?: () => void
onError?: (error: any) => void
}
interface ProxyChangeRequest {
groupName: string
proxyName: string
previousProxy?: string
fixed?: string
}
// 代理选择 Hook
export const useProxySelection = (options: ProxySelectionOptions = {}) => {
const { onError } = options
const recordSelection = useRecordSelection()
const forgetSelection = useForgetSelection()
const { verge } = useVerge()
const { onSuccess, onError } = options
const autoCloseConnection = verge?.auto_close_connection ?? false
// 切换节点
const syncTraySelection = useCallback(() => {
mutate(() => syncTrayProxySelection(), {
id: 'sync-tray-selection',
errorNotice: false,
}).catch((error) => {
console.error('[ProxySelection] 托盘状态同步失败:', error)
})
}, [])
const executeChange = useCallback(
async ({ groupName, proxyName, fixed }: ProxyChangeRequest) => {
async (request: ProxyChangeRequest) => {
const { groupName, proxyName, previousProxy, fixed } = request
const isFixedProxy = fixed === proxyName
if (isFixedProxy) {
debugLog(`[ProxySelection] 代理取消固定: ${groupName} -> ${proxyName}`)
} else {
debugLog(`[ProxySelection] 代理切换: ${groupName} -> ${proxyName}`)
}
try {
await mutate(
() => switchProxyNode(groupName, proxyName, fixed === proxyName),
const result = await mutate(
() =>
isFixedProxy
? unfixedProxy(groupName)
: selectNodeForGroup(groupName, proxyName),
{ id: `select-proxy-node:${groupName}`, errorNotice: false },
)
if (!result.ok) return
onSuccess?.()
syncTraySelection()
if (isFixedProxy) {
await forgetSelection(groupName)
debugLog(`[ProxySelection] 代理和状态同步完成: ${groupName}`)
} else {
await recordSelection(groupName, proxyName)
debugLog(
`[ProxySelection] 代理和状态同步完成: ${groupName} -> ${proxyName}`,
)
}
if (autoCloseConnection && previousProxy) {
void cleanupConnections(previousProxy)
}
} catch (error) {
console.error(
`[ProxySelection] Failed to switch proxy: ${groupName} -> ${proxyName}`,
`[ProxySelection] 代理切换失败: ${groupName} -> ${proxyName}`,
error,
)
onError?.(error)
}
},
[onError],
[
autoCloseConnection,
forgetSelection,
onError,
onSuccess,
recordSelection,
syncTraySelection,
],
)
const select = useCallback(
(groupName: string, proxyName: string, fixed?: string) => {
(
groupName: string,
proxyName: string,
previousProxy?: string,
fixed?: string,
) => {
void executeChange({
groupName,
proxyName,
previousProxy,
fixed,
})
},
+14 -1
View File
@@ -1,6 +1,6 @@
import { useCallback } from 'react'
import { recordSelectedNode } from '@/services/cmds'
import { forgetSelectedNode, recordSelectedNode } from '@/services/cmds'
import { mutate } from '@/services/mutate'
/**
@@ -19,3 +19,16 @@ export const useRecordSelection = () => {
}
}, [])
}
export const useForgetSelection = () => {
return useCallback(async (groupName: string) => {
try {
await mutate(() => forgetSelectedNode(groupName), {
id: `persist-selected-node:${groupName}`,
errorNotice: false,
})
} catch (error) {
console.error('[Selection] 清除代理选择失败:', error)
}
}, [])
}
+4 -2
View File
@@ -78,11 +78,13 @@ export const commands = {
}),
invokeUwpTool: () => __TAURI_INVOKE<null>('invoke_uwp_tool'),
copyClashEnv: () => __TAURI_INVOKE<null>('copy_clash_env'),
syncTrayProxySelection: () =>
__TAURI_INVOKE<null>('sync_tray_proxy_selection'),
/** Merges one selection pair into fresh backend state to avoid stale-list overwrites. */
recordSelectedNode: (groupName: string, node: string) =>
__TAURI_INVOKE<null>('record_selected_node', { groupName, node }),
switchProxyNode: (groupName: string, proxyName: string, unfix: boolean) =>
__TAURI_INVOKE<null>('switch_proxy_node', { groupName, proxyName, unfix }),
forgetSelectedNode: (groupName: string) =>
__TAURI_INVOKE<null>('forget_selected_node', { groupName }),
saveDnsConfig: (dnsConfig: YamlMapping) =>
__TAURI_INVOKE<null>('save_dns_config', { dnsConfig }),
applyDnsConfig: (apply: boolean) =>
+12 -2
View File
@@ -29,11 +29,14 @@ export interface BusHandlerDeps {
/**
* Pure per-event handler table for the bus. Handlers may trigger documented
* side effects (SWR revalidation, notice toasts) but write store state only
* through dispatched pure actions. Created exactly once per bus mount.
* through dispatched pure actions. Created exactly once per bus mount; the
* throttles below live in the returned closure, mirroring the previous
* scattered listeners.
*/
export const createEventBus = (deps: BusHandlerDeps) => {
let lastProfileId: string | null = null
let lastProfileChangeTime = 0
let lastProxyRefreshTime = 0
const refreshThrottle = 800
const handleProfileChanged = (newProfileId: string) => {
@@ -49,6 +52,13 @@ export const createEventBus = (deps: BusHandlerDeps) => {
deps.revalidateKeys(['getProfiles'])
}
const handleRefreshProxyConfig = () => {
const now = Date.now()
if (now - lastProxyRefreshTime <= refreshThrottle) return
lastProxyRefreshTime = now
deps.revalidateKeys(['getProxyView'])
}
const handlers: BusHandlers = {
'verge://refresh-clash-config': () =>
deps.revalidateKeys([
@@ -64,7 +74,7 @@ export const createEventBus = (deps: BusHandlerDeps) => {
'verge://refresh-verge-config': () =>
deps.revalidateKeys(['getVergeConfig', 'getSystemProxy', 'getAutoProxy']),
'verge://refresh-profiles': () => deps.revalidateKeys(['getProfiles']),
'verge://refresh-proxy-config': () => deps.revalidateKeys(['getProxyView']),
'verge://refresh-proxy-config': handleRefreshProxyConfig,
'verge://notice-message': (payload) => deps.handleNotice(payload),
'profile-changed': handleProfileChanged,
'verge://timer-updated': (uid) =>
+6 -6
View File
@@ -152,17 +152,17 @@ export async function patchClashMode(payload: string) {
return commands.patchClashMode(payload)
}
export async function syncTrayProxySelection() {
return commands.syncTrayProxySelection()
}
/** Sends one selection pair so the backend can merge against current profile state. */
export async function recordSelectedNode(groupName: string, node: string) {
return commands.recordSelectedNode(groupName, node)
}
export async function switchProxyNode(
groupName: string,
proxyName: string,
unfix: boolean,
) {
return commands.switchProxyNode(groupName, proxyName, unfix)
export async function forgetSelectedNode(groupName: string) {
return commands.forgetSelectedNode(groupName)
}
export async function getProxyView(): Promise<ProxyViewV1> {