Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
444f2172fa | ||
|
|
77a77c0ea7 | ||
|
|
dbf380a0d1 | ||
|
|
ade34f5217 | ||
|
|
e89607799a | ||
|
|
d05d8d6a9e | ||
|
|
b6aa50d3dc | ||
|
|
9df361935f | ||
|
|
98b8a122b6 | ||
|
|
c7232522ee | ||
|
|
5280f1d745 | ||
|
|
b52a081e7b | ||
|
|
f981a44861 | ||
|
|
d7c5ce0750 | ||
|
|
9ccc66ca1e | ||
|
|
8606af3616 | ||
|
|
f6e821ba6b | ||
|
|
e8dbcf819b | ||
|
|
bbe2ef4e8e | ||
|
|
dd15455031 | ||
|
|
12ac7bb338 | ||
|
|
46ef348f0d | ||
|
|
1a55cca8af | ||
|
|
81ee989f1f | ||
|
|
c9c06f8a3d | ||
|
|
72127979c3 | ||
|
|
1ad3ddef94 | ||
|
|
97ec5eabf7 | ||
|
|
e12e3a3f2d | ||
|
|
4ff625f23b | ||
|
|
e38dcd85ac | ||
|
|
0245baf1b6 | ||
|
|
10b55c043c | ||
|
|
457655b416 | ||
|
|
7e4506c860 | ||
|
|
794d376348 | ||
|
|
c60578f5b5 | ||
|
|
3a9a392a77 | ||
|
|
a13d4698be | ||
|
|
c046a1993e | ||
|
|
f709117cc4 | ||
|
|
30dd298fca | ||
|
|
0ff8bb8090 |
7
.github/workflows/ci.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: CI
|
name: Release CI
|
||||||
|
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ jobs:
|
|||||||
yarn run check
|
yarn run check
|
||||||
|
|
||||||
- name: Tauri build
|
- name: Tauri build
|
||||||
uses: tauri-apps/tauri-action@v0
|
uses: tauri-apps/tauri-action@b9ce5d7dc68082d21d30a60103b0ab8c5ddae3a1
|
||||||
# enable cache even though failed
|
# enable cache even though failed
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
env:
|
env:
|
||||||
@@ -63,7 +63,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
tagName: v__VERSION__
|
tagName: v__VERSION__
|
||||||
releaseName: "Clash Verge v__VERSION__"
|
releaseName: "Clash Verge v__VERSION__"
|
||||||
releaseBody: "Clash Verge now supports Windows and macos(intel)."
|
releaseBody: "Clash Verge now supports Windows and macos."
|
||||||
releaseDraft: false
|
releaseDraft: false
|
||||||
prerelease: true
|
prerelease: true
|
||||||
|
|
||||||
@@ -95,6 +95,5 @@ jobs:
|
|||||||
|
|
||||||
- name: Release update.json
|
- name: Release update.json
|
||||||
run: yarn run release
|
run: yarn run release
|
||||||
continue-on-error: true
|
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
10
README.md
@@ -11,19 +11,17 @@ A <a href="https://github.com/Dreamacro/clash">Clash</a> GUI based on <a href="h
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
Now it's no different from the others, even fewer. (WIP)
|
Now it's no different from the others, maybe fewer. (WIP)
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
You should install Rust and Nodejs. Then install tauri cli and packages.
|
You should install Rust and Nodejs, see [here](https://tauri.studio/docs/getting-started/prerequisites) for more details. Then install Nodejs packages.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
cargo install tauri-cli --git https://github.com/tauri-apps/tauri
|
|
||||||
|
|
||||||
yarn install
|
yarn install
|
||||||
```
|
```
|
||||||
|
|
||||||
Then download the clash binary... Or you can download it from [clash premium release](https://github.com/Dreamacro/clash/releases/tag/premium) and rename it according to [tauri config](https://tauri.studio/en/docs/api/config#tauri.bundle.externalBin).
|
Then download the clash binary... Or you can download it from [clash premium release](https://github.com/Dreamacro/clash/releases/tag/premium) and rename it according to [tauri config](https://tauri.studio/docs/api/config/#tauri.bundle.externalBin).
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
yarn run check
|
yarn run check
|
||||||
@@ -56,7 +54,7 @@ This is a learning project for Rust practice.
|
|||||||
|
|
||||||
## Contributions
|
## Contributions
|
||||||
|
|
||||||
PR welcome!
|
Issue and PR welcome!
|
||||||
|
|
||||||
## Acknowledgement
|
## Acknowledgement
|
||||||
|
|
||||||
|
|||||||
BIN
docs/demo1.png
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
BIN
docs/demo2.png
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 30 KiB |
BIN
docs/demo3.png
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 28 KiB |
BIN
docs/demo4.png
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 24 KiB |
BIN
docs/demo5.png
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 27 KiB |
BIN
docs/demo6.png
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 28 KiB |
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "clash-verge",
|
"name": "clash-verge",
|
||||||
"version": "0.0.15",
|
"version": "0.0.19",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "cargo tauri dev",
|
"dev": "tauri dev",
|
||||||
"build": "cargo tauri build",
|
"build": "tauri build",
|
||||||
"tauri": "tauri",
|
"tauri": "tauri",
|
||||||
"web:dev": "vite",
|
"web:dev": "vite",
|
||||||
"web:build": "tsc && vite build",
|
"web:build": "tsc && vite build",
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@actions/github": "^5.0.0",
|
"@actions/github": "^5.0.0",
|
||||||
"@tauri-apps/cli": "^1.0.0-rc.4",
|
"@tauri-apps/cli": "^1.0.0-rc.5",
|
||||||
"@types/fs-extra": "^9.0.13",
|
"@types/fs-extra": "^9.0.13",
|
||||||
"@types/js-cookie": "^3.0.1",
|
"@types/js-cookie": "^3.0.1",
|
||||||
"@types/react": "^17.0.0",
|
"@types/react": "^17.0.0",
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ async function resolveSidecar() {
|
|||||||
const sidecarFile = `clash-${host}${ext}`;
|
const sidecarFile = `clash-${host}${ext}`;
|
||||||
const sidecarPath = path.join(sidecarDir, sidecarFile);
|
const sidecarPath = path.join(sidecarDir, sidecarFile);
|
||||||
|
|
||||||
if (!(await fs.pathExists(sidecarDir))) await fs.mkdir(sidecarDir);
|
await fs.mkdirp(sidecarDir);
|
||||||
if (await fs.pathExists(sidecarPath)) return;
|
if (await fs.pathExists(sidecarPath)) return;
|
||||||
|
|
||||||
// download sidecar
|
// download sidecar
|
||||||
@@ -59,7 +59,7 @@ async function resolveSidecar() {
|
|||||||
const tempZip = path.join(tempDir, binInfo.zipfile);
|
const tempZip = path.join(tempDir, binInfo.zipfile);
|
||||||
const tempExe = path.join(tempDir, binInfo.exefile);
|
const tempExe = path.join(tempDir, binInfo.exefile);
|
||||||
|
|
||||||
if (!(await fs.pathExists(tempDir))) await fs.mkdir(tempDir);
|
await fs.mkdirp(tempDir);
|
||||||
if (!(await fs.pathExists(tempZip))) await downloadFile(binInfo.url, tempZip);
|
if (!(await fs.pathExists(tempZip))) await downloadFile(binInfo.url, tempZip);
|
||||||
|
|
||||||
if (binInfo.zip === "zip") {
|
if (binInfo.zip === "zip") {
|
||||||
@@ -96,8 +96,10 @@ async function resolveMmdb() {
|
|||||||
const url =
|
const url =
|
||||||
"https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb";
|
"https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb";
|
||||||
|
|
||||||
const resPath = path.join(cwd, "src-tauri", "resources", "Country.mmdb");
|
const resDir = path.join(cwd, "src-tauri", "resources");
|
||||||
|
const resPath = path.join(resDir, "Country.mmdb");
|
||||||
if (await fs.pathExists(resPath)) return;
|
if (await fs.pathExists(resPath)) return;
|
||||||
|
await fs.mkdirp(resDir);
|
||||||
await downloadFile(url, resPath);
|
await downloadFile(url, resPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,5 +120,5 @@ async function downloadFile(url, path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// main
|
/// main
|
||||||
resolveSidecar();
|
resolveSidecar().catch(console.error);
|
||||||
resolveMmdb();
|
resolveMmdb().catch(console.error);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { createRequire } from "module";
|
import fetch from "node-fetch";
|
||||||
import { getOctokit, context } from "@actions/github";
|
import { getOctokit, context } from "@actions/github";
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
const UPDATE_TAG_NAME = "updater";
|
||||||
|
const UPDATE_JSON_FILE = "update.json";
|
||||||
|
|
||||||
/// generate update.json
|
/// generate update.json
|
||||||
/// upload to update tag's release asset
|
/// upload to update tag's release asset
|
||||||
@@ -10,46 +11,85 @@ async function resolveRelease() {
|
|||||||
throw new Error("GITHUB_TOKEN is required");
|
throw new Error("GITHUB_TOKEN is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
const packageJson = require("../package.json");
|
const options = { owner: context.repo.owner, repo: context.repo.repo };
|
||||||
|
const github = getOctokit(process.env.GITHUB_TOKEN);
|
||||||
|
|
||||||
|
const { data: tags } = await github.rest.repos.listTags({
|
||||||
|
...options,
|
||||||
|
per_page: 10,
|
||||||
|
page: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
// get the latest publish tag
|
||||||
|
const tag = tags.find((t) => t.name.startsWith("v"));
|
||||||
|
|
||||||
|
console.log(tag);
|
||||||
|
console.log();
|
||||||
|
|
||||||
|
const { data: latestRelease } = await github.rest.repos.getReleaseByTag({
|
||||||
|
...options,
|
||||||
|
tag: tag.name,
|
||||||
|
});
|
||||||
|
|
||||||
const { version } = packageJson;
|
|
||||||
const urlPrefix = "https://github.com/zzzgydi/clash-verge/releases/download";
|
|
||||||
const updateData = {
|
const updateData = {
|
||||||
name: `v${version}`,
|
name: tag.name,
|
||||||
notes: `Version ${version} is available now!!!`,
|
notes: latestRelease.body, // use the release body directly
|
||||||
pub_date: new Date().toISOString(),
|
pub_date: new Date().toISOString(),
|
||||||
platforms: {
|
platforms: {
|
||||||
win64: {
|
win64: { signature: "", url: "" },
|
||||||
signature: "",
|
darwin: { signature: "", url: "" },
|
||||||
url: `${urlPrefix}/v${version}/clash-verge_${version}_x64.msi.zip`,
|
|
||||||
},
|
|
||||||
darwin: {
|
|
||||||
signature: "",
|
|
||||||
url: `${urlPrefix}/v${version}/clash-verge.app.tar.gz`,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(`Generating Version "${version}" update.json`);
|
const promises = latestRelease.assets.map(async (asset) => {
|
||||||
|
const { name, browser_download_url } = asset;
|
||||||
|
|
||||||
const github = getOctokit(process.env.GITHUB_TOKEN);
|
// win64 url
|
||||||
|
if (/\.msi\.zip$/.test(name)) {
|
||||||
const { data: release } = await github.rest.repos.getReleaseByTag({
|
updateData.platforms.win64.url = browser_download_url;
|
||||||
owner: context.repo.owner,
|
}
|
||||||
repo: context.repo.repo,
|
// darwin url
|
||||||
tag: "updater",
|
if (/\.app\.tar\.gz$/.test(name)) {
|
||||||
});
|
updateData.platforms.darwin.url = browser_download_url;
|
||||||
const { data: assets } = await github.rest.repos.listReleaseAssets({
|
}
|
||||||
owner: context.repo.owner,
|
// win64 signature
|
||||||
repo: context.repo.repo,
|
if (/\.msi\.zip\.sig$/.test(name)) {
|
||||||
release_id: release.id,
|
updateData.platforms.win64.signature = await getSignature(
|
||||||
|
browser_download_url
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// darwin signature
|
||||||
|
if (/\.app\.tar\.gz\.sig$/.test(name)) {
|
||||||
|
updateData.platforms.darwin.signature = await getSignature(
|
||||||
|
browser_download_url
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let asset of assets) {
|
await Promise.allSettled(promises);
|
||||||
if (asset.name === "update.json") {
|
console.log(updateData);
|
||||||
|
|
||||||
|
// maybe should test the signature as well
|
||||||
|
const { darwin, win64 } = updateData.platforms;
|
||||||
|
if (!darwin.url) {
|
||||||
|
console.log(`[Error]: failed to parse release for darwin`);
|
||||||
|
delete updateData.platforms.darwin;
|
||||||
|
}
|
||||||
|
if (!win64.url) {
|
||||||
|
console.log(`[Error]: failed to parse release for win64`);
|
||||||
|
delete updateData.platforms.win64;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update the update.json
|
||||||
|
const { data: updateRelease } = await github.rest.repos.getReleaseByTag({
|
||||||
|
...options,
|
||||||
|
tag: UPDATE_TAG_NAME,
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let asset of updateRelease.assets) {
|
||||||
|
if (asset.name === UPDATE_JSON_FILE) {
|
||||||
await github.rest.repos.deleteReleaseAsset({
|
await github.rest.repos.deleteReleaseAsset({
|
||||||
owner: context.repo.owner,
|
...options,
|
||||||
repo: context.repo.repo,
|
|
||||||
asset_id: asset.id,
|
asset_id: asset.id,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
@@ -57,12 +97,21 @@ async function resolveRelease() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await github.rest.repos.uploadReleaseAsset({
|
await github.rest.repos.uploadReleaseAsset({
|
||||||
owner: context.repo.owner,
|
...options,
|
||||||
repo: context.repo.repo,
|
release_id: updateRelease.id,
|
||||||
release_id: release.id,
|
name: UPDATE_JSON_FILE,
|
||||||
name: "update.json",
|
|
||||||
data: JSON.stringify(updateData, null, 2),
|
data: JSON.stringify(updateData, null, 2),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveRelease();
|
// get the signature file content
|
||||||
|
async function getSignature(url) {
|
||||||
|
const response = await fetch(url, {
|
||||||
|
method: "GET",
|
||||||
|
headers: { "Content-Type": "application/octet-stream" },
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.text();
|
||||||
|
}
|
||||||
|
|
||||||
|
resolveRelease().catch(console.error);
|
||||||
|
|||||||
365
src-tauri/Cargo.lock
generated
@@ -34,9 +34,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.53"
|
version = "1.0.55"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0"
|
checksum = "159bb86af3a200e19a068f4224eae4c8bb2d0fa054c7e5d1cacd5cef95e684cd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arc-swap"
|
name = "arc-swap"
|
||||||
@@ -64,7 +64,7 @@ checksum = "7915e26e0786f91768d23de32afafa4ee5e2ea76be21c0ecd8e14441543c1655"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"enumflags2",
|
"enumflags2",
|
||||||
"futures",
|
"futures",
|
||||||
"rand 0.8.4",
|
"rand 0.8.5",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_repr",
|
"serde_repr",
|
||||||
"zbus",
|
"zbus",
|
||||||
@@ -127,9 +127,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-lock"
|
name = "async-lock"
|
||||||
version = "2.4.0"
|
version = "2.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e6a8ea61bf9947a1007c5cada31e647dbc77b103c679858150003ba697ea798b"
|
checksum = "e97a171d191782fba31bb902b14ad94e24a68145032b7eedf871ab0bc0d077b6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"event-listener",
|
"event-listener",
|
||||||
]
|
]
|
||||||
@@ -180,10 +180,10 @@ version = "0.15.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "58aeb089fb698e06db8089971c7ee317ab9644bade33383f63631437b03aafb6"
|
checksum = "58aeb089fb698e06db8089971c7ee317ab9644bade33383f63631437b03aafb6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"gobject-sys 0.15.5",
|
"gobject-sys 0.15.5",
|
||||||
"libc",
|
"libc",
|
||||||
"system-deps 6.0.1",
|
"system-deps 6.0.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -252,7 +252,7 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"constant_time_eq",
|
"constant_time_eq",
|
||||||
"digest 0.10.2",
|
"digest 0.10.3",
|
||||||
"rayon",
|
"rayon",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -346,9 +346,9 @@ checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cairo-rs"
|
name = "cairo-rs"
|
||||||
version = "0.15.1"
|
version = "0.15.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b869e97a87170f96762f9f178eae8c461147e722ba21dd8814105bf5716bf14a"
|
checksum = "e8b14c80d8d1a02fa6d914b9d1afeeca9bc34257f8300d9696e1e331ae114223"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cairo-sys-rs",
|
"cairo-sys-rs",
|
||||||
@@ -363,9 +363,9 @@ version = "0.15.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3c55d429bef56ac9172d25fecb85dc8068307d17acd74b377866b7a1ef25d3c8"
|
checksum = "3c55d429bef56ac9172d25fecb85dc8068307d17acd74b377866b7a1ef25d3c8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"libc",
|
"libc",
|
||||||
"system-deps 6.0.1",
|
"system-deps 6.0.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -381,9 +381,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.72"
|
version = "1.0.73"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
|
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jobserver",
|
"jobserver",
|
||||||
]
|
]
|
||||||
@@ -416,6 +416,15 @@ dependencies = [
|
|||||||
"smallvec",
|
"smallvec",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-expr"
|
||||||
|
version = "0.10.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5e068cb2806bbc15b439846dc16c5f89f8599f2c3e4d73d4449d38f9b2f0b6c5"
|
||||||
|
dependencies = [
|
||||||
|
"smallvec",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
@@ -445,9 +454,11 @@ dependencies = [
|
|||||||
name = "clash-verge"
|
name = "clash-verge"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"auto-launch",
|
"auto-launch",
|
||||||
"chrono",
|
"chrono",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
"dunce",
|
||||||
"log",
|
"log",
|
||||||
"log4rs",
|
"log4rs",
|
||||||
"port_scanner",
|
"port_scanner",
|
||||||
@@ -622,11 +633,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crypto-common"
|
name = "crypto-common"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a4600d695eb3f6ce1cd44e6e291adceb2cc3ab12f20a33777ecd0bf6eba34e06"
|
checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"generic-array",
|
"generic-array",
|
||||||
|
"typenum",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -797,9 +809,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.10.2"
|
version = "0.10.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8cb780dce4f9a8f5c087362b3a4595936b2019e7c8b30f2c3e9a7e94e6ae9837"
|
checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"block-buffer 0.10.2",
|
"block-buffer 0.10.2",
|
||||||
"crypto-common",
|
"crypto-common",
|
||||||
@@ -868,6 +880,12 @@ dependencies = [
|
|||||||
"dtoa",
|
"dtoa",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dunce"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "easy-parallel"
|
name = "easy-parallel"
|
||||||
version = "3.2.0"
|
version = "3.2.0"
|
||||||
@@ -1121,9 +1139,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gdk"
|
name = "gdk"
|
||||||
version = "0.15.2"
|
version = "0.15.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "614258e81ec35ed8770e64a0838f3a47f95b398bc51e724d3b3fa09c1ee0f8d5"
|
checksum = "a6e05c1f572ab0e1f15be94217f0dc29088c248b14f792a5ff0af0d84bcda9e8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cairo-rs",
|
"cairo-rs",
|
||||||
@@ -1137,9 +1155,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gdk-pixbuf"
|
name = "gdk-pixbuf"
|
||||||
version = "0.15.4"
|
version = "0.15.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "73aa2f5de1b45710da90a55863276667dc3a3264aaf6a2aeace62bb015244d49"
|
checksum = "d8750501d75f318c2ec0314701bc8403901303210def80bafd13f6b6059a3f45"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"gdk-pixbuf-sys",
|
"gdk-pixbuf-sys",
|
||||||
@@ -1154,11 +1172,11 @@ version = "0.15.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "413424d9818621fa3cfc8a3a915cdb89a7c3c507d56761b4ec83a9a98e587171"
|
checksum = "413424d9818621fa3cfc8a3a915cdb89a7c3c507d56761b4ec83a9a98e587171"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gio-sys 0.15.5",
|
"gio-sys 0.15.6",
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"gobject-sys 0.15.5",
|
"gobject-sys 0.15.5",
|
||||||
"libc",
|
"libc",
|
||||||
"system-deps 6.0.1",
|
"system-deps 6.0.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1169,13 +1187,13 @@ checksum = "32e7a08c1e8f06f4177fb7e51a777b8c1689f743a7bc11ea91d44d2226073a88"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cairo-sys-rs",
|
"cairo-sys-rs",
|
||||||
"gdk-pixbuf-sys",
|
"gdk-pixbuf-sys",
|
||||||
"gio-sys 0.15.5",
|
"gio-sys 0.15.6",
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"gobject-sys 0.15.5",
|
"gobject-sys 0.15.5",
|
||||||
"libc",
|
"libc",
|
||||||
"pango-sys",
|
"pango-sys",
|
||||||
"pkg-config",
|
"pkg-config",
|
||||||
"system-deps 6.0.1",
|
"system-deps 6.0.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1185,9 +1203,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "b4b7f8c7a84b407aa9b143877e267e848ff34106578b64d1e0a24bf550716178"
|
checksum = "b4b7f8c7a84b407aa9b143877e267e848ff34106578b64d1e0a24bf550716178"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gdk-sys",
|
"gdk-sys",
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"libc",
|
"libc",
|
||||||
"system-deps 6.0.1",
|
"system-deps 6.0.2",
|
||||||
"x11",
|
"x11",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1227,9 +1245,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.2.4"
|
version = "0.2.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c"
|
checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -1238,15 +1256,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gio"
|
name = "gio"
|
||||||
version = "0.15.5"
|
version = "0.15.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "59105fa464928adf56b159c8d980cc11fbfbe414befb904caac5163d383049bf"
|
checksum = "96efd8a1c00d890f6b45671916e165b5e43ccec61957d443aff6d7e44f62d348"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-io",
|
"futures-io",
|
||||||
"gio-sys 0.15.5",
|
"gio-sys 0.15.6",
|
||||||
"glib",
|
"glib",
|
||||||
"libc",
|
"libc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@@ -1268,22 +1286,22 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gio-sys"
|
name = "gio-sys"
|
||||||
version = "0.15.5"
|
version = "0.15.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4f0bc4cfc9ebcdd05cc5057bc51b99c32f8f9bf246274f6a556ffd27279f8fe3"
|
checksum = "1d0fa5052773f5a56b8ae47dab09d040f5d9ce1311f4f99006e16e9a08269296"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"gobject-sys 0.15.5",
|
"gobject-sys 0.15.5",
|
||||||
"libc",
|
"libc",
|
||||||
"system-deps 6.0.1",
|
"system-deps 6.0.2",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glib"
|
name = "glib"
|
||||||
version = "0.15.5"
|
version = "0.15.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "41dcfbdb6cc6c02aee163339465d8a40d6f3f64c3a43f729a4195f0e153338b7"
|
checksum = "aa570813c504bdf7539a9400180c2dd4b789a819556fb86da7226d7d1b037b49"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
@@ -1291,7 +1309,7 @@ dependencies = [
|
|||||||
"futures-executor",
|
"futures-executor",
|
||||||
"futures-task",
|
"futures-task",
|
||||||
"glib-macros",
|
"glib-macros",
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"gobject-sys 0.15.5",
|
"gobject-sys 0.15.5",
|
||||||
"libc",
|
"libc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@@ -1301,13 +1319,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glib-macros"
|
name = "glib-macros"
|
||||||
version = "0.15.3"
|
version = "0.15.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e58b262ff65ef771003873cea8c10e0fe854f1c508d48d62a4111a1ff163f7d1"
|
checksum = "41bfd8d227dead0829ac142454e97531b93f576d0805d779c42bfd799c65c572"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"heck 0.4.0",
|
"heck 0.4.0",
|
||||||
"proc-macro-crate 1.1.0",
|
"proc-macro-crate 1.1.3",
|
||||||
"proc-macro-error",
|
"proc-macro-error",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -1326,12 +1344,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glib-sys"
|
name = "glib-sys"
|
||||||
version = "0.15.5"
|
version = "0.15.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fa1d4e1a63d8574541e5b92931e4e669ddc87ffa85d58e84e631dba13ad2e10c"
|
checksum = "f4366377bd56697de8aaee24e673c575d2694d72e7756324ded2b0428829a7b8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"system-deps 6.0.1",
|
"system-deps 6.0.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1370,16 +1388,16 @@ version = "0.15.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "df6859463843c20cf3837e3a9069b6ab2051aeeadf4c899d33344f4aea83189a"
|
checksum = "df6859463843c20cf3837e3a9069b6ab2051aeeadf4c899d33344f4aea83189a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"libc",
|
"libc",
|
||||||
"system-deps 6.0.1",
|
"system-deps 6.0.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gtk"
|
name = "gtk"
|
||||||
version = "0.15.3"
|
version = "0.15.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c7978eaec05bea63947c801d29a21372f2ed39aec0bf56bf7725d3599094675e"
|
checksum = "5f2d1326b36af927fe46ae2f89a8fec38c6f0d279ebc5ef07ffeeabb70300bfc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atk",
|
"atk",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
@@ -1408,22 +1426,22 @@ dependencies = [
|
|||||||
"cairo-sys-rs",
|
"cairo-sys-rs",
|
||||||
"gdk-pixbuf-sys",
|
"gdk-pixbuf-sys",
|
||||||
"gdk-sys",
|
"gdk-sys",
|
||||||
"gio-sys 0.15.5",
|
"gio-sys 0.15.6",
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"gobject-sys 0.15.5",
|
"gobject-sys 0.15.5",
|
||||||
"libc",
|
"libc",
|
||||||
"pango-sys",
|
"pango-sys",
|
||||||
"system-deps 6.0.1",
|
"system-deps 6.0.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gtk3-macros"
|
name = "gtk3-macros"
|
||||||
version = "0.15.1"
|
version = "0.15.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8c891188af69e77a1e8a0b1746fbd03b9b396e7d34d518c5331b15950259f541"
|
checksum = "24f518afe90c23fba585b2d7697856f9e6a7bbc62f65588035e66f6afb01a2e9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"proc-macro-crate 1.1.0",
|
"proc-macro-crate 1.1.3",
|
||||||
"proc-macro-error",
|
"proc-macro-error",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -1548,9 +1566,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http-range"
|
name = "http-range"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eee9694f83d9b7c09682fdb32213682939507884e5bcf227be9aff5d644b90dc"
|
checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "httparse"
|
name = "httparse"
|
||||||
@@ -1733,7 +1751,7 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "905fbb87419c5cde6e3269537e4ea7d46431f3008c5d057e915ef3f115e7793c"
|
checksum = "905fbb87419c5cde6e3269537e4ea7d46431f3008c5d057e915ef3f115e7793c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"gobject-sys 0.15.5",
|
"gobject-sys 0.15.5",
|
||||||
"libc",
|
"libc",
|
||||||
"system-deps 5.0.0",
|
"system-deps 5.0.0",
|
||||||
@@ -1817,9 +1835,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.117"
|
version = "0.2.119"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c"
|
checksum = "1bf2e165bb3457c8e098ea76f3e3bc9db55f87aa90d52d0e6be741470916aaa4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linked-hash-map"
|
name = "linked-hash-map"
|
||||||
@@ -1867,7 +1885,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"log-mdc",
|
"log-mdc",
|
||||||
"parking_lot",
|
"parking_lot 0.11.2",
|
||||||
"regex",
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"serde-value",
|
"serde-value",
|
||||||
@@ -1961,9 +1979,9 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mime_guess"
|
name = "mime_guess"
|
||||||
version = "2.0.3"
|
version = "2.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212"
|
checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"mime",
|
"mime",
|
||||||
"unicase",
|
"unicase",
|
||||||
@@ -1996,9 +2014,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mio"
|
name = "mio"
|
||||||
version = "0.7.14"
|
version = "0.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc"
|
checksum = "ba272f85fa0b41fc91872be579b3bbe0f56b792aa361a380eb669469f68dafb2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
@@ -2028,7 +2046,7 @@ dependencies = [
|
|||||||
"mime",
|
"mime",
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
"quick-error",
|
"quick-error",
|
||||||
"rand 0.8.4",
|
"rand 0.8.5",
|
||||||
"safemem",
|
"safemem",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"twoway",
|
"twoway",
|
||||||
@@ -2066,15 +2084,22 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ndk-glue"
|
name = "ndk-context"
|
||||||
version = "0.4.0"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d3e9e94628f24e7a3cb5b96a2dc5683acd9230bf11991c2a1677b87695138420"
|
checksum = "4e3c5cc68637e21fe8f077f6a1c9e0b9ca495bb74895226b476310f613325884"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ndk-glue"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9b1454575120e3265d2442222299c711ace58ba417532ee4f0fc71b860016b93"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"ndk",
|
"ndk",
|
||||||
|
"ndk-context",
|
||||||
"ndk-macro",
|
"ndk-macro",
|
||||||
"ndk-sys",
|
"ndk-sys",
|
||||||
]
|
]
|
||||||
@@ -2187,7 +2212,7 @@ version = "0.5.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0d992b768490d7fe0d8586d9b5745f6c49f557da6d81dc982b1d167ad4edbb21"
|
checksum = "0d992b768490d7fe0d8586d9b5745f6c49f557da6d81dc982b1d167ad4edbb21"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-crate 1.1.0",
|
"proc-macro-crate 1.1.3",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn",
|
||||||
@@ -2246,9 +2271,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "open"
|
name = "open"
|
||||||
version = "2.0.3"
|
version = "2.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4b1e014096a08da72e3287119e0c69a8f6fce61a031a55b1ce2607fe9c2b5a67"
|
checksum = "5a82915836ef43159bb6a3c64d884c42329ccd0b8afdca737cf1e3dd701709dc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"pathdiff",
|
"pathdiff",
|
||||||
"winapi",
|
"winapi",
|
||||||
@@ -2308,9 +2333,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "os_pipe"
|
name = "os_pipe"
|
||||||
version = "1.0.0"
|
version = "1.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0e3492ebca331b895fe23ed427dce2013d9b2e00c45964f12040b0db38b8ab27"
|
checksum = "2c92f2b54f081d635c77e7120862d48db8e91f7f21cef23ab1b4fe9971c59f55"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"winapi",
|
"winapi",
|
||||||
@@ -2318,9 +2343,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pango"
|
name = "pango"
|
||||||
version = "0.15.2"
|
version = "0.15.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "79211eff430c29cc38c69e0ab54bc78fa1568121ca9737707eee7f92a8417a94"
|
checksum = "78c7420fc01a390ec200da7395b64d705f5d82fe03e5d0708aee422c46538be7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"glib",
|
"glib",
|
||||||
@@ -2335,10 +2360,10 @@ version = "0.15.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7022c2fb88cd2d9d55e1a708a8c53a3ae8678234c4a54bf623400aeb7f31fac2"
|
checksum = "7022c2fb88cd2d9d55e1a708a8c53a3ae8678234c4a54bf623400aeb7f31fac2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"gobject-sys 0.15.5",
|
"gobject-sys 0.15.5",
|
||||||
"libc",
|
"libc",
|
||||||
"system-deps 6.0.1",
|
"system-deps 6.0.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2355,7 +2380,17 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"instant",
|
"instant",
|
||||||
"lock_api",
|
"lock_api",
|
||||||
"parking_lot_core",
|
"parking_lot_core 0.8.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot"
|
||||||
|
version = "0.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api",
|
||||||
|
"parking_lot_core 0.9.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2372,6 +2407,19 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "parking_lot_core"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"redox_syscall 0.2.10",
|
||||||
|
"smallvec",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pathdiff"
|
name = "pathdiff"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
@@ -2442,7 +2490,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
|
checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"phf_shared 0.10.0",
|
"phf_shared 0.10.0",
|
||||||
"rand 0.8.4",
|
"rand 0.8.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2601,9 +2649,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-crate"
|
name = "proc-macro-crate"
|
||||||
version = "1.1.0"
|
version = "1.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83"
|
checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"toml",
|
"toml",
|
||||||
@@ -2673,20 +2721,19 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"rand_chacha 0.2.2",
|
"rand_chacha 0.2.2",
|
||||||
"rand_core 0.5.1",
|
"rand_core 0.5.1",
|
||||||
"rand_hc 0.2.0",
|
"rand_hc",
|
||||||
"rand_pcg",
|
"rand_pcg",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand"
|
name = "rand"
|
||||||
version = "0.8.4"
|
version = "0.8.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8"
|
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"rand_chacha 0.3.1",
|
"rand_chacha 0.3.1",
|
||||||
"rand_core 0.6.3",
|
"rand_core 0.6.3",
|
||||||
"rand_hc 0.3.1",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2724,7 +2771,7 @@ version = "0.6.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
|
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom 0.2.4",
|
"getrandom 0.2.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2736,15 +2783,6 @@ dependencies = [
|
|||||||
"rand_core 0.5.1",
|
"rand_core 0.5.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rand_hc"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d51e9f596de227fda2ea6c84607f5558e196eeaf43c986b724ba4fb8fdf497e7"
|
|
||||||
dependencies = [
|
|
||||||
"rand_core 0.6.3",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rand_pcg"
|
name = "rand_pcg"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
@@ -2809,7 +2847,7 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
|
checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom 0.2.4",
|
"getrandom 0.2.5",
|
||||||
"redox_syscall 0.2.10",
|
"redox_syscall 0.2.10",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2893,7 +2931,7 @@ dependencies = [
|
|||||||
"ashpd",
|
"ashpd",
|
||||||
"block",
|
"block",
|
||||||
"dispatch",
|
"dispatch",
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"gobject-sys 0.15.5",
|
"gobject-sys 0.15.5",
|
||||||
"gtk-sys",
|
"gtk-sys",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
@@ -2925,7 +2963,7 @@ version = "0.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
|
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"semver 1.0.5",
|
"semver 1.0.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3031,9 +3069,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver"
|
name = "semver"
|
||||||
version = "1.0.5"
|
version = "1.0.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0486718e92ec9a68fbed73bb5ef687d71103b142595b406835649bebd33f72c7"
|
checksum = "a4a3381e03edd24287172047536f20cabde766e2cd3e65e6b00fb3af51c4f38d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver-parser"
|
name = "semver-parser"
|
||||||
@@ -3196,7 +3234,7 @@ checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"cpufeatures",
|
"cpufeatures",
|
||||||
"digest 0.10.2",
|
"digest 0.10.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3216,13 +3254,13 @@ checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.10.1"
|
version = "0.10.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "99c3bd8169c58782adad9290a9af5939994036b76187f7b4f0e6de91dbbfc0ec"
|
checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"cpufeatures",
|
"cpufeatures",
|
||||||
"digest 0.10.2",
|
"digest 0.10.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -3324,7 +3362,7 @@ checksum = "33994d0838dc2d152d17a62adf608a869b5e846b65b389af7f3dbc1de45c5b26"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"new_debug_unreachable",
|
"new_debug_unreachable",
|
||||||
"parking_lot",
|
"parking_lot 0.11.2",
|
||||||
"phf_shared 0.10.0",
|
"phf_shared 0.10.0",
|
||||||
"precomputed-hash",
|
"precomputed-hash",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -3432,11 +3470,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "system-deps"
|
name = "system-deps"
|
||||||
version = "6.0.1"
|
version = "6.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ad3a97fdef3daf935d929b3e97e5a6a680cd4622e40c2941ca0875d6566416f8"
|
checksum = "a1a45a1c4c9015217e12347f2a411b57ce2c4fc543913b14b6fe40483328e709"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-expr 0.9.1",
|
"cfg-expr 0.10.2",
|
||||||
"heck 0.4.0",
|
"heck 0.4.0",
|
||||||
"pkg-config",
|
"pkg-config",
|
||||||
"toml",
|
"toml",
|
||||||
@@ -3445,9 +3483,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tao"
|
name = "tao"
|
||||||
version = "0.6.1"
|
version = "0.6.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "402f170c4da28cc3108d854c7567d6904c82fc0e30e5b69f2a6b3e48f8a4f705"
|
checksum = "7b3b3bbc9151bce45db3cf9ccb808730c8df8786d0223f34591f6e5890503939"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cairo-rs",
|
"cairo-rs",
|
||||||
@@ -3463,7 +3501,7 @@ dependencies = [
|
|||||||
"gdkx11-sys",
|
"gdkx11-sys",
|
||||||
"gio",
|
"gio",
|
||||||
"glib",
|
"glib",
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"gtk",
|
"gtk",
|
||||||
"instant",
|
"instant",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@@ -3474,7 +3512,7 @@ dependencies = [
|
|||||||
"ndk-glue",
|
"ndk-glue",
|
||||||
"ndk-sys",
|
"ndk-sys",
|
||||||
"objc",
|
"objc",
|
||||||
"parking_lot",
|
"parking_lot 0.11.2",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"scopeguard",
|
"scopeguard",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -3510,10 +3548,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri"
|
name = "tauri"
|
||||||
version = "1.0.0-rc.2"
|
version = "1.0.0-rc.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3571de0bcfd1f4f7599cbb3fe42f28ea9f52c3e89914ff04eaba68b5ee36bb51"
|
checksum = "bb0c4a4ffd1f9b02cc3e974ce902f8132fb3d08ec6cce4ca193f97d921f5bce4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"attohttpc",
|
"attohttpc",
|
||||||
"base64",
|
"base64",
|
||||||
"bincode",
|
"bincode",
|
||||||
@@ -3534,11 +3573,11 @@ dependencies = [
|
|||||||
"open",
|
"open",
|
||||||
"os_pipe",
|
"os_pipe",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"rand 0.8.4",
|
"rand 0.8.5",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"regex",
|
"regex",
|
||||||
"rfd",
|
"rfd",
|
||||||
"semver 1.0.5",
|
"semver 1.0.6",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_repr",
|
"serde_repr",
|
||||||
@@ -3560,9 +3599,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-build"
|
name = "tauri-build"
|
||||||
version = "1.0.0-rc.1"
|
version = "1.0.0-rc.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a35ca6c70dce0dbe3441ab9e6d4ebae9a2315cfe8823662ac86cf517b22831e8"
|
checksum = "855e47d8cfb2219fc14d2eed2c09bfb35f9ecd71a40ca2084aeeee2d23e0b60d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cargo_toml",
|
"cargo_toml",
|
||||||
@@ -3573,9 +3612,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-codegen"
|
name = "tauri-codegen"
|
||||||
version = "1.0.0-rc.1"
|
version = "1.0.0-rc.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7d06ecdbd6beaf7348259f82885742f013c0c96ac139445ec7c4b8050cd18349"
|
checksum = "eef4656d174ba982198266da0c016573fe6c7c760e4290f05c8c384fe180007e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"blake3",
|
"blake3",
|
||||||
@@ -3594,9 +3633,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-macros"
|
name = "tauri-macros"
|
||||||
version = "1.0.0-rc.1"
|
version = "1.0.0-rc.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ba9ab86a4e81b31b227800c120b452dae137754e06d75b75c41c06cd06d301e2"
|
checksum = "a0993f5a867e321d26200b2d6394cdf482bd6cc5a0e4691bcabf811544f51cd4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck 0.4.0",
|
"heck 0.4.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@@ -3609,7 +3648,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-plugin-shadows"
|
name = "tauri-plugin-shadows"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
source = "git+https://github.com/tauri-apps/tauri-plugin-shadows#5ef6560af0c55ab5543f60eb9bfcb5f1de49a69e"
|
source = "git+https://github.com/tauri-apps/tauri-plugin-shadows#fac6f42f1cf43329f398871f5564448359458462"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cocoa",
|
"cocoa",
|
||||||
"objc",
|
"objc",
|
||||||
@@ -3620,7 +3659,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-plugin-vibrancy"
|
name = "tauri-plugin-vibrancy"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
source = "git+https://github.com/tauri-apps/tauri-plugin-vibrancy#b5cc16221d89a1cfc6dad9e36c4788e0459aaaf1"
|
source = "git+https://github.com/tauri-apps/tauri-plugin-vibrancy#561c4fa22c42073239ad37b4b406c303aa91e678"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cocoa",
|
"cocoa",
|
||||||
"objc",
|
"objc",
|
||||||
@@ -3630,9 +3669,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-runtime"
|
name = "tauri-runtime"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c683b979ec4841b86048a282cd86afbc13b418a0f546904b27fad06e882ad5d7"
|
checksum = "851cd65e2c9df4dd70a4f9e115fb2441ac89f1c80df79de0c15a448b4acd7768"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gtk",
|
"gtk",
|
||||||
"http",
|
"http",
|
||||||
@@ -3649,9 +3688,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-runtime-wry"
|
name = "tauri-runtime-wry"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ec025e7c906451fd7ff9e46d106a2e1b5b73e48013d13d52ffce614212b63fdc"
|
checksum = "0184f95e065fb80afadf53f0a5f87a75af2da774d0524fe8cb2976fbec4a0bf2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gtk",
|
"gtk",
|
||||||
"ico",
|
"ico",
|
||||||
@@ -3667,9 +3706,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-utils"
|
name = "tauri-utils"
|
||||||
version = "1.0.0-rc.1"
|
version = "1.0.0-rc.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "abcbfec197c4cb959376607ac2fd99cecca02bd6d52b794bd882959501e34533"
|
checksum = "0ad38ad698838886bf22ecb91c4b3d1ce178fdff7901ac7bff370103a4f51e59"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ctor",
|
"ctor",
|
||||||
"glob",
|
"glob",
|
||||||
@@ -3789,9 +3828,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.16.1"
|
version = "1.17.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0c27a64b625de6d309e8c57716ba93021dccf1b3b5c97edd6d3dd2d2135afc0a"
|
checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -3799,9 +3838,10 @@ dependencies = [
|
|||||||
"mio",
|
"mio",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"parking_lot",
|
"parking_lot 0.12.0",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"signal-hook-registry",
|
"signal-hook-registry",
|
||||||
|
"socket2",
|
||||||
"tokio-macros",
|
"tokio-macros",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
@@ -3882,9 +3922,9 @@ checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing"
|
name = "tracing"
|
||||||
version = "0.1.30"
|
version = "0.1.31"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2d8d93354fe2a8e50d5953f5ae2e47a3fc2ef03292e7ea46e3cc38f549525fb9"
|
checksum = "f6c650a8ef0cd2dd93736f033d21cbd1224c5a967aa0c258d00fcf7dafef9b9f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"log",
|
"log",
|
||||||
@@ -3927,9 +3967,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tracing-subscriber"
|
name = "tracing-subscriber"
|
||||||
version = "0.3.8"
|
version = "0.3.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "74786ce43333fcf51efe947aed9718fbe46d5c7328ec3f1029e818083966d9aa"
|
checksum = "9e0ab7bdc962035a87fba73f3acca9b8a8d0034c2e6f60b84aeaaddddc155dce"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term",
|
"ansi_term",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@@ -3976,7 +4016,7 @@ dependencies = [
|
|||||||
"http",
|
"http",
|
||||||
"httparse",
|
"httparse",
|
||||||
"log",
|
"log",
|
||||||
"rand 0.8.4",
|
"rand 0.8.5",
|
||||||
"sha-1 0.9.8",
|
"sha-1 0.9.8",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"url",
|
"url",
|
||||||
@@ -4083,7 +4123,7 @@ version = "0.8.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
|
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom 0.2.4",
|
"getrandom 0.2.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4272,9 +4312,9 @@ dependencies = [
|
|||||||
"gdk",
|
"gdk",
|
||||||
"gdk-sys",
|
"gdk-sys",
|
||||||
"gio",
|
"gio",
|
||||||
"gio-sys 0.15.5",
|
"gio-sys 0.15.6",
|
||||||
"glib",
|
"glib",
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"gobject-sys 0.15.5",
|
"gobject-sys 0.15.5",
|
||||||
"gtk",
|
"gtk",
|
||||||
"gtk-sys",
|
"gtk-sys",
|
||||||
@@ -4295,8 +4335,8 @@ dependencies = [
|
|||||||
"cairo-sys-rs",
|
"cairo-sys-rs",
|
||||||
"gdk-pixbuf-sys",
|
"gdk-pixbuf-sys",
|
||||||
"gdk-sys",
|
"gdk-sys",
|
||||||
"gio-sys 0.15.5",
|
"gio-sys 0.15.6",
|
||||||
"glib-sys 0.15.5",
|
"glib-sys 0.15.6",
|
||||||
"gobject-sys 0.15.5",
|
"gobject-sys 0.15.5",
|
||||||
"gtk-sys",
|
"gtk-sys",
|
||||||
"javascriptcore-rs-sys",
|
"javascriptcore-rs-sys",
|
||||||
@@ -4309,9 +4349,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webview2-com"
|
name = "webview2-com"
|
||||||
version = "0.11.0"
|
version = "0.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1975ce3573344c099935fe3903f1708dac69efe8539f1efee3ae54d8f9315fbb"
|
checksum = "bb8e90ac2d9ce39cdb70017aaec641be09fbdd702b7b332b9896d053eb469524"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"webview2-com-macros",
|
"webview2-com-macros",
|
||||||
"webview2-com-sys",
|
"webview2-com-sys",
|
||||||
@@ -4332,9 +4372,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webview2-com-sys"
|
name = "webview2-com-sys"
|
||||||
version = "0.11.0"
|
version = "0.13.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9a746838a94b7391f707209a246e3436d81d1e71832126a65a897d3ee5511040"
|
checksum = "92160310b3322397e4ff8a8285a7429d73a07a68fda44ee80879605b93e53f76"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"regex",
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -4437,6 +4477,19 @@ dependencies = [
|
|||||||
"windows_reader",
|
"windows_reader",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.32.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_msvc 0.32.0",
|
||||||
|
"windows_i686_gnu 0.32.0",
|
||||||
|
"windows_i686_msvc 0.32.0",
|
||||||
|
"windows_x86_64_gnu 0.32.0",
|
||||||
|
"windows_x86_64_msvc 0.32.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_msvc"
|
name = "windows_aarch64_msvc"
|
||||||
version = "0.30.0"
|
version = "0.30.0"
|
||||||
@@ -4560,9 +4613,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wry"
|
name = "wry"
|
||||||
version = "0.13.1"
|
version = "0.13.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "194b2750d8fe10fef189af5e2ca09e56cb8c5458a365d2b32842b024351f58c9"
|
checksum = "620bfe8ed3cde9310f32a69ffc654dfd8dae4ac5a0e08d6fbf0205a996fc7f0f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cocoa",
|
"cocoa",
|
||||||
"core-graphics",
|
"core-graphics",
|
||||||
@@ -4654,7 +4707,7 @@ dependencies = [
|
|||||||
"nix",
|
"nix",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"ordered-stream",
|
"ordered-stream",
|
||||||
"rand 0.8.4",
|
"rand 0.8.5",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_repr",
|
"serde_repr",
|
||||||
"sha1",
|
"sha1",
|
||||||
@@ -4671,7 +4724,7 @@ version = "2.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "36823cc10fddc3c6b19f048903262dacaf8274170e9a255784bdd8b4570a8040"
|
checksum = "36823cc10fddc3c6b19f048903262dacaf8274170e9a255784bdd8b4570a8040"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-crate 1.1.0",
|
"proc-macro-crate 1.1.3",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"regex",
|
"regex",
|
||||||
@@ -4752,7 +4805,7 @@ version = "3.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8c2cecc5a61c2a053f7f653a24cd15b3b0195d7f7ddb5042c837fb32e161fb7a"
|
checksum = "8c2cecc5a61c2a053f7f653a24cd15b3b0195d7f7ddb5042c837fb32e161fb7a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-crate 1.1.0",
|
"proc-macro-crate 1.1.3",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn",
|
"syn",
|
||||||
|
|||||||
@@ -10,15 +10,17 @@ edition = "2021"
|
|||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tauri-build = { version = "1.0.0-rc.1", features = [] }
|
tauri-build = { version = "1.0.0-rc.3", features = [] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0"
|
||||||
dirs = "4.0.0"
|
dirs = "4.0.0"
|
||||||
|
dunce = "1.0.2"
|
||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde_yaml = "0.8"
|
serde_yaml = "0.8"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tauri = { version = "1.0.0-rc.2", features = ["shell-all", "system-tray", "updater", "window-all"] }
|
tauri = { version = "1.0.0-rc.3", features = ["shell-all", "system-tray", "updater", "window-all"] }
|
||||||
tauri-plugin-shadows = { git = "https://github.com/tauri-apps/tauri-plugin-shadows", features = ["tauri-impl"] }
|
tauri-plugin-shadows = { git = "https://github.com/tauri-apps/tauri-plugin-shadows", features = ["tauri-impl"] }
|
||||||
tauri-plugin-vibrancy = { git = "https://github.com/tauri-apps/tauri-plugin-vibrancy", features = ["tauri-impl"] }
|
tauri-plugin-vibrancy = { git = "https://github.com/tauri-apps/tauri-plugin-vibrancy", features = ["tauri-impl"] }
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
# Default Config For Clash Core
|
|
||||||
|
|
||||||
mixed-port: 7890
|
|
||||||
log-level: info
|
|
||||||
allow-lan: false
|
|
||||||
external-controller: 127.0.0.1:9090
|
|
||||||
mode: rule
|
|
||||||
secret: ""
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
# Profile Template for clash verge
|
|
||||||
|
|
||||||
# the profile's name
|
|
||||||
name: New Profile
|
|
||||||
|
|
||||||
# the description of this profile(optional)
|
|
||||||
description:
|
|
||||||
|
|
||||||
# proxies defination (optional, the same as clash)
|
|
||||||
proxies:
|
|
||||||
|
|
||||||
# proxy-groups (optional, the same as clash)
|
|
||||||
proxy-groups:
|
|
||||||
|
|
||||||
# rules (optional, the same as clash)
|
|
||||||
rules:
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# Profiles Config for Clash Verge
|
|
||||||
|
|
||||||
current: 0
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
# Defaulf Config For Clash Verge
|
|
||||||
|
|
||||||
theme_mode: light
|
|
||||||
enable_self_startup: false
|
|
||||||
enable_system_proxy: false
|
|
||||||
system_proxy_bypass: localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;192.168.*;<local>
|
|
||||||
@@ -1,29 +1,46 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
core::{ClashInfo, ProfileItem, Profiles, VergeConfig},
|
core::{ClashInfo, ProfileItem, Profiles, VergeConfig},
|
||||||
states::{ClashState, ProfilesState, VergeState},
|
states::{ClashState, ProfilesState, VergeState},
|
||||||
utils::{dirs::app_home_dir, fetch::fetch_profile, sysopt::SysProxyConfig},
|
utils::{dirs, fetch::fetch_profile, sysopt::SysProxyConfig},
|
||||||
};
|
};
|
||||||
|
use anyhow::Result;
|
||||||
use serde_yaml::Mapping;
|
use serde_yaml::Mapping;
|
||||||
use std::process::Command;
|
use std::{path::PathBuf, process::Command};
|
||||||
use tauri::State;
|
use tauri::{api, State};
|
||||||
|
|
||||||
|
/// wrap the anyhow error
|
||||||
|
/// transform the error to String
|
||||||
|
macro_rules! wrap_err {
|
||||||
|
($stat: expr) => {
|
||||||
|
match $stat {
|
||||||
|
Ok(a) => Ok(a),
|
||||||
|
Err(err) => {
|
||||||
|
log::error!("{}", err.to_string());
|
||||||
|
Err(format!("{}", err.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// return the string literal error
|
||||||
|
macro_rules! ret_err {
|
||||||
|
($str: literal) => {
|
||||||
|
return Err($str.into())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// get all profiles from `profiles.yaml`
|
/// get all profiles from `profiles.yaml`
|
||||||
/// do not acquire the lock of ProfileLock
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn get_profiles(profiles_state: State<'_, ProfilesState>) -> Result<Profiles, String> {
|
pub fn get_profiles(profiles_state: State<'_, ProfilesState>) -> Result<Profiles, String> {
|
||||||
match profiles_state.0.lock() {
|
let profiles = profiles_state.0.lock().unwrap();
|
||||||
Ok(profiles) => Ok(profiles.clone()),
|
Ok(profiles.clone())
|
||||||
Err(_) => Err("failed to get profiles lock".into()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// synchronize data irregularly
|
/// synchronize data irregularly
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn sync_profiles(profiles_state: State<'_, ProfilesState>) -> Result<(), String> {
|
pub fn sync_profiles(profiles_state: State<'_, ProfilesState>) -> Result<(), String> {
|
||||||
match profiles_state.0.lock() {
|
let mut profiles = profiles_state.0.lock().unwrap();
|
||||||
Ok(mut profiles) => profiles.sync_file(),
|
wrap_err!(profiles.sync_file())
|
||||||
Err(_) => Err("failed to get profiles lock".into()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// import the profile from url
|
/// import the profile from url
|
||||||
@@ -34,13 +51,9 @@ pub async fn import_profile(
|
|||||||
with_proxy: bool,
|
with_proxy: bool,
|
||||||
profiles_state: State<'_, ProfilesState>,
|
profiles_state: State<'_, ProfilesState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
match fetch_profile(&url, with_proxy).await {
|
let result = fetch_profile(&url, with_proxy).await?;
|
||||||
Some(result) => {
|
let mut profiles = profiles_state.0.lock().unwrap();
|
||||||
let mut profiles = profiles_state.0.lock().unwrap();
|
wrap_err!(profiles.import_from_url(url, result))
|
||||||
profiles.import_from_url(url, result)
|
|
||||||
}
|
|
||||||
None => Err(format!("failed to fetch profile from `{}`", url)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// new a profile
|
/// new a profile
|
||||||
@@ -53,7 +66,7 @@ pub async fn new_profile(
|
|||||||
profiles_state: State<'_, ProfilesState>,
|
profiles_state: State<'_, ProfilesState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let mut profiles = profiles_state.0.lock().unwrap();
|
let mut profiles = profiles_state.0.lock().unwrap();
|
||||||
profiles.append_item(name, desc)?;
|
wrap_err!(profiles.append_item(name, desc))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,35 +83,34 @@ pub async fn update_profile(
|
|||||||
Ok(mut profile) => {
|
Ok(mut profile) => {
|
||||||
let items = profile.items.take().unwrap_or(vec![]);
|
let items = profile.items.take().unwrap_or(vec![]);
|
||||||
if index >= items.len() {
|
if index >= items.len() {
|
||||||
return Err("the index out of bound".into());
|
ret_err!("the index out of bound");
|
||||||
}
|
}
|
||||||
let url = match &items[index].url {
|
let url = match &items[index].url {
|
||||||
Some(u) => u.clone(),
|
Some(u) => u.clone(),
|
||||||
None => return Err("failed to update profile for `invalid url`".into()),
|
None => ret_err!("failed to update profile for `invalid url`"),
|
||||||
};
|
};
|
||||||
profile.items = Some(items);
|
profile.items = Some(items);
|
||||||
url
|
url
|
||||||
}
|
}
|
||||||
Err(_) => return Err("failed to get profiles lock".into()),
|
Err(_) => ret_err!("failed to get profiles lock"),
|
||||||
};
|
};
|
||||||
|
|
||||||
match fetch_profile(&url, with_proxy).await {
|
let result = fetch_profile(&url, with_proxy).await?;
|
||||||
Some(result) => match profiles_state.0.lock() {
|
|
||||||
Ok(mut profiles) => {
|
|
||||||
profiles.update_item(index, result)?;
|
|
||||||
|
|
||||||
// reactivate the profile
|
match profiles_state.0.lock() {
|
||||||
let current = profiles.current.clone().unwrap_or(0);
|
Ok(mut profiles) => {
|
||||||
if current == index {
|
wrap_err!(profiles.update_item(index, result))?;
|
||||||
let clash = clash_state.0.lock().unwrap();
|
|
||||||
profiles.activate(&clash)
|
// reactivate the profile
|
||||||
} else {
|
let current = profiles.current.clone().unwrap_or(0);
|
||||||
Ok(())
|
if current == index {
|
||||||
}
|
let clash = clash_state.0.lock().unwrap();
|
||||||
|
wrap_err!(profiles.activate(&clash))
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(_) => Err("failed to get profiles lock".into()),
|
}
|
||||||
},
|
Err(_) => ret_err!("failed to get profiles lock"),
|
||||||
None => Err(format!("failed to fetch profile from `{}`", url)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,14 +122,10 @@ pub fn select_profile(
|
|||||||
profiles_state: State<'_, ProfilesState>,
|
profiles_state: State<'_, ProfilesState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let mut profiles = profiles_state.0.lock().unwrap();
|
let mut profiles = profiles_state.0.lock().unwrap();
|
||||||
|
wrap_err!(profiles.put_current(index))?;
|
||||||
|
|
||||||
match profiles.put_current(index) {
|
let clash = clash_state.0.lock().unwrap();
|
||||||
Ok(()) => {
|
wrap_err!(profiles.activate(&clash))
|
||||||
let clash = clash_state.0.lock().unwrap();
|
|
||||||
profiles.activate(&clash)
|
|
||||||
}
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// delete profile item
|
/// delete profile item
|
||||||
@@ -128,16 +136,13 @@ pub fn delete_profile(
|
|||||||
profiles_state: State<'_, ProfilesState>,
|
profiles_state: State<'_, ProfilesState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let mut profiles = profiles_state.0.lock().unwrap();
|
let mut profiles = profiles_state.0.lock().unwrap();
|
||||||
match profiles.delete_item(index) {
|
|
||||||
Ok(change) => match change {
|
if wrap_err!(profiles.delete_item(index))? {
|
||||||
true => {
|
let clash = clash_state.0.lock().unwrap();
|
||||||
let clash = clash_state.0.lock().unwrap();
|
wrap_err!(profiles.activate(&clash))?;
|
||||||
profiles.activate(&clash)
|
|
||||||
}
|
|
||||||
false => Ok(()),
|
|
||||||
},
|
|
||||||
Err(err) => Err(err),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// patch the profile config
|
/// patch the profile config
|
||||||
@@ -147,10 +152,8 @@ pub fn patch_profile(
|
|||||||
profile: ProfileItem,
|
profile: ProfileItem,
|
||||||
profiles_state: State<'_, ProfilesState>,
|
profiles_state: State<'_, ProfilesState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
match profiles_state.0.lock() {
|
let mut profiles = profiles_state.0.lock().unwrap();
|
||||||
Ok(mut profiles) => profiles.patch_item(index, profile),
|
wrap_err!(profiles.patch_item(index, profile))
|
||||||
Err(_) => Err("can not get profiles lock".into()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// run vscode command to edit the profile
|
/// run vscode command to edit the profile
|
||||||
@@ -161,29 +164,41 @@ pub fn view_profile(index: usize, profiles_state: State<'_, ProfilesState>) -> R
|
|||||||
|
|
||||||
if index >= items.len() {
|
if index >= items.len() {
|
||||||
profiles.items = Some(items);
|
profiles.items = Some(items);
|
||||||
return Err("the index out of bound".into());
|
ret_err!("the index out of bound");
|
||||||
}
|
}
|
||||||
|
|
||||||
let file = items[index].file.clone().unwrap_or("".into());
|
let file = items[index].file.clone().unwrap_or("".into());
|
||||||
profiles.items = Some(items);
|
profiles.items = Some(items);
|
||||||
|
|
||||||
let path = app_home_dir().join("profiles").join(file);
|
let path = dirs::app_profiles_dir().join(file);
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
return Err("the file not found".into());
|
ret_err!("the file not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
// use vscode first
|
// use vscode first
|
||||||
if let Ok(code) = which::which("code") {
|
if let Ok(code) = which::which("code") {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
use std::os::windows::process::CommandExt;
|
||||||
|
|
||||||
|
return match Command::new(code)
|
||||||
|
.creation_flags(0x08000000)
|
||||||
|
.arg(path)
|
||||||
|
.spawn()
|
||||||
|
{
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(_) => Err("failed to open file by VScode".into()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
return match Command::new(code).arg(path).spawn() {
|
return match Command::new(code).arg(path).spawn() {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(_) => Err("failed to open file by VScode".into()),
|
Err(_) => Err("failed to open file by VScode".into()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
match open_command().arg(path).spawn() {
|
open_path_cmd(path, "failed to open file by `open`")
|
||||||
Ok(_) => Ok(()),
|
|
||||||
Err(_) => Err("failed to open file by `open`".into()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// restart the sidecar
|
/// restart the sidecar
|
||||||
@@ -195,23 +210,15 @@ pub fn restart_sidecar(
|
|||||||
let mut clash = clash_state.0.lock().unwrap();
|
let mut clash = clash_state.0.lock().unwrap();
|
||||||
let mut profiles = profiles_state.0.lock().unwrap();
|
let mut profiles = profiles_state.0.lock().unwrap();
|
||||||
|
|
||||||
match clash.restart_sidecar(&mut profiles) {
|
wrap_err!(clash.restart_sidecar(&mut profiles))
|
||||||
Ok(_) => Ok(()),
|
|
||||||
Err(err) => {
|
|
||||||
log::error!("{}", err);
|
|
||||||
Err(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get the clash core info from the state
|
/// get the clash core info from the state
|
||||||
/// the caller can also get the infomation by clash's api
|
/// the caller can also get the infomation by clash's api
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn get_clash_info(clash_state: State<'_, ClashState>) -> Result<ClashInfo, String> {
|
pub fn get_clash_info(clash_state: State<'_, ClashState>) -> Result<ClashInfo, String> {
|
||||||
match clash_state.0.lock() {
|
let clash = clash_state.0.lock().unwrap();
|
||||||
Ok(clash) => Ok(clash.info.clone()),
|
Ok(clash.info.clone())
|
||||||
Err(_) => Err("failed to get clash lock".into()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// update the clash core config
|
/// update the clash core config
|
||||||
@@ -227,26 +234,21 @@ pub fn patch_clash_config(
|
|||||||
let mut clash = clash_state.0.lock().unwrap();
|
let mut clash = clash_state.0.lock().unwrap();
|
||||||
let mut verge = verge_state.0.lock().unwrap();
|
let mut verge = verge_state.0.lock().unwrap();
|
||||||
let mut profiles = profiles_state.0.lock().unwrap();
|
let mut profiles = profiles_state.0.lock().unwrap();
|
||||||
clash.patch_config(payload, &mut verge, &mut profiles)
|
wrap_err!(clash.patch_config(payload, &mut verge, &mut profiles))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get the system proxy
|
/// get the system proxy
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn get_sys_proxy() -> Result<SysProxyConfig, String> {
|
pub fn get_sys_proxy() -> Result<SysProxyConfig, String> {
|
||||||
match SysProxyConfig::get_sys() {
|
wrap_err!(SysProxyConfig::get_sys())
|
||||||
Ok(value) => Ok(value),
|
|
||||||
Err(err) => Err(err.to_string()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get the current proxy config
|
/// get the current proxy config
|
||||||
/// which may not the same as system proxy
|
/// which may not the same as system proxy
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn get_cur_proxy(verge_state: State<'_, VergeState>) -> Result<Option<SysProxyConfig>, String> {
|
pub fn get_cur_proxy(verge_state: State<'_, VergeState>) -> Result<Option<SysProxyConfig>, String> {
|
||||||
match verge_state.0.lock() {
|
let verge = verge_state.0.lock().unwrap();
|
||||||
Ok(verge) => Ok(verge.cur_sysproxy.clone()),
|
Ok(verge.cur_sysproxy.clone())
|
||||||
Err(_) => Err("failed to get verge lock".into()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get the verge config
|
/// get the verge config
|
||||||
@@ -265,42 +267,69 @@ pub fn get_verge_config(verge_state: State<'_, VergeState>) -> Result<VergeConfi
|
|||||||
/// patch the verge config
|
/// patch the verge config
|
||||||
/// this command only save the config and not responsible for other things
|
/// this command only save the config and not responsible for other things
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn patch_verge_config(
|
pub fn patch_verge_config(
|
||||||
payload: VergeConfig,
|
payload: VergeConfig,
|
||||||
|
clash_state: State<'_, ClashState>,
|
||||||
verge_state: State<'_, VergeState>,
|
verge_state: State<'_, VergeState>,
|
||||||
|
profiles_state: State<'_, ProfilesState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
let tun_mode = payload.enable_tun_mode.clone();
|
||||||
|
|
||||||
let mut verge = verge_state.0.lock().unwrap();
|
let mut verge = verge_state.0.lock().unwrap();
|
||||||
verge.patch_config(payload)
|
wrap_err!(verge.patch_config(payload))?;
|
||||||
|
|
||||||
|
// change tun mode
|
||||||
|
if tun_mode.is_some() {
|
||||||
|
let mut clash = clash_state.0.lock().unwrap();
|
||||||
|
let profiles = profiles_state.0.lock().unwrap();
|
||||||
|
|
||||||
|
wrap_err!(clash.tun_mode(tun_mode.unwrap()))?;
|
||||||
|
clash.update_config();
|
||||||
|
wrap_err!(profiles.activate(&clash))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// kill all sidecars when update app
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn kill_sidecars() {
|
||||||
|
api::process::kill_children();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// open app config dir
|
/// open app config dir
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn open_app_dir() -> Result<(), String> {
|
pub fn open_app_dir() -> Result<(), String> {
|
||||||
let app_dir = app_home_dir();
|
let app_dir = dirs::app_home_dir();
|
||||||
|
open_path_cmd(app_dir, "failed to open app dir")
|
||||||
match open_command().arg(app_dir).spawn() {
|
|
||||||
Ok(_) => Ok(()),
|
|
||||||
Err(_) => Err("failed to open logs dir".into()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// open logs dir
|
/// open logs dir
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn open_logs_dir() -> Result<(), String> {
|
pub fn open_logs_dir() -> Result<(), String> {
|
||||||
let log_dir = app_home_dir().join("logs");
|
let log_dir = dirs::app_logs_dir();
|
||||||
|
open_path_cmd(log_dir, "failed to open logs dir")
|
||||||
match open_command().arg(log_dir).spawn() {
|
|
||||||
Ok(_) => Ok(()),
|
|
||||||
Err(_) => Err("failed to open logs dir".into()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get open/explorer command
|
/// get open/explorer command
|
||||||
fn open_command() -> Command {
|
fn open_path_cmd(dir: PathBuf, err_str: &str) -> Result<(), String> {
|
||||||
let open = if cfg!(target_os = "windows") {
|
#[cfg(target_os = "windows")]
|
||||||
"explorer"
|
{
|
||||||
} else {
|
use std::os::windows::process::CommandExt;
|
||||||
"open"
|
|
||||||
};
|
match Command::new("explorer")
|
||||||
Command::new(open)
|
.creation_flags(0x08000000)
|
||||||
|
.arg(dir)
|
||||||
|
.spawn()
|
||||||
|
{
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(_) => Err(err_str.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
match Command::new("open").arg(dir).spawn() {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(_) => Err(err_str.into()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use super::{Profiles, Verge};
|
use super::{Profiles, Verge};
|
||||||
use crate::utils::{config, dirs};
|
use crate::utils::{config, dirs};
|
||||||
|
use anyhow::{bail, Result};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_yaml::{Mapping, Value};
|
use serde_yaml::{Mapping, Value};
|
||||||
use tauri::api::process::{Command, CommandChild, CommandEvent};
|
use tauri::api::process::{Command, CommandChild, CommandEvent};
|
||||||
@@ -31,12 +32,9 @@ pub struct Clash {
|
|||||||
pub sidecar: Option<CommandChild>,
|
pub sidecar: Option<CommandChild>,
|
||||||
}
|
}
|
||||||
|
|
||||||
static CLASH_CONFIG: &str = "config.yaml";
|
|
||||||
|
|
||||||
// todo: be able to change config field
|
|
||||||
impl Clash {
|
impl Clash {
|
||||||
pub fn new() -> Clash {
|
pub fn new() -> Clash {
|
||||||
let config = Clash::get_config();
|
let config = Clash::read_config();
|
||||||
let info = Clash::get_info(&config);
|
let info = Clash::get_info(&config);
|
||||||
|
|
||||||
Clash {
|
Clash {
|
||||||
@@ -46,6 +44,20 @@ impl Clash {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// get clash config
|
||||||
|
fn read_config() -> Mapping {
|
||||||
|
config::read_yaml::<Mapping>(dirs::clash_path())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// save the clash config
|
||||||
|
fn save_config(&self) -> Result<()> {
|
||||||
|
config::save_yaml(
|
||||||
|
dirs::clash_path(),
|
||||||
|
&self.config,
|
||||||
|
Some("# Default Config For Clash Core\n\n"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// parse the clash's config.yaml
|
/// parse the clash's config.yaml
|
||||||
/// get some information
|
/// get some information
|
||||||
fn get_info(clash_config: &Mapping) -> ClashInfo {
|
fn get_info(clash_config: &Mapping) -> ClashInfo {
|
||||||
@@ -100,7 +112,7 @@ impl Clash {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// run clash sidecar
|
/// run clash sidecar
|
||||||
pub fn run_sidecar(&mut self) -> Result<(), String> {
|
pub fn run_sidecar(&mut self) -> Result<()> {
|
||||||
let app_dir = dirs::app_home_dir();
|
let app_dir = dirs::app_home_dir();
|
||||||
let app_dir = app_dir.as_os_str().to_str().unwrap();
|
let app_dir = app_dir.as_os_str().to_str().unwrap();
|
||||||
|
|
||||||
@@ -121,25 +133,23 @@ impl Clash {
|
|||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(err) => Err(err.to_string()),
|
Err(err) => bail!(err.to_string()),
|
||||||
},
|
},
|
||||||
Err(err) => Err(err.to_string()),
|
Err(err) => bail!(err.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// drop clash sidecar
|
/// drop clash sidecar
|
||||||
pub fn drop_sidecar(&mut self) -> Result<(), String> {
|
pub fn drop_sidecar(&mut self) -> Result<()> {
|
||||||
if let Some(sidecar) = self.sidecar.take() {
|
if let Some(sidecar) = self.sidecar.take() {
|
||||||
if let Err(err) = sidecar.kill() {
|
sidecar.kill()?;
|
||||||
return Err(format!("failed to drop clash for \"{}\"", err));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// restart clash sidecar
|
/// restart clash sidecar
|
||||||
/// should reactivate profile after restart
|
/// should reactivate profile after restart
|
||||||
pub fn restart_sidecar(&mut self, profiles: &mut Profiles) -> Result<(), String> {
|
pub fn restart_sidecar(&mut self, profiles: &mut Profiles) -> Result<()> {
|
||||||
self.update_config();
|
self.update_config();
|
||||||
self.drop_sidecar()?;
|
self.drop_sidecar()?;
|
||||||
self.run_sidecar()?;
|
self.run_sidecar()?;
|
||||||
@@ -148,31 +158,17 @@ impl Clash {
|
|||||||
|
|
||||||
/// update the clash info
|
/// update the clash info
|
||||||
pub fn update_config(&mut self) {
|
pub fn update_config(&mut self) {
|
||||||
self.config = Clash::get_config();
|
self.config = Clash::read_config();
|
||||||
self.info = Clash::get_info(&self.config);
|
self.info = Clash::get_info(&self.config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// get clash config
|
|
||||||
fn get_config() -> Mapping {
|
|
||||||
config::read_yaml::<Mapping>(dirs::app_home_dir().join(CLASH_CONFIG))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// save the clash config
|
|
||||||
fn save_config(&self) -> Result<(), String> {
|
|
||||||
config::save_yaml(
|
|
||||||
dirs::app_home_dir().join(CLASH_CONFIG),
|
|
||||||
&self.config,
|
|
||||||
Some("# Default Config For Clash Core\n\n"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// patch update the clash config
|
/// patch update the clash config
|
||||||
pub fn patch_config(
|
pub fn patch_config(
|
||||||
&mut self,
|
&mut self,
|
||||||
patch: Mapping,
|
patch: Mapping,
|
||||||
verge: &mut Verge,
|
verge: &mut Verge,
|
||||||
profiles: &mut Profiles,
|
profiles: &mut Profiles,
|
||||||
) -> Result<(), String> {
|
) -> Result<()> {
|
||||||
for (key, value) in patch.iter() {
|
for (key, value) in patch.iter() {
|
||||||
let value = value.clone();
|
let value = value.clone();
|
||||||
let key_str = key.as_str().clone().unwrap_or("");
|
let key_str = key.as_str().clone().unwrap_or("");
|
||||||
@@ -203,6 +199,48 @@ impl Clash {
|
|||||||
}
|
}
|
||||||
self.save_config()
|
self.save_config()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// enable tun mode
|
||||||
|
/// only revise the config and restart the
|
||||||
|
pub fn tun_mode(&mut self, enable: bool) -> Result<()> {
|
||||||
|
let tun_key = Value::String("tun".into());
|
||||||
|
let tun_val = self.config.get(&tun_key);
|
||||||
|
|
||||||
|
let mut new_val = Mapping::new();
|
||||||
|
|
||||||
|
if tun_val.is_some() && tun_val.as_ref().unwrap().is_mapping() {
|
||||||
|
new_val = tun_val.as_ref().unwrap().as_mapping().unwrap().clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! revise {
|
||||||
|
($map: expr, $key: expr, $val: expr) => {
|
||||||
|
let ret_key = Value::String($key.into());
|
||||||
|
if $map.contains_key(&ret_key) {
|
||||||
|
$map[&ret_key] = $val;
|
||||||
|
} else {
|
||||||
|
$map.insert(ret_key, $val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! append {
|
||||||
|
($map: expr, $key: expr, $val: expr) => {
|
||||||
|
let ret_key = Value::String($key.into());
|
||||||
|
if !$map.contains_key(&ret_key) {
|
||||||
|
$map.insert(ret_key, $val);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
revise!(new_val, "enable", Value::from(enable));
|
||||||
|
append!(new_val, "stack", Value::from("gvisor"));
|
||||||
|
append!(new_val, "auto-route", Value::from(true));
|
||||||
|
append!(new_val, "auto-detect-interface", Value::from(true));
|
||||||
|
|
||||||
|
revise!(self.config, "tun", Value::from(new_val));
|
||||||
|
|
||||||
|
self.save_config()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Clash {
|
impl Default for Clash {
|
||||||
@@ -214,7 +252,7 @@ impl Default for Clash {
|
|||||||
impl Drop for Clash {
|
impl Drop for Clash {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let Err(err) = self.drop_sidecar() {
|
if let Err(err) = self.drop_sidecar() {
|
||||||
log::error!("{}", err);
|
log::error!("{err}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
mod clash;
|
mod clash;
|
||||||
|
mod prfitem;
|
||||||
mod profiles;
|
mod profiles;
|
||||||
mod verge;
|
mod verge;
|
||||||
|
|
||||||
|
|||||||
332
src-tauri/src/core/prfitem.rs
Normal file
@@ -0,0 +1,332 @@
|
|||||||
|
//! Todos
|
||||||
|
//! refactor the profiles
|
||||||
|
|
||||||
|
use crate::utils::{config, dirs};
|
||||||
|
use anyhow::{bail, Result};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_yaml::{Mapping, Value};
|
||||||
|
use std::{fs, str::FromStr};
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||||
|
pub struct PrfItem {
|
||||||
|
pub uid: Option<String>,
|
||||||
|
|
||||||
|
/// profile item type
|
||||||
|
/// enum value: remote | local | script | merge
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub itype: Option<String>,
|
||||||
|
|
||||||
|
/// profile name
|
||||||
|
pub name: Option<String>,
|
||||||
|
|
||||||
|
/// profile description
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub desc: Option<String>,
|
||||||
|
|
||||||
|
/// profile file
|
||||||
|
pub file: Option<String>,
|
||||||
|
|
||||||
|
/// source url
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub url: Option<String>,
|
||||||
|
|
||||||
|
/// selected infomation
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub selected: Option<Vec<PrfSelected>>,
|
||||||
|
|
||||||
|
/// user info
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub extra: Option<PrfExtra>,
|
||||||
|
|
||||||
|
/// updated time
|
||||||
|
pub updated: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||||
|
pub struct PrfSelected {
|
||||||
|
pub name: Option<String>,
|
||||||
|
pub now: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, Copy, Deserialize, Serialize)]
|
||||||
|
pub struct PrfExtra {
|
||||||
|
pub upload: usize,
|
||||||
|
pub download: usize,
|
||||||
|
pub total: usize,
|
||||||
|
pub expire: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
type FileData = String;
|
||||||
|
|
||||||
|
impl PrfItem {
|
||||||
|
pub fn gen_now() -> usize {
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_secs() as _
|
||||||
|
}
|
||||||
|
|
||||||
|
/// generate the uid
|
||||||
|
pub fn gen_uid(prefix: &str) -> String {
|
||||||
|
let now = Self::gen_now();
|
||||||
|
format!("{prefix}{now}")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// parse the string
|
||||||
|
fn parse_str<T: FromStr>(target: &str, key: &str) -> Option<T> {
|
||||||
|
match target.find(key) {
|
||||||
|
Some(idx) => {
|
||||||
|
let idx = idx + key.len();
|
||||||
|
let value = &target[idx..];
|
||||||
|
match match value.split(';').nth(0) {
|
||||||
|
Some(value) => value.trim().parse(),
|
||||||
|
None => value.trim().parse(),
|
||||||
|
} {
|
||||||
|
Ok(r) => Some(r),
|
||||||
|
Err(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn from_url(url: &str, with_proxy: bool) -> Result<(Self, FileData)> {
|
||||||
|
let mut builder = reqwest::ClientBuilder::new();
|
||||||
|
|
||||||
|
if !with_proxy {
|
||||||
|
builder = builder.no_proxy();
|
||||||
|
}
|
||||||
|
|
||||||
|
let resp = builder.build()?.get(url).send().await?;
|
||||||
|
let header = resp.headers();
|
||||||
|
|
||||||
|
// parse the Subscription Userinfo
|
||||||
|
let extra = match header.get("Subscription-Userinfo") {
|
||||||
|
Some(value) => {
|
||||||
|
let sub_info = value.to_str().unwrap_or("");
|
||||||
|
|
||||||
|
Some(PrfExtra {
|
||||||
|
upload: PrfItem::parse_str(sub_info, "upload=").unwrap_or(0),
|
||||||
|
download: PrfItem::parse_str(sub_info, "download=").unwrap_or(0),
|
||||||
|
total: PrfItem::parse_str(sub_info, "total=").unwrap_or(0),
|
||||||
|
expire: PrfItem::parse_str(sub_info, "expire=").unwrap_or(0),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let uid = PrfItem::gen_uid("r");
|
||||||
|
let file = format!("{uid}.yaml");
|
||||||
|
let name = uid.clone();
|
||||||
|
let data = resp.text_with_charset("utf-8").await?;
|
||||||
|
|
||||||
|
let item = PrfItem {
|
||||||
|
uid: Some(uid),
|
||||||
|
itype: Some("remote".into()),
|
||||||
|
name: Some(name),
|
||||||
|
desc: None,
|
||||||
|
file: Some(file),
|
||||||
|
url: Some(url.into()),
|
||||||
|
selected: None,
|
||||||
|
extra,
|
||||||
|
updated: Some(PrfItem::gen_now()),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok((item, data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// ## Profiles Config
|
||||||
|
///
|
||||||
|
/// Define the `profiles.yaml` schema
|
||||||
|
///
|
||||||
|
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||||
|
pub struct Profiles {
|
||||||
|
/// same as PrfConfig.current
|
||||||
|
current: Option<String>,
|
||||||
|
|
||||||
|
/// same as PrfConfig.chain
|
||||||
|
chain: Option<Vec<String>>,
|
||||||
|
|
||||||
|
/// profile list
|
||||||
|
items: Option<Vec<PrfItem>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Profiles {
|
||||||
|
pub fn new() -> Profiles {
|
||||||
|
Profiles::read_file()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// read the config from the file
|
||||||
|
pub fn read_file() -> Self {
|
||||||
|
config::read_yaml::<Self>(dirs::profiles_path())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// save the config to the file
|
||||||
|
pub fn save_file(&self) -> Result<()> {
|
||||||
|
config::save_yaml(
|
||||||
|
dirs::profiles_path(),
|
||||||
|
self,
|
||||||
|
Some("# Profiles Config for Clash Verge\n\n"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// get the current uid
|
||||||
|
pub fn get_current(&self) -> Option<String> {
|
||||||
|
self.current.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// only change the main to the target id
|
||||||
|
pub fn put_current(&mut self, uid: String) -> Result<()> {
|
||||||
|
if self.items.is_none() {
|
||||||
|
self.items = Some(vec![]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let items = self.items.as_ref().unwrap();
|
||||||
|
let some_uid = Some(uid.clone());
|
||||||
|
|
||||||
|
for each in items.iter() {
|
||||||
|
if each.uid == some_uid {
|
||||||
|
self.current = some_uid;
|
||||||
|
return self.save_file();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bail!("invalid uid \"{uid}\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// append new item
|
||||||
|
/// return the new item's uid
|
||||||
|
pub fn append_item(&mut self, item: PrfItem) -> Result<()> {
|
||||||
|
if item.uid.is_none() {
|
||||||
|
bail!("the uid should not be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut items = self.items.take().unwrap_or(vec![]);
|
||||||
|
items.push(item);
|
||||||
|
self.items = Some(items);
|
||||||
|
self.save_file()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// update the item's value
|
||||||
|
pub fn patch_item(&mut self, uid: String, item: PrfItem) -> Result<()> {
|
||||||
|
let mut items = self.items.take().unwrap_or(vec![]);
|
||||||
|
|
||||||
|
macro_rules! patch {
|
||||||
|
($lv: expr, $rv: expr, $key: tt) => {
|
||||||
|
if ($rv.$key).is_some() {
|
||||||
|
$lv.$key = $rv.$key;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
for mut each in items.iter_mut() {
|
||||||
|
if each.uid == Some(uid.clone()) {
|
||||||
|
patch!(each, item, itype);
|
||||||
|
patch!(each, item, name);
|
||||||
|
patch!(each, item, desc);
|
||||||
|
patch!(each, item, file);
|
||||||
|
patch!(each, item, url);
|
||||||
|
patch!(each, item, selected);
|
||||||
|
patch!(each, item, extra);
|
||||||
|
|
||||||
|
each.updated = Some(PrfItem::gen_now());
|
||||||
|
|
||||||
|
self.items = Some(items);
|
||||||
|
return self.save_file();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.items = Some(items);
|
||||||
|
bail!("failed to found the uid \"{uid}\"")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// delete item
|
||||||
|
/// if delete the main then return true
|
||||||
|
pub fn delete_item(&mut self, uid: String) -> Result<bool> {
|
||||||
|
let current = self.current.as_ref().unwrap_or(&uid);
|
||||||
|
let current = current.clone();
|
||||||
|
|
||||||
|
let mut items = self.items.take().unwrap_or(vec![]);
|
||||||
|
let mut index = None;
|
||||||
|
|
||||||
|
// get the index
|
||||||
|
for i in 0..items.len() {
|
||||||
|
if items[i].uid == Some(uid.clone()) {
|
||||||
|
index = Some(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(index) = index {
|
||||||
|
items.remove(index).file.map(|file| {
|
||||||
|
let path = dirs::app_profiles_dir().join(file);
|
||||||
|
if path.exists() {
|
||||||
|
let _ = fs::remove_file(path);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete the original uid
|
||||||
|
if current == uid {
|
||||||
|
self.current = match items.len() > 0 {
|
||||||
|
true => items[0].uid.clone(),
|
||||||
|
false => None,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
self.items = Some(items);
|
||||||
|
self.save_file()?;
|
||||||
|
Ok(current == uid)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// only generate config mapping
|
||||||
|
pub fn gen_activate(&self) -> Result<Mapping> {
|
||||||
|
if self.current.is_none() {
|
||||||
|
bail!("invalid main uid on profiles");
|
||||||
|
}
|
||||||
|
|
||||||
|
let current = self.current.clone().unwrap();
|
||||||
|
|
||||||
|
for item in self.items.as_ref().unwrap().iter() {
|
||||||
|
if item.uid == Some(current.clone()) {
|
||||||
|
let file_path = match item.file.clone() {
|
||||||
|
Some(file) => dirs::app_profiles_dir().join(file),
|
||||||
|
None => bail!("failed to get the file field"),
|
||||||
|
};
|
||||||
|
|
||||||
|
if !file_path.exists() {
|
||||||
|
bail!("failed to read the file \"{}\"", file_path.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut new_config = Mapping::new();
|
||||||
|
let def_config = config::read_yaml::<Mapping>(file_path.clone());
|
||||||
|
|
||||||
|
// Only the following fields are allowed:
|
||||||
|
// proxies/proxy-providers/proxy-groups/rule-providers/rules
|
||||||
|
let valid_keys = vec![
|
||||||
|
"proxies",
|
||||||
|
"proxy-providers",
|
||||||
|
"proxy-groups",
|
||||||
|
"rule-providers",
|
||||||
|
"rules",
|
||||||
|
];
|
||||||
|
|
||||||
|
valid_keys.iter().for_each(|key| {
|
||||||
|
let key = Value::String(key.to_string());
|
||||||
|
if def_config.contains_key(&key) {
|
||||||
|
let value = def_config[&key].clone();
|
||||||
|
new_config.insert(key, value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return Ok(new_config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bail!("failed to found the uid \"{current}\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
use super::{Clash, ClashInfo};
|
use super::{Clash, ClashInfo};
|
||||||
use crate::utils::{config, dirs};
|
use crate::utils::{config, dirs, tmpl};
|
||||||
|
use anyhow::{bail, Result};
|
||||||
use reqwest::header::HeaderMap;
|
use reqwest::header::HeaderMap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_yaml::{Mapping, Value};
|
use serde_yaml::{Mapping, Value};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env::temp_dir;
|
use std::fs::{remove_file, File};
|
||||||
use std::fs::File;
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
@@ -24,18 +24,30 @@ pub struct Profiles {
|
|||||||
pub struct ProfileItem {
|
pub struct ProfileItem {
|
||||||
/// profile name
|
/// profile name
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
|
|
||||||
/// profile description
|
/// profile description
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub desc: Option<String>,
|
pub desc: Option<String>,
|
||||||
|
|
||||||
/// profile file
|
/// profile file
|
||||||
pub file: Option<String>,
|
pub file: Option<String>,
|
||||||
|
|
||||||
/// current mode
|
/// current mode
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub mode: Option<String>,
|
pub mode: Option<String>,
|
||||||
|
|
||||||
/// source url
|
/// source url
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub url: Option<String>,
|
pub url: Option<String>,
|
||||||
|
|
||||||
/// selected infomation
|
/// selected infomation
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub selected: Option<Vec<ProfileSelected>>,
|
pub selected: Option<Vec<ProfileSelected>>,
|
||||||
|
|
||||||
/// user info
|
/// user info
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub extra: Option<ProfileExtra>,
|
pub extra: Option<ProfileExtra>,
|
||||||
|
|
||||||
/// updated time
|
/// updated time
|
||||||
pub updated: Option<usize>,
|
pub updated: Option<usize>,
|
||||||
}
|
}
|
||||||
@@ -60,32 +72,29 @@ pub struct ProfileResponse {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
pub file: String,
|
pub file: String,
|
||||||
pub data: String,
|
pub data: String,
|
||||||
pub extra: ProfileExtra,
|
pub extra: Option<ProfileExtra>,
|
||||||
}
|
}
|
||||||
|
|
||||||
static PROFILE_YAML: &str = "profiles.yaml";
|
|
||||||
static PROFILE_TEMP: &str = "clash-verge-runtime.yaml";
|
|
||||||
|
|
||||||
impl Profiles {
|
impl Profiles {
|
||||||
/// read the config from the file
|
/// read the config from the file
|
||||||
pub fn read_file() -> Self {
|
pub fn read_file() -> Self {
|
||||||
config::read_yaml::<Profiles>(dirs::app_home_dir().join(PROFILE_YAML))
|
config::read_yaml::<Profiles>(dirs::profiles_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// save the config to the file
|
/// save the config to the file
|
||||||
pub fn save_file(&self) -> Result<(), String> {
|
pub fn save_file(&self) -> Result<()> {
|
||||||
config::save_yaml(
|
config::save_yaml(
|
||||||
dirs::app_home_dir().join(PROFILE_YAML),
|
dirs::profiles_path(),
|
||||||
self,
|
self,
|
||||||
Some("# Profiles Config for Clash Verge\n\n"),
|
Some("# Profiles Config for Clash Verge\n\n"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// sync the config between file and memory
|
/// sync the config between file and memory
|
||||||
pub fn sync_file(&mut self) -> Result<(), String> {
|
pub fn sync_file(&mut self) -> Result<()> {
|
||||||
let data = config::read_yaml::<Self>(dirs::app_home_dir().join(PROFILE_YAML));
|
let data = config::read_yaml::<Self>(dirs::profiles_path());
|
||||||
if data.current.is_none() {
|
if data.current.is_none() {
|
||||||
Err("failed to read profiles.yaml".into())
|
bail!("failed to read profiles.yaml")
|
||||||
} else {
|
} else {
|
||||||
self.current = data.current;
|
self.current = data.current;
|
||||||
self.items = data.items;
|
self.items = data.items;
|
||||||
@@ -95,9 +104,9 @@ impl Profiles {
|
|||||||
|
|
||||||
/// import the new profile from the url
|
/// import the new profile from the url
|
||||||
/// and update the config file
|
/// and update the config file
|
||||||
pub fn import_from_url(&mut self, url: String, result: ProfileResponse) -> Result<(), String> {
|
pub fn import_from_url(&mut self, url: String, result: ProfileResponse) -> Result<()> {
|
||||||
// save the profile file
|
// save the profile file
|
||||||
let path = dirs::app_home_dir().join("profiles").join(&result.file);
|
let path = dirs::app_profiles_dir().join(&result.file);
|
||||||
let file_data = result.data.as_bytes();
|
let file_data = result.data.as_bytes();
|
||||||
File::create(path).unwrap().write(file_data).unwrap();
|
File::create(path).unwrap().write(file_data).unwrap();
|
||||||
|
|
||||||
@@ -117,7 +126,7 @@ impl Profiles {
|
|||||||
mode: Some(format!("rule")),
|
mode: Some(format!("rule")),
|
||||||
url: Some(url),
|
url: Some(url),
|
||||||
selected: Some(vec![]),
|
selected: Some(vec![]),
|
||||||
extra: Some(result.extra),
|
extra: result.extra,
|
||||||
updated: Some(now as usize),
|
updated: Some(now as usize),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -130,11 +139,11 @@ impl Profiles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// set the current and save to file
|
/// set the current and save to file
|
||||||
pub fn put_current(&mut self, index: usize) -> Result<(), String> {
|
pub fn put_current(&mut self, index: usize) -> Result<()> {
|
||||||
let items = self.items.take().unwrap_or(vec![]);
|
let items = self.items.take().unwrap_or(vec![]);
|
||||||
|
|
||||||
if index >= items.len() {
|
if index >= items.len() {
|
||||||
return Err("the index out of bound".into());
|
bail!("the index out of bound");
|
||||||
}
|
}
|
||||||
|
|
||||||
self.items = Some(items);
|
self.items = Some(items);
|
||||||
@@ -144,7 +153,7 @@ impl Profiles {
|
|||||||
|
|
||||||
/// append new item
|
/// append new item
|
||||||
/// return the new item's index
|
/// return the new item's index
|
||||||
pub fn append_item(&mut self, name: String, desc: String) -> Result<(usize, PathBuf), String> {
|
pub fn append_item(&mut self, name: String, desc: String) -> Result<(usize, PathBuf)> {
|
||||||
let mut items = self.items.take().unwrap_or(vec![]);
|
let mut items = self.items.take().unwrap_or(vec![]);
|
||||||
|
|
||||||
// create a new profile file
|
// create a new profile file
|
||||||
@@ -153,18 +162,9 @@ impl Profiles {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.as_secs();
|
.as_secs();
|
||||||
let file = format!("{}.yaml", now);
|
let file = format!("{}.yaml", now);
|
||||||
let path = dirs::app_home_dir().join("profiles").join(&file);
|
let path = dirs::app_profiles_dir().join(&file);
|
||||||
|
|
||||||
let file_data = b"# Profile Template for clash verge\n
|
match File::create(&path).unwrap().write(tmpl::ITEM_CONFIG) {
|
||||||
# proxies defination (optional, the same as clash)
|
|
||||||
proxies:\n
|
|
||||||
# proxy-groups (optional, the same as clash)
|
|
||||||
proxy-groups:\n
|
|
||||||
# rules (optional, the same as clash)
|
|
||||||
rules:\n\n
|
|
||||||
";
|
|
||||||
|
|
||||||
match File::create(&path).unwrap().write(file_data) {
|
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
items.push(ProfileItem {
|
items.push(ProfileItem {
|
||||||
name: Some(name),
|
name: Some(name),
|
||||||
@@ -181,14 +181,14 @@ rules:\n\n
|
|||||||
self.items = Some(items);
|
self.items = Some(items);
|
||||||
Ok((index, path))
|
Ok((index, path))
|
||||||
}
|
}
|
||||||
Err(_) => Err("failed to create file".into()),
|
Err(_) => bail!("failed to create file"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// update the target profile
|
/// update the target profile
|
||||||
/// and save to config file
|
/// and save to config file
|
||||||
/// only support the url item
|
/// only support the url item
|
||||||
pub fn update_item(&mut self, index: usize, result: ProfileResponse) -> Result<(), String> {
|
pub fn update_item(&mut self, index: usize, result: ProfileResponse) -> Result<()> {
|
||||||
let mut items = self.items.take().unwrap_or(vec![]);
|
let mut items = self.items.take().unwrap_or(vec![]);
|
||||||
|
|
||||||
let now = SystemTime::now()
|
let now = SystemTime::now()
|
||||||
@@ -198,12 +198,12 @@ rules:\n\n
|
|||||||
|
|
||||||
// update file
|
// update file
|
||||||
let file_path = &items[index].file.as_ref().unwrap();
|
let file_path = &items[index].file.as_ref().unwrap();
|
||||||
let file_path = dirs::app_home_dir().join("profiles").join(file_path);
|
let file_path = dirs::app_profiles_dir().join(file_path);
|
||||||
let file_data = result.data.as_bytes();
|
let file_data = result.data.as_bytes();
|
||||||
File::create(file_path).unwrap().write(file_data).unwrap();
|
File::create(file_path).unwrap().write(file_data).unwrap();
|
||||||
|
|
||||||
items[index].name = Some(result.name);
|
items[index].name = Some(result.name);
|
||||||
items[index].extra = Some(result.extra);
|
items[index].extra = result.extra;
|
||||||
items[index].updated = Some(now);
|
items[index].updated = Some(now);
|
||||||
|
|
||||||
self.items = Some(items);
|
self.items = Some(items);
|
||||||
@@ -211,10 +211,10 @@ rules:\n\n
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// patch item
|
/// patch item
|
||||||
pub fn patch_item(&mut self, index: usize, profile: ProfileItem) -> Result<(), String> {
|
pub fn patch_item(&mut self, index: usize, profile: ProfileItem) -> Result<()> {
|
||||||
let mut items = self.items.take().unwrap_or(vec![]);
|
let mut items = self.items.take().unwrap_or(vec![]);
|
||||||
if index >= items.len() {
|
if index >= items.len() {
|
||||||
return Err("index out of bound".into());
|
bail!("index out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
if profile.name.is_some() {
|
if profile.name.is_some() {
|
||||||
@@ -241,15 +241,26 @@ rules:\n\n
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// delete the item
|
/// delete the item
|
||||||
pub fn delete_item(&mut self, index: usize) -> Result<bool, String> {
|
pub fn delete_item(&mut self, index: usize) -> Result<bool> {
|
||||||
let mut current = self.current.clone().unwrap_or(0);
|
let mut current = self.current.clone().unwrap_or(0);
|
||||||
let mut items = self.items.clone().unwrap_or(vec![]);
|
let mut items = self.items.clone().unwrap_or(vec![]);
|
||||||
|
|
||||||
if index >= items.len() {
|
if index >= items.len() {
|
||||||
return Err("index out of bound".into());
|
bail!("index out of range");
|
||||||
}
|
}
|
||||||
|
|
||||||
items.remove(index);
|
let mut rm_item = items.remove(index);
|
||||||
|
|
||||||
|
// delete the file
|
||||||
|
if let Some(file) = rm_item.file.take() {
|
||||||
|
let file_path = dirs::app_profiles_dir().join(file);
|
||||||
|
|
||||||
|
if file_path.exists() {
|
||||||
|
if let Err(err) = remove_file(file_path) {
|
||||||
|
log::error!("{err}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut should_change = false;
|
let mut should_change = false;
|
||||||
|
|
||||||
@@ -270,33 +281,34 @@ rules:\n\n
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// activate current profile
|
/// activate current profile
|
||||||
pub fn activate(&self, clash: &Clash) -> Result<(), String> {
|
pub fn activate(&self, clash: &Clash) -> Result<()> {
|
||||||
let current = self.current.unwrap_or(0);
|
let current = self.current.unwrap_or(0);
|
||||||
match self.items.clone() {
|
match self.items.clone() {
|
||||||
Some(items) => {
|
Some(items) => {
|
||||||
if current >= items.len() {
|
if current >= items.len() {
|
||||||
return Err("the index out of bound".into());
|
bail!("the index out of bound");
|
||||||
}
|
}
|
||||||
|
|
||||||
let profile = items[current].clone();
|
let profile = items[current].clone();
|
||||||
let clash_config = clash.config.clone();
|
let clash_config = clash.config.clone();
|
||||||
let clash_info = clash.info.clone();
|
let clash_info = clash.info.clone();
|
||||||
|
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
let mut count = 5; // retry times
|
let mut count = 5; // retry times
|
||||||
let mut err = String::from("");
|
let mut err = None;
|
||||||
while count > 0 {
|
while count > 0 {
|
||||||
match activate_profile(&profile, &clash_config, &clash_info).await {
|
match activate_profile(&profile, &clash_config, &clash_info).await {
|
||||||
Ok(_) => return,
|
Ok(_) => return,
|
||||||
Err(e) => err = e,
|
Err(e) => err = Some(e),
|
||||||
}
|
}
|
||||||
count -= 1;
|
count -= 1;
|
||||||
}
|
}
|
||||||
log::error!("failed to activate for `{}`", err);
|
log::error!("failed to activate for `{}`", err.unwrap());
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
None => Err("empty profiles".into()),
|
None => bail!("empty profiles"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -306,28 +318,30 @@ pub async fn activate_profile(
|
|||||||
profile_item: &ProfileItem,
|
profile_item: &ProfileItem,
|
||||||
clash_config: &Mapping,
|
clash_config: &Mapping,
|
||||||
clash_info: &ClashInfo,
|
clash_info: &ClashInfo,
|
||||||
) -> Result<(), String> {
|
) -> Result<()> {
|
||||||
// temp profile's path
|
// temp profile's path
|
||||||
let temp_path = temp_dir().join(PROFILE_TEMP);
|
let temp_path = dirs::profiles_temp_path();
|
||||||
|
|
||||||
// generate temp profile
|
// generate temp profile
|
||||||
{
|
{
|
||||||
let file_name = match profile_item.file.clone() {
|
let file_name = match profile_item.file.clone() {
|
||||||
Some(file_name) => file_name,
|
Some(file_name) => file_name,
|
||||||
None => return Err("profile item should have `file` field".into()),
|
None => bail!("profile item should have `file` field"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let file_path = dirs::app_home_dir().join("profiles").join(file_name);
|
let file_path = dirs::app_profiles_dir().join(file_name);
|
||||||
if !file_path.exists() {
|
if !file_path.exists() {
|
||||||
return Err(format!(
|
bail!(
|
||||||
"profile `{}` not exists",
|
"profile `{}` not exists",
|
||||||
file_path.as_os_str().to_str().unwrap()
|
file_path.as_os_str().to_str().unwrap()
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// begin to generate the new profile config
|
// begin to generate the new profile config
|
||||||
let def_config = config::read_yaml::<Mapping>(file_path.clone());
|
let def_config = config::read_yaml::<Mapping>(file_path.clone());
|
||||||
let mut new_config = Mapping::new();
|
|
||||||
|
// use the clash config except 5 keys below
|
||||||
|
let mut new_config = clash_config.clone();
|
||||||
|
|
||||||
// Only the following fields are allowed:
|
// Only the following fields are allowed:
|
||||||
// proxies/proxy-providers/proxy-groups/rule-providers/rules
|
// proxies/proxy-providers/proxy-groups/rule-providers/rules
|
||||||
@@ -346,24 +360,6 @@ pub async fn activate_profile(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// add some of the clash `config.yaml` config to it
|
|
||||||
let valid_keys = vec![
|
|
||||||
"mixed-port",
|
|
||||||
"log-level",
|
|
||||||
"allow-lan",
|
|
||||||
"external-controller",
|
|
||||||
"secret",
|
|
||||||
"mode",
|
|
||||||
"ipv6",
|
|
||||||
];
|
|
||||||
valid_keys.iter().for_each(|key| {
|
|
||||||
let key = Value::String(key.to_string());
|
|
||||||
if clash_config.contains_key(&key) {
|
|
||||||
let value = clash_config[&key].clone();
|
|
||||||
new_config.insert(key, value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
config::save_yaml(
|
config::save_yaml(
|
||||||
temp_path.clone(),
|
temp_path.clone(),
|
||||||
&new_config,
|
&new_config,
|
||||||
@@ -386,12 +382,13 @@ pub async fn activate_profile(
|
|||||||
let mut data = HashMap::new();
|
let mut data = HashMap::new();
|
||||||
data.insert("path", temp_path.as_os_str().to_str().unwrap());
|
data.insert("path", temp_path.as_os_str().to_str().unwrap());
|
||||||
|
|
||||||
let client = match reqwest::ClientBuilder::new().no_proxy().build() {
|
let client = reqwest::ClientBuilder::new().no_proxy().build()?;
|
||||||
Ok(c) => c,
|
|
||||||
Err(_) => return Err("failed to create http::put".into()),
|
client
|
||||||
};
|
.put(server)
|
||||||
match client.put(server).headers(headers).json(&data).send().await {
|
.headers(headers)
|
||||||
Ok(_) => Ok(()),
|
.json(&data)
|
||||||
Err(err) => Err(format!("request failed `{}`", err.to_string())),
|
.send()
|
||||||
}
|
.await?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
use crate::utils::{config, dirs, sysopt::SysProxyConfig};
|
use crate::{
|
||||||
|
core::Clash,
|
||||||
|
utils::{config, dirs, sysopt::SysProxyConfig},
|
||||||
|
};
|
||||||
|
use anyhow::{bail, Result};
|
||||||
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
|
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tauri::api::path::resource_dir;
|
use std::sync::Arc;
|
||||||
|
use tauri::{async_runtime::Mutex, utils::platform::current_exe};
|
||||||
|
|
||||||
/// ### `verge.yaml` schema
|
/// ### `verge.yaml` schema
|
||||||
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||||
@@ -13,27 +18,37 @@ pub struct VergeConfig {
|
|||||||
/// maybe be able to set the alpha
|
/// maybe be able to set the alpha
|
||||||
pub theme_blur: Option<bool>,
|
pub theme_blur: Option<bool>,
|
||||||
|
|
||||||
|
/// enable traffic graph default is true
|
||||||
|
pub traffic_graph: Option<bool>,
|
||||||
|
|
||||||
|
/// clash tun mode
|
||||||
|
pub enable_tun_mode: Option<bool>,
|
||||||
|
|
||||||
/// can the app auto startup
|
/// can the app auto startup
|
||||||
pub enable_auto_launch: Option<bool>,
|
pub enable_auto_launch: Option<bool>,
|
||||||
|
|
||||||
/// set system proxy
|
/// set system proxy
|
||||||
pub enable_system_proxy: Option<bool>,
|
pub enable_system_proxy: Option<bool>,
|
||||||
|
|
||||||
|
/// enable proxy guard
|
||||||
|
pub enable_proxy_guard: Option<bool>,
|
||||||
|
|
||||||
/// set system proxy bypass
|
/// set system proxy bypass
|
||||||
pub system_proxy_bypass: Option<String>,
|
pub system_proxy_bypass: Option<String>,
|
||||||
}
|
|
||||||
|
|
||||||
static VERGE_CONFIG: &str = "verge.yaml";
|
/// proxy guard duration
|
||||||
|
pub proxy_guard_duration: Option<u64>,
|
||||||
|
}
|
||||||
|
|
||||||
impl VergeConfig {
|
impl VergeConfig {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
config::read_yaml::<VergeConfig>(dirs::app_home_dir().join(VERGE_CONFIG))
|
config::read_yaml::<VergeConfig>(dirs::verge_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Save Verge App Config
|
/// Save Verge App Config
|
||||||
pub fn save_file(&self) -> Result<(), String> {
|
pub fn save_file(&self) -> Result<()> {
|
||||||
config::save_yaml(
|
config::save_yaml(
|
||||||
dirs::app_home_dir().join(VERGE_CONFIG),
|
dirs::verge_path(),
|
||||||
self,
|
self,
|
||||||
Some("# The Config for Clash Verge App\n\n"),
|
Some("# The Config for Clash Verge App\n\n"),
|
||||||
)
|
)
|
||||||
@@ -50,6 +65,9 @@ pub struct Verge {
|
|||||||
pub cur_sysproxy: Option<SysProxyConfig>,
|
pub cur_sysproxy: Option<SysProxyConfig>,
|
||||||
|
|
||||||
pub auto_launch: Option<AutoLaunch>,
|
pub auto_launch: Option<AutoLaunch>,
|
||||||
|
|
||||||
|
/// record whether the guard async is running or not
|
||||||
|
guard_state: Arc<Mutex<bool>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Verge {
|
impl Default for Verge {
|
||||||
@@ -65,6 +83,7 @@ impl Verge {
|
|||||||
old_sysproxy: None,
|
old_sysproxy: None,
|
||||||
cur_sysproxy: None,
|
cur_sysproxy: None,
|
||||||
auto_launch: None,
|
auto_launch: None,
|
||||||
|
guard_state: Arc::new(Mutex::new(false)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +108,9 @@ impl Verge {
|
|||||||
|
|
||||||
self.cur_sysproxy = Some(sysproxy);
|
self.cur_sysproxy = Some(sysproxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// launchs the system proxy guard
|
||||||
|
Verge::guard_proxy(self.guard_state.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// reset the sysproxy
|
/// reset the sysproxy
|
||||||
@@ -102,13 +124,11 @@ impl Verge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// init the auto launch
|
/// init the auto launch
|
||||||
pub fn init_launch(&mut self, package_info: &tauri::PackageInfo) {
|
pub fn init_launch(&mut self) {
|
||||||
let app_name = "clash-verge";
|
let app_exe = current_exe().unwrap();
|
||||||
let app_path = get_app_path(app_name);
|
let app_exe = dunce::canonicalize(app_exe).unwrap();
|
||||||
let app_path = resource_dir(package_info, &tauri::Env::default())
|
let app_name = app_exe.file_stem().unwrap().to_str().unwrap();
|
||||||
.unwrap()
|
let app_path = app_exe.as_os_str().to_str().unwrap();
|
||||||
.join(app_path);
|
|
||||||
let app_path = app_path.as_os_str().to_str().unwrap();
|
|
||||||
|
|
||||||
let auto = AutoLaunchBuilder::new()
|
let auto = AutoLaunchBuilder::new()
|
||||||
.set_app_name(app_name)
|
.set_app_name(app_name)
|
||||||
@@ -119,30 +139,28 @@ impl Verge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// sync the startup when run the app
|
/// sync the startup when run the app
|
||||||
pub fn sync_launch(&self) -> Result<(), String> {
|
pub fn sync_launch(&self) -> Result<()> {
|
||||||
let enable = self.config.enable_auto_launch.clone().unwrap_or(false);
|
let enable = self.config.enable_auto_launch.clone().unwrap_or(false);
|
||||||
if !enable {
|
if !enable {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.auto_launch.is_none() {
|
if self.auto_launch.is_none() {
|
||||||
return Err("should init the auto launch first".into());
|
bail!("should init the auto launch first");
|
||||||
}
|
}
|
||||||
|
|
||||||
let auto_launch = self.auto_launch.clone().unwrap();
|
let auto_launch = self.auto_launch.clone().unwrap();
|
||||||
|
|
||||||
let is_enabled = auto_launch.is_enabled().unwrap_or(false);
|
let is_enabled = auto_launch.is_enabled().unwrap_or(false);
|
||||||
if !is_enabled {
|
if !is_enabled {
|
||||||
if let Err(_) = auto_launch.enable() {
|
auto_launch.enable()?;
|
||||||
return Err("failed to enable auto-launch".into());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// update the startup
|
/// update the startup
|
||||||
fn update_launch(&mut self, enable: bool) -> Result<(), String> {
|
fn update_launch(&mut self, enable: bool) -> Result<()> {
|
||||||
let conf_enable = self.config.enable_auto_launch.clone().unwrap_or(false);
|
let conf_enable = self.config.enable_auto_launch.clone().unwrap_or(false);
|
||||||
|
|
||||||
if enable == conf_enable {
|
if enable == conf_enable {
|
||||||
@@ -151,43 +169,18 @@ impl Verge {
|
|||||||
|
|
||||||
let auto_launch = self.auto_launch.clone().unwrap();
|
let auto_launch = self.auto_launch.clone().unwrap();
|
||||||
|
|
||||||
let result = if enable {
|
match enable {
|
||||||
auto_launch.enable()
|
true => auto_launch.enable()?,
|
||||||
} else {
|
false => auto_launch.disable()?,
|
||||||
auto_launch.disable()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match result {
|
Ok(())
|
||||||
Ok(_) => Ok(()),
|
|
||||||
Err(err) => {
|
|
||||||
log::error!("{err}");
|
|
||||||
Err("failed to set system startup info".into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn guard_thread(&mut self) -> Result<(), String> {
|
|
||||||
// let sysproxy = self.cur_sysproxy.clone();
|
|
||||||
|
|
||||||
// use std::{thread, time};
|
|
||||||
// tauri::async_runtime::spawn(async move {
|
|
||||||
// if let Some(sysproxy) = sysproxy {
|
|
||||||
// sysproxy.set_sys();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let ten_millis = time::Duration::from_millis(10);
|
|
||||||
// let now = time::Instant::now();
|
|
||||||
|
|
||||||
// thread::sleep(ten_millis);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Ok(())
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// patch verge config
|
/// patch verge config
|
||||||
/// There should be only one update at a time here
|
/// There should be only one update at a time here
|
||||||
/// so call the save_file at the end is savely
|
/// so call the save_file at the end is savely
|
||||||
pub fn patch_config(&mut self, patch: VergeConfig) -> Result<(), String> {
|
pub fn patch_config(&mut self, patch: VergeConfig) -> Result<()> {
|
||||||
// only change it
|
// only change it
|
||||||
if patch.theme_mode.is_some() {
|
if patch.theme_mode.is_some() {
|
||||||
self.config.theme_mode = patch.theme_mode;
|
self.config.theme_mode = patch.theme_mode;
|
||||||
@@ -195,6 +188,9 @@ impl Verge {
|
|||||||
if patch.theme_blur.is_some() {
|
if patch.theme_blur.is_some() {
|
||||||
self.config.theme_blur = patch.theme_blur;
|
self.config.theme_blur = patch.theme_blur;
|
||||||
}
|
}
|
||||||
|
if patch.traffic_graph.is_some() {
|
||||||
|
self.config.traffic_graph = patch.traffic_graph;
|
||||||
|
}
|
||||||
|
|
||||||
// should update system startup
|
// should update system startup
|
||||||
if patch.enable_auto_launch.is_some() {
|
if patch.enable_auto_launch.is_some() {
|
||||||
@@ -206,34 +202,122 @@ impl Verge {
|
|||||||
// should update system proxy
|
// should update system proxy
|
||||||
if patch.enable_system_proxy.is_some() {
|
if patch.enable_system_proxy.is_some() {
|
||||||
let enable = patch.enable_system_proxy.unwrap();
|
let enable = patch.enable_system_proxy.unwrap();
|
||||||
|
|
||||||
if let Some(mut sysproxy) = self.cur_sysproxy.take() {
|
if let Some(mut sysproxy) = self.cur_sysproxy.take() {
|
||||||
sysproxy.enable = enable;
|
sysproxy.enable = enable;
|
||||||
if sysproxy.set_sys().is_err() {
|
if sysproxy.set_sys().is_err() {
|
||||||
|
self.cur_sysproxy = Some(sysproxy);
|
||||||
|
|
||||||
log::error!("failed to set system proxy");
|
log::error!("failed to set system proxy");
|
||||||
return Err("failed to set system proxy".into());
|
bail!("failed to set system proxy");
|
||||||
}
|
}
|
||||||
self.cur_sysproxy = Some(sysproxy);
|
self.cur_sysproxy = Some(sysproxy);
|
||||||
}
|
}
|
||||||
self.config.enable_system_proxy = Some(enable);
|
self.config.enable_system_proxy = Some(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo
|
|
||||||
// should update system proxy too
|
// should update system proxy too
|
||||||
if patch.system_proxy_bypass.is_some() {
|
if patch.system_proxy_bypass.is_some() {
|
||||||
self.config.system_proxy_bypass = patch.system_proxy_bypass;
|
let bypass = patch.system_proxy_bypass.unwrap();
|
||||||
|
|
||||||
|
if let Some(mut sysproxy) = self.cur_sysproxy.take() {
|
||||||
|
if sysproxy.enable {
|
||||||
|
sysproxy.bypass = bypass.clone();
|
||||||
|
|
||||||
|
if sysproxy.set_sys().is_err() {
|
||||||
|
self.cur_sysproxy = Some(sysproxy);
|
||||||
|
|
||||||
|
log::error!("failed to set system proxy");
|
||||||
|
bail!("failed to set system proxy");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.cur_sysproxy = Some(sysproxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.config.system_proxy_bypass = Some(bypass);
|
||||||
|
}
|
||||||
|
|
||||||
|
// proxy guard
|
||||||
|
// only change it
|
||||||
|
if patch.enable_proxy_guard.is_some() {
|
||||||
|
self.config.enable_proxy_guard = patch.enable_proxy_guard;
|
||||||
|
}
|
||||||
|
if patch.proxy_guard_duration.is_some() {
|
||||||
|
self.config.proxy_guard_duration = patch.proxy_guard_duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
// relaunch the guard
|
||||||
|
if patch.enable_system_proxy.is_some() || patch.enable_proxy_guard.is_some() {
|
||||||
|
Verge::guard_proxy(self.guard_state.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle the tun mode
|
||||||
|
if patch.enable_tun_mode.is_some() {
|
||||||
|
self.config.enable_tun_mode = patch.enable_tun_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.config.save_file()
|
self.config.save_file()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the target app_path
|
impl Verge {
|
||||||
fn get_app_path(app_name: &str) -> String {
|
/// launch a system proxy guard
|
||||||
#[cfg(target_os = "linux")]
|
/// read config from file directly
|
||||||
let ext = "";
|
pub fn guard_proxy(guard_state: Arc<Mutex<bool>>) {
|
||||||
#[cfg(target_os = "macos")]
|
use tokio::time::{sleep, Duration};
|
||||||
let ext = "";
|
|
||||||
#[cfg(target_os = "windows")]
|
tauri::async_runtime::spawn(async move {
|
||||||
let ext = ".exe";
|
// if it is running, exit
|
||||||
String::from(app_name) + ext
|
let mut state = guard_state.lock().await;
|
||||||
|
if *state {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*state = true;
|
||||||
|
std::mem::drop(state);
|
||||||
|
|
||||||
|
// default duration is 10s
|
||||||
|
let mut wait_secs = 10u64;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
sleep(Duration::from_secs(wait_secs)).await;
|
||||||
|
|
||||||
|
log::debug!("[Guard]: heartbeat detection");
|
||||||
|
|
||||||
|
let verge = Verge::new();
|
||||||
|
|
||||||
|
let enable_proxy = verge.config.enable_system_proxy.unwrap_or(false);
|
||||||
|
let enable_guard = verge.config.enable_proxy_guard.unwrap_or(false);
|
||||||
|
let guard_duration = verge.config.proxy_guard_duration.unwrap_or(10);
|
||||||
|
|
||||||
|
// update duration
|
||||||
|
wait_secs = guard_duration;
|
||||||
|
|
||||||
|
// stop loop
|
||||||
|
if !enable_guard || !enable_proxy {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
log::info!("[Guard]: try to guard proxy");
|
||||||
|
|
||||||
|
let clash = Clash::new();
|
||||||
|
|
||||||
|
match &clash.info.port {
|
||||||
|
Some(port) => {
|
||||||
|
let bypass = verge.config.system_proxy_bypass.clone();
|
||||||
|
let sysproxy = SysProxyConfig::new(true, port.clone(), bypass);
|
||||||
|
|
||||||
|
if let Err(err) = sysproxy.set_sys() {
|
||||||
|
log::error!("[Guard]: {err}");
|
||||||
|
log::error!("[Guard]: fail to set system proxy");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => log::error!("[Guard]: fail to parse clash port"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut state = guard_state.lock().await;
|
||||||
|
*state = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,18 +19,19 @@ fn main() -> std::io::Result<()> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let menu = SystemTrayMenu::new()
|
let tray_menu = SystemTrayMenu::new()
|
||||||
.add_item(CustomMenuItem::new("open_window", "Show"))
|
.add_item(CustomMenuItem::new("open_window", "Show"))
|
||||||
.add_item(CustomMenuItem::new("restart_clash", "Restart Clash"))
|
.add_item(CustomMenuItem::new("restart_clash", "Restart Clash"))
|
||||||
.add_native_item(SystemTrayMenuItem::Separator)
|
.add_native_item(SystemTrayMenuItem::Separator)
|
||||||
.add_item(CustomMenuItem::new("quit", "Quit").accelerator("CmdOrControl+Q"));
|
.add_item(CustomMenuItem::new("quit", "Quit").accelerator("CmdOrControl+Q"));
|
||||||
|
|
||||||
tauri::Builder::default()
|
#[allow(unused_mut)]
|
||||||
|
let mut builder = tauri::Builder::default()
|
||||||
.manage(states::VergeState::default())
|
.manage(states::VergeState::default())
|
||||||
.manage(states::ClashState::default())
|
.manage(states::ClashState::default())
|
||||||
.manage(states::ProfilesState::default())
|
.manage(states::ProfilesState::default())
|
||||||
.setup(|app| Ok(resolve::resolve_setup(app)))
|
.setup(|app| Ok(resolve::resolve_setup(app)))
|
||||||
.system_tray(SystemTray::new().with_menu(menu))
|
.system_tray(SystemTray::new().with_menu(tray_menu))
|
||||||
.on_system_tray_event(move |app_handle, event| match event {
|
.on_system_tray_event(move |app_handle, event| match event {
|
||||||
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
|
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
|
||||||
"open_window" => {
|
"open_window" => {
|
||||||
@@ -74,6 +75,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
cmds::restart_sidecar,
|
cmds::restart_sidecar,
|
||||||
cmds::get_sys_proxy,
|
cmds::get_sys_proxy,
|
||||||
cmds::get_cur_proxy,
|
cmds::get_cur_proxy,
|
||||||
|
cmds::kill_sidecars,
|
||||||
cmds::open_app_dir,
|
cmds::open_app_dir,
|
||||||
cmds::open_logs_dir,
|
cmds::open_logs_dir,
|
||||||
// clash
|
// clash
|
||||||
@@ -92,7 +94,26 @@ fn main() -> std::io::Result<()> {
|
|||||||
cmds::select_profile,
|
cmds::select_profile,
|
||||||
cmds::get_profiles,
|
cmds::get_profiles,
|
||||||
cmds::sync_profiles,
|
cmds::sync_profiles,
|
||||||
])
|
]);
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
{
|
||||||
|
use tauri::{Menu, MenuItem, Submenu};
|
||||||
|
|
||||||
|
let submenu_file = Submenu::new(
|
||||||
|
"File",
|
||||||
|
Menu::new()
|
||||||
|
.add_native_item(MenuItem::Undo)
|
||||||
|
.add_native_item(MenuItem::Redo)
|
||||||
|
.add_native_item(MenuItem::Copy)
|
||||||
|
.add_native_item(MenuItem::Paste)
|
||||||
|
.add_native_item(MenuItem::Cut)
|
||||||
|
.add_native_item(MenuItem::SelectAll),
|
||||||
|
);
|
||||||
|
builder = builder.menu(Menu::new().add_submenu(submenu_file));
|
||||||
|
}
|
||||||
|
|
||||||
|
builder
|
||||||
.build(tauri::generate_context!())
|
.build(tauri::generate_context!())
|
||||||
.expect("error while running tauri application")
|
.expect("error while running tauri application")
|
||||||
.run(|app_handle, e| match e {
|
.run(|app_handle, e| match e {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use anyhow::{Context, Result};
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
use serde::{de::DeserializeOwned, Serialize};
|
||||||
use std::{fs, path::PathBuf};
|
use std::{fs, path::PathBuf};
|
||||||
|
|
||||||
@@ -7,26 +8,16 @@ pub fn read_yaml<T: DeserializeOwned + Default>(path: PathBuf) -> T {
|
|||||||
serde_yaml::from_str::<T>(&yaml_str).unwrap_or(T::default())
|
serde_yaml::from_str::<T>(&yaml_str).unwrap_or(T::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// - save the data to the file
|
/// save the data to the file
|
||||||
/// - can set `prefix` string to add some comments
|
/// can set `prefix` string to add some comments
|
||||||
pub fn save_yaml<T: Serialize>(
|
pub fn save_yaml<T: Serialize>(path: PathBuf, data: &T, prefix: Option<&str>) -> Result<()> {
|
||||||
path: PathBuf,
|
let data_str = serde_yaml::to_string(data)?;
|
||||||
data: &T,
|
|
||||||
prefix: Option<&str>,
|
|
||||||
) -> Result<(), String> {
|
|
||||||
match serde_yaml::to_string(data) {
|
|
||||||
Ok(data_str) => {
|
|
||||||
let yaml_str = match prefix {
|
|
||||||
Some(prefix) => format!("{}{}", prefix, data_str),
|
|
||||||
None => data_str,
|
|
||||||
};
|
|
||||||
|
|
||||||
let path_str = path.as_os_str().to_string_lossy().to_string();
|
let yaml_str = match prefix {
|
||||||
match fs::write(path, yaml_str.as_bytes()) {
|
Some(prefix) => format!("{prefix}{data_str}"),
|
||||||
Ok(_) => Ok(()),
|
None => data_str,
|
||||||
Err(_) => Err(format!("can not save file `{}`", path_str)),
|
};
|
||||||
}
|
|
||||||
}
|
let path_str = path.as_os_str().to_string_lossy().to_string();
|
||||||
Err(_) => Err("can not convert the data to yaml".into()),
|
fs::write(path, yaml_str.as_bytes()).context(format!("failed to save file \"{path_str}\""))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use std::env::temp_dir;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use tauri::{
|
use tauri::{
|
||||||
api::path::{home_dir, resource_dir},
|
api::path::{home_dir, resource_dir},
|
||||||
@@ -18,3 +19,34 @@ pub fn app_resources_dir(package_info: &PackageInfo) -> PathBuf {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.join("resources")
|
.join("resources")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// profiles dir
|
||||||
|
pub fn app_profiles_dir() -> PathBuf {
|
||||||
|
app_home_dir().join("profiles")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// logs dir
|
||||||
|
pub fn app_logs_dir() -> PathBuf {
|
||||||
|
app_home_dir().join("logs")
|
||||||
|
}
|
||||||
|
|
||||||
|
static CLASH_CONFIG: &str = "config.yaml";
|
||||||
|
static VERGE_CONFIG: &str = "verge.yaml";
|
||||||
|
static PROFILE_YAML: &str = "profiles.yaml";
|
||||||
|
static PROFILE_TEMP: &str = "clash-verge-runtime.yaml";
|
||||||
|
|
||||||
|
pub fn clash_path() -> PathBuf {
|
||||||
|
app_home_dir().join(CLASH_CONFIG)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn verge_path() -> PathBuf {
|
||||||
|
app_home_dir().join(VERGE_CONFIG)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn profiles_path() -> PathBuf {
|
||||||
|
app_home_dir().join(PROFILE_YAML)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn profiles_temp_path() -> PathBuf {
|
||||||
|
temp_dir().join(PROFILE_TEMP)
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,66 +22,63 @@ fn parse_string<T: FromStr>(target: &str, key: &str) -> Option<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// fetch and parse the profile
|
/// fetch and parse the profile url
|
||||||
pub async fn fetch_profile(url: &str, with_proxy: bool) -> Option<ProfileResponse> {
|
/// maybe it contains some Subscription infomations, maybe not
|
||||||
|
pub async fn fetch_profile(url: &str, with_proxy: bool) -> Result<ProfileResponse, String> {
|
||||||
let builder = reqwest::ClientBuilder::new();
|
let builder = reqwest::ClientBuilder::new();
|
||||||
let client = match with_proxy {
|
let client = match with_proxy {
|
||||||
true => builder.build(),
|
true => builder.build(),
|
||||||
false => builder.no_proxy().build(),
|
false => builder.no_proxy().build(),
|
||||||
};
|
};
|
||||||
let resp = match client {
|
|
||||||
Ok(client) => match client.get(url).send().await {
|
let resp = match client.unwrap().get(url).send().await {
|
||||||
Ok(res) => res,
|
Ok(res) => res,
|
||||||
Err(_) => return None,
|
Err(_) => return Err("failed to create https client".into()),
|
||||||
},
|
|
||||||
Err(_) => return None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let header = resp.headers();
|
let header = resp.headers();
|
||||||
|
|
||||||
// parse the Subscription Userinfo
|
// parse the Subscription Userinfo
|
||||||
let extra = {
|
let extra = match header.get("Subscription-Userinfo") {
|
||||||
let sub_info = match header.get("Subscription-Userinfo") {
|
Some(value) => {
|
||||||
Some(value) => value.to_str().unwrap_or(""),
|
let sub_info = value.to_str().unwrap_or("");
|
||||||
None => "",
|
|
||||||
};
|
|
||||||
|
|
||||||
ProfileExtra {
|
Some(ProfileExtra {
|
||||||
upload: parse_string(sub_info, "upload=").unwrap_or(0),
|
upload: parse_string(sub_info, "upload=").unwrap_or(0),
|
||||||
download: parse_string(sub_info, "download=").unwrap_or(0),
|
download: parse_string(sub_info, "download=").unwrap_or(0),
|
||||||
total: parse_string(sub_info, "total=").unwrap_or(0),
|
total: parse_string(sub_info, "total=").unwrap_or(0),
|
||||||
expire: parse_string(sub_info, "expire=").unwrap_or(0),
|
expire: parse_string(sub_info, "expire=").unwrap_or(0),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// parse the `name` and `file`
|
let file = {
|
||||||
let (name, file) = {
|
|
||||||
let now = SystemTime::now()
|
let now = SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_secs();
|
.as_secs();
|
||||||
let file = format!("{}.yaml", now);
|
format!("{}.yaml", now)
|
||||||
let name = header.get("Content-Disposition").unwrap().to_str().unwrap();
|
};
|
||||||
let name = parse_string::<String>(name, "filename=");
|
|
||||||
|
|
||||||
match name {
|
let name = match header.get("Content-Disposition") {
|
||||||
Some(f) => (f, file),
|
Some(name) => {
|
||||||
None => (file.clone(), file),
|
let name = name.to_str().unwrap();
|
||||||
|
parse_string::<String>(name, "filename=").unwrap_or(file.clone())
|
||||||
}
|
}
|
||||||
|
None => file.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// get the data
|
// get the data
|
||||||
let data = match resp.text_with_charset("utf-8").await {
|
match resp.text_with_charset("utf-8").await {
|
||||||
Ok(d) => d,
|
Ok(data) => Ok(ProfileResponse {
|
||||||
Err(_) => return None,
|
file,
|
||||||
};
|
name,
|
||||||
|
data,
|
||||||
Some(ProfileResponse {
|
extra,
|
||||||
file,
|
}),
|
||||||
name,
|
Err(_) => Err("failed to parse the response data".into()),
|
||||||
data,
|
}
|
||||||
extra,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
extern crate serde_yaml;
|
use crate::utils::{dirs, tmpl};
|
||||||
|
|
||||||
use crate::utils::dirs;
|
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use log4rs::append::console::ConsoleAppender;
|
use log4rs::append::console::ConsoleAppender;
|
||||||
use log4rs::append::file::FileAppender;
|
use log4rs::append::file::FileAppender;
|
||||||
use log4rs::config::{Appender, Config, Root};
|
use log4rs::config::{Appender, Config, Root};
|
||||||
use log4rs::encode::pattern::PatternEncoder;
|
use log4rs::encode::pattern::PatternEncoder;
|
||||||
use std::fs::{self, File};
|
use std::fs;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use tauri::PackageInfo;
|
use tauri::PackageInfo;
|
||||||
@@ -41,52 +39,30 @@ fn init_log(log_dir: &PathBuf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize all the files from resources
|
/// Initialize all the files from resources
|
||||||
fn init_config_file(app_dir: &PathBuf, res_dir: &PathBuf) {
|
fn init_config(app_dir: &PathBuf) -> std::io::Result<()> {
|
||||||
// target path
|
// target path
|
||||||
let clash_path = app_dir.join("config.yaml");
|
let clash_path = app_dir.join("config.yaml");
|
||||||
let verge_path = app_dir.join("verge.yaml");
|
let verge_path = app_dir.join("verge.yaml");
|
||||||
let profile_path = app_dir.join("profiles.yaml");
|
let profile_path = app_dir.join("profiles.yaml");
|
||||||
let mmdb_path = app_dir.join("Country.mmdb");
|
|
||||||
|
|
||||||
// template path
|
|
||||||
let clash_tmpl = res_dir.join("config_tmp.yaml");
|
|
||||||
let verge_tmpl = res_dir.join("verge_tmp.yaml");
|
|
||||||
let profiles_tmpl = res_dir.join("profiles_tmp.yaml");
|
|
||||||
let mmdb_tmpl = res_dir.join("Country.mmdb");
|
|
||||||
|
|
||||||
if !clash_path.exists() {
|
if !clash_path.exists() {
|
||||||
if clash_tmpl.exists() {
|
fs::File::create(clash_path)?.write(tmpl::CLASH_CONFIG)?;
|
||||||
fs::copy(clash_tmpl, clash_path).unwrap();
|
|
||||||
} else {
|
|
||||||
// make sure that the config.yaml not null
|
|
||||||
let content = b"\
|
|
||||||
mixed-port: 7890\n\
|
|
||||||
log-level: info\n\
|
|
||||||
allow-lan: false\n\
|
|
||||||
external-controller: 127.0.0.1:9090\n\
|
|
||||||
secret: \"\"\n";
|
|
||||||
File::create(clash_path).unwrap().write(content).unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if !verge_path.exists() {
|
||||||
// only copy it
|
fs::File::create(verge_path)?.write(tmpl::VERGE_CONFIG)?;
|
||||||
if !verge_path.exists() && verge_tmpl.exists() {
|
|
||||||
fs::copy(verge_tmpl, verge_path).unwrap();
|
|
||||||
}
|
}
|
||||||
if !profile_path.exists() && profiles_tmpl.exists() {
|
if !profile_path.exists() {
|
||||||
fs::copy(profiles_tmpl, profile_path).unwrap();
|
fs::File::create(profile_path)?.write(tmpl::PROFILES_CONFIG)?;
|
||||||
}
|
|
||||||
if !mmdb_path.exists() && mmdb_tmpl.exists() {
|
|
||||||
fs::copy(mmdb_tmpl, mmdb_path).unwrap();
|
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// initialize app
|
/// initialize app
|
||||||
pub fn init_app(package_info: &PackageInfo) {
|
pub fn init_app(package_info: &PackageInfo) {
|
||||||
// create app dir
|
// create app dir
|
||||||
let app_dir = dirs::app_home_dir();
|
let app_dir = dirs::app_home_dir();
|
||||||
let log_dir = app_dir.join("logs");
|
let log_dir = dirs::app_logs_dir();
|
||||||
let profiles_dir = app_dir.join("profiles");
|
let profiles_dir = dirs::app_profiles_dir();
|
||||||
|
|
||||||
let res_dir = dirs::app_resources_dir(package_info);
|
let res_dir = dirs::app_resources_dir(package_info);
|
||||||
|
|
||||||
@@ -101,5 +77,14 @@ pub fn init_app(package_info: &PackageInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init_log(&log_dir);
|
init_log(&log_dir);
|
||||||
init_config_file(&app_dir, &res_dir);
|
if let Err(err) = init_config(&app_dir) {
|
||||||
|
log::error!("{err}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy the resource file
|
||||||
|
let mmdb_path = app_dir.join("Country.mmdb");
|
||||||
|
let mmdb_tmpl = res_dir.join("Country.mmdb");
|
||||||
|
if !mmdb_path.exists() && mmdb_tmpl.exists() {
|
||||||
|
fs::copy(mmdb_tmpl, mmdb_path).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,3 +5,4 @@ pub mod init;
|
|||||||
pub mod resolve;
|
pub mod resolve;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
pub mod sysopt;
|
pub mod sysopt;
|
||||||
|
pub mod tmpl;
|
||||||
|
|||||||
@@ -1,24 +1,10 @@
|
|||||||
use super::{init, server};
|
use super::{init, server};
|
||||||
use crate::{core::Profiles, states};
|
use crate::{core::Profiles, states};
|
||||||
use tauri::{App, AppHandle, Manager};
|
use tauri::{App, AppHandle, Manager};
|
||||||
use tauri_plugin_shadows::Shadows;
|
|
||||||
|
|
||||||
/// handle something when start app
|
/// handle something when start app
|
||||||
pub fn resolve_setup(app: &App) {
|
pub fn resolve_setup(app: &App) {
|
||||||
// set shadow when window decorations
|
resolve_window(app);
|
||||||
let window = app.get_window("main").unwrap();
|
|
||||||
window.set_shadow(true);
|
|
||||||
|
|
||||||
// enable system blur
|
|
||||||
use tauri_plugin_vibrancy::Vibrancy;
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
window.apply_blur();
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
{
|
|
||||||
use tauri_plugin_vibrancy::MacOSVibrancy;
|
|
||||||
#[allow(deprecated)]
|
|
||||||
window.apply_vibrancy(MacOSVibrancy::AppearanceBased);
|
|
||||||
}
|
|
||||||
|
|
||||||
// setup a simple http server for singleton
|
// setup a simple http server for singleton
|
||||||
server::embed_server(&app.handle());
|
server::embed_server(&app.handle());
|
||||||
@@ -36,18 +22,27 @@ pub fn resolve_setup(app: &App) {
|
|||||||
let mut profiles = profiles_state.0.lock().unwrap();
|
let mut profiles = profiles_state.0.lock().unwrap();
|
||||||
|
|
||||||
if let Err(err) = clash.run_sidecar() {
|
if let Err(err) = clash.run_sidecar() {
|
||||||
log::error!("{}", err);
|
log::error!("{err}");
|
||||||
}
|
}
|
||||||
|
|
||||||
*profiles = Profiles::read_file();
|
*profiles = Profiles::read_file();
|
||||||
if let Err(err) = profiles.activate(&clash) {
|
if let Err(err) = profiles.activate(&clash) {
|
||||||
log::error!("{}", err);
|
log::error!("{err}");
|
||||||
}
|
}
|
||||||
|
|
||||||
verge.init_sysproxy(clash.info.port.clone());
|
verge.init_sysproxy(clash.info.port.clone());
|
||||||
verge.init_launch(app.package_info());
|
// enable tun mode
|
||||||
|
if verge.config.enable_tun_mode.clone().unwrap_or(false)
|
||||||
|
&& verge.cur_sysproxy.is_some()
|
||||||
|
&& verge.cur_sysproxy.as_ref().unwrap().enable
|
||||||
|
{
|
||||||
|
log::info!("enable tun mode");
|
||||||
|
clash.tun_mode(true).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
verge.init_launch();
|
||||||
if let Err(err) = verge.sync_launch() {
|
if let Err(err) = verge.sync_launch() {
|
||||||
log::error!("{}", err);
|
log::error!("{err}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,3 +53,34 @@ pub fn resolve_reset(app_handle: &AppHandle) {
|
|||||||
|
|
||||||
verge.reset_sysproxy();
|
verge.reset_sysproxy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// customize the window theme
|
||||||
|
fn resolve_window(app: &App) {
|
||||||
|
let window = app.get_window("main").unwrap();
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
use tauri_plugin_shadows::Shadows;
|
||||||
|
use tauri_plugin_vibrancy::Vibrancy;
|
||||||
|
|
||||||
|
window.set_decorations(false).unwrap();
|
||||||
|
window.set_shadow(true);
|
||||||
|
window.apply_blur();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
{
|
||||||
|
use tauri::LogicalSize;
|
||||||
|
use tauri::Size::Logical;
|
||||||
|
window.set_decorations(true).unwrap();
|
||||||
|
window
|
||||||
|
.set_size(Logical(LogicalSize {
|
||||||
|
width: 800.0,
|
||||||
|
height: 610.0,
|
||||||
|
}))
|
||||||
|
.unwrap();
|
||||||
|
// use tauri_plugin_vibrancy::MacOSVibrancy;
|
||||||
|
// #[allow(deprecated)]
|
||||||
|
// window.apply_vibrancy(MacOSVibrancy::AppearanceBased);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
42
src-tauri/src/utils/tmpl.rs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
///! Some config file template
|
||||||
|
|
||||||
|
/// template for clash core `config.yaml`
|
||||||
|
pub const CLASH_CONFIG: &[u8] = br#"# Default Config For Clash Core
|
||||||
|
|
||||||
|
mixed-port: 7890
|
||||||
|
log-level: info
|
||||||
|
allow-lan: false
|
||||||
|
external-controller: 127.0.0.1:9090
|
||||||
|
mode: rule
|
||||||
|
secret: ""
|
||||||
|
"#;
|
||||||
|
|
||||||
|
/// template for `profiles.yaml`
|
||||||
|
pub const PROFILES_CONFIG: &[u8] = b"# Profiles Config for Clash Verge
|
||||||
|
|
||||||
|
current: 0
|
||||||
|
items: ~
|
||||||
|
";
|
||||||
|
|
||||||
|
/// template for `verge.yaml`
|
||||||
|
pub const VERGE_CONFIG: &[u8] = b"# Defaulf Config For Clash Verge
|
||||||
|
|
||||||
|
theme_mode: light
|
||||||
|
theme_blur: false
|
||||||
|
traffic_graph: true
|
||||||
|
enable_self_startup: false
|
||||||
|
enable_system_proxy: false
|
||||||
|
enable_proxy_guard: false
|
||||||
|
proxy_guard_duration: 10
|
||||||
|
system_proxy_bypass: localhost;127.*;10.*;192.168.*;<local>
|
||||||
|
";
|
||||||
|
|
||||||
|
/// template for new a profile item
|
||||||
|
pub const ITEM_CONFIG: &[u8] = b"# Profile Template for clash verge\n\n
|
||||||
|
# proxies defination (optional, the same as clash)
|
||||||
|
proxies:\n
|
||||||
|
# proxy-groups (optional, the same as clash)
|
||||||
|
proxy-groups:\n
|
||||||
|
# rules (optional, the same as clash)
|
||||||
|
rules:\n\n
|
||||||
|
";
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "clash-verge",
|
"productName": "clash-verge",
|
||||||
"version": "0.0.15"
|
"version": "0.0.19"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
"distDir": "../dist",
|
"distDir": "../dist",
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ body {
|
|||||||
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
|
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
|
||||||
sans-serif;
|
sans-serif;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
flex: 0 1 180px;
|
flex: 0 1 180px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 180px;
|
max-width: 168px;
|
||||||
max-height: 180px;
|
max-height: 168px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 0 8px;
|
padding: 0 8px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -79,3 +79,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.macos.layout {
|
||||||
|
.layout__right .the-content {
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,38 @@
|
|||||||
|
import useSWR from "swr";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useRecoilValue } from "recoil";
|
import { useRecoilValue } from "recoil";
|
||||||
import { Box, Typography } from "@mui/material";
|
import { Box, Typography } from "@mui/material";
|
||||||
import { ArrowDownward, ArrowUpward } from "@mui/icons-material";
|
import { ArrowDownward, ArrowUpward } from "@mui/icons-material";
|
||||||
import { getInfomation } from "../../services/api";
|
import { listen } from "@tauri-apps/api/event";
|
||||||
import { ApiType } from "../../services/types";
|
import { ApiType } from "../../services/types";
|
||||||
import { atomClashPort } from "../../states/setting";
|
import { getInfomation } from "../../services/api";
|
||||||
|
import { getVergeConfig } from "../../services/cmds";
|
||||||
|
import { atomClashPort } from "../../services/states";
|
||||||
|
import useLogSetup from "./use-log-setup";
|
||||||
|
import useTrafficGraph from "./use-traffic-graph";
|
||||||
import parseTraffic from "../../utils/parse-traffic";
|
import parseTraffic from "../../utils/parse-traffic";
|
||||||
|
|
||||||
const LayoutTraffic = () => {
|
const LayoutTraffic = () => {
|
||||||
const portValue = useRecoilValue(atomClashPort);
|
const portValue = useRecoilValue(atomClashPort);
|
||||||
const [traffic, setTraffic] = useState({ up: 0, down: 0 });
|
const [traffic, setTraffic] = useState({ up: 0, down: 0 });
|
||||||
|
const { canvasRef, appendData, toggleStyle } = useTrafficGraph();
|
||||||
|
const [refresh, setRefresh] = useState({});
|
||||||
|
|
||||||
|
// whether hide traffic graph
|
||||||
|
const { data } = useSWR("getVergeConfig", getVergeConfig);
|
||||||
|
const trafficGraph = data?.traffic_graph ?? true;
|
||||||
|
|
||||||
|
// setup log ws during layout
|
||||||
|
useLogSetup();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let unlisten: () => void = null!;
|
||||||
|
|
||||||
|
// should reconnect the traffic ws
|
||||||
|
listen("restart_clash", () => setRefresh({})).then((fn) => (unlisten = fn));
|
||||||
|
|
||||||
|
return () => unlisten?.();
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let ws: WebSocket | null = null;
|
let ws: WebSocket | null = null;
|
||||||
@@ -19,12 +42,14 @@ const LayoutTraffic = () => {
|
|||||||
ws = new WebSocket(`ws://${server}/traffic?token=${secret}`);
|
ws = new WebSocket(`ws://${server}/traffic?token=${secret}`);
|
||||||
|
|
||||||
ws.addEventListener("message", (event) => {
|
ws.addEventListener("message", (event) => {
|
||||||
setTraffic(JSON.parse(event.data) as ApiType.TrafficItem);
|
const data = JSON.parse(event.data) as ApiType.TrafficItem;
|
||||||
|
appendData(data);
|
||||||
|
setTraffic(data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return () => ws?.close();
|
return () => ws?.close();
|
||||||
}, [portValue]);
|
}, [portValue, refresh]);
|
||||||
|
|
||||||
const [up, upUnit] = parseTraffic(traffic.up);
|
const [up, upUnit] = parseTraffic(traffic.up);
|
||||||
const [down, downUnit] = parseTraffic(traffic.down);
|
const [down, downUnit] = parseTraffic(traffic.down);
|
||||||
@@ -44,7 +69,14 @@ const LayoutTraffic = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box width="110px">
|
<Box width="110px" position="relative" onClick={toggleStyle}>
|
||||||
|
{trafficGraph && (
|
||||||
|
<canvas
|
||||||
|
ref={canvasRef}
|
||||||
|
style={{ width: "100%", height: 60, marginBottom: 6 }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<Box mb={1.5} display="flex" alignItems="center" whiteSpace="nowrap">
|
<Box mb={1.5} display="flex" alignItems="center" whiteSpace="nowrap">
|
||||||
<ArrowUpward
|
<ArrowUpward
|
||||||
fontSize="small"
|
fontSize="small"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
DialogContentText,
|
DialogContentText,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import { killSidecars } from "../../services/cmds";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
@@ -31,6 +32,7 @@ const UpdateDialog = (props: Props) => {
|
|||||||
try {
|
try {
|
||||||
setUploading(true);
|
setUploading(true);
|
||||||
uploadingState = true;
|
uploadingState = true;
|
||||||
|
await killSidecars();
|
||||||
await installUpdate();
|
await installUpdate();
|
||||||
await relaunch();
|
await relaunch();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
49
src/components/layout/use-log-setup.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import dayjs from "dayjs";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { useSetRecoilState } from "recoil";
|
||||||
|
import { listen } from "@tauri-apps/api/event";
|
||||||
|
import { ApiType } from "../../services/types";
|
||||||
|
import { getInfomation } from "../../services/api";
|
||||||
|
import { atomLogData } from "../../services/states";
|
||||||
|
|
||||||
|
const MAX_LOG_NUM = 1000;
|
||||||
|
|
||||||
|
// setup the log websocket
|
||||||
|
export default function useLogSetup() {
|
||||||
|
const setLogData = useSetRecoilState(atomLogData);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let ws: WebSocket = null!;
|
||||||
|
let unlisten: () => void = null!;
|
||||||
|
|
||||||
|
const handler = (event: MessageEvent<any>) => {
|
||||||
|
const data = JSON.parse(event.data) as ApiType.LogItem;
|
||||||
|
const time = dayjs().format("MM-DD HH:mm:ss");
|
||||||
|
setLogData((l) => {
|
||||||
|
if (l.length >= MAX_LOG_NUM) l.shift();
|
||||||
|
return [...l, { ...data, time }];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const { server = "", secret = "" } = await getInfomation();
|
||||||
|
|
||||||
|
ws = new WebSocket(`ws://${server}/logs?token=${secret}`);
|
||||||
|
ws.addEventListener("message", handler);
|
||||||
|
|
||||||
|
// reconnect the websocket
|
||||||
|
unlisten = await listen("restart_clash", async () => {
|
||||||
|
const { server = "", secret = "" } = await getInfomation();
|
||||||
|
|
||||||
|
ws?.close();
|
||||||
|
ws = new WebSocket(`ws://${server}/logs?token=${secret}`);
|
||||||
|
ws.addEventListener("message", handler);
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
ws?.close();
|
||||||
|
unlisten?.();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
146
src/components/layout/use-traffic-graph.ts
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
import { useRef } from "react";
|
||||||
|
|
||||||
|
const minPoint = 10;
|
||||||
|
const maxPoint = 36;
|
||||||
|
|
||||||
|
const refLineAlpha = 0.5;
|
||||||
|
const refLineWidth = 2;
|
||||||
|
const refLineColor = "#ccc";
|
||||||
|
|
||||||
|
const upLineAlpha = 0.6;
|
||||||
|
const upLineWidth = 4;
|
||||||
|
const upLineColor = "#9c27b0";
|
||||||
|
|
||||||
|
const downLineAlpha = 1;
|
||||||
|
const downLineWidth = 4;
|
||||||
|
const downLineColor = "#5b5c9d";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* draw the traffic graph
|
||||||
|
*/
|
||||||
|
export default function useTrafficGraph() {
|
||||||
|
type TrafficData = { up: number; down: number };
|
||||||
|
const listRef = useRef<TrafficData[]>([]);
|
||||||
|
const styleRef = useRef(true);
|
||||||
|
const canvasRef = useRef<HTMLCanvasElement>(null!);
|
||||||
|
|
||||||
|
const drawGraph = () => {
|
||||||
|
const canvas = canvasRef.current!;
|
||||||
|
|
||||||
|
if (!canvas) return;
|
||||||
|
|
||||||
|
const context = canvas.getContext("2d")!;
|
||||||
|
const width = canvas.width;
|
||||||
|
const height = canvas.height;
|
||||||
|
const l1 = height * 0.2;
|
||||||
|
const l2 = height * 0.6;
|
||||||
|
const dl = height * 0.4;
|
||||||
|
|
||||||
|
context.clearRect(0, 0, width, height);
|
||||||
|
|
||||||
|
// Reference lines
|
||||||
|
context.beginPath();
|
||||||
|
context.globalAlpha = refLineAlpha;
|
||||||
|
context.lineWidth = refLineWidth;
|
||||||
|
context.strokeStyle = refLineColor;
|
||||||
|
context.moveTo(0, l1);
|
||||||
|
context.lineTo(width, l1);
|
||||||
|
context.moveTo(0, l2);
|
||||||
|
context.lineTo(width, l2);
|
||||||
|
context.stroke();
|
||||||
|
context.closePath();
|
||||||
|
|
||||||
|
const countY = (value: number) => {
|
||||||
|
let v = value;
|
||||||
|
if (v < 1024) v = (v / 1024) * dl;
|
||||||
|
else if (v < 1048576) v = dl + (v / 1048576) * dl;
|
||||||
|
else v = 2 * dl + (v / 10485760) * l1;
|
||||||
|
return height - v;
|
||||||
|
};
|
||||||
|
|
||||||
|
const drawBezier = (list: number[]) => {
|
||||||
|
const len = list.length;
|
||||||
|
const size = Math.min(Math.max(len, minPoint), maxPoint);
|
||||||
|
const axis = width / size;
|
||||||
|
|
||||||
|
let lx = 0;
|
||||||
|
let ly = height;
|
||||||
|
let llx = 0;
|
||||||
|
let lly = height;
|
||||||
|
|
||||||
|
list.forEach((val, index) => {
|
||||||
|
const x = (axis * index) | 0;
|
||||||
|
const y = countY(val);
|
||||||
|
const s = 0.25;
|
||||||
|
|
||||||
|
if (index === 0) context.moveTo(x, y);
|
||||||
|
else {
|
||||||
|
let nx = (axis * (index + 1)) | 0;
|
||||||
|
let ny = index < len - 1 ? countY(list[index + 1]) | 0 : 0;
|
||||||
|
const ax = (lx + (x - llx) * s) | 0;
|
||||||
|
const ay = (ly + (y - lly) * s) | 0;
|
||||||
|
const bx = (x - (nx - lx) * s) | 0;
|
||||||
|
const by = (y - (ny - ly) * s) | 0;
|
||||||
|
context.bezierCurveTo(ax, ay, bx, by, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
llx = lx;
|
||||||
|
lly = ly;
|
||||||
|
lx = x;
|
||||||
|
ly = y;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const drawLine = (list: number[]) => {
|
||||||
|
const len = list.length;
|
||||||
|
const size = Math.min(Math.max(len, minPoint), maxPoint);
|
||||||
|
const axis = width / size;
|
||||||
|
|
||||||
|
list.forEach((val, index) => {
|
||||||
|
const x = (axis * index) | 0;
|
||||||
|
const y = countY(val);
|
||||||
|
|
||||||
|
if (index === 0) context.moveTo(x, y);
|
||||||
|
else context.lineTo(x, y);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const listUp = listRef.current.map((v) => v.up);
|
||||||
|
const listDown = listRef.current.map((v) => v.down);
|
||||||
|
const lineStyle = styleRef.current;
|
||||||
|
|
||||||
|
context.beginPath();
|
||||||
|
context.globalAlpha = upLineAlpha;
|
||||||
|
context.lineWidth = upLineWidth;
|
||||||
|
context.strokeStyle = upLineColor;
|
||||||
|
lineStyle ? drawLine(listUp) : drawBezier(listUp);
|
||||||
|
context.stroke();
|
||||||
|
context.closePath();
|
||||||
|
|
||||||
|
context.beginPath();
|
||||||
|
context.globalAlpha = downLineAlpha;
|
||||||
|
context.lineWidth = downLineWidth;
|
||||||
|
context.strokeStyle = downLineColor;
|
||||||
|
lineStyle ? drawLine(listDown) : drawBezier(listDown);
|
||||||
|
context.stroke();
|
||||||
|
context.closePath();
|
||||||
|
};
|
||||||
|
|
||||||
|
const appendData = (data: TrafficData) => {
|
||||||
|
const list = listRef.current;
|
||||||
|
if (list.length > maxPoint) list.shift();
|
||||||
|
list.push(data);
|
||||||
|
drawGraph();
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleStyle = () => {
|
||||||
|
styleRef.current = !styleRef.current;
|
||||||
|
drawGraph();
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
canvasRef,
|
||||||
|
appendData,
|
||||||
|
toggleStyle,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useRef, useState } from "react";
|
import React, { useState } from "react";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import {
|
import {
|
||||||
alpha,
|
alpha,
|
||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
MenuItem,
|
MenuItem,
|
||||||
Menu,
|
Menu,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import { useLockFn } from "ahooks";
|
||||||
import { useSWRConfig } from "swr";
|
import { useSWRConfig } from "swr";
|
||||||
import { RefreshRounded } from "@mui/icons-material";
|
import { RefreshRounded } from "@mui/icons-material";
|
||||||
import { CmdType } from "../../services/types";
|
import { CmdType } from "../../services/types";
|
||||||
@@ -59,8 +60,11 @@ const ProfileItem: React.FC<Props> = (props) => {
|
|||||||
const progress = Math.round(((download + upload) * 100) / (total + 0.1));
|
const progress = Math.round(((download + upload) * 100) / (total + 0.1));
|
||||||
const fromnow = updated > 0 ? dayjs(updated * 1000).fromNow() : "";
|
const fromnow = updated > 0 ? dayjs(updated * 1000).fromNow() : "";
|
||||||
|
|
||||||
// url or file mode
|
// local file mode
|
||||||
const isUrlMode = itemData.url && extra;
|
// remote file mode
|
||||||
|
// subscription url mode
|
||||||
|
const hasUrl = !!itemData.url;
|
||||||
|
const hasExtra = !!extra; // only subscription url has extra info
|
||||||
|
|
||||||
const onView = async () => {
|
const onView = async () => {
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
@@ -90,20 +94,16 @@ const ProfileItem: React.FC<Props> = (props) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteRef = useRef(false);
|
const onDelete = useLockFn(async () => {
|
||||||
const onDelete = async () => {
|
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
if (deleteRef.current) return;
|
|
||||||
deleteRef.current = true;
|
|
||||||
try {
|
try {
|
||||||
await deleteProfile(index);
|
await deleteProfile(index);
|
||||||
mutate("getProfiles");
|
mutate("getProfiles");
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
Notice.error(err.toString());
|
Notice.error(err.toString());
|
||||||
} finally {
|
|
||||||
deleteRef.current = false;
|
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
const handleContextMenu = (
|
const handleContextMenu = (
|
||||||
event: React.MouseEvent<HTMLDivElement, MouseEvent>
|
event: React.MouseEvent<HTMLDivElement, MouseEvent>
|
||||||
@@ -178,7 +178,8 @@ const ProfileItem: React.FC<Props> = (props) => {
|
|||||||
{name}
|
{name}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
{isUrlMode && (
|
{/* only if has url can it be updated */}
|
||||||
|
{hasUrl && (
|
||||||
<IconButton
|
<IconButton
|
||||||
sx={{
|
sx={{
|
||||||
width: 26,
|
width: 26,
|
||||||
@@ -197,43 +198,43 @@ const ProfileItem: React.FC<Props> = (props) => {
|
|||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
{isUrlMode ? (
|
{/* the second line show url's info or description */}
|
||||||
<>
|
{hasUrl ? (
|
||||||
<Box sx={boxStyle}>
|
<Box sx={boxStyle}>
|
||||||
<Typography noWrap title={`From: ${from}`}>
|
<Typography noWrap title={`From: ${from}`}>
|
||||||
{from}
|
{from}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Typography
|
<Typography
|
||||||
noWrap
|
noWrap
|
||||||
flex="1 0 auto"
|
flex="1 0 auto"
|
||||||
fontSize={14}
|
fontSize={14}
|
||||||
textAlign="right"
|
textAlign="right"
|
||||||
title="updated time"
|
title="updated time"
|
||||||
>
|
>
|
||||||
{fromnow}
|
{fromnow}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Box sx={{ ...boxStyle, fontSize: 14 }}>
|
|
||||||
<span title="used / total">
|
|
||||||
{parseTraffic(upload + download)} / {parseTraffic(total)}
|
|
||||||
</span>
|
|
||||||
<span title="expire time">{expire}</span>
|
|
||||||
</Box>
|
|
||||||
</>
|
|
||||||
) : (
|
) : (
|
||||||
<>
|
<Box sx={boxStyle}>
|
||||||
<Box sx={boxStyle}>
|
<Typography noWrap title={itemData.desc}>
|
||||||
<Typography noWrap title={itemData.desc}>
|
{itemData.desc}
|
||||||
{itemData.desc}
|
</Typography>
|
||||||
</Typography>
|
</Box>
|
||||||
</Box>
|
)}
|
||||||
|
|
||||||
<Box sx={{ ...boxStyle, fontSize: 14, justifyContent: "flex-end" }}>
|
{/* the third line show extra info or last updated time */}
|
||||||
<span title="updated time">{parseExpire(updated)}</span>
|
{hasExtra ? (
|
||||||
</Box>
|
<Box sx={{ ...boxStyle, fontSize: 14 }}>
|
||||||
</>
|
<span title="used / total">
|
||||||
|
{parseTraffic(upload + download)} / {parseTraffic(total)}
|
||||||
|
</span>
|
||||||
|
<span title="expire time">{expire}</span>
|
||||||
|
</Box>
|
||||||
|
) : (
|
||||||
|
<Box sx={{ ...boxStyle, fontSize: 14, justifyContent: "flex-end" }}>
|
||||||
|
<span title="updated time">{parseExpire(updated)}</span>
|
||||||
|
</Box>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<LinearProgress
|
<LinearProgress
|
||||||
@@ -250,8 +251,12 @@ const ProfileItem: React.FC<Props> = (props) => {
|
|||||||
anchorPosition={position}
|
anchorPosition={position}
|
||||||
anchorReference="anchorPosition"
|
anchorReference="anchorPosition"
|
||||||
>
|
>
|
||||||
{(isUrlMode ? urlModeMenu : fileModeMenu).map((item) => (
|
{(hasUrl ? urlModeMenu : fileModeMenu).map((item) => (
|
||||||
<MenuItem key={item.label} onClick={item.handler}>
|
<MenuItem
|
||||||
|
key={item.label}
|
||||||
|
onClick={item.handler}
|
||||||
|
sx={{ minWidth: 133 }}
|
||||||
|
>
|
||||||
{item.label}
|
{item.label}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
|
|||||||
150
src/components/proxy/proxy-global.tsx
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
import { useSWRConfig } from "swr";
|
||||||
|
import { useLockFn } from "ahooks";
|
||||||
|
import { Virtuoso } from "react-virtuoso";
|
||||||
|
import { Box, IconButton, TextField } from "@mui/material";
|
||||||
|
import {
|
||||||
|
MyLocationRounded,
|
||||||
|
NetworkCheckRounded,
|
||||||
|
FilterAltRounded,
|
||||||
|
FilterAltOffRounded,
|
||||||
|
VisibilityRounded,
|
||||||
|
VisibilityOffRounded,
|
||||||
|
} from "@mui/icons-material";
|
||||||
|
import { ApiType } from "../../services/types";
|
||||||
|
import { updateProxy } from "../../services/api";
|
||||||
|
import delayManager from "../../services/delay";
|
||||||
|
import useFilterProxy from "./use-filter-proxy";
|
||||||
|
import ProxyItem from "./proxy-item";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
groupName: string;
|
||||||
|
curProxy?: string;
|
||||||
|
proxies: ApiType.ProxyItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProxyGlobal = (props: Props) => {
|
||||||
|
const { groupName, curProxy, proxies } = props;
|
||||||
|
|
||||||
|
const { mutate } = useSWRConfig();
|
||||||
|
const [now, setNow] = useState(curProxy || "DIRECT");
|
||||||
|
const [showType, setShowType] = useState(true);
|
||||||
|
const [showFilter, setShowFilter] = useState(false);
|
||||||
|
const [filterText, setFilterText] = useState("");
|
||||||
|
|
||||||
|
const virtuosoRef = useRef<any>();
|
||||||
|
const filterProxies = useFilterProxy(proxies, groupName, filterText);
|
||||||
|
|
||||||
|
const onChangeProxy = useLockFn(async (name: string) => {
|
||||||
|
await updateProxy("GLOBAL", name);
|
||||||
|
mutate("getProxies");
|
||||||
|
setNow(name);
|
||||||
|
});
|
||||||
|
|
||||||
|
const onLocation = (smooth = true) => {
|
||||||
|
const index = filterProxies.findIndex((p) => p.name === now);
|
||||||
|
|
||||||
|
if (index >= 0) {
|
||||||
|
virtuosoRef.current?.scrollToIndex?.({
|
||||||
|
index,
|
||||||
|
align: "center",
|
||||||
|
behavior: smooth ? "smooth" : "auto",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onCheckAll = useLockFn(async () => {
|
||||||
|
const names = filterProxies.map((p) => p.name);
|
||||||
|
|
||||||
|
await delayManager.checkListDelay(
|
||||||
|
{ names, groupName, skipNum: 8, maxTimeout: 600 },
|
||||||
|
() => mutate("getProxies")
|
||||||
|
);
|
||||||
|
|
||||||
|
mutate("getProxies");
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => onLocation(false), [groupName]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!showFilter) setFilterText("");
|
||||||
|
}, [showFilter]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (groupName === "DIRECT") setNow("DIRECT");
|
||||||
|
if (groupName === "GLOBAL") setNow(curProxy || "DIRECT");
|
||||||
|
}, [groupName, curProxy]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
px: 3,
|
||||||
|
my: 0.5,
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
button: { mr: 0.5 },
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
title="location"
|
||||||
|
onClick={() => onLocation(true)}
|
||||||
|
>
|
||||||
|
<MyLocationRounded />
|
||||||
|
</IconButton>
|
||||||
|
|
||||||
|
<IconButton size="small" title="check" onClick={onCheckAll}>
|
||||||
|
<NetworkCheckRounded />
|
||||||
|
</IconButton>
|
||||||
|
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
title="check"
|
||||||
|
onClick={() => setShowType(!showType)}
|
||||||
|
>
|
||||||
|
{showType ? <VisibilityRounded /> : <VisibilityOffRounded />}
|
||||||
|
</IconButton>
|
||||||
|
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
title="check"
|
||||||
|
onClick={() => setShowFilter(!showFilter)}
|
||||||
|
>
|
||||||
|
{showFilter ? <FilterAltRounded /> : <FilterAltOffRounded />}
|
||||||
|
</IconButton>
|
||||||
|
|
||||||
|
{showFilter && (
|
||||||
|
<TextField
|
||||||
|
autoFocus
|
||||||
|
hiddenLabel
|
||||||
|
value={filterText}
|
||||||
|
size="small"
|
||||||
|
variant="outlined"
|
||||||
|
placeholder="Filter conditions"
|
||||||
|
onChange={(e) => setFilterText(e.target.value)}
|
||||||
|
sx={{ ml: 0.5, flex: "1 1 auto", input: { py: 0.65, px: 1 } }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Virtuoso
|
||||||
|
ref={virtuosoRef}
|
||||||
|
style={{ height: "calc(100% - 40px)" }}
|
||||||
|
totalCount={filterProxies.length}
|
||||||
|
itemContent={(index) => (
|
||||||
|
<ProxyItem
|
||||||
|
groupName={groupName}
|
||||||
|
proxy={filterProxies[index]}
|
||||||
|
selected={filterProxies[index].name === now}
|
||||||
|
showType={showType}
|
||||||
|
onClick={onChangeProxy}
|
||||||
|
sx={{ py: 0, px: 2 }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProxyGlobal;
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { useSWRConfig } from "swr";
|
import { useSWRConfig } from "swr";
|
||||||
|
import { useLockFn } from "ahooks";
|
||||||
import { Virtuoso } from "react-virtuoso";
|
import { Virtuoso } from "react-virtuoso";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
@@ -9,6 +10,7 @@ import {
|
|||||||
List,
|
List,
|
||||||
ListItem,
|
ListItem,
|
||||||
ListItemText,
|
ListItemText,
|
||||||
|
TextField,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import {
|
import {
|
||||||
SendRounded,
|
SendRounded,
|
||||||
@@ -16,11 +18,16 @@ import {
|
|||||||
ExpandMoreRounded,
|
ExpandMoreRounded,
|
||||||
MyLocationRounded,
|
MyLocationRounded,
|
||||||
NetworkCheckRounded,
|
NetworkCheckRounded,
|
||||||
|
FilterAltRounded,
|
||||||
|
FilterAltOffRounded,
|
||||||
|
VisibilityRounded,
|
||||||
|
VisibilityOffRounded,
|
||||||
} from "@mui/icons-material";
|
} from "@mui/icons-material";
|
||||||
import { ApiType } from "../../services/types";
|
import { ApiType } from "../../services/types";
|
||||||
import { updateProxy } from "../../services/api";
|
import { updateProxy } from "../../services/api";
|
||||||
import { getProfiles, patchProfile } from "../../services/cmds";
|
import { getProfiles, patchProfile } from "../../services/cmds";
|
||||||
import delayManager from "../../services/delay";
|
import delayManager from "../../services/delay";
|
||||||
|
import useFilterProxy from "./use-filter-proxy";
|
||||||
import ProxyItem from "./proxy-item";
|
import ProxyItem from "./proxy-item";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -29,27 +36,31 @@ interface Props {
|
|||||||
|
|
||||||
const ProxyGroup = ({ group }: Props) => {
|
const ProxyGroup = ({ group }: Props) => {
|
||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
|
|
||||||
const listRef = useRef<any>();
|
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [now, setNow] = useState(group.now);
|
const [now, setNow] = useState(group.now);
|
||||||
|
const [showType, setShowType] = useState(false);
|
||||||
|
const [showFilter, setShowFilter] = useState(false);
|
||||||
|
const [filterText, setFilterText] = useState("");
|
||||||
|
|
||||||
const proxies = group.all ?? [];
|
const proxies = group.all ?? [];
|
||||||
|
const virtuosoRef = useRef<any>();
|
||||||
|
const filterProxies = useFilterProxy(proxies, group.name, filterText);
|
||||||
|
|
||||||
|
const onChangeProxy = useLockFn(async (name: string) => {
|
||||||
|
// Todo: support another proxy group type
|
||||||
|
if (group.type !== "Selector") return;
|
||||||
|
|
||||||
const onSelect = async (name: string) => {
|
|
||||||
// can not call update
|
|
||||||
if (group.type !== "Selector") {
|
|
||||||
// Todo
|
|
||||||
// error Tips
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const oldValue = now;
|
const oldValue = now;
|
||||||
try {
|
try {
|
||||||
setNow(name);
|
setNow(name);
|
||||||
await updateProxy(group.name, name);
|
await updateProxy(group.name, name);
|
||||||
|
} catch {
|
||||||
|
setNow(oldValue);
|
||||||
|
return; // do not update profile
|
||||||
|
}
|
||||||
|
|
||||||
const profiles = await getProfiles().catch(console.error);
|
try {
|
||||||
if (!profiles) return;
|
const profiles = await getProfiles();
|
||||||
const profile = profiles.items![profiles.current!]!;
|
const profile = profiles.items![profiles.current!]!;
|
||||||
if (!profile) return;
|
if (!profile) return;
|
||||||
if (!profile.selected) profile.selected = [];
|
if (!profile.selected) profile.selected = [];
|
||||||
@@ -63,41 +74,46 @@ const ProxyGroup = ({ group }: Props) => {
|
|||||||
} else {
|
} else {
|
||||||
profile.selected[index] = { name: group.name, now: name };
|
profile.selected[index] = { name: group.name, now: name };
|
||||||
}
|
}
|
||||||
|
await patchProfile(profiles.current!, profile);
|
||||||
patchProfile(profiles.current!, profile).catch(console.error);
|
} catch (err) {
|
||||||
} catch {
|
console.error(err);
|
||||||
setNow(oldValue);
|
|
||||||
// Todo
|
|
||||||
// error tips
|
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
const onLocation = () => {
|
const onLocation = (smooth = true) => {
|
||||||
const index = proxies.findIndex((p) => p.name === now);
|
const index = filterProxies.findIndex((p) => p.name === now);
|
||||||
|
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
listRef.current?.scrollToIndex?.({
|
virtuosoRef.current?.scrollToIndex?.({
|
||||||
index,
|
index,
|
||||||
align: "center",
|
align: "center",
|
||||||
behavior: "smooth",
|
behavior: smooth ? "smooth" : "auto",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onCheckAll = async () => {
|
const onCheckAll = useLockFn(async () => {
|
||||||
let names = proxies.map((p) => p.name);
|
const names = filterProxies.map((p) => p.name);
|
||||||
|
const groupName = group.name;
|
||||||
|
|
||||||
while (names.length) {
|
await delayManager.checkListDelay(
|
||||||
const list = names.slice(0, 10);
|
{ names, groupName, skipNum: 8, maxTimeout: 600 },
|
||||||
names = names.slice(10);
|
() => mutate("getProxies")
|
||||||
|
);
|
||||||
|
|
||||||
await Promise.all(
|
mutate("getProxies");
|
||||||
list.map((n) => delayManager.checkDelay(n, group.name))
|
});
|
||||||
);
|
|
||||||
|
|
||||||
mutate("getProxies");
|
useEffect(() => {
|
||||||
|
if (!showFilter) setFilterText("");
|
||||||
|
}, [showFilter]);
|
||||||
|
|
||||||
|
// auto scroll to current index
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
setTimeout(() => onLocation(false), 5);
|
||||||
}
|
}
|
||||||
};
|
}, [open]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -119,27 +135,84 @@ const ProxyGroup = ({ group }: Props) => {
|
|||||||
</ListItem>
|
</ListItem>
|
||||||
|
|
||||||
<Collapse in={open} timeout="auto" unmountOnExit>
|
<Collapse in={open} timeout="auto" unmountOnExit>
|
||||||
<Box sx={{ pl: 4, pr: 3, my: 0.5 }}>
|
<Box
|
||||||
<IconButton size="small" title="location" onClick={onLocation}>
|
sx={{
|
||||||
|
pl: 4,
|
||||||
|
pr: 3,
|
||||||
|
my: 0.5,
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
button: { mr: 0.5 },
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
title="location"
|
||||||
|
onClick={() => onLocation(true)}
|
||||||
|
>
|
||||||
<MyLocationRounded />
|
<MyLocationRounded />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
||||||
<IconButton size="small" title="check" onClick={onCheckAll}>
|
<IconButton size="small" title="check" onClick={onCheckAll}>
|
||||||
<NetworkCheckRounded />
|
<NetworkCheckRounded />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
title="check"
|
||||||
|
onClick={() => setShowType(!showType)}
|
||||||
|
>
|
||||||
|
{showType ? <VisibilityRounded /> : <VisibilityOffRounded />}
|
||||||
|
</IconButton>
|
||||||
|
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
title="check"
|
||||||
|
onClick={() => setShowFilter(!showFilter)}
|
||||||
|
>
|
||||||
|
{showFilter ? <FilterAltRounded /> : <FilterAltOffRounded />}
|
||||||
|
</IconButton>
|
||||||
|
|
||||||
|
{showFilter && (
|
||||||
|
<TextField
|
||||||
|
autoFocus
|
||||||
|
hiddenLabel
|
||||||
|
value={filterText}
|
||||||
|
size="small"
|
||||||
|
variant="outlined"
|
||||||
|
placeholder="Filter conditions"
|
||||||
|
onChange={(e) => setFilterText(e.target.value)}
|
||||||
|
sx={{ ml: 0.5, flex: "1 1 auto", input: { py: 0.65, px: 1 } }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
{proxies.length >= 10 ? (
|
{!filterProxies.length && (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
py: 3,
|
||||||
|
fontSize: 18,
|
||||||
|
textAlign: "center",
|
||||||
|
color: "text.secondary",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Empty
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{filterProxies.length >= 10 ? (
|
||||||
<Virtuoso
|
<Virtuoso
|
||||||
ref={listRef}
|
ref={virtuosoRef}
|
||||||
style={{ height: "320px", marginBottom: "4px" }}
|
style={{ height: "320px", marginBottom: "4px" }}
|
||||||
totalCount={proxies.length}
|
totalCount={filterProxies.length}
|
||||||
itemContent={(index) => (
|
itemContent={(index) => (
|
||||||
<ProxyItem
|
<ProxyItem
|
||||||
groupName={group.name}
|
groupName={group.name}
|
||||||
proxy={proxies[index]}
|
proxy={filterProxies[index]}
|
||||||
selected={proxies[index].name === now}
|
selected={filterProxies[index].name === now}
|
||||||
|
showType={showType}
|
||||||
sx={{ py: 0, pl: 4 }}
|
sx={{ py: 0, pl: 4 }}
|
||||||
onClick={onSelect}
|
onClick={onChangeProxy}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
@@ -149,14 +222,15 @@ const ProxyGroup = ({ group }: Props) => {
|
|||||||
disablePadding
|
disablePadding
|
||||||
sx={{ maxHeight: "320px", overflow: "auto", mb: "4px" }}
|
sx={{ maxHeight: "320px", overflow: "auto", mb: "4px" }}
|
||||||
>
|
>
|
||||||
{proxies.map((proxy) => (
|
{filterProxies.map((proxy) => (
|
||||||
<ProxyItem
|
<ProxyItem
|
||||||
key={proxy.name}
|
key={proxy.name}
|
||||||
groupName={group.name}
|
groupName={group.name}
|
||||||
proxy={proxy}
|
proxy={proxy}
|
||||||
selected={proxy.name === now}
|
selected={proxy.name === now}
|
||||||
|
showType={showType}
|
||||||
sx={{ py: 0, pl: 4 }}
|
sx={{ py: 0, pl: 4 }}
|
||||||
onClick={onSelect}
|
onClick={onChangeProxy}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</List>
|
</List>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { CheckCircleOutlineRounded } from "@mui/icons-material";
|
import { CheckCircleOutlineRounded } from "@mui/icons-material";
|
||||||
import {
|
import {
|
||||||
alpha,
|
alpha,
|
||||||
@@ -18,6 +18,7 @@ interface Props {
|
|||||||
groupName: string;
|
groupName: string;
|
||||||
proxy: ApiType.ProxyItem;
|
proxy: ApiType.ProxyItem;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
|
showType?: boolean;
|
||||||
sx?: SxProps<Theme>;
|
sx?: SxProps<Theme>;
|
||||||
onClick?: (name: string) => void;
|
onClick?: (name: string) => void;
|
||||||
}
|
}
|
||||||
@@ -27,8 +28,20 @@ const Widget = styled(Box)(() => ({
|
|||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const TypeBox = styled(Box)(({ theme }) => ({
|
||||||
|
display: "inline-block",
|
||||||
|
border: "1px solid #ccc",
|
||||||
|
borderColor: alpha(theme.palette.text.secondary, 0.36),
|
||||||
|
color: alpha(theme.palette.text.secondary, 0.42),
|
||||||
|
borderRadius: 4,
|
||||||
|
fontSize: 10,
|
||||||
|
marginLeft: 4,
|
||||||
|
padding: "0 2px",
|
||||||
|
lineHeight: 1.25,
|
||||||
|
}));
|
||||||
|
|
||||||
const ProxyItem = (props: Props) => {
|
const ProxyItem = (props: Props) => {
|
||||||
const { groupName, proxy, selected, sx, onClick } = props;
|
const { groupName, proxy, selected, showType = true, sx, onClick } = props;
|
||||||
const [delay, setDelay] = useState(-1);
|
const [delay, setDelay] = useState(-1);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -37,14 +50,19 @@ const ProxyItem = (props: Props) => {
|
|||||||
}
|
}
|
||||||
}, [proxy]);
|
}, [proxy]);
|
||||||
|
|
||||||
|
const delayRef = useRef(false);
|
||||||
const onDelay = (e: any) => {
|
const onDelay = (e: any) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
|
if (delayRef.current) return;
|
||||||
|
delayRef.current = true;
|
||||||
|
|
||||||
delayManager
|
delayManager
|
||||||
.checkDelay(proxy.name, groupName)
|
.checkDelay(proxy.name, groupName)
|
||||||
.then((result) => setDelay(result))
|
.then((result) => setDelay(result))
|
||||||
.catch(() => setDelay(1e6));
|
.catch(() => setDelay(1e6))
|
||||||
|
.finally(() => (delayRef.current = false));
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -78,7 +96,17 @@ const ProxyItem = (props: Props) => {
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<ListItemText title={proxy.name} secondary={proxy.name} />
|
<ListItemText
|
||||||
|
title={proxy.name}
|
||||||
|
secondary={
|
||||||
|
<>
|
||||||
|
{proxy.name}
|
||||||
|
|
||||||
|
{showType && <TypeBox>{proxy.type}</TypeBox>}
|
||||||
|
{showType && proxy.udp && <TypeBox>UDP</TypeBox>}
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
|
||||||
<ListItemIcon
|
<ListItemIcon
|
||||||
sx={{ justifyContent: "flex-end", color: "primary.main" }}
|
sx={{ justifyContent: "flex-end", color: "primary.main" }}
|
||||||
|
|||||||
49
src/components/proxy/use-filter-proxy.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import { useMemo } from "react";
|
||||||
|
import { ApiType } from "../../services/types";
|
||||||
|
import delayManager from "../../services/delay";
|
||||||
|
|
||||||
|
const regex1 = /delay([=<>])(\d+|timeout|error)/i;
|
||||||
|
const regex2 = /type=(.*)/i;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* filter the proxy
|
||||||
|
* according to the regular conditions
|
||||||
|
*/
|
||||||
|
export default function useFilterProxy(
|
||||||
|
proxies: ApiType.ProxyItem[],
|
||||||
|
groupName: string,
|
||||||
|
filterText: string
|
||||||
|
) {
|
||||||
|
return useMemo(() => {
|
||||||
|
if (!filterText) return proxies;
|
||||||
|
|
||||||
|
const res1 = regex1.exec(filterText);
|
||||||
|
if (res1) {
|
||||||
|
const symbol = res1[1];
|
||||||
|
const symbol2 = res1[2].toLowerCase();
|
||||||
|
const value =
|
||||||
|
symbol2 === "error" ? 1e5 : symbol2 === "timeout" ? 3000 : +symbol2;
|
||||||
|
|
||||||
|
return proxies.filter((p) => {
|
||||||
|
const delay = delayManager.getDelay(p.name, groupName);
|
||||||
|
|
||||||
|
if (delay < 0) return false;
|
||||||
|
if (symbol === "=" && symbol2 === "error") return delay >= 1e5;
|
||||||
|
if (symbol === "=" && symbol2 === "timeout")
|
||||||
|
return delay < 1e5 && delay >= 3000;
|
||||||
|
if (symbol === "=") return delay == value;
|
||||||
|
if (symbol === "<") return delay <= value;
|
||||||
|
if (symbol === ">") return delay >= value;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const res2 = regex2.exec(filterText);
|
||||||
|
if (res2) {
|
||||||
|
const type = res2[1].toLowerCase();
|
||||||
|
return proxies.filter((p) => p.type.toLowerCase().includes(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
return proxies.filter((p) => p.name.includes(filterText.trim()));
|
||||||
|
}, [proxies, groupName, filterText]);
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ interface Props<Value> {
|
|||||||
value?: Value;
|
value?: Value;
|
||||||
valueProps?: string;
|
valueProps?: string;
|
||||||
onChangeProps?: string;
|
onChangeProps?: string;
|
||||||
|
waitTime?: number;
|
||||||
onChange?: (value: Value) => void;
|
onChange?: (value: Value) => void;
|
||||||
onFormat?: (...args: any[]) => Value;
|
onFormat?: (...args: any[]) => Value;
|
||||||
onGuard?: (value: Value, oldValue: Value) => Promise<void>;
|
onGuard?: (value: Value, oldValue: Value) => Promise<void>;
|
||||||
@@ -18,6 +19,7 @@ function GuardState<T>(props: Props<T>) {
|
|||||||
children,
|
children,
|
||||||
valueProps = "value",
|
valueProps = "value",
|
||||||
onChangeProps = "onChange",
|
onChangeProps = "onChange",
|
||||||
|
waitTime = 0, // debounce wait time default 0
|
||||||
onGuard = noop,
|
onGuard = noop,
|
||||||
onCatch = noop,
|
onCatch = noop,
|
||||||
onChange = noop,
|
onChange = noop,
|
||||||
@@ -25,34 +27,61 @@ function GuardState<T>(props: Props<T>) {
|
|||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const lockRef = useRef(false);
|
const lockRef = useRef(false);
|
||||||
|
const saveRef = useRef(value);
|
||||||
|
const lastRef = useRef(0);
|
||||||
|
const timeRef = useRef<any>();
|
||||||
|
|
||||||
if (isValidElement(children)) {
|
if (!isValidElement(children)) {
|
||||||
const childProps = { ...children.props };
|
return children as any;
|
||||||
|
|
||||||
childProps[valueProps] = value;
|
|
||||||
childProps[onChangeProps] = async (...args: any[]) => {
|
|
||||||
// 多次操作无效
|
|
||||||
if (lockRef.current) return;
|
|
||||||
|
|
||||||
lockRef.current = true;
|
|
||||||
const oldValue = value;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const newValue = (onFormat as any)(...args);
|
|
||||||
// 先在ui上响应操作
|
|
||||||
onChange(newValue);
|
|
||||||
await onGuard(newValue, oldValue!);
|
|
||||||
} catch (err: any) {
|
|
||||||
// 状态回退
|
|
||||||
onChange(oldValue!);
|
|
||||||
onCatch(err);
|
|
||||||
}
|
|
||||||
lockRef.current = false;
|
|
||||||
};
|
|
||||||
return cloneElement(children, childProps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return children as any;
|
const childProps = { ...children.props };
|
||||||
|
|
||||||
|
childProps[valueProps] = value;
|
||||||
|
childProps[onChangeProps] = async (...args: any[]) => {
|
||||||
|
// 多次操作无效
|
||||||
|
if (lockRef.current) return;
|
||||||
|
|
||||||
|
lockRef.current = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const newValue = (onFormat as any)(...args);
|
||||||
|
// 先在ui上响应操作
|
||||||
|
onChange(newValue);
|
||||||
|
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
// save the old value
|
||||||
|
if (waitTime <= 0 || now - lastRef.current >= waitTime) {
|
||||||
|
saveRef.current = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastRef.current = now;
|
||||||
|
|
||||||
|
if (waitTime <= 0) {
|
||||||
|
await onGuard(newValue, value!);
|
||||||
|
} else {
|
||||||
|
// debounce guard
|
||||||
|
clearTimeout(timeRef.current);
|
||||||
|
|
||||||
|
timeRef.current = setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
await onGuard(newValue, saveRef.current!);
|
||||||
|
} catch (err: any) {
|
||||||
|
// 状态回退
|
||||||
|
onChange(saveRef.current!);
|
||||||
|
onCatch(err);
|
||||||
|
}
|
||||||
|
}, waitTime);
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
// 状态回退
|
||||||
|
onChange(saveRef.current!);
|
||||||
|
onCatch(err);
|
||||||
|
}
|
||||||
|
lockRef.current = false;
|
||||||
|
};
|
||||||
|
return cloneElement(children, childProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default GuardState;
|
export default GuardState;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { useEffect, useState } from "react";
|
|
||||||
import { useDebounceFn } from "ahooks";
|
|
||||||
import { useSetRecoilState } from "recoil";
|
|
||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
|
import { useSetRecoilState } from "recoil";
|
||||||
import {
|
import {
|
||||||
ListItemText,
|
ListItemText,
|
||||||
TextField,
|
TextField,
|
||||||
@@ -11,7 +9,7 @@ import {
|
|||||||
Typography,
|
Typography,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { ApiType } from "../../services/types";
|
import { ApiType } from "../../services/types";
|
||||||
import { atomClashPort } from "../../states/setting";
|
import { atomClashPort } from "../../services/states";
|
||||||
import { patchClashConfig } from "../../services/cmds";
|
import { patchClashConfig } from "../../services/cmds";
|
||||||
import { SettingList, SettingItem } from "./setting";
|
import { SettingList, SettingItem } from "./setting";
|
||||||
import { getClashConfig, getVersion, updateConfigs } from "../../services/api";
|
import { getClashConfig, getVersion, updateConfigs } from "../../services/api";
|
||||||
@@ -25,18 +23,16 @@ interface Props {
|
|||||||
const SettingClash = ({ onError }: Props) => {
|
const SettingClash = ({ onError }: Props) => {
|
||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
const { data: clashConfig } = useSWR("getClashConfig", getClashConfig);
|
const { data: clashConfig } = useSWR("getClashConfig", getClashConfig);
|
||||||
|
const { data: versionData } = useSWR("getVersion", getVersion);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ipv6 = false,
|
ipv6 = false,
|
||||||
"allow-lan": allowLan = false,
|
"allow-lan": allowLan = false,
|
||||||
"log-level": logLevel = "silent",
|
"log-level": logLevel = "silent",
|
||||||
"mixed-port": thePort = 0,
|
"mixed-port": mixedPort = 0,
|
||||||
} = clashConfig ?? {};
|
} = clashConfig ?? {};
|
||||||
|
|
||||||
const setPort = useSetRecoilState(atomClashPort);
|
const setGlobalClashPort = useSetRecoilState(atomClashPort);
|
||||||
const [mixedPort, setMixedPort] = useState(thePort);
|
|
||||||
|
|
||||||
useEffect(() => setMixedPort(thePort), [thePort]);
|
|
||||||
|
|
||||||
const onSwitchFormat = (_e: any, value: boolean) => value;
|
const onSwitchFormat = (_e: any, value: boolean) => value;
|
||||||
const onChangeData = (patch: Partial<ApiType.ConfigData>) => {
|
const onChangeData = (patch: Partial<ApiType.ConfigData>) => {
|
||||||
@@ -47,35 +43,25 @@ const SettingClash = ({ onError }: Props) => {
|
|||||||
await patchClashConfig(patch);
|
await patchClashConfig(patch);
|
||||||
};
|
};
|
||||||
|
|
||||||
// restart clash when port is changed
|
const onUpdatePort = async (port: number) => {
|
||||||
const { run: onUpdatePort } = useDebounceFn(
|
if (port < 1000) {
|
||||||
async (port: number) => {
|
throw new Error("The port should not < 1000");
|
||||||
try {
|
}
|
||||||
if (port < 1000) {
|
if (port > 65536) {
|
||||||
throw new Error("The port should not < 1000");
|
throw new Error("The port should not > 65536");
|
||||||
}
|
}
|
||||||
if (port > 65536) {
|
await patchClashConfig({ "mixed-port": port });
|
||||||
throw new Error("The port should not > 65536");
|
setGlobalClashPort(port);
|
||||||
}
|
Notice.success("Change Clash port successfully!");
|
||||||
await patchClashConfig({ "mixed-port": port });
|
|
||||||
onChangeData({ "mixed-port": port });
|
// update the config
|
||||||
setPort(port);
|
mutate("getClashConfig");
|
||||||
Notice.success("Change Clash port successfully!");
|
};
|
||||||
} catch (err: any) {
|
|
||||||
setMixedPort(thePort); // back to old port value
|
|
||||||
Notice.error(err.message ?? err.toString());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ wait: 1000 }
|
|
||||||
);
|
|
||||||
|
|
||||||
// get clash core version
|
// get clash core version
|
||||||
const [clashVer, setClashVer] = useState("");
|
const clashVer = versionData?.premium
|
||||||
useEffect(() => {
|
? `${versionData.version} Premium`
|
||||||
getVersion().then(({ premium, version }) => {
|
: versionData?.version || "-";
|
||||||
setClashVer(premium ? `${version} Premium` : version);
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingList title="Clash Setting">
|
<SettingList title="Clash Setting">
|
||||||
@@ -130,9 +116,11 @@ const SettingClash = ({ onError }: Props) => {
|
|||||||
<ListItemText primary="Mixed Port" />
|
<ListItemText primary="Mixed Port" />
|
||||||
<GuardState
|
<GuardState
|
||||||
value={mixedPort!}
|
value={mixedPort!}
|
||||||
|
onCatch={onError}
|
||||||
onFormat={(e: any) => +e.target.value?.replace(/\D+/, "")}
|
onFormat={(e: any) => +e.target.value?.replace(/\D+/, "")}
|
||||||
onChange={setMixedPort}
|
onChange={(e) => onChangeData({ "mixed-port": e })}
|
||||||
onGuard={onUpdatePort}
|
onGuard={onUpdatePort}
|
||||||
|
waitTime={800}
|
||||||
>
|
>
|
||||||
<TextField autoComplete="off" size="small" sx={{ width: 120 }} />
|
<TextField autoComplete="off" size="small" sx={{ width: 120 }} />
|
||||||
</GuardState>
|
</GuardState>
|
||||||
|
|||||||
@@ -15,9 +15,11 @@ const SettingSystem = ({ onError }: Props) => {
|
|||||||
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
enable_auto_launch: startup = false,
|
enable_tun_mode = false,
|
||||||
enable_system_proxy: proxy = false,
|
enable_auto_launch = false,
|
||||||
system_proxy_bypass: bypass = "",
|
enable_system_proxy = false,
|
||||||
|
system_proxy_bypass = "",
|
||||||
|
enable_proxy_guard = false,
|
||||||
} = vergeConfig ?? {};
|
} = vergeConfig ?? {};
|
||||||
|
|
||||||
const onSwitchFormat = (_e: any, value: boolean) => value;
|
const onSwitchFormat = (_e: any, value: boolean) => value;
|
||||||
@@ -27,10 +29,24 @@ const SettingSystem = ({ onError }: Props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingList title="System Setting">
|
<SettingList title="System Setting">
|
||||||
|
<SettingItem>
|
||||||
|
<ListItemText primary="Tun Mode" />
|
||||||
|
<GuardState
|
||||||
|
value={enable_tun_mode}
|
||||||
|
valueProps="checked"
|
||||||
|
onCatch={onError}
|
||||||
|
onFormat={onSwitchFormat}
|
||||||
|
onChange={(e) => onChangeData({ enable_tun_mode: e })}
|
||||||
|
onGuard={(e) => patchVergeConfig({ enable_tun_mode: e })}
|
||||||
|
>
|
||||||
|
<Switch edge="end" />
|
||||||
|
</GuardState>
|
||||||
|
</SettingItem>
|
||||||
|
|
||||||
<SettingItem>
|
<SettingItem>
|
||||||
<ListItemText primary="Auto Launch" />
|
<ListItemText primary="Auto Launch" />
|
||||||
<GuardState
|
<GuardState
|
||||||
value={startup}
|
value={enable_auto_launch}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={onSwitchFormat}
|
onFormat={onSwitchFormat}
|
||||||
@@ -51,7 +67,7 @@ const SettingSystem = ({ onError }: Props) => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<GuardState
|
<GuardState
|
||||||
value={proxy}
|
value={enable_system_proxy}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={onSwitchFormat}
|
onFormat={onSwitchFormat}
|
||||||
@@ -65,15 +81,32 @@ const SettingSystem = ({ onError }: Props) => {
|
|||||||
</GuardState>
|
</GuardState>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|
||||||
{proxy && (
|
{enable_system_proxy && (
|
||||||
|
<SettingItem>
|
||||||
|
<ListItemText primary="Proxy Guard" />
|
||||||
|
<GuardState
|
||||||
|
value={enable_proxy_guard}
|
||||||
|
valueProps="checked"
|
||||||
|
onCatch={onError}
|
||||||
|
onFormat={onSwitchFormat}
|
||||||
|
onChange={(e) => onChangeData({ enable_proxy_guard: e })}
|
||||||
|
onGuard={(e) => patchVergeConfig({ enable_proxy_guard: e })}
|
||||||
|
>
|
||||||
|
<Switch edge="end" />
|
||||||
|
</GuardState>
|
||||||
|
</SettingItem>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{enable_system_proxy && (
|
||||||
<SettingItem>
|
<SettingItem>
|
||||||
<ListItemText primary="Proxy Bypass" />
|
<ListItemText primary="Proxy Bypass" />
|
||||||
<GuardState
|
<GuardState
|
||||||
value={bypass ?? ""}
|
value={system_proxy_bypass ?? ""}
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={(e: any) => e.target.value}
|
onFormat={(e: any) => e.target.value}
|
||||||
onChange={(e) => onChangeData({ system_proxy_bypass: e })}
|
onChange={(e) => onChangeData({ system_proxy_bypass: e })}
|
||||||
onGuard={(e) => patchVergeConfig({ system_proxy_bypass: e })}
|
onGuard={(e) => patchVergeConfig({ system_proxy_bypass: e })}
|
||||||
|
waitTime={1000}
|
||||||
>
|
>
|
||||||
<TextField autoComplete="off" size="small" sx={{ width: 120 }} />
|
<TextField autoComplete="off" size="small" sx={{ width: 120 }} />
|
||||||
</GuardState>
|
</GuardState>
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import {
|
|||||||
openLogsDir,
|
openLogsDir,
|
||||||
patchVergeConfig,
|
patchVergeConfig,
|
||||||
} from "../../services/cmds";
|
} from "../../services/cmds";
|
||||||
|
import { ArrowForward } from "@mui/icons-material";
|
||||||
import { SettingList, SettingItem } from "./setting";
|
import { SettingList, SettingItem } from "./setting";
|
||||||
import { CmdType } from "../../services/types";
|
import { CmdType } from "../../services/types";
|
||||||
import { version } from "../../../package.json";
|
import { version } from "../../../package.json";
|
||||||
import GuardState from "./guard-state";
|
|
||||||
import PaletteSwitch from "./palette-switch";
|
import PaletteSwitch from "./palette-switch";
|
||||||
import { ArrowForward } from "@mui/icons-material";
|
import GuardState from "./guard-state";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onError?: (err: Error) => void;
|
onError?: (err: Error) => void;
|
||||||
@@ -21,7 +21,7 @@ const SettingVerge = ({ onError }: Props) => {
|
|||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
||||||
|
|
||||||
const { theme_mode: mode = "light", theme_blur: blur = false } =
|
const { theme_mode = "light", theme_blur = false, traffic_graph } =
|
||||||
vergeConfig ?? {};
|
vergeConfig ?? {};
|
||||||
|
|
||||||
const onSwitchFormat = (_e: any, value: boolean) => value;
|
const onSwitchFormat = (_e: any, value: boolean) => value;
|
||||||
@@ -34,13 +34,13 @@ const SettingVerge = ({ onError }: Props) => {
|
|||||||
<SettingItem>
|
<SettingItem>
|
||||||
<ListItemText primary="Theme Mode" />
|
<ListItemText primary="Theme Mode" />
|
||||||
<GuardState
|
<GuardState
|
||||||
value={mode === "dark"}
|
value={theme_mode === "dark"}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={onSwitchFormat}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ theme_mode: e ? "dark" : "light" })}
|
onChange={(e) => onChangeData({ theme_mode: e ? "dark" : "light" })}
|
||||||
onGuard={(c) =>
|
onGuard={(e) =>
|
||||||
patchVergeConfig({ theme_mode: c ? "dark" : "light" })
|
patchVergeConfig({ theme_mode: e ? "dark" : "light" })
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<PaletteSwitch edge="end" />
|
<PaletteSwitch edge="end" />
|
||||||
@@ -50,7 +50,7 @@ const SettingVerge = ({ onError }: Props) => {
|
|||||||
<SettingItem>
|
<SettingItem>
|
||||||
<ListItemText primary="Theme Blur" />
|
<ListItemText primary="Theme Blur" />
|
||||||
<GuardState
|
<GuardState
|
||||||
value={blur}
|
value={theme_blur}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={onSwitchFormat}
|
onFormat={onSwitchFormat}
|
||||||
@@ -62,15 +62,22 @@ const SettingVerge = ({ onError }: Props) => {
|
|||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|
||||||
<SettingItem>
|
<SettingItem>
|
||||||
<ListItemText primary="Open App Dir" />
|
<ListItemText primary="Traffic Graph" />
|
||||||
<IconButton
|
<GuardState
|
||||||
color="inherit"
|
value={traffic_graph ?? true}
|
||||||
size="small"
|
valueProps="checked"
|
||||||
onClick={() => {
|
onCatch={onError}
|
||||||
console.log("click");
|
onFormat={onSwitchFormat}
|
||||||
openAppDir().then(console.log).catch(console.log);
|
onChange={(e) => onChangeData({ traffic_graph: e })}
|
||||||
}}
|
onGuard={(e) => patchVergeConfig({ traffic_graph: e })}
|
||||||
>
|
>
|
||||||
|
<Switch edge="end" />
|
||||||
|
</GuardState>
|
||||||
|
</SettingItem>
|
||||||
|
|
||||||
|
<SettingItem>
|
||||||
|
<ListItemText primary="Open App Dir" />
|
||||||
|
<IconButton color="inherit" size="small" onClick={openAppDir}>
|
||||||
<ArrowForward />
|
<ArrowForward />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|||||||
@@ -1,25 +1,26 @@
|
|||||||
import useSWR, { SWRConfig, useSWRConfig } from "swr";
|
import useSWR, { SWRConfig, useSWRConfig } from "swr";
|
||||||
import { useEffect, useMemo } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
import { Route, Routes } from "react-router-dom";
|
import { Route, Routes } from "react-router-dom";
|
||||||
import { useRecoilState } from "recoil";
|
|
||||||
import { alpha, createTheme, List, Paper, ThemeProvider } from "@mui/material";
|
import { alpha, createTheme, List, Paper, ThemeProvider } from "@mui/material";
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { listen } from "@tauri-apps/api/event";
|
||||||
import { appWindow } from "@tauri-apps/api/window";
|
import { appWindow } from "@tauri-apps/api/window";
|
||||||
import { atomPaletteMode, atomThemeBlur } from "../states/setting";
|
|
||||||
import { getVergeConfig } from "../services/cmds";
|
|
||||||
import { getAxios } from "../services/api";
|
|
||||||
import { routers } from "./_routers";
|
import { routers } from "./_routers";
|
||||||
|
import { getAxios } from "../services/api";
|
||||||
|
import { getVergeConfig } from "../services/cmds";
|
||||||
import LogoSvg from "../assets/image/logo.svg";
|
import LogoSvg from "../assets/image/logo.svg";
|
||||||
import LayoutItem from "../components/layout/layout-item";
|
import LayoutItem from "../components/layout/layout-item";
|
||||||
import LayoutControl from "../components/layout/layout-control";
|
import LayoutControl from "../components/layout/layout-control";
|
||||||
import LayoutTraffic from "../components/layout/layout-traffic";
|
import LayoutTraffic from "../components/layout/layout-traffic";
|
||||||
import UpdateButton from "../components/layout/update-button";
|
import UpdateButton from "../components/layout/update-button";
|
||||||
|
|
||||||
|
const isMacos = navigator.userAgent.includes("Mac OS X");
|
||||||
|
|
||||||
const Layout = () => {
|
const Layout = () => {
|
||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
const [mode, setMode] = useRecoilState(atomPaletteMode);
|
const { data } = useSWR("getVergeConfig", getVergeConfig);
|
||||||
const [blur, setBlur] = useRecoilState(atomThemeBlur);
|
|
||||||
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
const blur = !!data?.theme_blur;
|
||||||
|
const mode = data?.theme_mode ?? "light";
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.addEventListener("keydown", (e) => {
|
window.addEventListener("keydown", (e) => {
|
||||||
@@ -36,12 +37,6 @@ const Layout = () => {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!vergeConfig) return;
|
|
||||||
setBlur(!!vergeConfig.theme_blur);
|
|
||||||
setMode(vergeConfig.theme_mode ?? "light");
|
|
||||||
}, [vergeConfig]);
|
|
||||||
|
|
||||||
const theme = useMemo(() => {
|
const theme = useMemo(() => {
|
||||||
// const background = mode === "light" ? "#f5f5f5" : "#000";
|
// const background = mode === "light" ? "#f5f5f5" : "#000";
|
||||||
const selectColor = mode === "light" ? "#f5f5f5" : "#d5d5d5";
|
const selectColor = mode === "light" ? "#f5f5f5" : "#d5d5d5";
|
||||||
@@ -74,7 +69,7 @@ const Layout = () => {
|
|||||||
<Paper
|
<Paper
|
||||||
square
|
square
|
||||||
elevation={0}
|
elevation={0}
|
||||||
className="layout"
|
className={`${isMacos ? "macos " : ""}layout`}
|
||||||
onPointerDown={onDragging}
|
onPointerDown={onDragging}
|
||||||
sx={[
|
sx={[
|
||||||
(theme) => ({
|
(theme) => ({
|
||||||
@@ -103,9 +98,11 @@ const Layout = () => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="layout__right" data-windrag>
|
<div className="layout__right" data-windrag>
|
||||||
<div className="the-bar">
|
{!isMacos && (
|
||||||
<LayoutControl />
|
<div className="the-bar">
|
||||||
</div>
|
<LayoutControl />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="the-content">
|
<div className="the-content">
|
||||||
<Routes>
|
<Routes>
|
||||||
|
|||||||
@@ -1,38 +1,12 @@
|
|||||||
import dayjs from "dayjs";
|
import { useRecoilState } from "recoil";
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import { Button, Paper } from "@mui/material";
|
import { Button, Paper } from "@mui/material";
|
||||||
import { Virtuoso } from "react-virtuoso";
|
import { Virtuoso } from "react-virtuoso";
|
||||||
import { ApiType } from "../services/types";
|
import { atomLogData } from "../services/states";
|
||||||
import { getInfomation } from "../services/api";
|
|
||||||
import BasePage from "../components/base/base-page";
|
import BasePage from "../components/base/base-page";
|
||||||
import LogItem from "../components/log/log-item";
|
import LogItem from "../components/log/log-item";
|
||||||
|
|
||||||
let logCache: ApiType.LogItem[] = [];
|
|
||||||
|
|
||||||
const LogPage = () => {
|
const LogPage = () => {
|
||||||
const [logData, setLogData] = useState(logCache);
|
const [logData, setLogData] = useRecoilState(atomLogData);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let ws: WebSocket | null = null;
|
|
||||||
|
|
||||||
getInfomation().then((result) => {
|
|
||||||
const { server = "", secret = "" } = result;
|
|
||||||
ws = new WebSocket(`ws://${server}/logs?token=${secret}`);
|
|
||||||
|
|
||||||
ws.addEventListener("message", (event) => {
|
|
||||||
const data = JSON.parse(event.data) as ApiType.LogItem;
|
|
||||||
const time = dayjs().format("MM-DD HH:mm:ss");
|
|
||||||
setLogData((l) => (logCache = [...l, { ...data, time }]));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => ws?.close();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const onClear = () => {
|
|
||||||
setLogData([]);
|
|
||||||
logCache = [];
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BasePage
|
<BasePage
|
||||||
@@ -43,7 +17,7 @@ const LogPage = () => {
|
|||||||
size="small"
|
size="small"
|
||||||
sx={{ mt: 1 }}
|
sx={{ mt: 1 }}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={onClear}
|
onClick={() => setLogData([])}
|
||||||
>
|
>
|
||||||
Clear
|
Clear
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
import { useLockFn } from "ahooks";
|
||||||
import { Box, Button, Grid, TextField } from "@mui/material";
|
import { Box, Button, Grid, TextField } from "@mui/material";
|
||||||
import {
|
import {
|
||||||
getProfiles,
|
getProfiles,
|
||||||
@@ -81,37 +82,27 @@ const ProfilePage = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const lockRef = useRef(false);
|
const onSelect = useLockFn(async (index: number, force: boolean) => {
|
||||||
const onSelect = async (index: number, force: boolean) => {
|
|
||||||
if (lockRef.current) return;
|
|
||||||
if (!force && index === profiles.current) return;
|
if (!force && index === profiles.current) return;
|
||||||
lockRef.current = true;
|
|
||||||
try {
|
try {
|
||||||
await selectProfile(index);
|
await selectProfile(index);
|
||||||
mutate("getProfiles", { ...profiles, current: index }, true);
|
mutate("getProfiles", { ...profiles, current: index }, true);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
err && Notice.error(err.toString());
|
err && Notice.error(err.toString());
|
||||||
} finally {
|
|
||||||
lockRef.current = false;
|
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
const lockNewRef = useRef(false);
|
|
||||||
const [dialogOpen, setDialogOpen] = useState(false);
|
const [dialogOpen, setDialogOpen] = useState(false);
|
||||||
const onNew = async (name: string, desc: string) => {
|
const onNew = useLockFn(async (name: string, desc: string) => {
|
||||||
if (lockNewRef.current) return;
|
|
||||||
lockNewRef.current = true;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await newProfile(name, desc);
|
await newProfile(name, desc);
|
||||||
setDialogOpen(false);
|
setDialogOpen(false);
|
||||||
mutate("getProfiles");
|
mutate("getProfiles");
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
err && Notice.error(err.toString());
|
err && Notice.error(err.toString());
|
||||||
} finally {
|
|
||||||
lockNewRef.current = false;
|
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BasePage title="Profiles">
|
<BasePage title="Profiles">
|
||||||
|
|||||||
@@ -1,90 +1,51 @@
|
|||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect } from "react";
|
||||||
import { Virtuoso } from "react-virtuoso";
|
import { useLockFn } from "ahooks";
|
||||||
import { Button, ButtonGroup, List, Paper } from "@mui/material";
|
import { Button, ButtonGroup, List, Paper } from "@mui/material";
|
||||||
import { getClashConfig, updateConfigs, updateProxy } from "../services/api";
|
import { getClashConfig, updateConfigs } from "../services/api";
|
||||||
import { patchClashConfig } from "../services/cmds";
|
import { patchClashConfig } from "../services/cmds";
|
||||||
import { getProxies } from "../services/api";
|
import { getProxies } from "../services/api";
|
||||||
import BasePage from "../components/base/base-page";
|
import BasePage from "../components/base/base-page";
|
||||||
import ProxyItem from "../components/proxy/proxy-item";
|
|
||||||
import ProxyGroup from "../components/proxy/proxy-group";
|
import ProxyGroup from "../components/proxy/proxy-group";
|
||||||
|
import ProxyGlobal from "../components/proxy/proxy-global";
|
||||||
|
|
||||||
const ProxyPage = () => {
|
const ProxyPage = () => {
|
||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
const { data: proxiesData } = useSWR("getProxies", getProxies);
|
const { data: proxiesData } = useSWR("getProxies", getProxies);
|
||||||
const { data: clashConfig } = useSWR("getClashConfig", getClashConfig);
|
const { data: clashConfig } = useSWR("getClashConfig", getClashConfig);
|
||||||
const [curProxy, setCurProxy] = useState<string>("DIRECT");
|
|
||||||
const curMode = clashConfig?.mode.toLowerCase();
|
|
||||||
|
|
||||||
// proxy groups
|
|
||||||
const { groups = [] } = proxiesData ?? {};
|
|
||||||
// proxies and sorted
|
|
||||||
const filterProxies = useMemo(() => {
|
|
||||||
if (!proxiesData?.proxies) return [];
|
|
||||||
|
|
||||||
const list = Object.values(proxiesData.proxies);
|
|
||||||
const retList = list.filter(
|
|
||||||
(p) => !p.all?.length && p.name !== "DIRECT" && p.name !== "REJECT"
|
|
||||||
);
|
|
||||||
const direct = list.filter((p) => p.name === "DIRECT");
|
|
||||||
const reject = list.filter((p) => p.name === "REJECT");
|
|
||||||
|
|
||||||
return direct.concat(retList).concat(reject);
|
|
||||||
}, [proxiesData]);
|
|
||||||
|
|
||||||
const modeList = ["rule", "global", "direct"];
|
const modeList = ["rule", "global", "direct"];
|
||||||
const asGroup = curMode === "rule" && groups.length;
|
const curMode = clashConfig?.mode.toLowerCase() ?? "direct";
|
||||||
|
const { groups = [], proxies = [] } = proxiesData ?? {};
|
||||||
|
|
||||||
// make sure that fetch the proxies successfully
|
// make sure that fetch the proxies successfully
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
(curMode === "rule" && !groups.length) ||
|
(curMode === "rule" && !groups.length) ||
|
||||||
(curMode === "global" && filterProxies.length < 4)
|
(curMode === "global" && proxies.length < 2)
|
||||||
) {
|
) {
|
||||||
setTimeout(() => mutate("getProxies"), 500);
|
setTimeout(() => mutate("getProxies"), 500);
|
||||||
}
|
}
|
||||||
}, [groups, filterProxies, curMode]);
|
}, [groups, proxies, curMode]);
|
||||||
|
|
||||||
// update the current proxy
|
const onChangeMode = useLockFn(async (mode: string) => {
|
||||||
useEffect(() => {
|
// switch rapidly
|
||||||
if (curMode === "direct") setCurProxy("DIRECT");
|
await updateConfigs({ mode });
|
||||||
if (curMode === "global") {
|
await patchClashConfig({ mode });
|
||||||
const globalNow = proxiesData?.proxies?.GLOBAL?.now;
|
mutate("getClashConfig");
|
||||||
setCurProxy(globalNow || "DIRECT");
|
});
|
||||||
}
|
|
||||||
}, [curMode, proxiesData]);
|
|
||||||
|
|
||||||
const changeLockRef = useRef(false);
|
|
||||||
const onChangeMode = async (mode: string) => {
|
|
||||||
if (changeLockRef.current) return;
|
|
||||||
changeLockRef.current = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// switch rapidly
|
|
||||||
await updateConfigs({ mode });
|
|
||||||
await patchClashConfig({ mode });
|
|
||||||
mutate("getClashConfig");
|
|
||||||
} finally {
|
|
||||||
changeLockRef.current = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onChangeProxy = async (name: string) => {
|
|
||||||
if (curMode !== "global") return;
|
|
||||||
await updateProxy("GLOBAL", name);
|
|
||||||
setCurProxy(name);
|
|
||||||
};
|
|
||||||
|
|
||||||
// difference style
|
// difference style
|
||||||
const pageStyle = asGroup ? {} : { height: "100%" };
|
const showGroup = curMode === "rule" && !!groups.length;
|
||||||
const paperStyle: any = asGroup
|
const pageStyle = showGroup ? {} : { height: "100%" };
|
||||||
|
const paperStyle: any = showGroup
|
||||||
? { mb: 0.5 }
|
? { mb: 0.5 }
|
||||||
: { py: 1, height: "100%", boxSizing: "border-box" };
|
: { py: 1, height: "100%", boxSizing: "border-box" };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BasePage
|
<BasePage
|
||||||
contentStyle={pageStyle}
|
contentStyle={pageStyle}
|
||||||
title={asGroup ? "Proxy Groups" : "Proxies"}
|
title={showGroup ? "Proxy Groups" : "Proxies"}
|
||||||
header={
|
header={
|
||||||
<ButtonGroup size="small">
|
<ButtonGroup size="small">
|
||||||
{modeList.map((mode) => (
|
{modeList.map((mode) => (
|
||||||
@@ -101,26 +62,25 @@ const ProxyPage = () => {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<Paper sx={{ borderRadius: 1, boxShadow: 2, ...paperStyle }}>
|
<Paper sx={{ borderRadius: 1, boxShadow: 2, ...paperStyle }}>
|
||||||
{asGroup ? (
|
{curMode === "rule" && !!groups.length && (
|
||||||
<List>
|
<List>
|
||||||
{groups.map((group) => (
|
{groups.map((group) => (
|
||||||
<ProxyGroup key={group.name} group={group} />
|
<ProxyGroup key={group.name} group={group} />
|
||||||
))}
|
))}
|
||||||
</List>
|
</List>
|
||||||
) : (
|
)}
|
||||||
// virtual list
|
{((curMode === "rule" && !groups.length) || curMode === "global") && (
|
||||||
<Virtuoso
|
<ProxyGlobal
|
||||||
style={{ height: "100%" }}
|
groupName="GLOBAL"
|
||||||
totalCount={filterProxies.length}
|
curProxy={proxiesData?.global?.now}
|
||||||
itemContent={(index) => (
|
proxies={proxies}
|
||||||
<ProxyItem
|
/>
|
||||||
groupName="GLOBAL"
|
)}
|
||||||
proxy={filterProxies[index]}
|
{curMode === "direct" && (
|
||||||
selected={filterProxies[index].name === curProxy}
|
<ProxyGlobal
|
||||||
onClick={onChangeProxy}
|
groupName="DIRECT"
|
||||||
sx={{ py: 0, px: 2 }}
|
curProxy="DIRECT"
|
||||||
/>
|
proxies={[proxiesData?.direct!].filter(Boolean)}
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Paper>
|
</Paper>
|
||||||
|
|||||||
@@ -84,33 +84,41 @@ export async function updateProxy(group: string, proxy: string) {
|
|||||||
export async function getProxies() {
|
export async function getProxies() {
|
||||||
const instance = await getAxios();
|
const instance = await getAxios();
|
||||||
const response = await instance.get<any, any>("/proxies");
|
const response = await instance.get<any, any>("/proxies");
|
||||||
const proxies = (response?.proxies ?? {}) as Record<
|
const records = (response?.proxies ?? {}) as Record<
|
||||||
string,
|
string,
|
||||||
ApiType.ProxyItem
|
ApiType.ProxyItem
|
||||||
>;
|
>;
|
||||||
|
|
||||||
const global = proxies["GLOBAL"];
|
const global = records["GLOBAL"];
|
||||||
|
const direct = records["DIRECT"];
|
||||||
|
const reject = records["REJECT"];
|
||||||
const order = global?.all;
|
const order = global?.all;
|
||||||
|
|
||||||
let groups: ApiType.ProxyGroupItem[] = [];
|
let groups: ApiType.ProxyGroupItem[] = [];
|
||||||
|
|
||||||
if (order) {
|
if (order) {
|
||||||
groups = order
|
groups = order
|
||||||
.filter((name) => proxies[name]?.all)
|
.filter((name) => records[name]?.all)
|
||||||
.map((name) => proxies[name])
|
.map((name) => records[name])
|
||||||
.map((each) => ({
|
.map((each) => ({
|
||||||
...each,
|
...each,
|
||||||
all: each.all!.map((item) => proxies[item]),
|
all: each.all!.map((item) => records[item]),
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
groups = Object.values(proxies)
|
groups = Object.values(records)
|
||||||
.filter((each) => each.name !== "GLOBAL" && each.all)
|
.filter((each) => each.name !== "GLOBAL" && each.all)
|
||||||
.map((each) => ({
|
.map((each) => ({
|
||||||
...each,
|
...each,
|
||||||
all: each.all!.map((item) => proxies[item]),
|
all: each.all!.map((item) => records[item]),
|
||||||
}));
|
}));
|
||||||
groups.sort((a, b) => b.name.localeCompare(a.name));
|
groups.sort((a, b) => b.name.localeCompare(a.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return { global, groups, proxies };
|
const proxies = [direct, reject].concat(
|
||||||
|
Object.values(records).filter(
|
||||||
|
(p) => !p.all?.length && p.name !== "DIRECT" && p.name !== "REJECT"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return { global, direct, groups, records, proxies };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ export async function getSystemProxy() {
|
|||||||
return invoke<any>("get_sys_proxy");
|
return invoke<any>("get_sys_proxy");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function killSidecars() {
|
||||||
|
return invoke<any>("kill_sidecars");
|
||||||
|
}
|
||||||
|
|
||||||
export async function openAppDir() {
|
export async function openAppDir() {
|
||||||
return invoke<void>("open_app_dir");
|
return invoke<void>("open_app_dir");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,39 @@ class DelayManager {
|
|||||||
this.setDelay(name, group, delay);
|
this.setDelay(name, group, delay);
|
||||||
return delay;
|
return delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async checkListDelay(
|
||||||
|
options: {
|
||||||
|
names: readonly string[];
|
||||||
|
groupName: string;
|
||||||
|
skipNum: number;
|
||||||
|
maxTimeout: number;
|
||||||
|
},
|
||||||
|
callback: Function
|
||||||
|
) {
|
||||||
|
let names = [...options.names];
|
||||||
|
const { groupName, skipNum, maxTimeout } = options;
|
||||||
|
|
||||||
|
while (names.length) {
|
||||||
|
const list = names.slice(0, skipNum);
|
||||||
|
names = names.slice(skipNum);
|
||||||
|
|
||||||
|
let called = false;
|
||||||
|
setTimeout(() => {
|
||||||
|
if (!called) {
|
||||||
|
called = true;
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}, maxTimeout);
|
||||||
|
|
||||||
|
await Promise.all(list.map((n) => this.checkDelay(n, groupName)));
|
||||||
|
|
||||||
|
if (!called) {
|
||||||
|
called = true;
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new DelayManager();
|
export default new DelayManager();
|
||||||
|
|||||||
12
src/services/states.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { atom } from "recoil";
|
||||||
|
import { ApiType } from "./types";
|
||||||
|
|
||||||
|
export const atomClashPort = atom<number>({
|
||||||
|
key: "atomClashPort",
|
||||||
|
default: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const atomLogData = atom<ApiType.LogItem[]>({
|
||||||
|
key: "atomLogData",
|
||||||
|
default: [],
|
||||||
|
});
|
||||||
@@ -112,8 +112,11 @@ export namespace CmdType {
|
|||||||
export interface VergeConfig {
|
export interface VergeConfig {
|
||||||
theme_mode?: "light" | "dark";
|
theme_mode?: "light" | "dark";
|
||||||
theme_blur?: boolean;
|
theme_blur?: boolean;
|
||||||
|
traffic_graph?: boolean;
|
||||||
|
enable_tun_mode?: boolean;
|
||||||
enable_auto_launch?: boolean;
|
enable_auto_launch?: boolean;
|
||||||
enable_system_proxy?: boolean;
|
enable_system_proxy?: boolean;
|
||||||
|
enable_proxy_guard?: boolean;
|
||||||
system_proxy_bypass?: string;
|
system_proxy_bypass?: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
import { atom } from "recoil";
|
|
||||||
|
|
||||||
export const atomPaletteMode = atom<"light" | "dark">({
|
|
||||||
key: "atomPaletteMode",
|
|
||||||
default: "light",
|
|
||||||
});
|
|
||||||
|
|
||||||
export const atomThemeBlur = atom<boolean>({
|
|
||||||
key: "atomThemeBlur",
|
|
||||||
default: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const atomClashPort = atom<number>({
|
|
||||||
key: "atomClashPort",
|
|
||||||
default: 0,
|
|
||||||
});
|
|
||||||