Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5af234524 | ||
|
|
b5c41750f7 | ||
|
|
6083824eec | ||
|
|
40977785c3 | ||
|
|
5eddf4f1aa | ||
|
|
99a8e25411 | ||
|
|
08587d8f2f | ||
|
|
3480d50f61 | ||
|
|
43af55252d | ||
|
|
9c43b31fc0 | ||
|
|
9ec7184aa1 | ||
|
|
4e2cb30db7 | ||
|
|
9ca83d3291 | ||
|
|
6b2172d873 | ||
|
|
1a5d9f7dad | ||
|
|
a8425862f0 | ||
|
|
a3a3db6abb | ||
|
|
d6c3bc57c0 | ||
|
|
59c09f90f9 | ||
|
|
d982b83e14 | ||
|
|
cc0e930d34 | ||
|
|
3c3d77fbea | ||
|
|
da7453fdbf | ||
|
|
5fcd25506e | ||
|
|
4979a472de | ||
|
|
4e8d4f4591 | ||
|
|
0f5d2b15e0 | ||
|
|
7fc9631434 | ||
|
|
df5953dd7b | ||
|
|
8f5b2b4a0e | ||
|
|
43c63ffa70 |
@@ -1,26 +1,24 @@
|
|||||||
name: Release Project
|
name: CI
|
||||||
|
|
||||||
on:
|
on: [push]
|
||||||
push:
|
|
||||||
tags:
|
env:
|
||||||
- v*
|
CARGO_INCREMENTAL: 0
|
||||||
|
RUST_BACKTRACE: short
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-tauri:
|
release:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
matrix:
|
||||||
platform: [windows-latest, macos-latest]
|
os: [windows-latest, macos-11]
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
if: |
|
||||||
|
startsWith(github.repository, 'zzzgydi') &&
|
||||||
|
startsWith(github.ref, 'refs/tags/v')
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Install Node
|
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: 14
|
|
||||||
|
|
||||||
- name: Install Rust
|
- name: Install Rust
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
@@ -28,6 +26,14 @@ jobs:
|
|||||||
profile: minimal
|
profile: minimal
|
||||||
override: true
|
override: true
|
||||||
|
|
||||||
|
- name: Rust Cache
|
||||||
|
uses: Swatinem/rust-cache@ce325b60658c1b38465c06cc965b79baf32c1e72
|
||||||
|
|
||||||
|
- name: Install Node
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 14
|
||||||
|
|
||||||
- name: Get yarn cache dir path
|
- name: Get yarn cache dir path
|
||||||
id: yarn-cache-dir-path
|
id: yarn-cache-dir-path
|
||||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||||
@@ -41,14 +47,13 @@ jobs:
|
|||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-yarn-
|
${{ runner.os }}-yarn-
|
||||||
|
|
||||||
- name: Rust Cache
|
|
||||||
uses: Swatinem/rust-cache@ce325b60658c1b38465c06cc965b79baf32c1e72
|
|
||||||
|
|
||||||
- name: Yarn install and check
|
- name: Yarn install and check
|
||||||
run: yarn && yarn run check
|
run: yarn && yarn run check
|
||||||
|
|
||||||
- name: Tauri build
|
- name: Tauri build
|
||||||
uses: tauri-apps/tauri-action@v0
|
uses: tauri-apps/tauri-action@v0
|
||||||
|
# enable cache even though failed
|
||||||
|
continue-on-error: true
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "clash-verge",
|
"name": "clash-verge",
|
||||||
"version": "0.0.8",
|
"version": "0.0.11",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "cargo tauri dev",
|
"dev": "cargo tauri dev",
|
||||||
|
|||||||
@@ -11,10 +11,16 @@ async function resolvePublish() {
|
|||||||
|
|
||||||
let [a, b, c] = packageJson.version.split(".").map(Number);
|
let [a, b, c] = packageJson.version.split(".").map(Number);
|
||||||
|
|
||||||
if (flag === "major") a += 1;
|
if (flag === "major") {
|
||||||
else if (flag === "minor") b += 1;
|
a += 1;
|
||||||
else if (flag === "patch") c += 1;
|
b = 0;
|
||||||
else throw new Error(`invalid flag "${flag}"`);
|
c = 0;
|
||||||
|
} else if (flag === "minor") {
|
||||||
|
b += 1;
|
||||||
|
c = 0;
|
||||||
|
} else if (flag === "patch") {
|
||||||
|
c += 1;
|
||||||
|
} else throw new Error(`invalid flag "${flag}"`);
|
||||||
|
|
||||||
const nextVersion = `${a}.${b}.${c}`;
|
const nextVersion = `${a}.${b}.${c}`;
|
||||||
packageJson.version = nextVersion;
|
packageJson.version = nextVersion;
|
||||||
|
|||||||
231
src-tauri/Cargo.lock
generated
231
src-tauri/Cargo.lock
generated
@@ -42,6 +42,7 @@ checksum = "84450d0b4a8bd1ba4144ce8ce718fbc5d071358b1e5384bace6536b3d1f2d5b3"
|
|||||||
name = "app"
|
name = "app"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"auto-launch",
|
||||||
"chrono",
|
"chrono",
|
||||||
"dirs 4.0.0",
|
"dirs 4.0.0",
|
||||||
"log",
|
"log",
|
||||||
@@ -54,8 +55,10 @@ dependencies = [
|
|||||||
"tauri",
|
"tauri",
|
||||||
"tauri-build",
|
"tauri-build",
|
||||||
"tauri-plugin-shadows",
|
"tauri-plugin-shadows",
|
||||||
|
"tauri-plugin-vibrancy",
|
||||||
"tokio",
|
"tokio",
|
||||||
"warp",
|
"warp",
|
||||||
|
"which",
|
||||||
"winreg 0.10.1",
|
"winreg 0.10.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -144,6 +147,16 @@ dependencies = [
|
|||||||
"wildmatch",
|
"wildmatch",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "auto-launch"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f0ab475f9b1049a9d4e9c83f45ff27ec3bce4a6cb8e58e7f29030f8992af8c5"
|
||||||
|
dependencies = [
|
||||||
|
"dirs 4.0.0",
|
||||||
|
"winreg 0.10.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@@ -184,16 +197,16 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blake3"
|
name = "blake3"
|
||||||
version = "1.2.0"
|
version = "1.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "526c210b4520e416420759af363083471656e819a75e831b8d2c9d5a584f2413"
|
checksum = "882e99e4a0cb2ae6cb6e442102e8e6b7131718d94110e64c3e6a34ea9b106f37"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"arrayvec 0.7.2",
|
"arrayvec 0.7.2",
|
||||||
"cc",
|
"cc",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"constant_time_eq",
|
"constant_time_eq",
|
||||||
"digest",
|
"digest 0.10.1",
|
||||||
"rayon",
|
"rayon",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -212,6 +225,15 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "block-buffer"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f1d36a02058e76b040de25a4464ba1c80935655595b661505c8b39b664828b95"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bstr"
|
name = "bstr"
|
||||||
version = "0.2.17"
|
version = "0.2.17"
|
||||||
@@ -233,9 +255,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bumpalo"
|
name = "bumpalo"
|
||||||
version = "3.8.0"
|
version = "3.9.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c"
|
checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "byteorder"
|
name = "byteorder"
|
||||||
@@ -377,8 +399,8 @@ dependencies = [
|
|||||||
"bitflags",
|
"bitflags",
|
||||||
"block",
|
"block",
|
||||||
"cocoa-foundation",
|
"cocoa-foundation",
|
||||||
"core-foundation 0.9.2",
|
"core-foundation",
|
||||||
"core-graphics 0.22.3",
|
"core-graphics",
|
||||||
"foreign-types",
|
"foreign-types",
|
||||||
"libc",
|
"libc",
|
||||||
"objc",
|
"objc",
|
||||||
@@ -392,7 +414,7 @@ checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"block",
|
"block",
|
||||||
"core-foundation 0.9.2",
|
"core-foundation",
|
||||||
"core-graphics-types",
|
"core-graphics-types",
|
||||||
"foreign-types",
|
"foreign-types",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -420,50 +442,22 @@ 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 = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
|
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "core-foundation"
|
|
||||||
version = "0.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171"
|
|
||||||
dependencies = [
|
|
||||||
"core-foundation-sys 0.7.0",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.9.2"
|
version = "0.9.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3"
|
checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"core-foundation-sys 0.8.3",
|
"core-foundation-sys",
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "core-foundation-sys"
|
|
||||||
version = "0.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-foundation-sys"
|
name = "core-foundation-sys"
|
||||||
version = "0.8.3"
|
version = "0.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
|
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "core-graphics"
|
|
||||||
version = "0.19.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b3889374e6ea6ab25dba90bb5d96202f61108058361f6dc72e8b03e6f8bbe923"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"core-foundation 0.7.0",
|
|
||||||
"foreign-types",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "core-graphics"
|
name = "core-graphics"
|
||||||
version = "0.22.3"
|
version = "0.22.3"
|
||||||
@@ -471,7 +465,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb"
|
checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"core-foundation 0.9.2",
|
"core-foundation",
|
||||||
"core-graphics-types",
|
"core-graphics-types",
|
||||||
"foreign-types",
|
"foreign-types",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -484,24 +478,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b"
|
checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"core-foundation 0.9.2",
|
"core-foundation",
|
||||||
"foreign-types",
|
"foreign-types",
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "core-video-sys"
|
|
||||||
version = "0.1.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "34ecad23610ad9757664d644e369246edde1803fcb43ed72876565098a5d3828"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if 0.1.10",
|
|
||||||
"core-foundation-sys 0.7.0",
|
|
||||||
"core-graphics 0.19.2",
|
|
||||||
"libc",
|
|
||||||
"objc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
@@ -522,9 +503,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-channel"
|
name = "crossbeam-channel"
|
||||||
version = "0.5.1"
|
version = "0.5.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
|
checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
@@ -543,9 +524,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-epoch"
|
name = "crossbeam-epoch"
|
||||||
version = "0.9.5"
|
version = "0.9.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd"
|
checksum = "97242a70df9b89a65d0b6df3c4bf5b9ce03c5b7309019777fbde37e7537f8762"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
@@ -556,14 +537,23 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-utils"
|
name = "crossbeam-utils"
|
||||||
version = "0.8.5"
|
version = "0.8.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
|
checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-common"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "683d6b536309245c849479fba3da410962a43ed8e51c26b729208ec0ac2798d0"
|
||||||
|
dependencies = [
|
||||||
|
"generic-array",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cssparser"
|
name = "cssparser"
|
||||||
version = "0.27.2"
|
version = "0.27.2"
|
||||||
@@ -685,6 +675,18 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "digest"
|
||||||
|
version = "0.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b697d66081d42af4fba142d56918a3cb21dc8eb63372c6b85d14f44fb9c5979b"
|
||||||
|
dependencies = [
|
||||||
|
"block-buffer 0.10.0",
|
||||||
|
"crypto-common",
|
||||||
|
"generic-array",
|
||||||
|
"subtle",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dirs"
|
name = "dirs"
|
||||||
version = "1.0.5"
|
version = "1.0.5"
|
||||||
@@ -766,9 +768,9 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embed_plist"
|
name = "embed_plist"
|
||||||
version = "1.2.0"
|
version = "1.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "53dd2e43a7d32952a6054141ee0d75183958620e84e5eab045de362dff13dc99"
|
checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "encoding_rs"
|
name = "encoding_rs"
|
||||||
@@ -1269,9 +1271,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.3.9"
|
version = "0.3.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8f072413d126e57991455e0a922b31e4c8ba7c2ffbebf6b78b4f8521397d65cd"
|
checksum = "0c9de88456263e249e241fcd211d3954e2c9b0ef7ccfc235a444eb367cae3689"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"fnv",
|
"fnv",
|
||||||
@@ -1485,9 +1487,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "1.7.0"
|
version = "1.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
|
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"autocfg",
|
"autocfg",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
@@ -2135,9 +2137,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ordered-float"
|
name = "ordered-float"
|
||||||
version = "2.9.0"
|
version = "2.10.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8aa3d135650b150c29f0c3e385896f9d3ceb42d2d87b02f0d7a8cbd0fc7e19a6"
|
checksum = "7940cf2ca942593318d07fcf2596cdca60a85c9e7fab408a5e21a4f9dcd40d87"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
@@ -2702,15 +2704,16 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest"
|
name = "reqwest"
|
||||||
version = "0.11.8"
|
version = "0.11.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7c4e0a76dc12a116108933f6301b95e83634e0c47b0afbed6abbaa0601e99258"
|
checksum = "87f242f1488a539a79bac6dbe7c8609ae43b7914b7736210f239a37cccb32525"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"bytes",
|
"bytes",
|
||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
"h2",
|
||||||
"http",
|
"http",
|
||||||
"http-body",
|
"http-body",
|
||||||
"hyper",
|
"hyper",
|
||||||
@@ -2844,8 +2847,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87"
|
checksum = "525bc1abfda2e1998d152c45cf13e696f76d0a4972310b22fac1658b05df7c87"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"core-foundation 0.9.2",
|
"core-foundation",
|
||||||
"core-foundation-sys 0.8.3",
|
"core-foundation-sys",
|
||||||
"libc",
|
"libc",
|
||||||
"security-framework-sys",
|
"security-framework-sys",
|
||||||
]
|
]
|
||||||
@@ -2856,7 +2859,7 @@ version = "2.4.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e"
|
checksum = "a9dd14d83160b528b7bfd66439110573efcfbe281b17fc2ca9f39f550d619c7e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"core-foundation-sys 0.8.3",
|
"core-foundation-sys",
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2996,10 +2999,10 @@ version = "0.9.8"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6"
|
checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"block-buffer",
|
"block-buffer 0.9.0",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"cpufeatures",
|
"cpufeatures",
|
||||||
"digest",
|
"digest 0.9.0",
|
||||||
"opaque-debug",
|
"opaque-debug",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -3166,10 +3169,16 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "subtle"
|
||||||
version = "1.0.84"
|
version = "2.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ecb2e6da8ee5eb9a61068762a32fa9619cc591ceb055b3687f4cd4051ec2e06b"
|
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "1.0.85"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -3210,15 +3219,14 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tao"
|
name = "tao"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
source = "git+https://github.com/tauri-apps/tao?branch=next#f8866a084afe18983c91c67401d8759697578a9c"
|
source = "git+https://github.com/tauri-apps/tao?branch=next#a3a2e0cfc49ddfa8cdf65cf9870fb8e3d45b4bc0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cairo-rs",
|
"cairo-rs",
|
||||||
"cc",
|
"cc",
|
||||||
"cocoa",
|
"cocoa",
|
||||||
"core-foundation 0.9.2",
|
"core-foundation",
|
||||||
"core-graphics 0.22.3",
|
"core-graphics",
|
||||||
"core-video-sys",
|
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"dispatch",
|
"dispatch",
|
||||||
"gdk",
|
"gdk",
|
||||||
@@ -3242,12 +3250,25 @@ dependencies = [
|
|||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"scopeguard",
|
"scopeguard",
|
||||||
"serde",
|
"serde",
|
||||||
|
"tao-core-video-sys",
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
"windows 0.29.0",
|
"windows 0.29.0",
|
||||||
"windows_macros",
|
"windows_macros",
|
||||||
"x11-dl",
|
"x11-dl",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tao-core-video-sys"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "271450eb289cb4d8d0720c6ce70c72c8c858c93dd61fc625881616752e6b98f6"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if 1.0.0",
|
||||||
|
"core-foundation-sys",
|
||||||
|
"libc",
|
||||||
|
"objc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tar"
|
name = "tar"
|
||||||
version = "0.4.38"
|
version = "0.4.38"
|
||||||
@@ -3262,7 +3283,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri"
|
name = "tauri"
|
||||||
version = "1.0.0-beta.8"
|
version = "1.0.0-beta.8"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#46f2eae8aad7c6a228eaf48480d5603dae6454b4"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#c6e05380f7a3b5de3a12db9414a0d7d96102737a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"attohttpc",
|
"attohttpc",
|
||||||
"base64",
|
"base64",
|
||||||
@@ -3324,7 +3345,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-codegen"
|
name = "tauri-codegen"
|
||||||
version = "1.0.0-beta.4"
|
version = "1.0.0-beta.4"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#46f2eae8aad7c6a228eaf48480d5603dae6454b4"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#c6e05380f7a3b5de3a12db9414a0d7d96102737a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"blake3",
|
"blake3",
|
||||||
"kuchiki",
|
"kuchiki",
|
||||||
@@ -3342,7 +3363,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-macros"
|
name = "tauri-macros"
|
||||||
version = "1.0.0-beta.5"
|
version = "1.0.0-beta.5"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#46f2eae8aad7c6a228eaf48480d5603dae6454b4"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#c6e05380f7a3b5de3a12db9414a0d7d96102737a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -3361,10 +3382,21 @@ dependencies = [
|
|||||||
"windows 0.29.0",
|
"windows 0.29.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-plugin-vibrancy"
|
||||||
|
version = "0.0.0"
|
||||||
|
source = "git+https://github.com/tauri-apps/tauri-plugin-vibrancy#b4fceab0d4a6d024f1b9916c126f10f513101128"
|
||||||
|
dependencies = [
|
||||||
|
"cocoa",
|
||||||
|
"objc",
|
||||||
|
"tauri",
|
||||||
|
"windows 0.29.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-runtime"
|
name = "tauri-runtime"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#46f2eae8aad7c6a228eaf48480d5603dae6454b4"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#c6e05380f7a3b5de3a12db9414a0d7d96102737a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gtk",
|
"gtk",
|
||||||
"http",
|
"http",
|
||||||
@@ -3382,7 +3414,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-runtime-wry"
|
name = "tauri-runtime-wry"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#46f2eae8aad7c6a228eaf48480d5603dae6454b4"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#c6e05380f7a3b5de3a12db9414a0d7d96102737a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gtk",
|
"gtk",
|
||||||
"ico",
|
"ico",
|
||||||
@@ -3417,7 +3449,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-utils"
|
name = "tauri-utils"
|
||||||
version = "1.0.0-beta.3"
|
version = "1.0.0-beta.3"
|
||||||
source = "git+https://github.com/tauri-apps/tauri?branch=next#46f2eae8aad7c6a228eaf48480d5603dae6454b4"
|
source = "git+https://github.com/tauri-apps/tauri?branch=next#c6e05380f7a3b5de3a12db9414a0d7d96102737a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck 0.4.0",
|
"heck 0.4.0",
|
||||||
"html5ever",
|
"html5ever",
|
||||||
@@ -3434,13 +3466,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tempfile"
|
name = "tempfile"
|
||||||
version = "3.2.0"
|
version = "3.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22"
|
checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
|
"fastrand",
|
||||||
"libc",
|
"libc",
|
||||||
"rand 0.8.4",
|
|
||||||
"redox_syscall 0.2.10",
|
"redox_syscall 0.2.10",
|
||||||
"remove_dir_all",
|
"remove_dir_all",
|
||||||
"winapi",
|
"winapi",
|
||||||
@@ -4079,6 +4111,17 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "which"
|
||||||
|
version = "4.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ea187a8ef279bc014ec368c27a920da2024d2a711109bfbe3440585d5cf27ad9"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
"lazy_static",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wildmatch"
|
name = "wildmatch"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
@@ -4283,7 +4326,7 @@ version = "0.12.2"
|
|||||||
source = "git+https://github.com/tauri-apps/wry?rev=3284f8d442978269f7654edbdfc9bc51022eaa40#3284f8d442978269f7654edbdfc9bc51022eaa40"
|
source = "git+https://github.com/tauri-apps/wry?rev=3284f8d442978269f7654edbdfc9bc51022eaa40#3284f8d442978269f7654edbdfc9bc51022eaa40"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cocoa",
|
"cocoa",
|
||||||
"core-graphics 0.22.3",
|
"core-graphics",
|
||||||
"gdk",
|
"gdk",
|
||||||
"gio",
|
"gio",
|
||||||
"glib",
|
"glib",
|
||||||
@@ -4402,18 +4445,18 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zstd"
|
name = "zstd"
|
||||||
version = "0.9.1+zstd.1.5.1"
|
version = "0.9.2+zstd.1.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "538b8347df9257b7fbce37677ef7535c00a3c7bf1f81023cc328ed7fe4b41de8"
|
checksum = "2390ea1bf6c038c39674f22d95f0564725fc06034a47129179810b2fc58caa54"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zstd-safe",
|
"zstd-safe",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zstd-safe"
|
name = "zstd-safe"
|
||||||
version = "4.1.2+zstd.1.5.1"
|
version = "4.1.3+zstd.1.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9fb4cfe2f6e6d35c5d27ecd9d256c4b6f7933c4895654917460ec56c29336cc1"
|
checksum = "e99d81b99fb3c2c2c794e3fe56c305c63d5173a16a46b5850b07c935ffc7db79"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"zstd-sys",
|
"zstd-sys",
|
||||||
|
|||||||
@@ -22,12 +22,15 @@ serde = { version = "1.0", features = ["derive"] }
|
|||||||
# tauri = { git = "https://github.com/tauri-apps/tauri", rev = "5e0d59ec", features = ["api-all", "system-tray"] }
|
# tauri = { git = "https://github.com/tauri-apps/tauri", rev = "5e0d59ec", features = ["api-all", "system-tray"] }
|
||||||
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "next", features = ["api-all", "system-tray", "updater"] }
|
tauri = { git = "https://github.com/tauri-apps/tauri", branch = "next", features = ["api-all", "system-tray", "updater"] }
|
||||||
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"] }
|
||||||
|
|
||||||
reqwest = { version = "0.11", features = ["json"] }
|
reqwest = { version = "0.11", features = ["json"] }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
log = "0.4.14"
|
log = "0.4.14"
|
||||||
log4rs = "1.0.0"
|
log4rs = "1.0.0"
|
||||||
warp = "0.3"
|
warp = "0.3"
|
||||||
|
which = "4.2.2"
|
||||||
|
auto-launch = "0.2"
|
||||||
port_scanner = "0.1.5"
|
port_scanner = "0.1.5"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ use crate::{
|
|||||||
states::{ClashState, ProfilesState, VergeState},
|
states::{ClashState, ProfilesState, VergeState},
|
||||||
utils::{
|
utils::{
|
||||||
config::{read_clash, save_clash},
|
config::{read_clash, save_clash},
|
||||||
|
dirs::app_home_dir,
|
||||||
fetch::fetch_profile,
|
fetch::fetch_profile,
|
||||||
sysopt::SysProxyConfig,
|
sysopt::SysProxyConfig,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use serde_yaml::Mapping;
|
use serde_yaml::Mapping;
|
||||||
use tauri::{AppHandle, Manager, State};
|
use std::process::Command;
|
||||||
|
use tauri::State;
|
||||||
|
|
||||||
/// get all profiles from `profiles.yaml`
|
/// get all profiles from `profiles.yaml`
|
||||||
/// do not acquire the lock of ProfileLock
|
/// do not acquire the lock of ProfileLock
|
||||||
@@ -29,11 +31,15 @@ pub fn sync_profiles(profiles: State<'_, ProfilesState>) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Import the profile from url
|
/// import the profile from url
|
||||||
/// and save to `profiles.yaml`
|
/// and save to `profiles.yaml`
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn import_profile(url: String, profiles: State<'_, ProfilesState>) -> Result<(), String> {
|
pub async fn import_profile(
|
||||||
match fetch_profile(&url).await {
|
url: String,
|
||||||
|
with_proxy: bool,
|
||||||
|
profiles: State<'_, ProfilesState>,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
match fetch_profile(&url, with_proxy).await {
|
||||||
Some(result) => {
|
Some(result) => {
|
||||||
let mut profiles = profiles.0.lock().unwrap();
|
let mut profiles = profiles.0.lock().unwrap();
|
||||||
profiles.import_from_url(url, result)
|
profiles.import_from_url(url, result)
|
||||||
@@ -43,12 +49,10 @@ pub async fn import_profile(url: String, profiles: State<'_, ProfilesState>) ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Update the profile
|
/// Update the profile
|
||||||
/// and save to `profiles.yaml`
|
|
||||||
/// http request firstly
|
|
||||||
/// then acquire the lock of `profiles.yaml`
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn update_profile(
|
pub async fn update_profile(
|
||||||
index: usize,
|
index: usize,
|
||||||
|
with_proxy: bool,
|
||||||
clash: State<'_, ClashState>,
|
clash: State<'_, ClashState>,
|
||||||
profiles: State<'_, ProfilesState>,
|
profiles: State<'_, ProfilesState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
@@ -69,7 +73,7 @@ pub async fn update_profile(
|
|||||||
Err(_) => return Err("failed to get profiles lock".into()),
|
Err(_) => return Err("failed to get profiles lock".into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
match fetch_profile(&url).await {
|
match fetch_profile(&url, with_proxy).await {
|
||||||
Some(result) => match profiles.0.lock() {
|
Some(result) => match profiles.0.lock() {
|
||||||
Ok(mut profiles) => {
|
Ok(mut profiles) => {
|
||||||
profiles.update_item(index, result)?;
|
profiles.update_item(index, result)?;
|
||||||
@@ -140,6 +144,34 @@ pub fn patch_profile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// run vscode command to edit the profile
|
||||||
|
#[tauri::command]
|
||||||
|
pub fn edit_profile(index: usize, profiles_state: State<'_, ProfilesState>) -> Result<(), String> {
|
||||||
|
let mut profiles = profiles_state.0.lock().unwrap();
|
||||||
|
let items = profiles.items.take().unwrap_or(vec![]);
|
||||||
|
|
||||||
|
if index >= items.len() {
|
||||||
|
profiles.items = Some(items);
|
||||||
|
return Err("the index out of bound".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
let file = items[index].file.clone().unwrap_or("".into());
|
||||||
|
profiles.items = Some(items);
|
||||||
|
|
||||||
|
let path = app_home_dir().join("profiles").join(file);
|
||||||
|
if !path.exists() {
|
||||||
|
return Err("failed to open the file".into());
|
||||||
|
}
|
||||||
|
|
||||||
|
match which::which("code") {
|
||||||
|
Ok(code) => match Command::new(code).arg(path).status() {
|
||||||
|
Ok(_) => Ok(()),
|
||||||
|
Err(_) => Err("failed to open file by VScode".into()),
|
||||||
|
},
|
||||||
|
Err(_) => Err("please install VScode for edit".into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// restart the sidecar
|
/// restart the sidecar
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn restart_sidecar(
|
pub fn restart_sidecar(
|
||||||
@@ -231,25 +263,3 @@ pub async fn patch_verge_config(
|
|||||||
let mut verge = verge_state.0.lock().unwrap();
|
let mut verge = verge_state.0.lock().unwrap();
|
||||||
verge.patch_config(payload)
|
verge.patch_config(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// start dragging window
|
|
||||||
#[tauri::command]
|
|
||||||
pub fn win_drag(app_handle: AppHandle) {
|
|
||||||
let window = app_handle.get_window("main").unwrap();
|
|
||||||
window.start_dragging().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// hide the window
|
|
||||||
#[tauri::command]
|
|
||||||
pub fn win_hide(app_handle: AppHandle) {
|
|
||||||
let window = app_handle.get_window("main").unwrap();
|
|
||||||
window.hide().unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// mini the window
|
|
||||||
#[tauri::command]
|
|
||||||
pub fn win_mini(app_handle: AppHandle) {
|
|
||||||
let window = app_handle.get_window("main").unwrap();
|
|
||||||
// todo: these methods still has bug on Windows
|
|
||||||
window.minimize().unwrap();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -312,7 +312,10 @@ pub async fn activate_profile(profile_item: &ProfileItem, info: &ClashInfo) -> R
|
|||||||
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 = reqwest::Client::new();
|
let client = match reqwest::ClientBuilder::new().no_proxy().build() {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(_) => return Err("failed to create http::put".into()),
|
||||||
|
};
|
||||||
match client.put(server).headers(headers).json(&data).send().await {
|
match client.put(server).headers(headers).json(&data).send().await {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(err) => Err(format!("request failed `{}`", err.to_string())),
|
Err(err) => Err(format!("request failed `{}`", err.to_string())),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::utils::{config, dirs, startup, sysopt::SysProxyConfig};
|
use crate::utils::{config, dirs, sysopt::SysProxyConfig};
|
||||||
|
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::path::PathBuf;
|
|
||||||
use tauri::api::path::resource_dir;
|
use tauri::api::path::resource_dir;
|
||||||
|
|
||||||
/// ### `verge.yaml` schema
|
/// ### `verge.yaml` schema
|
||||||
@@ -9,8 +9,12 @@ pub struct VergeConfig {
|
|||||||
/// `light` or `dark`
|
/// `light` or `dark`
|
||||||
pub theme_mode: Option<String>,
|
pub theme_mode: Option<String>,
|
||||||
|
|
||||||
|
/// enable blur mode
|
||||||
|
/// maybe be able to set the alpha
|
||||||
|
pub theme_blur: Option<bool>,
|
||||||
|
|
||||||
/// can the app auto startup
|
/// can the app auto startup
|
||||||
pub enable_self_startup: 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>,
|
||||||
@@ -45,7 +49,7 @@ pub struct Verge {
|
|||||||
|
|
||||||
pub cur_sysproxy: Option<SysProxyConfig>,
|
pub cur_sysproxy: Option<SysProxyConfig>,
|
||||||
|
|
||||||
pub exe_path: Option<PathBuf>,
|
pub auto_launch: Option<AutoLaunch>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Verge {
|
impl Default for Verge {
|
||||||
@@ -60,7 +64,7 @@ impl Verge {
|
|||||||
config: VergeConfig::new(),
|
config: VergeConfig::new(),
|
||||||
old_sysproxy: None,
|
old_sysproxy: None,
|
||||||
cur_sysproxy: None,
|
cur_sysproxy: None,
|
||||||
exe_path: None,
|
auto_launch: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,53 +101,61 @@ impl Verge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// set the exe_path
|
/// init the auto launch
|
||||||
pub fn set_exe_path(&mut self, package_info: &tauri::PackageInfo) {
|
pub fn init_launch(&mut self, package_info: &tauri::PackageInfo) {
|
||||||
let exe = if cfg!(target_os = "windows") {
|
let app_name = "clash-verge";
|
||||||
"clash-verge.exe"
|
let app_path = get_app_path(app_name);
|
||||||
} else {
|
let app_path = resource_dir(package_info).unwrap().join(app_path);
|
||||||
"clash-verge"
|
let app_path = app_path.as_os_str().to_str().unwrap();
|
||||||
};
|
|
||||||
let path = resource_dir(package_info).unwrap().join(exe);
|
let auto = AutoLaunchBuilder::new()
|
||||||
self.exe_path = Some(path);
|
.set_app_name(app_name)
|
||||||
|
.set_app_path(app_path)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
self.auto_launch = Some(auto);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// sync the startup when run the app
|
/// sync the startup when run the app
|
||||||
pub fn sync_startup(&self) -> Result<(), String> {
|
pub fn sync_launch(&self) -> Result<(), String> {
|
||||||
let enable = self.config.enable_self_startup.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.exe_path.is_none() {
|
|
||||||
return Err("should init the exe_path first".into());
|
if self.auto_launch.is_none() {
|
||||||
|
return Err("should init the auto launch first".into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let exe_path = self.exe_path.clone().unwrap();
|
let auto_launch = self.auto_launch.clone().unwrap();
|
||||||
match startup::get_startup(&exe_path) {
|
|
||||||
Ok(sys_enable) => {
|
let is_enabled = auto_launch.is_enabled().unwrap_or(false);
|
||||||
if sys_enable || (!sys_enable && startup::set_startup(true, &exe_path).is_ok()) {
|
if !is_enabled {
|
||||||
Ok(())
|
if let Err(_) = auto_launch.enable() {
|
||||||
} else {
|
return Err("failed to enable auto-launch".into());
|
||||||
Err("failed to sync startup".into())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(_) => Err("failed to get system startup info".into()),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// update the startup
|
/// update the startup
|
||||||
fn update_startup(&mut self, enable: bool) -> Result<(), String> {
|
fn update_launch(&mut self, enable: bool) -> Result<(), String> {
|
||||||
let conf_enable = self.config.enable_self_startup.clone().unwrap_or(false);
|
let conf_enable = self.config.enable_auto_launch.clone().unwrap_or(false);
|
||||||
|
|
||||||
if enable == conf_enable {
|
if enable == conf_enable {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
if self.exe_path.is_none() {
|
|
||||||
return Err("should init the exe_path first".into());
|
let auto_launch = self.auto_launch.clone().unwrap();
|
||||||
}
|
|
||||||
let exe_path = self.exe_path.clone().unwrap();
|
let result = if enable {
|
||||||
match startup::set_startup(enable, &exe_path) {
|
auto_launch.enable()
|
||||||
|
} else {
|
||||||
|
auto_launch.disable()
|
||||||
|
};
|
||||||
|
|
||||||
|
match result {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(_) => Err("failed to set system startup info".into()),
|
Err(_) => Err("failed to set system startup info".into()),
|
||||||
}
|
}
|
||||||
@@ -157,12 +169,15 @@ impl Verge {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
if patch.theme_blur.is_some() {
|
||||||
|
self.config.theme_blur = patch.theme_blur;
|
||||||
|
}
|
||||||
|
|
||||||
// should update system startup
|
// should update system startup
|
||||||
if patch.enable_self_startup.is_some() {
|
if patch.enable_auto_launch.is_some() {
|
||||||
let enable = patch.enable_self_startup.unwrap();
|
let enable = patch.enable_auto_launch.unwrap();
|
||||||
self.update_startup(enable)?;
|
self.update_launch(enable)?;
|
||||||
self.config.enable_self_startup = Some(enable);
|
self.config.enable_auto_launch = Some(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// should update system proxy
|
// should update system proxy
|
||||||
@@ -180,7 +195,7 @@ impl Verge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
// should update system proxt 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;
|
self.config.system_proxy_bypass = patch.system_proxy_bypass;
|
||||||
}
|
}
|
||||||
@@ -188,3 +203,14 @@ impl Verge {
|
|||||||
self.config.save_file()
|
self.config.save_file()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the target app_path
|
||||||
|
fn get_app_path(app_name: &str) -> String {
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
let ext = "";
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
let ext = ".app";
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
let ext = ".exe";
|
||||||
|
String::from(app_name) + ext
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
windows_subsystem = "windows"
|
windows_subsystem = "windows"
|
||||||
)]
|
)]
|
||||||
|
|
||||||
extern crate tauri;
|
|
||||||
|
|
||||||
mod cmds;
|
mod cmds;
|
||||||
mod core;
|
mod core;
|
||||||
mod states;
|
mod states;
|
||||||
@@ -37,6 +35,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
|
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
|
||||||
"open_window" => {
|
"open_window" => {
|
||||||
let window = app_handle.get_window("main").unwrap();
|
let window = app_handle.get_window("main").unwrap();
|
||||||
|
window.unminimize().unwrap();
|
||||||
window.show().unwrap();
|
window.show().unwrap();
|
||||||
window.set_focus().unwrap();
|
window.set_focus().unwrap();
|
||||||
}
|
}
|
||||||
@@ -63,6 +62,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
},
|
},
|
||||||
SystemTrayEvent::LeftClick { .. } => {
|
SystemTrayEvent::LeftClick { .. } => {
|
||||||
let window = app_handle.get_window("main").unwrap();
|
let window = app_handle.get_window("main").unwrap();
|
||||||
|
window.unminimize().unwrap();
|
||||||
window.show().unwrap();
|
window.show().unwrap();
|
||||||
window.set_focus().unwrap();
|
window.set_focus().unwrap();
|
||||||
}
|
}
|
||||||
@@ -73,9 +73,6 @@ 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::win_drag,
|
|
||||||
cmds::win_hide,
|
|
||||||
cmds::win_mini,
|
|
||||||
// clash
|
// clash
|
||||||
cmds::get_clash_info,
|
cmds::get_clash_info,
|
||||||
cmds::patch_clash_config,
|
cmds::patch_clash_config,
|
||||||
@@ -83,13 +80,14 @@ fn main() -> std::io::Result<()> {
|
|||||||
cmds::get_verge_config,
|
cmds::get_verge_config,
|
||||||
cmds::patch_verge_config,
|
cmds::patch_verge_config,
|
||||||
// profile
|
// profile
|
||||||
|
cmds::edit_profile,
|
||||||
|
cmds::patch_profile,
|
||||||
cmds::import_profile,
|
cmds::import_profile,
|
||||||
cmds::update_profile,
|
cmds::update_profile,
|
||||||
cmds::delete_profile,
|
cmds::delete_profile,
|
||||||
cmds::select_profile,
|
cmds::select_profile,
|
||||||
cmds::patch_profile,
|
|
||||||
cmds::sync_profiles,
|
|
||||||
cmds::get_profiles,
|
cmds::get_profiles,
|
||||||
|
cmds::sync_profiles,
|
||||||
])
|
])
|
||||||
.build(tauri::generate_context!())
|
.build(tauri::generate_context!())
|
||||||
.expect("error while running tauri application")
|
.expect("error while running tauri application")
|
||||||
|
|||||||
@@ -23,11 +23,20 @@ fn parse_string<T: FromStr>(target: &str, key: &str) -> Option<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// fetch and parse the profile
|
/// fetch and parse the profile
|
||||||
pub async fn fetch_profile(url: &str) -> Option<ProfileResponse> {
|
pub async fn fetch_profile(url: &str, with_proxy: bool) -> Option<ProfileResponse> {
|
||||||
let resp = match reqwest::get(url).await {
|
let builder = reqwest::ClientBuilder::new();
|
||||||
Ok(res) => res,
|
let client = match with_proxy {
|
||||||
|
true => builder.build(),
|
||||||
|
false => builder.no_proxy().build(),
|
||||||
|
};
|
||||||
|
let resp = match client {
|
||||||
|
Ok(client) => match client.get(url).send().await {
|
||||||
|
Ok(res) => res,
|
||||||
|
Err(_) => return None,
|
||||||
|
},
|
||||||
Err(_) => return None,
|
Err(_) => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let header = resp.headers();
|
let header = resp.headers();
|
||||||
|
|
||||||
// parse the Subscription Userinfo
|
// parse the Subscription Userinfo
|
||||||
|
|||||||
@@ -4,5 +4,4 @@ pub mod fetch;
|
|||||||
pub mod init;
|
pub mod init;
|
||||||
pub mod resolve;
|
pub mod resolve;
|
||||||
pub mod server;
|
pub mod server;
|
||||||
pub mod startup;
|
|
||||||
pub mod sysopt;
|
pub mod sysopt;
|
||||||
|
|||||||
@@ -9,6 +9,16 @@ pub fn resolve_setup(app: &App) {
|
|||||||
let window = app.get_window("main").unwrap();
|
let window = app.get_window("main").unwrap();
|
||||||
window.set_shadow(true);
|
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;
|
||||||
|
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());
|
||||||
|
|
||||||
@@ -33,9 +43,9 @@ pub fn resolve_setup(app: &App) {
|
|||||||
log::error!("{}", err);
|
log::error!("{}", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
verge.set_exe_path(app.package_info());
|
|
||||||
verge.init_sysproxy(clash.info.port.clone());
|
verge.init_sysproxy(clash.info.port.clone());
|
||||||
if let Err(err) = verge.sync_startup() {
|
verge.init_launch(app.package_info());
|
||||||
|
if let Err(err) = verge.sync_launch() {
|
||||||
log::error!("{}", err);
|
log::error!("{}", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
use std::io;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
|
|
||||||
static APP_KEY: &str = "ClashVerge";
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
/// get the startup value
|
|
||||||
/// whether as same as the exe_path
|
|
||||||
pub fn get_startup(exe_path: &PathBuf) -> io::Result<bool> {
|
|
||||||
use winreg::enums::*;
|
|
||||||
use winreg::RegKey;
|
|
||||||
|
|
||||||
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
|
|
||||||
let cur_var = hkcu.open_subkey_with_flags(
|
|
||||||
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
|
||||||
KEY_READ,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
match cur_var.get_value::<String, _>(APP_KEY) {
|
|
||||||
Ok(path) => {
|
|
||||||
let exe_path = exe_path.clone();
|
|
||||||
let exe_path = exe_path.as_os_str().to_str().unwrap();
|
|
||||||
Ok(path == exe_path)
|
|
||||||
}
|
|
||||||
Err(_) => Ok(false),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
/// set the startup on windows
|
|
||||||
/// delete the reg key if disabled
|
|
||||||
pub fn set_startup(enable: bool, exe_path: &PathBuf) -> io::Result<()> {
|
|
||||||
use winreg::enums::*;
|
|
||||||
use winreg::RegKey;
|
|
||||||
|
|
||||||
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
|
|
||||||
let cur_var = hkcu.open_subkey_with_flags(
|
|
||||||
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
|
||||||
KEY_SET_VALUE,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
match enable {
|
|
||||||
true => {
|
|
||||||
let exe_path = exe_path.clone();
|
|
||||||
let exe_path = exe_path.as_os_str().to_str().unwrap();
|
|
||||||
cur_var.set_value::<&str, _>(APP_KEY, &exe_path)
|
|
||||||
}
|
|
||||||
false => cur_var.delete_value(APP_KEY),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
#[test]
|
|
||||||
fn test() {
|
|
||||||
let path = PathBuf::from(r"D:\Software\Clash Verge\clash-verge.exe");
|
|
||||||
|
|
||||||
assert!(set_startup(true, &path).is_ok());
|
|
||||||
assert_eq!(get_startup(&path).unwrap(), true);
|
|
||||||
|
|
||||||
assert!(set_startup(false, &path).is_ok());
|
|
||||||
assert_eq!(get_startup(&path).unwrap(), false);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "clash-verge",
|
"productName": "clash-verge",
|
||||||
"version": "0.0.8"
|
"version": "0.0.11"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
"distDir": "../dist",
|
"distDir": "../dist",
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
"resizable": true,
|
"resizable": true,
|
||||||
"fullscreen": false,
|
"fullscreen": false,
|
||||||
"decorations": false,
|
"decorations": false,
|
||||||
"transparent": false,
|
"transparent": true,
|
||||||
"minWidth": 600,
|
"minWidth": 600,
|
||||||
"minHeight": 520
|
"minHeight": 520
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,3 +28,4 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@import "./layout.scss";
|
@import "./layout.scss";
|
||||||
|
@import "./page.scss";
|
||||||
|
|||||||
@@ -27,6 +27,10 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.the-newbtn {
|
.the-newbtn {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: 20px;
|
right: 20px;
|
||||||
@@ -54,27 +58,24 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
flex: 1 1 75%;
|
flex: 1 1 75%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding: 2px 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
|
|
||||||
.the-bar {
|
.the-bar {
|
||||||
flex: 0 0 30px;
|
position: absolute;
|
||||||
width: 100%;
|
top: 2px;
|
||||||
height: 30px;
|
right: 8px;
|
||||||
padding: 0 16px;
|
height: 36px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: flex-end;
|
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
z-index: 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.the-content {
|
.the-content {
|
||||||
flex: 1 1 100%;
|
position: absolute;
|
||||||
overflow: auto;
|
left: 0;
|
||||||
box-sizing: border-box;
|
right: 0;
|
||||||
scrollbar-gutter: stable;
|
top: 30px;
|
||||||
|
bottom: 10px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/assets/styles/page.scss
Normal file
33
src/assets/styles/page.scss
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
.base-page {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
> header {
|
||||||
|
flex: 0 0 58px;
|
||||||
|
width: 90%;
|
||||||
|
max-width: 850px;
|
||||||
|
margin: 0 auto;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
> section {
|
||||||
|
position: relative;
|
||||||
|
flex: 1 1 100%;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: auto;
|
||||||
|
padding: 8px 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
scrollbar-gutter: stable;
|
||||||
|
|
||||||
|
.base-content {
|
||||||
|
width: 90%;
|
||||||
|
max-width: 850px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
32
src/components/base-page.tsx
Normal file
32
src/components/base-page.tsx
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { Typography } from "@mui/material";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
title?: React.ReactNode; // the page title
|
||||||
|
header?: React.ReactNode; // something behind title
|
||||||
|
contentStyle?: React.CSSProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BasePage: React.FC<Props> = (props) => {
|
||||||
|
const { title, header, contentStyle, children } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="base-page" data-windrag>
|
||||||
|
<header data-windrag>
|
||||||
|
<Typography variant="h4" component="h1">
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
{header}
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section data-windrag>
|
||||||
|
<div className="base-content" style={contentStyle} data-windrag>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default BasePage;
|
||||||
41
src/components/layout-control.tsx
Normal file
41
src/components/layout-control.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { Button } from "@mui/material";
|
||||||
|
import { appWindow } from "@tauri-apps/api/window";
|
||||||
|
import {
|
||||||
|
CloseRounded,
|
||||||
|
CropSquareRounded,
|
||||||
|
HorizontalRuleRounded,
|
||||||
|
} from "@mui/icons-material";
|
||||||
|
|
||||||
|
const LayoutControl = () => {
|
||||||
|
const minWidth = 40;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
sx={{ minWidth, svg: { transform: "scale(0.9)" } }}
|
||||||
|
onClick={() => appWindow.minimize()}
|
||||||
|
>
|
||||||
|
<HorizontalRuleRounded fontSize="small" />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
sx={{ minWidth, svg: { transform: "scale(0.9)" } }}
|
||||||
|
onClick={() => appWindow.toggleMaximize()}
|
||||||
|
>
|
||||||
|
<CropSquareRounded fontSize="small" />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
sx={{ minWidth, svg: { transform: "scale(1.05)" } }}
|
||||||
|
onClick={() => appWindow.hide()}
|
||||||
|
>
|
||||||
|
<CloseRounded fontSize="small" />
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LayoutControl;
|
||||||
92
src/components/notice.tsx
Normal file
92
src/components/notice.tsx
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
import ReactDOM from "react-dom";
|
||||||
|
import { ReactNode, useState } from "react";
|
||||||
|
import { Box, IconButton, Slide, Snackbar, Typography } from "@mui/material";
|
||||||
|
import { Close, CheckCircleRounded, ErrorRounded } from "@mui/icons-material";
|
||||||
|
|
||||||
|
interface InnerProps {
|
||||||
|
type: string;
|
||||||
|
duration?: number;
|
||||||
|
message: ReactNode;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const NoticeInner = (props: InnerProps) => {
|
||||||
|
const { type, message, duration = 2000, onClose } = props;
|
||||||
|
const [visible, setVisible] = useState(true);
|
||||||
|
|
||||||
|
const onBtnClose = () => {
|
||||||
|
setVisible(false);
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
const onAutoClose = (_e: any, reason: string) => {
|
||||||
|
if (reason !== "clickaway") onBtnClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
const msgElement =
|
||||||
|
type === "info" ? (
|
||||||
|
message
|
||||||
|
) : (
|
||||||
|
<Box sx={{ display: "flex", alignItems: "center" }}>
|
||||||
|
{type === "error" && <ErrorRounded color="error" />}
|
||||||
|
{type === "success" && <CheckCircleRounded color="success" />}
|
||||||
|
|
||||||
|
<Typography
|
||||||
|
sx={{ ml: 1, wordWrap: "break-word", wordBreak: "break-all" }}
|
||||||
|
>
|
||||||
|
{message}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Snackbar
|
||||||
|
open={visible}
|
||||||
|
anchorOrigin={{ vertical: "top", horizontal: "right" }}
|
||||||
|
autoHideDuration={duration}
|
||||||
|
onClose={onAutoClose}
|
||||||
|
message={msgElement}
|
||||||
|
sx={{ maxWidth: 360 }}
|
||||||
|
TransitionComponent={(p) => <Slide {...p} direction="left" />}
|
||||||
|
transitionDuration={200}
|
||||||
|
action={
|
||||||
|
<IconButton size="small" color="inherit" onClick={onBtnClose}>
|
||||||
|
<Close fontSize="inherit" />
|
||||||
|
</IconButton>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
interface NoticeInstance {
|
||||||
|
(props: Omit<InnerProps, "onClose">): void;
|
||||||
|
|
||||||
|
info(message: ReactNode, duration?: number): void;
|
||||||
|
error(message: ReactNode, duration?: number): void;
|
||||||
|
success(message: ReactNode, duration?: number): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
let parent: HTMLDivElement = null!;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
const Notice: NoticeInstance = (props) => {
|
||||||
|
if (!parent) {
|
||||||
|
parent = document.createElement("div");
|
||||||
|
document.body.appendChild(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
const container = document.createElement("div");
|
||||||
|
parent.appendChild(container);
|
||||||
|
|
||||||
|
const onUnmount = () => {
|
||||||
|
const result = ReactDOM.unmountComponentAtNode(container);
|
||||||
|
if (result && parent) parent.removeChild(container);
|
||||||
|
};
|
||||||
|
|
||||||
|
ReactDOM.render(<NoticeInner {...props} onClose={onUnmount} />, container);
|
||||||
|
};
|
||||||
|
|
||||||
|
(["info", "error", "success"] as const).forEach((type) => {
|
||||||
|
Notice[type] = (message, duration) => Notice({ type, message, duration });
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Notice;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useRef, useState } from "react";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import {
|
import {
|
||||||
alpha,
|
alpha,
|
||||||
@@ -14,7 +14,8 @@ import {
|
|||||||
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";
|
||||||
import { updateProfile, deleteProfile } from "../services/cmds";
|
import { updateProfile, deleteProfile, editProfile } from "../services/cmds";
|
||||||
|
import Notice from "./notice";
|
||||||
import parseTraffic from "../utils/parse-traffic";
|
import parseTraffic from "../utils/parse-traffic";
|
||||||
import relativeTime from "dayjs/plugin/relativeTime";
|
import relativeTime from "dayjs/plugin/relativeTime";
|
||||||
|
|
||||||
@@ -32,19 +33,19 @@ const Wrapper = styled(Box)(({ theme }) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const round = keyframes`
|
const round = keyframes`
|
||||||
from { transform: rotate(0deg); }
|
from { transform: rotate(0deg); }
|
||||||
to { transform: rotate(360deg); }
|
to { transform: rotate(360deg); }
|
||||||
`;
|
`;
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
index: number;
|
index: number;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
itemData: CmdType.ProfileItem;
|
itemData: CmdType.ProfileItem;
|
||||||
onClick: () => void;
|
onSelect: (force: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProfileItemComp: React.FC<Props> = (props) => {
|
const ProfileItem: React.FC<Props> = (props) => {
|
||||||
const { index, selected, itemData, onClick } = props;
|
const { index, selected, itemData, onSelect } = props;
|
||||||
|
|
||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
@@ -58,27 +59,46 @@ const ProfileItemComp: 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() : "";
|
||||||
|
|
||||||
const onUpdate = async () => {
|
const onEdit = async () => {
|
||||||
|
setAnchorEl(null);
|
||||||
|
try {
|
||||||
|
await editProfile(index);
|
||||||
|
} catch (err: any) {
|
||||||
|
Notice.error(err.toString());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onForceSelect = () => {
|
||||||
|
setAnchorEl(null);
|
||||||
|
onSelect(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onUpdateWrapper = (withProxy: boolean) => async () => {
|
||||||
setAnchorEl(null);
|
setAnchorEl(null);
|
||||||
if (loading) return;
|
if (loading) return;
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
await updateProfile(index);
|
await updateProfile(index, withProxy);
|
||||||
mutate("getProfiles");
|
mutate("getProfiles");
|
||||||
} catch (err) {
|
} catch (err: any) {
|
||||||
console.error(err);
|
Notice.error(err.toString());
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteRef = useRef(false);
|
||||||
const onDelete = 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) {
|
} catch (err: any) {
|
||||||
console.error(err);
|
Notice.error(err.toString());
|
||||||
|
} finally {
|
||||||
|
deleteRef.current = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -121,7 +141,7 @@ const ProfileItemComp: React.FC<Props> = (props) => {
|
|||||||
|
|
||||||
return { bgcolor, color, "& h2": { color: h2color } };
|
return { bgcolor, color, "& h2": { color: h2color } };
|
||||||
}}
|
}}
|
||||||
onClick={onClick}
|
onClick={() => onSelect(false)}
|
||||||
onContextMenu={handleContextMenu}
|
onContextMenu={handleContextMenu}
|
||||||
>
|
>
|
||||||
<Box display="flex" justifyContent="space-between">
|
<Box display="flex" justifyContent="space-between">
|
||||||
@@ -145,7 +165,7 @@ const ProfileItemComp: React.FC<Props> = (props) => {
|
|||||||
disabled={loading}
|
disabled={loading}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
onUpdate();
|
onUpdateWrapper(false)();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<RefreshRounded />
|
<RefreshRounded />
|
||||||
@@ -196,9 +216,11 @@ const ProfileItemComp: React.FC<Props> = (props) => {
|
|||||||
anchorPosition={position}
|
anchorPosition={position}
|
||||||
anchorReference="anchorPosition"
|
anchorReference="anchorPosition"
|
||||||
>
|
>
|
||||||
<MenuItem onClick={onUpdate}>Update</MenuItem>
|
<MenuItem onClick={onForceSelect}>Select</MenuItem>
|
||||||
|
<MenuItem onClick={onEdit}>Edit(VScode)</MenuItem>
|
||||||
|
<MenuItem onClick={onUpdateWrapper(false)}>Update</MenuItem>
|
||||||
|
<MenuItem onClick={onUpdateWrapper(true)}>Update(Proxy)</MenuItem>
|
||||||
<MenuItem onClick={onDelete}>Delete</MenuItem>
|
<MenuItem onClick={onDelete}>Delete</MenuItem>
|
||||||
{/* <MenuItem>Update(proxy)</MenuItem> */}
|
|
||||||
</Menu>
|
</Menu>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@@ -216,4 +238,4 @@ function parseExpire(expire?: number) {
|
|||||||
return dayjs(expire * 1000).format("YYYY-MM-DD");
|
return dayjs(expire * 1000).format("YYYY-MM-DD");
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ProfileItemComp;
|
export default ProfileItem;
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Virtuoso } from "react-virtuoso";
|
import { Virtuoso } from "react-virtuoso";
|
||||||
import {
|
import {
|
||||||
alpha,
|
|
||||||
Box,
|
Box,
|
||||||
Collapse,
|
Collapse,
|
||||||
Divider,
|
Divider,
|
||||||
IconButton,
|
IconButton,
|
||||||
List,
|
List,
|
||||||
ListItem,
|
ListItem,
|
||||||
ListItemButton,
|
|
||||||
ListItemIcon,
|
|
||||||
ListItemText,
|
ListItemText,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import {
|
import {
|
||||||
@@ -18,53 +15,11 @@ import {
|
|||||||
ExpandMoreRounded,
|
ExpandMoreRounded,
|
||||||
MyLocationRounded,
|
MyLocationRounded,
|
||||||
NetworkCheckRounded,
|
NetworkCheckRounded,
|
||||||
CheckCircleOutlineRounded,
|
|
||||||
} from "@mui/icons-material";
|
} from "@mui/icons-material";
|
||||||
import { updateProxy } from "../services/api";
|
import { updateProxy } from "../services/api";
|
||||||
import { ApiType } from "../services/types";
|
import { ApiType } from "../services/types";
|
||||||
import { getProfiles, patchProfile } from "../services/cmds";
|
import { getProfiles, patchProfile } from "../services/cmds";
|
||||||
|
import ProxyItem from "./proxy-item";
|
||||||
interface ItemProps {
|
|
||||||
proxy: ApiType.ProxyItem;
|
|
||||||
selected: boolean;
|
|
||||||
onClick?: (name: string) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Item = ({ proxy, selected, onClick }: ItemProps) => {
|
|
||||||
return (
|
|
||||||
<ListItem sx={{ py: 0, pl: 4 }}>
|
|
||||||
<ListItemButton
|
|
||||||
dense
|
|
||||||
selected={selected}
|
|
||||||
onClick={() => onClick?.(proxy.name)}
|
|
||||||
sx={[
|
|
||||||
{
|
|
||||||
borderRadius: 1,
|
|
||||||
},
|
|
||||||
({ palette: { mode, primary } }) => {
|
|
||||||
const bgcolor =
|
|
||||||
mode === "light"
|
|
||||||
? alpha(primary.main, 0.15)
|
|
||||||
: alpha(primary.main, 0.35);
|
|
||||||
const color = mode === "light" ? primary.main : primary.light;
|
|
||||||
|
|
||||||
return {
|
|
||||||
"&.Mui-selected": { bgcolor },
|
|
||||||
"&.Mui-selected .MuiListItemText-secondary": { color },
|
|
||||||
};
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<ListItemText title={proxy.name} secondary={proxy.name} />
|
|
||||||
<ListItemIcon
|
|
||||||
sx={{ justifyContent: "flex-end", color: "primary.main" }}
|
|
||||||
>
|
|
||||||
{selected && <CheckCircleOutlineRounded sx={{ fontSize: 16 }} />}
|
|
||||||
</ListItemIcon>
|
|
||||||
</ListItemButton>
|
|
||||||
</ListItem>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
group: ApiType.ProxyGroupItem;
|
group: ApiType.ProxyGroupItem;
|
||||||
@@ -143,12 +98,13 @@ const ProxyGroup = ({ group }: Props) => {
|
|||||||
|
|
||||||
{proxies.length >= 10 ? (
|
{proxies.length >= 10 ? (
|
||||||
<Virtuoso
|
<Virtuoso
|
||||||
style={{ height: "400px", marginBottom: "4px" }}
|
style={{ height: "320px", marginBottom: "4px" }}
|
||||||
totalCount={proxies.length}
|
totalCount={proxies.length}
|
||||||
itemContent={(index) => (
|
itemContent={(index) => (
|
||||||
<Item
|
<ProxyItem
|
||||||
proxy={proxies[index]}
|
proxy={proxies[index]}
|
||||||
selected={proxies[index].name === now}
|
selected={proxies[index].name === now}
|
||||||
|
sx={{ py: 0, pl: 4 }}
|
||||||
onClick={onUpdate}
|
onClick={onUpdate}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -157,13 +113,14 @@ const ProxyGroup = ({ group }: Props) => {
|
|||||||
<List
|
<List
|
||||||
component="div"
|
component="div"
|
||||||
disablePadding
|
disablePadding
|
||||||
sx={{ maxHeight: "400px", overflow: "auto", mb: "4px" }}
|
sx={{ maxHeight: "320px", overflow: "auto", mb: "4px" }}
|
||||||
>
|
>
|
||||||
{proxies.map((proxy) => (
|
{proxies.map((proxy) => (
|
||||||
<Item
|
<ProxyItem
|
||||||
key={proxy.name}
|
key={proxy.name}
|
||||||
proxy={proxy}
|
proxy={proxy}
|
||||||
selected={proxy.name === now}
|
selected={proxy.name === now}
|
||||||
|
sx={{ py: 0, pl: 4 }}
|
||||||
onClick={onUpdate}
|
onClick={onUpdate}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|||||||
58
src/components/proxy-item.tsx
Normal file
58
src/components/proxy-item.tsx
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import { CheckCircleOutlineRounded } from "@mui/icons-material";
|
||||||
|
import {
|
||||||
|
alpha,
|
||||||
|
ListItem,
|
||||||
|
ListItemButton,
|
||||||
|
ListItemIcon,
|
||||||
|
ListItemText,
|
||||||
|
SxProps,
|
||||||
|
Theme,
|
||||||
|
} from "@mui/material";
|
||||||
|
import { ApiType } from "../services/types";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
proxy: ApiType.ProxyItem;
|
||||||
|
selected: boolean;
|
||||||
|
sx?: SxProps<Theme>;
|
||||||
|
onClick?: (name: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProxyItem = (props: Props) => {
|
||||||
|
const { proxy, selected, sx, onClick } = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ListItem sx={sx}>
|
||||||
|
<ListItemButton
|
||||||
|
dense
|
||||||
|
selected={selected}
|
||||||
|
onClick={() => onClick?.(proxy.name)}
|
||||||
|
sx={[
|
||||||
|
{
|
||||||
|
borderRadius: 1,
|
||||||
|
},
|
||||||
|
({ palette: { mode, primary } }) => {
|
||||||
|
const bgcolor =
|
||||||
|
mode === "light"
|
||||||
|
? alpha(primary.main, 0.15)
|
||||||
|
: alpha(primary.main, 0.35);
|
||||||
|
const color = mode === "light" ? primary.main : primary.light;
|
||||||
|
|
||||||
|
return {
|
||||||
|
"&.Mui-selected": { bgcolor },
|
||||||
|
"&.Mui-selected .MuiListItemText-secondary": { color },
|
||||||
|
};
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<ListItemText title={proxy.name} secondary={proxy.name} />
|
||||||
|
<ListItemIcon
|
||||||
|
sx={{ justifyContent: "flex-end", color: "primary.main" }}
|
||||||
|
>
|
||||||
|
{selected && <CheckCircleOutlineRounded sx={{ fontSize: 16 }} />}
|
||||||
|
</ListItemIcon>
|
||||||
|
</ListItemButton>
|
||||||
|
</ListItem>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProxyItem;
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
import { ListItem, styled } from "@mui/material";
|
|
||||||
|
|
||||||
const SettingItem = styled(ListItem)(() => ({
|
|
||||||
paddingTop: 5,
|
|
||||||
paddingBottom: 5,
|
|
||||||
}));
|
|
||||||
|
|
||||||
export default SettingItem;
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { cloneElement, isValidElement, ReactNode, useRef } from "react";
|
import { cloneElement, isValidElement, ReactNode, useRef } from "react";
|
||||||
import noop from "../utils/noop";
|
import noop from "../../utils/noop";
|
||||||
|
|
||||||
interface Props<Value> {
|
interface Props<Value> {
|
||||||
value?: Value;
|
value?: Value;
|
||||||
@@ -1,18 +1,16 @@
|
|||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
import {
|
import {
|
||||||
List,
|
|
||||||
ListItemText,
|
ListItemText,
|
||||||
ListSubheader,
|
|
||||||
TextField,
|
TextField,
|
||||||
Switch,
|
Switch,
|
||||||
Select,
|
Select,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { getClashConfig, updateConfigs } from "../services/api";
|
import { getClashConfig, updateConfigs } from "../../services/api";
|
||||||
import { patchClashConfig } from "../services/cmds";
|
import { SettingList, SettingItem } from "./setting";
|
||||||
import { ApiType } from "../services/types";
|
import { patchClashConfig } from "../../services/cmds";
|
||||||
|
import { ApiType } from "../../services/types";
|
||||||
import GuardState from "./guard-state";
|
import GuardState from "./guard-state";
|
||||||
import SettingItem from "./setting-item";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onError?: (err: Error) => void;
|
onError?: (err: Error) => void;
|
||||||
@@ -30,22 +28,16 @@ const SettingClash = ({ onError }: Props) => {
|
|||||||
} = clashConfig ?? {};
|
} = clashConfig ?? {};
|
||||||
|
|
||||||
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>) => {
|
||||||
mutate("getClashConfig", { ...clashConfig, ...patch }, false);
|
mutate("getClashConfig", { ...clashConfig, ...patch }, false);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onUpdateData = async (patch: Partial<ApiType.ConfigData>) => {
|
const onUpdateData = async (patch: Partial<ApiType.ConfigData>) => {
|
||||||
await updateConfigs(patch);
|
await updateConfigs(patch);
|
||||||
await patchClashConfig(patch);
|
await patchClashConfig(patch);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<List>
|
<SettingList title="Clash Setting">
|
||||||
<ListSubheader sx={{ background: "transparent" }}>
|
|
||||||
Clash Setting
|
|
||||||
</ListSubheader>
|
|
||||||
|
|
||||||
<SettingItem>
|
<SettingItem>
|
||||||
<ListItemText primary="Allow Lan" />
|
<ListItemText primary="Allow Lan" />
|
||||||
<GuardState
|
<GuardState
|
||||||
@@ -102,7 +94,7 @@ const SettingClash = ({ onError }: Props) => {
|
|||||||
disabled
|
disabled
|
||||||
/>
|
/>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
</List>
|
</SettingList>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
67
src/components/setting/setting-system.tsx
Normal file
67
src/components/setting/setting-system.tsx
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
|
import { Box, ListItemText, Switch } from "@mui/material";
|
||||||
|
import { getVergeConfig, patchVergeConfig } from "../../services/cmds";
|
||||||
|
import { SettingList, SettingItem } from "./setting";
|
||||||
|
import { CmdType } from "../../services/types";
|
||||||
|
import GuardState from "./guard-state";
|
||||||
|
import SysproxyTooltip from "./sysproxy-tooltip";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
onError?: (err: Error) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SettingSystem = ({ onError }: Props) => {
|
||||||
|
const { mutate } = useSWRConfig();
|
||||||
|
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
||||||
|
|
||||||
|
const {
|
||||||
|
enable_auto_launch: startup = false,
|
||||||
|
enable_system_proxy: proxy = false,
|
||||||
|
} = vergeConfig ?? {};
|
||||||
|
|
||||||
|
const onSwitchFormat = (_e: any, value: boolean) => value;
|
||||||
|
const onChangeData = (patch: Partial<CmdType.VergeConfig>) => {
|
||||||
|
mutate("getVergeConfig", { ...vergeConfig, ...patch }, false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SettingList title="System Setting">
|
||||||
|
<SettingItem>
|
||||||
|
<ListItemText primary="Auto Launch" />
|
||||||
|
<GuardState
|
||||||
|
value={startup}
|
||||||
|
valueProps="checked"
|
||||||
|
onCatch={onError}
|
||||||
|
onFormat={onSwitchFormat}
|
||||||
|
onChange={(e) => onChangeData({ enable_auto_launch: e })}
|
||||||
|
onGuard={(e) => patchVergeConfig({ enable_auto_launch: e })}
|
||||||
|
>
|
||||||
|
<Switch edge="end" />
|
||||||
|
</GuardState>
|
||||||
|
</SettingItem>
|
||||||
|
|
||||||
|
<SettingItem>
|
||||||
|
<ListItemText
|
||||||
|
primary={
|
||||||
|
<Box sx={{ display: "flex", alignItems: "center" }}>
|
||||||
|
System Proxy
|
||||||
|
<SysproxyTooltip />
|
||||||
|
</Box>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<GuardState
|
||||||
|
value={proxy}
|
||||||
|
valueProps="checked"
|
||||||
|
onCatch={onError}
|
||||||
|
onFormat={onSwitchFormat}
|
||||||
|
onChange={(e) => onChangeData({ enable_system_proxy: e })}
|
||||||
|
onGuard={(e) => patchVergeConfig({ enable_system_proxy: e })}
|
||||||
|
>
|
||||||
|
<Switch edge="end" />
|
||||||
|
</GuardState>
|
||||||
|
</SettingItem>
|
||||||
|
</SettingList>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SettingSystem;
|
||||||
@@ -1,16 +1,10 @@
|
|||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
import {
|
import { ListItemText, Switch, Typography } from "@mui/material";
|
||||||
List,
|
import { getVergeConfig, patchVergeConfig } from "../../services/cmds";
|
||||||
ListItemText,
|
import { SettingList, SettingItem } from "./setting";
|
||||||
ListSubheader,
|
import { CmdType } from "../../services/types";
|
||||||
Switch,
|
import { version } from "../../../package.json";
|
||||||
Typography,
|
|
||||||
} from "@mui/material";
|
|
||||||
import { getVergeConfig, patchVergeConfig } from "../services/cmds";
|
|
||||||
import { CmdType } from "../services/types";
|
|
||||||
import { version } from "../../package.json";
|
|
||||||
import GuardState from "./guard-state";
|
import GuardState from "./guard-state";
|
||||||
import SettingItem from "./setting-item";
|
|
||||||
import PaletteSwitch from "./palette-switch";
|
import PaletteSwitch from "./palette-switch";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -21,11 +15,8 @@ const SettingVerge = ({ onError }: Props) => {
|
|||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
||||||
|
|
||||||
const {
|
const { theme_mode: mode = "light", theme_blur: blur = false } =
|
||||||
theme_mode: mode = "light",
|
vergeConfig ?? {};
|
||||||
enable_self_startup: startup = false,
|
|
||||||
enable_system_proxy: proxy = false,
|
|
||||||
} = vergeConfig ?? {};
|
|
||||||
|
|
||||||
const onSwitchFormat = (_e: any, value: boolean) => value;
|
const onSwitchFormat = (_e: any, value: boolean) => value;
|
||||||
const onChangeData = (patch: Partial<CmdType.VergeConfig>) => {
|
const onChangeData = (patch: Partial<CmdType.VergeConfig>) => {
|
||||||
@@ -33,11 +24,7 @@ const SettingVerge = ({ onError }: Props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<List>
|
<SettingList title="Verge Setting">
|
||||||
<ListSubheader sx={{ background: "transparent" }}>
|
|
||||||
Common Setting
|
|
||||||
</ListSubheader>
|
|
||||||
|
|
||||||
<SettingItem>
|
<SettingItem>
|
||||||
<ListItemText primary="Theme Mode" />
|
<ListItemText primary="Theme Mode" />
|
||||||
<GuardState
|
<GuardState
|
||||||
@@ -55,28 +42,14 @@ const SettingVerge = ({ onError }: Props) => {
|
|||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
|
||||||
<SettingItem>
|
<SettingItem>
|
||||||
<ListItemText primary="Self Startup" />
|
<ListItemText primary="Theme Blur" />
|
||||||
<GuardState
|
<GuardState
|
||||||
value={startup}
|
value={blur}
|
||||||
valueProps="checked"
|
valueProps="checked"
|
||||||
onCatch={onError}
|
onCatch={onError}
|
||||||
onFormat={onSwitchFormat}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ enable_self_startup: e })}
|
onChange={(e) => onChangeData({ theme_blur: e })}
|
||||||
onGuard={(e) => patchVergeConfig({ enable_self_startup: e })}
|
onGuard={(e) => patchVergeConfig({ theme_blur: e })}
|
||||||
>
|
|
||||||
<Switch edge="end" />
|
|
||||||
</GuardState>
|
|
||||||
</SettingItem>
|
|
||||||
|
|
||||||
<SettingItem>
|
|
||||||
<ListItemText primary="System Proxy" />
|
|
||||||
<GuardState
|
|
||||||
value={proxy}
|
|
||||||
valueProps="checked"
|
|
||||||
onCatch={onError}
|
|
||||||
onFormat={onSwitchFormat}
|
|
||||||
onChange={(e) => onChangeData({ enable_system_proxy: e })}
|
|
||||||
onGuard={(e) => patchVergeConfig({ enable_system_proxy: e })}
|
|
||||||
>
|
>
|
||||||
<Switch edge="end" />
|
<Switch edge="end" />
|
||||||
</GuardState>
|
</GuardState>
|
||||||
@@ -86,7 +59,7 @@ const SettingVerge = ({ onError }: Props) => {
|
|||||||
<ListItemText primary="Version" />
|
<ListItemText primary="Version" />
|
||||||
<Typography sx={{ py: "6px" }}>v{version}</Typography>
|
<Typography sx={{ py: "6px" }}>v{version}</Typography>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
</List>
|
</SettingList>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
17
src/components/setting/setting.tsx
Normal file
17
src/components/setting/setting.tsx
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { List, ListItem, ListSubheader, styled } from "@mui/material";
|
||||||
|
|
||||||
|
export const SettingItem = styled(ListItem)(() => ({
|
||||||
|
paddingTop: 5,
|
||||||
|
paddingBottom: 5,
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const SettingList: React.FC<{ title: string }> = (props) => (
|
||||||
|
<List>
|
||||||
|
<ListSubheader sx={{ background: "transparent" }} disableSticky>
|
||||||
|
{props.title}
|
||||||
|
</ListSubheader>
|
||||||
|
|
||||||
|
{props.children}
|
||||||
|
</List>
|
||||||
|
);
|
||||||
52
src/components/setting/sysproxy-tooltip.tsx
Normal file
52
src/components/setting/sysproxy-tooltip.tsx
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { InfoRounded } from "@mui/icons-material";
|
||||||
|
import { ClickAwayListener, Tooltip } from "@mui/material";
|
||||||
|
import { getSystemProxy } from "../../services/cmds";
|
||||||
|
|
||||||
|
const SysproxyTooltip = () => {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const [info, setInfo] = useState<any>({});
|
||||||
|
|
||||||
|
const onShow = async () => {
|
||||||
|
const data = await getSystemProxy();
|
||||||
|
setInfo(data ?? {});
|
||||||
|
setOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
const timer = setTimeout(() => setOpen(false), 2000);
|
||||||
|
return () => clearTimeout(timer);
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
|
// todo: add error info
|
||||||
|
const showTitle = (
|
||||||
|
<div>
|
||||||
|
<div>Enable: {(!!info.enable).toString()}</div>
|
||||||
|
<div>Server: {info.server}</div>
|
||||||
|
<div>Bypass: {info.bypass}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ClickAwayListener onClickAway={() => setOpen(false)}>
|
||||||
|
<Tooltip
|
||||||
|
PopperProps={{
|
||||||
|
disablePortal: true,
|
||||||
|
}}
|
||||||
|
onClose={() => setOpen(false)}
|
||||||
|
open={open}
|
||||||
|
disableFocusListener
|
||||||
|
disableHoverListener
|
||||||
|
disableTouchListener
|
||||||
|
placement="top"
|
||||||
|
title={showTitle}
|
||||||
|
arrow
|
||||||
|
>
|
||||||
|
<InfoRounded fontSize="small" onClick={onShow} />
|
||||||
|
</Tooltip>
|
||||||
|
</ClickAwayListener>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SysproxyTooltip;
|
||||||
40
src/components/update-button.tsx
Normal file
40
src/components/update-button.tsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import useSWR from "swr";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { Button } from "@mui/material";
|
||||||
|
import { checkUpdate } from "@tauri-apps/api/updater";
|
||||||
|
import UpdateDialog from "./update-dialog";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const UpdateButton = (props: Props) => {
|
||||||
|
const { className } = props;
|
||||||
|
|
||||||
|
const [dialogOpen, setDialogOpen] = useState(false);
|
||||||
|
const { data: updateInfo } = useSWR("checkUpdate", checkUpdate, {
|
||||||
|
errorRetryCount: 2,
|
||||||
|
revalidateIfStale: false,
|
||||||
|
focusThrottleInterval: 36e5, // 1 hour
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!updateInfo?.shouldUpdate) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
color="error"
|
||||||
|
variant="contained"
|
||||||
|
size="small"
|
||||||
|
className={className}
|
||||||
|
onClick={() => setDialogOpen(true)}
|
||||||
|
>
|
||||||
|
New
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<UpdateDialog open={dialogOpen} onClose={() => setDialogOpen(false)} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UpdateButton;
|
||||||
@@ -1,70 +1,34 @@
|
|||||||
import { useEffect, useMemo, useState } from "react";
|
|
||||||
import useSWR, { SWRConfig } from "swr";
|
import useSWR, { SWRConfig } from "swr";
|
||||||
|
import { useEffect, useMemo } from "react";
|
||||||
import { Route, Routes } from "react-router-dom";
|
import { Route, Routes } from "react-router-dom";
|
||||||
import { useRecoilState } from "recoil";
|
import { useRecoilState } from "recoil";
|
||||||
import {
|
import { alpha, createTheme, List, Paper, ThemeProvider } from "@mui/material";
|
||||||
Button,
|
import { appWindow } from "@tauri-apps/api/window";
|
||||||
createTheme,
|
import { atomPaletteMode, atomThemeBlur } from "../states/setting";
|
||||||
IconButton,
|
import { getVergeConfig } from "../services/cmds";
|
||||||
List,
|
import { routers } from "./_routers";
|
||||||
Paper,
|
|
||||||
ThemeProvider,
|
|
||||||
} from "@mui/material";
|
|
||||||
import { HorizontalRuleRounded, CloseRounded } from "@mui/icons-material";
|
|
||||||
import { checkUpdate } from "@tauri-apps/api/updater";
|
|
||||||
import { atomPaletteMode } from "../states/setting";
|
|
||||||
import { getVergeConfig, windowDrag, windowHide } from "../services/cmds";
|
|
||||||
import LogoSvg from "../assets/image/logo.svg";
|
import LogoSvg from "../assets/image/logo.svg";
|
||||||
import LogPage from "./log";
|
|
||||||
import ProfilePage from "./profile";
|
|
||||||
import ProxyPage from "./proxy";
|
|
||||||
import SettingPage from "./setting";
|
|
||||||
import ConnectionsPage from "./connections";
|
|
||||||
import LayoutItem from "../components/layout-item";
|
|
||||||
import Traffic from "../components/traffic";
|
import Traffic from "../components/traffic";
|
||||||
import UpdateDialog from "../components/update-dialog";
|
import LayoutItem from "../components/layout-item";
|
||||||
|
import UpdateButton from "../components/update-button";
|
||||||
const routers = [
|
import LayoutControl from "../components/layout-control";
|
||||||
{
|
|
||||||
label: "Proxy",
|
|
||||||
link: "/",
|
|
||||||
ele: ProxyPage,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Profile",
|
|
||||||
link: "/profile",
|
|
||||||
ele: ProfilePage,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Connections",
|
|
||||||
link: "/connections",
|
|
||||||
ele: ConnectionsPage,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Log",
|
|
||||||
link: "/log",
|
|
||||||
ele: LogPage,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Setting",
|
|
||||||
link: "/setting",
|
|
||||||
ele: SettingPage,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const Layout = () => {
|
const Layout = () => {
|
||||||
const [mode, setMode] = useRecoilState(atomPaletteMode);
|
const [mode, setMode] = useRecoilState(atomPaletteMode);
|
||||||
|
const [blur, setBlur] = useRecoilState(atomThemeBlur);
|
||||||
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
const { data: vergeConfig } = useSWR("getVergeConfig", getVergeConfig);
|
||||||
const { data: updateInfo } = useSWR("checkUpdate", checkUpdate, {
|
|
||||||
errorRetryCount: 2,
|
|
||||||
revalidateIfStale: false,
|
|
||||||
focusThrottleInterval: 36e5, // 1 hour
|
|
||||||
});
|
|
||||||
const [dialogOpen, setDialogOpen] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMode(vergeConfig?.theme_mode ?? "light");
|
window.addEventListener("keydown", (e) => {
|
||||||
}, [vergeConfig?.theme_mode]);
|
if (e.key === "Escape") appWindow.hide();
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
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";
|
||||||
@@ -86,36 +50,34 @@ const Layout = () => {
|
|||||||
});
|
});
|
||||||
}, [mode]);
|
}, [mode]);
|
||||||
|
|
||||||
|
const onDragging = (e: any) => {
|
||||||
|
if (e?.target?.dataset?.windrag) {
|
||||||
|
appWindow.startDragging();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SWRConfig value={{}}>
|
<SWRConfig value={{}}>
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
<Paper square elevation={0} className="layout">
|
<Paper
|
||||||
<div className="layout__left">
|
square
|
||||||
<div className="the-logo">
|
elevation={0}
|
||||||
<img
|
className="layout"
|
||||||
src={LogoSvg}
|
onPointerDown={onDragging}
|
||||||
width="100%"
|
sx={[
|
||||||
alt=""
|
(theme) => ({
|
||||||
onPointerDown={(e) => {
|
bgcolor: alpha(theme.palette.background.paper, blur ? 0.85 : 1),
|
||||||
windowDrag();
|
}),
|
||||||
e.preventDefault();
|
]}
|
||||||
}}
|
>
|
||||||
/>
|
<div className="layout__left" data-windrag>
|
||||||
|
<div className="the-logo" data-windrag>
|
||||||
|
<img src={LogoSvg} alt="" data-windrag />
|
||||||
|
|
||||||
{updateInfo?.shouldUpdate && (
|
<UpdateButton className="the-newbtn" />
|
||||||
<Button
|
|
||||||
color="error"
|
|
||||||
variant="contained"
|
|
||||||
size="small"
|
|
||||||
className="the-newbtn"
|
|
||||||
onClick={() => setDialogOpen(true)}
|
|
||||||
>
|
|
||||||
New
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<List className="the-menu">
|
<List className="the-menu" data-windrag>
|
||||||
{routers.map((router) => (
|
{routers.map((router) => (
|
||||||
<LayoutItem key={router.label} to={router.link}>
|
<LayoutItem key={router.label} to={router.link}>
|
||||||
{router.label}
|
{router.label}
|
||||||
@@ -123,29 +85,17 @@ const Layout = () => {
|
|||||||
))}
|
))}
|
||||||
</List>
|
</List>
|
||||||
|
|
||||||
<div className="the-traffic">
|
<div className="the-traffic" data-windrag>
|
||||||
<Traffic />
|
<Traffic />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="layout__right">
|
<div className="layout__right" data-windrag>
|
||||||
<div
|
<div className="the-bar">
|
||||||
className="the-bar"
|
<LayoutControl />
|
||||||
onPointerDown={(e) =>
|
|
||||||
e.target === e.currentTarget && windowDrag()
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{/* todo: onClick = windowMini */}
|
|
||||||
<IconButton size="small" sx={{ mx: 1 }} onClick={windowHide}>
|
|
||||||
<HorizontalRuleRounded fontSize="inherit" />
|
|
||||||
</IconButton>
|
|
||||||
|
|
||||||
<IconButton size="small" onClick={windowHide}>
|
|
||||||
<CloseRounded fontSize="inherit" />
|
|
||||||
</IconButton>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="the-content">
|
<div className="the-content" data-windrag>
|
||||||
<Routes>
|
<Routes>
|
||||||
{routers.map(({ label, link, ele: Ele }) => (
|
{routers.map(({ label, link, ele: Ele }) => (
|
||||||
<Route key={label} path={link} element={<Ele />} />
|
<Route key={label} path={link} element={<Ele />} />
|
||||||
@@ -154,7 +104,6 @@ const Layout = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Paper>
|
</Paper>
|
||||||
<UpdateDialog open={dialogOpen} onClose={() => setDialogOpen(false)} />
|
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</SWRConfig>
|
</SWRConfig>
|
||||||
);
|
);
|
||||||
|
|||||||
33
src/pages/_routers.tsx
Normal file
33
src/pages/_routers.tsx
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import LogsPage from "./logs";
|
||||||
|
import ProxiesPage from "./proxies";
|
||||||
|
import ProfilesPage from "./profiles";
|
||||||
|
import SettingsPage from "./settings";
|
||||||
|
import ConnectionsPage from "./connections";
|
||||||
|
|
||||||
|
export const routers = [
|
||||||
|
{
|
||||||
|
label: "Proxies",
|
||||||
|
link: "/",
|
||||||
|
ele: ProxiesPage,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Profiles",
|
||||||
|
link: "/profile",
|
||||||
|
ele: ProfilesPage,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Connections",
|
||||||
|
link: "/connections",
|
||||||
|
ele: ConnectionsPage,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Logs",
|
||||||
|
link: "/logs",
|
||||||
|
ele: LogsPage,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Settings",
|
||||||
|
link: "/settings",
|
||||||
|
ele: SettingsPage,
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Box, Paper, Typography } from "@mui/material";
|
import { Paper } from "@mui/material";
|
||||||
import { Virtuoso } from "react-virtuoso";
|
import { Virtuoso } from "react-virtuoso";
|
||||||
import { getInfomation } from "../services/api";
|
|
||||||
import { ApiType } from "../services/types";
|
import { ApiType } from "../services/types";
|
||||||
|
import { getInfomation } from "../services/api";
|
||||||
|
import BasePage from "../components/base-page";
|
||||||
import ConnectionItem from "../components/connection-item";
|
import ConnectionItem from "../components/connection-item";
|
||||||
|
|
||||||
const ConnectionsPage = () => {
|
const ConnectionsPage = () => {
|
||||||
@@ -26,25 +27,14 @@ const ConnectionsPage = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<BasePage title="Connections" contentStyle={{ height: "100%" }}>
|
||||||
sx={{
|
<Paper sx={{ boxShadow: 2, height: "100%" }}>
|
||||||
width: 0.9,
|
|
||||||
maxWidth: "850px",
|
|
||||||
height: "100%",
|
|
||||||
mx: "auto",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography variant="h4" component="h1" sx={{ py: 2 }}>
|
|
||||||
Connections
|
|
||||||
</Typography>
|
|
||||||
|
|
||||||
<Paper sx={{ boxShadow: 2, height: "calc(100% - 100px)" }}>
|
|
||||||
<Virtuoso
|
<Virtuoso
|
||||||
data={conn.connections}
|
data={conn.connections}
|
||||||
itemContent={(index, item) => <ConnectionItem value={item} />}
|
itemContent={(index, item) => <ConnectionItem value={item} />}
|
||||||
/>
|
/>
|
||||||
</Paper>
|
</Paper>
|
||||||
</Box>
|
</BasePage>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Box, Button, Paper, Typography } 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 { ApiType } from "../services/types";
|
||||||
import { getInfomation } from "../services/api";
|
import { getInfomation } from "../services/api";
|
||||||
|
import BasePage from "../components/base-page";
|
||||||
import LogItem from "../components/log-item";
|
import LogItem from "../components/log-item";
|
||||||
|
|
||||||
let logCache: ApiType.LogItem[] = [];
|
let logCache: ApiType.LogItem[] = [];
|
||||||
@@ -28,33 +29,27 @@ const LogPage = () => {
|
|||||||
return () => ws?.close();
|
return () => ws?.close();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const onClear = () => {
|
||||||
|
setLogData([]);
|
||||||
|
logCache = [];
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<BasePage
|
||||||
sx={{
|
title="Logs"
|
||||||
position: "relative",
|
contentStyle={{ height: "100%" }}
|
||||||
width: 0.9,
|
header={
|
||||||
maxWidth: "850px",
|
<Button
|
||||||
height: "100%",
|
size="small"
|
||||||
mx: "auto",
|
sx={{ mt: 1 }}
|
||||||
}}
|
variant="contained"
|
||||||
|
onClick={onClear}
|
||||||
|
>
|
||||||
|
Clear
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<Typography variant="h4" component="h1" sx={{ py: 2 }}>
|
<Paper sx={{ boxShadow: 2, height: "100%" }}>
|
||||||
Logs
|
|
||||||
</Typography>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
variant="contained"
|
|
||||||
sx={{ position: "absolute", top: 22, right: 0 }}
|
|
||||||
onClick={() => {
|
|
||||||
setLogData([]);
|
|
||||||
logCache = [];
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Clear
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Paper sx={{ boxShadow: 2, height: "calc(100% - 100px)" }}>
|
|
||||||
<Virtuoso
|
<Virtuoso
|
||||||
initialTopMostItemIndex={999}
|
initialTopMostItemIndex={999}
|
||||||
data={logData}
|
data={logData}
|
||||||
@@ -62,7 +57,7 @@ const LogPage = () => {
|
|||||||
followOutput={"smooth"}
|
followOutput={"smooth"}
|
||||||
/>
|
/>
|
||||||
</Paper>
|
</Paper>
|
||||||
</Box>
|
</BasePage>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useRef, useState } from "react";
|
|
||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
import { Box, Button, Grid, TextField, Typography } from "@mui/material";
|
import { useEffect, useRef, useState } from "react";
|
||||||
|
import { Box, Button, Grid, TextField } from "@mui/material";
|
||||||
import {
|
import {
|
||||||
getProfiles,
|
getProfiles,
|
||||||
selectProfile,
|
selectProfile,
|
||||||
@@ -8,14 +8,14 @@ import {
|
|||||||
importProfile,
|
importProfile,
|
||||||
} from "../services/cmds";
|
} from "../services/cmds";
|
||||||
import { getProxies, updateProxy } from "../services/api";
|
import { getProxies, updateProxy } from "../services/api";
|
||||||
import ProfileItemComp from "../components/profile-item";
|
|
||||||
import useNotice from "../utils/use-notice";
|
|
||||||
import noop from "../utils/noop";
|
import noop from "../utils/noop";
|
||||||
|
import Notice from "../components/notice";
|
||||||
|
import BasePage from "../components/base-page";
|
||||||
|
import ProfileItem from "../components/profile-item";
|
||||||
|
|
||||||
const ProfilePage = () => {
|
const ProfilePage = () => {
|
||||||
const [url, setUrl] = useState("");
|
const [url, setUrl] = useState("");
|
||||||
const [disabled, setDisabled] = useState(false);
|
const [disabled, setDisabled] = useState(false);
|
||||||
const [notice, noticeElement] = useNotice();
|
|
||||||
|
|
||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
const { data: profiles = {} } = useSWR("getProfiles", getProfiles);
|
const { data: profiles = {} } = useSWR("getProfiles", getProfiles);
|
||||||
@@ -71,37 +71,31 @@ const ProfilePage = () => {
|
|||||||
await importProfile(url);
|
await importProfile(url);
|
||||||
mutate("getProfiles", getProfiles());
|
mutate("getProfiles", getProfiles());
|
||||||
if (!profiles.items?.length) selectProfile(0).catch(noop);
|
if (!profiles.items?.length) selectProfile(0).catch(noop);
|
||||||
notice.success("Successfully import profile.");
|
Notice.success("Successfully import profile.");
|
||||||
} catch {
|
} catch {
|
||||||
notice.error("Failed to import profile.");
|
Notice.error("Failed to import profile.");
|
||||||
} finally {
|
} finally {
|
||||||
setDisabled(false);
|
setDisabled(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const lockRef = useRef(false);
|
const lockRef = useRef(false);
|
||||||
const onProfileChange = (index: number) => {
|
const onSelect = async (index: number, force: boolean) => {
|
||||||
if (index === profiles.current || lockRef.current) return;
|
|
||||||
if (lockRef.current) return;
|
if (lockRef.current) return;
|
||||||
|
if (!force && index === profiles.current) return;
|
||||||
lockRef.current = true;
|
lockRef.current = true;
|
||||||
selectProfile(index)
|
try {
|
||||||
.then(() => {
|
await selectProfile(index);
|
||||||
mutate("getProfiles", { ...profiles, current: index }, true);
|
mutate("getProfiles", { ...profiles, current: index }, true);
|
||||||
})
|
} catch (err: any) {
|
||||||
.catch((err) => {
|
err && Notice.error(err.toString());
|
||||||
console.error(err);
|
} finally {
|
||||||
})
|
lockRef.current = false;
|
||||||
.finally(() => {
|
}
|
||||||
lockRef.current = false;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ width: 0.9, maxWidth: "850px", mx: "auto", mb: 2 }}>
|
<BasePage title="Profiles">
|
||||||
<Typography variant="h4" component="h1" sx={{ py: 2, mb: 1 }}>
|
|
||||||
Profiles
|
|
||||||
</Typography>
|
|
||||||
|
|
||||||
<Box sx={{ display: "flex", mb: 3 }}>
|
<Box sx={{ display: "flex", mb: 3 }}>
|
||||||
<TextField
|
<TextField
|
||||||
id="profile_url"
|
id="profile_url"
|
||||||
@@ -111,7 +105,7 @@ const ProfilePage = () => {
|
|||||||
fullWidth
|
fullWidth
|
||||||
value={url}
|
value={url}
|
||||||
onChange={(e) => setUrl(e.target.value)}
|
onChange={(e) => setUrl(e.target.value)}
|
||||||
sx={{ mr: 4 }}
|
sx={{ mr: 2 }}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
disabled={!url || disabled}
|
disabled={!url || disabled}
|
||||||
@@ -125,18 +119,16 @@ const ProfilePage = () => {
|
|||||||
<Grid container spacing={3}>
|
<Grid container spacing={3}>
|
||||||
{profiles?.items?.map((item, idx) => (
|
{profiles?.items?.map((item, idx) => (
|
||||||
<Grid item xs={12} sm={6} key={item.file}>
|
<Grid item xs={12} sm={6} key={item.file}>
|
||||||
<ProfileItemComp
|
<ProfileItem
|
||||||
index={idx}
|
index={idx}
|
||||||
selected={profiles.current === idx}
|
selected={profiles.current === idx}
|
||||||
itemData={item}
|
itemData={item}
|
||||||
onClick={() => onProfileChange(idx)}
|
onSelect={(f) => onSelect(idx, f)}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
</BasePage>
|
||||||
{noticeElement}
|
|
||||||
</Box>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { Box, List, Paper, Typography } from "@mui/material";
|
import { List, Paper } from "@mui/material";
|
||||||
import { getProxies } from "../services/api";
|
import { getProxies } from "../services/api";
|
||||||
|
import BasePage from "../components/base-page";
|
||||||
|
import ProxyItem from "../components/proxy-item";
|
||||||
import ProxyGroup from "../components/proxy-group";
|
import ProxyGroup from "../components/proxy-group";
|
||||||
|
|
||||||
const ProxyPage = () => {
|
const ProxyPage = () => {
|
||||||
const { mutate } = useSWRConfig();
|
const { mutate } = useSWRConfig();
|
||||||
const { data: proxiesData } = useSWR("getProxies", getProxies);
|
const { data: proxiesData } = useSWR("getProxies", getProxies);
|
||||||
const { groups = [] } = proxiesData ?? {};
|
const { groups = [], proxies = [] } = proxiesData ?? {};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// fix the empty proxies on the first sight
|
// fix the empty proxies on the first sight
|
||||||
@@ -18,21 +20,30 @@ const ProxyPage = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ width: 0.9, maxWidth: "850px", mx: "auto", mb: 2 }}>
|
<BasePage title={groups.length ? "Proxy Groups" : "Proxies"}>
|
||||||
<Typography variant="h4" component="h1" sx={{ py: 2 }}>
|
<Paper sx={{ borderRadius: 1, boxShadow: 2, mb: 1 }}>
|
||||||
Proxy Groups
|
{groups.length > 0 && (
|
||||||
</Typography>
|
|
||||||
|
|
||||||
{groups.length > 0 && (
|
|
||||||
<Paper sx={{ borderRadius: 1, boxShadow: 2 }}>
|
|
||||||
<List>
|
<List>
|
||||||
{groups.map((group) => (
|
{groups.map((group) => (
|
||||||
<ProxyGroup key={group.name} group={group} />
|
<ProxyGroup key={group.name} group={group} />
|
||||||
))}
|
))}
|
||||||
</List>
|
</List>
|
||||||
</Paper>
|
)}
|
||||||
)}
|
|
||||||
</Box>
|
{!groups.length && (
|
||||||
|
<List>
|
||||||
|
{Object.values(proxies).map((proxy) => (
|
||||||
|
<ProxyItem
|
||||||
|
key={proxy.name}
|
||||||
|
proxy={proxy}
|
||||||
|
selected={false}
|
||||||
|
sx={{ py: 0, px: 2 }}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</List>
|
||||||
|
)}
|
||||||
|
</Paper>
|
||||||
|
</BasePage>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import { Box, Paper, Typography } from "@mui/material";
|
|
||||||
import SettingVerge from "../components/setting-verge";
|
|
||||||
import SettingClash from "../components/setting-clash";
|
|
||||||
|
|
||||||
const SettingPage = () => {
|
|
||||||
return (
|
|
||||||
<Box sx={{ width: 0.9, maxWidth: 850, mx: "auto", mb: 2 }}>
|
|
||||||
<Typography variant="h4" component="h1" sx={{ py: 2 }}>
|
|
||||||
Setting
|
|
||||||
</Typography>
|
|
||||||
|
|
||||||
<Paper sx={{ borderRadius: 1, boxShadow: 2 }}>
|
|
||||||
<SettingVerge />
|
|
||||||
</Paper>
|
|
||||||
|
|
||||||
<Paper sx={{ borderRadius: 1, boxShadow: 2, mt: 3 }}>
|
|
||||||
<SettingClash />
|
|
||||||
</Paper>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SettingPage;
|
|
||||||
30
src/pages/settings.tsx
Normal file
30
src/pages/settings.tsx
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { Paper } from "@mui/material";
|
||||||
|
import BasePage from "../components/base-page";
|
||||||
|
import SettingVerge from "../components/setting/setting-verge";
|
||||||
|
import SettingClash from "../components/setting/setting-clash";
|
||||||
|
import SettingSystem from "../components/setting/setting-system";
|
||||||
|
import Notice from "../components/notice";
|
||||||
|
|
||||||
|
const SettingPage = () => {
|
||||||
|
const onError = (error: any) => {
|
||||||
|
error && Notice.error(error.toString());
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BasePage title="Settings">
|
||||||
|
<Paper sx={{ borderRadius: 1, boxShadow: 2, mb: 3 }}>
|
||||||
|
<SettingClash onError={onError} />
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
<Paper sx={{ borderRadius: 1, boxShadow: 2, mb: 3 }}>
|
||||||
|
<SettingSystem onError={onError} />
|
||||||
|
</Paper>
|
||||||
|
|
||||||
|
<Paper sx={{ borderRadius: 1, boxShadow: 2 }}>
|
||||||
|
<SettingVerge onError={onError} />
|
||||||
|
</Paper>
|
||||||
|
</BasePage>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SettingPage;
|
||||||
@@ -9,12 +9,16 @@ export async function syncProfiles() {
|
|||||||
return invoke<void>("sync_profiles");
|
return invoke<void>("sync_profiles");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function importProfile(url: string) {
|
export async function editProfile(index: number) {
|
||||||
return invoke<void>("import_profile", { url });
|
return invoke<void>("edit_profile", { index });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateProfile(index: number) {
|
export async function importProfile(url: string) {
|
||||||
return invoke<void>("update_profile", { index });
|
return invoke<void>("import_profile", { url, withProxy: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateProfile(index: number, withProxy: boolean) {
|
||||||
|
return invoke<void>("update_profile", { index, withProxy });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteProfile(index: number) {
|
export async function deleteProfile(index: number) {
|
||||||
@@ -36,18 +40,6 @@ export async function restartSidecar() {
|
|||||||
return invoke<void>("restart_sidecar");
|
return invoke<void>("restart_sidecar");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function windowDrag() {
|
|
||||||
return invoke<void>("win_drag");
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function windowHide() {
|
|
||||||
return invoke<void>("win_hide");
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function windowMini() {
|
|
||||||
return invoke<void>("win_mini");
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getClashInfo() {
|
export async function getClashInfo() {
|
||||||
return invoke<CmdType.ClashInfo | null>("get_clash_info");
|
return invoke<CmdType.ClashInfo | null>("get_clash_info");
|
||||||
}
|
}
|
||||||
@@ -63,3 +55,7 @@ export async function getVergeConfig() {
|
|||||||
export async function patchVergeConfig(payload: CmdType.VergeConfig) {
|
export async function patchVergeConfig(payload: CmdType.VergeConfig) {
|
||||||
return invoke<void>("patch_verge_config", { payload });
|
return invoke<void>("patch_verge_config", { payload });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getSystemProxy() {
|
||||||
|
return invoke<any>("get_sys_proxy");
|
||||||
|
}
|
||||||
|
|||||||
@@ -110,7 +110,8 @@ export namespace CmdType {
|
|||||||
|
|
||||||
export interface VergeConfig {
|
export interface VergeConfig {
|
||||||
theme_mode?: "light" | "dark";
|
theme_mode?: "light" | "dark";
|
||||||
enable_self_startup?: boolean;
|
theme_blur?: boolean;
|
||||||
|
enable_auto_launch?: boolean;
|
||||||
enable_system_proxy?: boolean;
|
enable_system_proxy?: boolean;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,3 +4,8 @@ export const atomPaletteMode = atom<"light" | "dark">({
|
|||||||
key: "atomPaletteMode",
|
key: "atomPaletteMode",
|
||||||
default: "light",
|
default: "light",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const atomThemeBlur = atom<boolean>({
|
||||||
|
key: "atomThemeBlur",
|
||||||
|
default: false,
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,68 +0,0 @@
|
|||||||
import { useMemo, useState } from "react";
|
|
||||||
import { Box, IconButton, Slide, Snackbar } from "@mui/material";
|
|
||||||
import { Close, CheckCircleRounded, ErrorRounded } from "@mui/icons-material";
|
|
||||||
|
|
||||||
interface NoticeInstance {
|
|
||||||
info: (msg: string) => void;
|
|
||||||
error: (msg: string) => void;
|
|
||||||
success: (msg: string) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const useNotice = () => {
|
|
||||||
const [message, setMessage] = useState("");
|
|
||||||
const [level, setLevel] = useState<"info" | "error" | "success">("info");
|
|
||||||
|
|
||||||
const handleClose = (_e: any, reason: string) => {
|
|
||||||
if (reason !== "clickaway") setMessage("");
|
|
||||||
};
|
|
||||||
|
|
||||||
const msgElement =
|
|
||||||
level === "info" ? (
|
|
||||||
message
|
|
||||||
) : (
|
|
||||||
<Box sx={{ display: "flex", alignItems: "center" }}>
|
|
||||||
{level === "error" && <ErrorRounded color="error" />}
|
|
||||||
{level === "success" && <CheckCircleRounded color="success" />}
|
|
||||||
<span style={{ marginLeft: 4 }}>{message}</span>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
|
|
||||||
const element = useMemo(
|
|
||||||
() => (
|
|
||||||
<Snackbar
|
|
||||||
open={!!message}
|
|
||||||
anchorOrigin={{ vertical: "top", horizontal: "right" }}
|
|
||||||
autoHideDuration={3000}
|
|
||||||
onClose={handleClose}
|
|
||||||
message={msgElement}
|
|
||||||
sx={{ maxWidth: 360 }}
|
|
||||||
TransitionComponent={(p) => <Slide {...p} direction="left" />}
|
|
||||||
transitionDuration={200}
|
|
||||||
action={
|
|
||||||
<IconButton
|
|
||||||
size="small"
|
|
||||||
color="inherit"
|
|
||||||
onClick={() => setMessage("")}
|
|
||||||
>
|
|
||||||
<Close fontSize="small" />
|
|
||||||
</IconButton>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
[message]
|
|
||||||
);
|
|
||||||
|
|
||||||
const instance = (Object.fromEntries(
|
|
||||||
(["info", "error", "success"] as const).map((item) => [
|
|
||||||
item,
|
|
||||||
(msg: string) => {
|
|
||||||
setLevel(item);
|
|
||||||
setMessage(msg);
|
|
||||||
},
|
|
||||||
])
|
|
||||||
) as unknown) as NoticeInstance;
|
|
||||||
|
|
||||||
return [instance, element] as const;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default useNotice;
|
|
||||||
Reference in New Issue
Block a user