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
9ccc66ca
There was an error fetching the commit references. Please try again later.
Unverified
Commit
9ccc66ca
authored
3 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
feat: use enhanced guard-state
parent
8606af36
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/setting/setting-clash.tsx
+20
-30
20 additions, 30 deletions
src/components/setting/setting-clash.tsx
src/components/setting/setting-system.tsx
+1
-0
1 addition, 0 deletions
src/components/setting/setting-system.tsx
with
21 additions
and
30 deletions
src/components/setting/setting-clash.tsx
+
20
−
30
View file @
9ccc66ca
import
{
useEffect
,
useState
}
from
"
react
"
;
import
{
useDebounceFn
}
from
"
ahooks
"
;
import
{
useSetRecoilState
}
from
"
recoil
"
;
import
useSWR
,
{
useSWRConfig
}
from
"
swr
"
;
import
{
useSetRecoilState
}
from
"
recoil
"
;
import
{
ListItemText
,
TextField
,
...
...
@@ -31,13 +29,10 @@ const SettingClash = ({ onError }: Props) => {
ipv6
=
false
,
"
allow-lan
"
:
allowLan
=
false
,
"
log-level
"
:
logLevel
=
"
silent
"
,
"
mixed-port
"
:
the
Port
=
0
,
"
mixed-port
"
:
mixed
Port
=
0
,
}
=
clashConfig
??
{};
const
setPort
=
useSetRecoilState
(
atomClashPort
);
const
[
mixedPort
,
setMixedPort
]
=
useState
(
thePort
);
useEffect
(()
=>
setMixedPort
(
thePort
),
[
thePort
]);
const
setGlobalClashPort
=
useSetRecoilState
(
atomClashPort
);
const
onSwitchFormat
=
(
_e
:
any
,
value
:
boolean
)
=>
value
;
const
onChangeData
=
(
patch
:
Partial
<
ApiType
.
ConfigData
>
)
=>
{
...
...
@@ -48,27 +43,20 @@ const SettingClash = ({ onError }: Props) => {
await
patchClashConfig
(
patch
);
};
// restart clash when port is changed
const
{
run
:
onUpdatePort
}
=
useDebounceFn
(
async
(
port
:
number
)
=>
{
try
{
if
(
port
<
1000
)
{
throw
new
Error
(
"
The port should not < 1000
"
);
}
if
(
port
>
65536
)
{
throw
new
Error
(
"
The port should not > 65536
"
);
}
await
patchClashConfig
({
"
mixed-port
"
:
port
});
onChangeData
({
"
mixed-port
"
:
port
});
setPort
(
port
);
Notice
.
success
(
"
Change Clash port successfully!
"
);
}
catch
(
err
:
any
)
{
setMixedPort
(
thePort
);
// back to old port value
Notice
.
error
(
err
.
message
??
err
.
toString
());
}
},
{
wait
:
1000
}
);
const
onUpdatePort
=
async
(
port
:
number
)
=>
{
if
(
port
<
1000
)
{
throw
new
Error
(
"
The port should not < 1000
"
);
}
if
(
port
>
65536
)
{
throw
new
Error
(
"
The port should not > 65536
"
);
}
await
patchClashConfig
({
"
mixed-port
"
:
port
});
setGlobalClashPort
(
port
);
Notice
.
success
(
"
Change Clash port successfully!
"
);
// update the config
mutate
(
"
getClashConfig
"
);
};
// get clash core version
const
clashVer
=
versionData
?.
premium
...
...
@@ -128,9 +116,11 @@ const SettingClash = ({ onError }: Props) => {
<
ListItemText
primary
=
"Mixed Port"
/>
<
GuardState
value
=
{
mixedPort
!
}
onCatch
=
{
onError
}
onFormat
=
{
(
e
:
any
)
=>
+
e
.
target
.
value
?.
replace
(
/
\D
+/
,
""
)
}
onChange
=
{
setM
ixed
P
ort
}
onChange
=
{
(
e
)
=>
onChangeData
({
"
m
ixed
-p
ort
"
:
e
})
}
onGuard
=
{
onUpdatePort
}
waitTime
=
{
800
}
>
<
TextField
autoComplete
=
"off"
size
=
"small"
sx
=
{
{
width
:
120
}
}
/>
</
GuardState
>
...
...
This diff is collapsed.
Click to expand it.
src/components/setting/setting-system.tsx
+
1
−
0
View file @
9ccc66ca
...
...
@@ -91,6 +91,7 @@ const SettingSystem = ({ onError }: Props) => {
onFormat
=
{
(
e
:
any
)
=>
e
.
target
.
value
}
onChange
=
{
(
e
)
=>
onChangeData
({
system_proxy_bypass
:
e
})
}
onGuard
=
{
(
e
)
=>
patchVergeConfig
({
system_proxy_bypass
:
e
})
}
waitTime
=
{
1000
}
>
<
TextField
autoComplete
=
"off"
size
=
"small"
sx
=
{
{
width
:
120
}
}
/>
</
GuardState
>
...
...
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