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
b3cd2074
There was an error fetching the commit references. Please try again later.
Commit
b3cd2074
authored
3 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
feat: delay put profiles and retry
parent
03f9fa4b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src-tauri/src/utils/clash.rs
+21
-16
21 additions, 16 deletions
src-tauri/src/utils/clash.rs
with
21 additions
and
16 deletions
src-tauri/src/utils/clash.rs
+
21
−
16
View file @
b3cd2074
extern
crate
log
;
use
crate
::{
config
::
ProfilesConfig
,
events
::{
emit
::{
clash_start
,
ClashInfoPayload
},
state
,
},
utils
::{
app_home_dir
,
clash
,
config
::{
read_clash_controller
,
read_profiles
,
read_yaml
,
save_yaml
},
},
utils
::{
app_home_dir
,
clash
,
config
},
};
use
reqwest
::
header
::
HeaderMap
;
use
serde_yaml
::{
Mapping
,
Value
};
...
...
@@ -40,15 +38,7 @@ pub fn run_clash_bin(app_handle: &AppHandle) -> ClashInfoPayload {
match
result
{
Ok
((
mut
rx
,
cmd_child
))
=>
{
log
::
info!
(
"Successfully execute clash sidecar"
);
payload
.controller
=
Some
(
read_clash_controller
());
// update the profile
let
payload_
=
payload
.clone
();
tauri
::
async_runtime
::
spawn
(
async
move
{
if
let
Err
(
err
)
=
clash
::
put_clash_profile
(
&
payload_
)
.await
{
log
::
error!
(
"failed to put config for `{}`"
,
err
);
};
});
payload
.controller
=
Some
(
config
::
read_clash_controller
());
if
let
Ok
(
mut
state
)
=
app_handle
.state
::
<
state
::
ClashSidecarState
>
()
.0
.lock
()
{
*
state
=
Some
(
cmd_child
);
...
...
@@ -63,6 +53,21 @@ pub fn run_clash_bin(app_handle: &AppHandle) -> ClashInfoPayload {
}
}
});
// update the profile
let
payload_
=
payload
.clone
();
tauri
::
async_runtime
::
spawn
(
async
move
{
let
mut
count
=
5
;
// retry times
let
mut
err
=
String
::
from
(
""
);
while
count
>
0
{
match
clash
::
put_clash_profile
(
&
payload_
)
.await
{
Ok
(
_
)
=>
return
,
Err
(
e
)
=>
err
=
e
,
}
count
-=
1
;
}
log
::
error!
(
"failed to put config for `{}`"
,
err
);
});
}
Err
(
err
)
=>
{
log
::
error!
(
"Failed to execute clash sidecar for
\"
{}
\"
"
,
err
);
...
...
@@ -78,7 +83,7 @@ pub fn run_clash_bin(app_handle: &AppHandle) -> ClashInfoPayload {
/// Update the clash profile firstly
pub
async
fn
put_clash_profile
(
payload
:
&
ClashInfoPayload
)
->
Result
<
(),
String
>
{
let
profile
=
{
let
profiles
=
read_
pro
file
s
();
let
profiles
=
ProfilesConfig
::
read_file
();
let
current
=
profiles
.current
.unwrap_or
(
0
)
as
usize
;
match
profiles
.items
{
Some
(
items
)
=>
{
...
...
@@ -111,7 +116,7 @@ pub async fn put_clash_profile(payload: &ClashInfoPayload) -> Result<(), String>
// Only the following fields are allowed:
// proxies/proxy-providers/proxy-groups/rule-providers/rules
let
config
=
read_yaml
::
<
Mapping
>
(
file_path
.clone
());
let
config
=
config
::
read_yaml
::
<
Mapping
>
(
file_path
.clone
());
let
mut
new_config
=
Mapping
::
new
();
vec!
[
"proxies"
,
...
...
@@ -129,7 +134,7 @@ pub async fn put_clash_profile(payload: &ClashInfoPayload) -> Result<(), String>
}
});
match
save_yaml
(
match
config
::
save_yaml
(
temp_path
.clone
(),
&
new_config
,
Some
(
"# Clash Verge Temp File"
),
...
...
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