Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Clash Verge
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Clash Verge
Commits
38effaf7
There was an error fetching the commit references. Please try again later.
Unverified
Commit
38effaf7
authored
3 years ago
by
GyDi
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feat: reimplement enhanced mode
parent
a68eb4a7
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src-tauri/Cargo.lock
+93
-31
93 additions, 31 deletions
src-tauri/Cargo.lock
src-tauri/Cargo.toml
+1
-0
1 addition, 0 deletions
src-tauri/Cargo.toml
src-tauri/src/core/enhance.rs
+203
-1
203 additions, 1 deletion
src-tauri/src/core/enhance.rs
with
297 additions
and
32 deletions
src-tauri/Cargo.lock
+
93
−
31
View file @
38effaf7
...
@@ -64,7 +64,7 @@ version = "0.12.1"
...
@@ -64,7 +64,7 @@ version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
dependencies = [
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -131,7 +131,7 @@ dependencies = [
...
@@ -131,7 +131,7 @@ dependencies = [
"slab",
"slab",
"socket2",
"socket2",
"waker-fn",
"waker-fn",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -168,7 +168,7 @@ dependencies = [
...
@@ -168,7 +168,7 @@ dependencies = [
"libc",
"libc",
"once_cell",
"once_cell",
"signal-hook 0.3.14",
"signal-hook 0.3.14",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -484,7 +484,7 @@ dependencies = [
...
@@ -484,7 +484,7 @@ dependencies = [
"num-integer",
"num-integer",
"num-traits",
"num-traits",
"time 0.1.44",
"time 0.1.44",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -504,6 +504,7 @@ dependencies = [
...
@@ -504,6 +504,7 @@ dependencies = [
"open 2.1.3",
"open 2.1.3",
"parking_lot 0.12.1",
"parking_lot 0.12.1",
"port_scanner",
"port_scanner",
"quick-js",
"reqwest",
"reqwest",
"runas",
"runas",
"serde",
"serde",
...
@@ -592,6 +593,15 @@ version = "0.4.0"
...
@@ -592,6 +593,15 @@ 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 = "copy_dir"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e4281031634644843bd2f5aa9c48cf98fc48d6b083bd90bb11becf10deaf8b0"
dependencies = [
"walkdir 0.1.8",
]
[[package]]
[[package]]
name = "core-foundation"
name = "core-foundation"
version = "0.9.3"
version = "0.9.3"
...
@@ -791,7 +801,7 @@ dependencies = [
...
@@ -791,7 +801,7 @@ dependencies = [
"rand 0.8.5",
"rand 0.8.5",
"shared_library",
"shared_library",
"termwiz",
"termwiz",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -918,7 +928,7 @@ checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
...
@@ -918,7 +928,7 @@ checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
dependencies = [
"libc",
"libc",
"redox_users",
"redox_users",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -929,7 +939,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
...
@@ -929,7 +939,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
dependencies = [
"libc",
"libc",
"redox_users",
"redox_users",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -1035,7 +1045,7 @@ checksum = "7199d965852c3bac31f779ef99cbb4537f80e952e2d6aa0ffeb30cce00f4f46e"
...
@@ -1035,7 +1045,7 @@ checksum = "7199d965852c3bac31f779ef99cbb4537f80e952e2d6aa0ffeb30cce00f4f46e"
dependencies = [
dependencies = [
"libc",
"libc",
"thiserror",
"thiserror",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -1296,7 +1306,7 @@ dependencies = [
...
@@ -1296,7 +1306,7 @@ dependencies = [
"libc",
"libc",
"log",
"log",
"rustversion",
"rustversion",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -1364,7 +1374,7 @@ dependencies = [
...
@@ -1364,7 +1374,7 @@ dependencies = [
"gobject-sys",
"gobject-sys",
"libc",
"libc",
"system-deps 6.0.2",
"system-deps 6.0.2",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -1724,7 +1734,7 @@ dependencies = [
...
@@ -1724,7 +1734,7 @@ dependencies = [
"regex",
"regex",
"same-file",
"same-file",
"thread_local",
"thread_local",
"walkdir",
"walkdir
2.3.2
",
"winapi-util",
"winapi-util",
]
]
...
@@ -1831,7 +1841,7 @@ dependencies = [
...
@@ -1831,7 +1841,7 @@ dependencies = [
"jni-sys",
"jni-sys",
"log",
"log",
"thiserror",
"thiserror",
"walkdir",
"walkdir
2.3.2
",
]
]
[[package]]
[[package]]
...
@@ -1845,7 +1855,7 @@ dependencies = [
...
@@ -1845,7 +1855,7 @@ dependencies = [
"jni-sys",
"jni-sys",
"log",
"log",
"thiserror",
"thiserror",
"walkdir",
"walkdir
2.3.2
",
]
]
[[package]]
[[package]]
...
@@ -1874,6 +1884,16 @@ dependencies = [
...
@@ -1874,6 +1884,16 @@ dependencies = [
"treediff",
"treediff",
]
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
[[package]]
name = "kuchiki"
name = "kuchiki"
version = "0.8.1"
version = "0.8.1"
...
@@ -1929,7 +1949,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
...
@@ -1929,7 +1949,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
dependencies = [
dependencies = [
"cfg-if 1.0.0",
"cfg-if 1.0.0",
"winapi",
"winapi 0.3.9",
]
[[package]]
name = "libquickjs-sys"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f0b24e9bd171b75ae0295bd428fb8fe58410fb23156e5f34a4657a70c3cee96"
dependencies = [
"cc",
"copy_dir",
]
]
[[package]]
[[package]]
...
@@ -1996,7 +2026,7 @@ dependencies = [
...
@@ -1996,7 +2026,7 @@ dependencies = [
"thiserror",
"thiserror",
"thread-id",
"thread-id",
"typemap",
"typemap",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -2475,7 +2505,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
...
@@ -2475,7 +2505,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c92f2b54f081d635c77e7120862d48db8e91f7f21cef23ab1b4fe9971c59f55"
checksum = "2c92f2b54f081d635c77e7120862d48db8e91f7f21cef23ab1b4fe9971c59f55"
dependencies = [
dependencies = [
"libc",
"libc",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -2541,7 +2571,7 @@ dependencies = [
...
@@ -2541,7 +2571,7 @@ dependencies = [
"libc",
"libc",
"redox_syscall",
"redox_syscall",
"smallvec",
"smallvec",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -2778,7 +2808,7 @@ dependencies = [
...
@@ -2778,7 +2808,7 @@ dependencies = [
"libc",
"libc",
"log",
"log",
"wepoll-ffi",
"wepoll-ffi",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -2854,6 +2884,16 @@ version = "1.2.3"
...
@@ -2854,6 +2884,16 @@ version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quick-js"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19cb4cefcb00f4ab9b332664d06005a74f582ac16aa959c6ad5912957bd83e5f"
dependencies = [
"libquickjs-sys",
"once_cell",
]
[[package]]
[[package]]
name = "quote"
name = "quote"
version = "1.0.20"
version = "1.0.20"
...
@@ -3005,7 +3045,7 @@ version = "0.5.3"
...
@@ -3005,7 +3045,7 @@ version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
dependencies = [
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -3447,7 +3487,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
...
@@ -3447,7 +3487,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef"
checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef"
dependencies = [
dependencies = [
"libc",
"libc",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -3532,7 +3572,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
...
@@ -3532,7 +3572,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0"
checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0"
dependencies = [
dependencies = [
"libc",
"libc",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -3800,7 +3840,7 @@ dependencies = [
...
@@ -3800,7 +3840,7 @@ dependencies = [
"thiserror",
"thiserror",
"time 0.3.11",
"time 0.3.11",
"uuid 1.1.2",
"uuid 1.1.2",
"walkdir",
"walkdir
2.3.2
",
]
]
[[package]]
[[package]]
...
@@ -3880,7 +3920,7 @@ dependencies = [
...
@@ -3880,7 +3920,7 @@ dependencies = [
"serde_with",
"serde_with",
"thiserror",
"thiserror",
"url",
"url",
"walkdir",
"walkdir
2.3.2
",
"windows",
"windows",
]
]
...
@@ -3895,7 +3935,7 @@ dependencies = [
...
@@ -3895,7 +3935,7 @@ dependencies = [
"libc",
"libc",
"redox_syscall",
"redox_syscall",
"remove_dir_all",
"remove_dir_all",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -3960,7 +4000,7 @@ dependencies = [
...
@@ -3960,7 +4000,7 @@ dependencies = [
"ucd-trie",
"ucd-trie",
"unicode-segmentation",
"unicode-segmentation",
"vtparse",
"vtparse",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -3997,7 +4037,7 @@ checksum = "5fdfe0627923f7411a43ec9ec9c39c3a9b4151be313e0922042581fb6c9b717f"
...
@@ -3997,7 +4037,7 @@ checksum = "5fdfe0627923f7411a43ec9ec9c39c3a9b4151be313e0922042581fb6c9b717f"
dependencies = [
dependencies = [
"libc",
"libc",
"redox_syscall",
"redox_syscall",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -4017,7 +4057,7 @@ checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
...
@@ -4017,7 +4057,7 @@ checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
dependencies = [
"libc",
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -4064,7 +4104,7 @@ dependencies = [
...
@@ -4064,7 +4104,7 @@ dependencies = [
"signal-hook-registry",
"signal-hook-registry",
"socket2",
"socket2",
"tokio-macros",
"tokio-macros",
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -4441,6 +4481,16 @@ version = "1.1.0"
...
@@ -4441,6 +4481,16 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
[[package]]
name = "walkdir"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c66c0b9792f0a765345452775f3adbd28dde9d33f30d13e5dcc5ae17cf6f3780"
dependencies = [
"kernel32-sys",
"winapi 0.2.8",
]
[[package]]
[[package]]
name = "walkdir"
name = "walkdir"
version = "2.3.2"
version = "2.3.2"
...
@@ -4448,7 +4498,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
...
@@ -4448,7 +4498,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
dependencies = [
dependencies = [
"same-file",
"same-file",
"winapi",
"winapi
0.3.9
",
"winapi-util",
"winapi-util",
]
]
...
@@ -4706,6 +4756,12 @@ version = "2.1.1"
...
@@ -4706,6 +4756,12 @@ version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee583bdc5ff1cf9db20e9db5bb3ff4c3089a8f6b8b31aff265c9aba85812db86"
checksum = "ee583bdc5ff1cf9db20e9db5bb3ff4c3089a8f6b8b31aff265c9aba85812db86"
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
[[package]]
[[package]]
name = "winapi"
name = "winapi"
version = "0.3.9"
version = "0.3.9"
...
@@ -4716,6 +4772,12 @@ dependencies = [
...
@@ -4716,6 +4772,12 @@ dependencies = [
"winapi-x86_64-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
]
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
[[package]]
[[package]]
name = "winapi-i686-pc-windows-gnu"
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
version = "0.4.0"
...
@@ -4728,7 +4790,7 @@ version = "0.1.5"
...
@@ -4728,7 +4790,7 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
dependencies = [
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
@@ -4886,7 +4948,7 @@ version = "0.10.1"
...
@@ -4886,7 +4948,7 @@ version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
dependencies = [
dependencies = [
"winapi",
"winapi
0.3.9
",
]
]
[[package]]
[[package]]
...
...
This diff is collapsed.
Click to expand it.
src-tauri/Cargo.toml
+
1
−
0
View file @
38effaf7
...
@@ -33,6 +33,7 @@ tokio = { version = "1", features = ["full"] }
...
@@ -33,6 +33,7 @@ tokio = { version = "1", features = ["full"] }
serde
=
{
version
=
"1.0"
,
features
=
[
"derive"
]
}
serde
=
{
version
=
"1.0"
,
features
=
[
"derive"
]
}
reqwest
=
{
version
=
"0.11"
,
features
=
[
"json"
]
}
reqwest
=
{
version
=
"0.11"
,
features
=
[
"json"
]
}
tauri
=
{
version
=
"1.0.0"
,
features
=
[
"process-all"
,
"shell-all"
,
"system-tray"
,
"updater"
,
"window-all"
]
}
tauri
=
{
version
=
"1.0.0"
,
features
=
[
"process-all"
,
"shell-all"
,
"system-tray"
,
"updater"
,
"window-all"
]
}
quick-js
=
{
version
=
"0.4.1"
}
window-shadows
=
{
version
=
"0.1"
}
window-shadows
=
{
version
=
"0.1"
}
window-vibrancy
=
{
version
=
"0.1"
}
window-vibrancy
=
{
version
=
"0.1"
}
...
...
This diff is collapsed.
Click to expand it.
src-tauri/src/core/enhance.rs
+
203
−
1
View file @
38effaf7
use
super
::
prfitem
::
PrfItem
;
use
super
::
prfitem
::
PrfItem
;
use
crate
::
utils
::{
config
,
dirs
};
use
crate
::
utils
::{
config
,
dirs
};
use
anyhow
::
Result
;
use
serde
::{
Deserialize
,
Serialize
};
use
serde
::{
Deserialize
,
Serialize
};
use
serde_yaml
::
Mapping
;
use
serde_yaml
::
{
self
,
Mapping
,
Sequence
,
Value
}
;
use
std
::
fs
;
use
std
::
fs
;
#[derive(Default,
Debug,
Clone,
Serialize,
Deserialize)]
#[derive(Default,
Debug,
Clone,
Serialize,
Deserialize)]
...
@@ -64,3 +65,204 @@ impl PrfData {
...
@@ -64,3 +65,204 @@ impl PrfData {
}
}
}
}
}
}
fn
get_valid_list
(
valid
:
Vec
<
String
>
)
->
Vec
<
String
>
{
let
mut
valid_list
:
Vec
<
String
>
=
vec!
[
"rules"
,
"proxies"
,
"proxy-groups"
,
"proxy-providers"
,
"rule-providers"
,
]
.iter
()
.map
(|
s
|
s
.to_string
())
.collect
();
valid_list
.extend
(
valid
);
valid_list
}
fn
use_valid_filter
(
config
:
Mapping
,
valid
:
Vec
<
String
>
)
->
Mapping
{
let
valid
=
get_valid_list
(
valid
);
let
mut
new_config
=
Mapping
::
new
();
valid
.iter
()
.for_each
(|
k
|
{
let
k
=
Value
::
from
(
k
.clone
());
if
let
Some
(
value
)
=
config
.get
(
&
k
)
{
new_config
.insert
(
k
,
value
.clone
());
}
});
new_config
}
pub
fn
use_merge
(
merge
:
Mapping
,
config
:
Mapping
,
valid
:
Vec
<
String
>
)
->
Mapping
{
let
valid_list
=
get_valid_list
(
valid
);
let
mut
config
=
config
;
valid_list
.iter
()
.for_each
(|
key
|
{
let
key
=
Value
::
String
(
key
.into
());
if
let
Some
(
value
)
=
merge
.get
(
&
key
)
{
config
.insert
(
key
,
value
.clone
());
}
});
vec!
[
"rules"
,
"proxies"
,
"proxy-groups"
]
.iter
()
.for_each
(|
key_str
|
{
let
key_val
=
Value
::
from
(
key_str
.to_string
());
let
mut
list
=
Sequence
::
default
();
list
=
config
.get
(
&
key_val
)
.map_or
(
list
.clone
(),
|
val
|
{
val
.as_sequence
()
.map_or
(
list
,
|
v
|
v
.clone
())
});
let
pre_key
=
Value
::
from
(
format!
(
"prepend-{key_str}"
));
let
post_key
=
Value
::
from
(
format!
(
"append-{key_str}"
));
if
let
Some
(
pre_val
)
=
merge
.get
(
&
pre_key
)
{
if
pre_val
.is_sequence
()
{
let
mut
pre_val
=
pre_val
.as_sequence
()
.unwrap
()
.clone
();
pre_val
.extend
(
list
);
list
=
pre_val
;
}
}
if
let
Some
(
post_val
)
=
merge
.get
(
&
post_key
)
{
if
post_val
.is_sequence
()
{
list
.extend
(
post_val
.as_sequence
()
.unwrap
()
.clone
());
}
}
config
.insert
(
key_val
,
Value
::
from
(
list
));
});
config
}
pub
fn
use_script
(
script
:
String
,
config
:
Mapping
,
valid
:
Vec
<
String
>
,
)
->
Result
<
(
Mapping
,
Vec
<
(
String
,
String
)
>
)
>
{
use
quick_js
::{
Context
,
JsValue
};
use
std
::
sync
::{
Arc
,
Mutex
};
let
context
=
Context
::
new
()
.unwrap
();
let
outputs
=
Arc
::
new
(
Mutex
::
new
(
vec!
[]));
let
copy_outputs
=
outputs
.clone
();
context
.add_callback
(
"__verge__log__"
,
move
|
level
:
String
,
data
:
String
|
{
let
mut
out
=
copy_outputs
.lock
()
.unwrap
();
out
.push
((
level
,
data
));
JsValue
::
Undefined
})
?
;
context
.eval
(
r#"var console = Object.freeze({
log(data){__verge__log__("log",JSON.stringify(data))},
info(data){__verge__log__("info",JSON.stringify(data))},
error(data){__verge__log__("error",JSON.stringify(data))},
});"#
,
)
?
;
let
config_str
=
serde_json
::
to_string
(
&
config
)
?
;
let
code
=
format!
(
"
\n
{script}
\n
;
\n
JSON.stringify(main({config_str}))"
);
let
result
=
context
.eval
(
code
.as_str
())
?
;
let
mut
out
=
outputs
.lock
()
.unwrap
();
match
result
.into_string
()
{
Some
(
result
)
=>
match
serde_json
::
from_str
::
<
Mapping
>
(
result
.as_str
())
{
Ok
(
config
)
=>
{
let
config
=
use_valid_filter
(
config
,
valid
);
Ok
((
config
,
out
.to_vec
()))
}
Err
(
_
)
=>
{
out
.push
((
"error"
.into
(),
"failed to parse json string"
.into
()));
Ok
((
config
,
out
.to_vec
()))
}
},
None
=>
{
out
.push
((
"error"
.into
(),
"main function should return object"
.into
()));
Ok
((
config
,
out
.to_vec
()))
}
}
}
#[test]
fn
test_merge
()
->
Result
<
()
>
{
let
merge
=
r"
prepend-rules:
- prepend
- 1123123
append-rules:
- append
prepend-proxies:
- 9999
append-proxies:
- 1111
rules:
- replace
proxy-groups:
- 123781923810
tun:
enable: true
dns:
enable: true
"
;
let
config
=
r"
rules:
- aaaaa
script: test
"
;
let
merge
=
serde_yaml
::
from_str
::
<
Mapping
>
(
merge
)
?
;
let
config
=
serde_yaml
::
from_str
::
<
Mapping
>
(
config
)
?
;
let
result
=
serde_yaml
::
to_string
(
&
use_merge
(
merge
,
config
,
vec!
[
"tun"
]
.iter
()
.map
(|
s
|
s
.to_string
())
.collect
(),
))
?
;
println!
(
"{result}"
);
Ok
(())
}
#[test]
fn
test_script
()
{
let
script
=
r#"
function main(config) {
config.rules = [...config.rules, "add"];
config.proxies = ["111"];
console.log(config);
return config;
}
"#
;
let
config
=
r#"
rules:
- 111
- 222
tun:
enable: false
dns:
enable: false
"#
;
let
config
=
serde_yaml
::
from_str
(
config
)
.unwrap
();
let
(
config
,
results
)
=
use_script
(
script
.into
(),
config
,
vec!
[
"tun"
]
.iter
()
.map
(|
s
|
s
.to_string
())
.collect
(),
)
.unwrap
();
let
config_str
=
serde_yaml
::
to_string
(
&
config
)
.unwrap
();
println!
(
"{config_str}"
);
dbg!
(
results
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment