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
14bda4f3
There was an error fetching the commit references. Please try again later.
Commit
14bda4f3
authored
3 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
feat: record selected proxy
parent
61b9670b
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/components/proxy-group.tsx
+20
-0
20 additions, 0 deletions
src/components/proxy-group.tsx
src/pages/profile.tsx
+45
-4
45 additions, 4 deletions
src/pages/profile.tsx
src/pages/proxy.tsx
+2
-2
2 additions, 2 deletions
src/pages/proxy.tsx
src/services/cmds.ts
+2
-5
2 additions, 5 deletions
src/services/cmds.ts
with
69 additions
and
11 deletions
src/components/proxy-group.tsx
+
20
−
0
View file @
14bda4f3
...
@@ -22,6 +22,8 @@ import {
...
@@ -22,6 +22,8 @@ import {
}
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
,
setProfiles
}
from
"
../services/cmds
"
;
import
noop
from
"
../utils/noop
"
;
interface
ItemProps
{
interface
ItemProps
{
proxy
:
ApiType
.
ProxyItem
;
proxy
:
ApiType
.
ProxyItem
;
...
@@ -86,6 +88,24 @@ const ProxyGroup = ({ group }: Props) => {
...
@@ -86,6 +88,24 @@ const ProxyGroup = ({ group }: Props) => {
try
{
try
{
setNow
(
name
);
setNow
(
name
);
await
updateProxy
(
group
.
name
,
name
);
await
updateProxy
(
group
.
name
,
name
);
const
profiles
=
await
getProfiles
().
catch
(
console
.
error
);
if
(
!
profiles
)
return
;
const
profile
=
profiles
.
items
!
[
profiles
.
current
!
]
!
;
if
(
!
profile
)
return
;
if
(
!
profile
.
selected
)
profile
.
selected
=
[];
const
index
=
profile
.
selected
.
findIndex
(
(
item
)
=>
item
.
name
===
group
.
name
);
if
(
index
<
0
)
{
profile
.
selected
.
push
({
name
:
group
.
name
,
now
:
name
});
}
else
{
profile
.
selected
[
index
]
=
{
name
:
group
.
name
,
now
:
name
};
}
setProfiles
(
profiles
.
current
!
,
profile
).
catch
(
console
.
error
);
}
catch
{
}
catch
{
setNow
(
oldValue
);
setNow
(
oldValue
);
// Todo
// Todo
...
...
This diff is collapsed.
Click to expand it.
src/pages/profile.tsx
+
45
−
4
View file @
14bda4f3
import
{
useRef
,
useState
}
from
"
react
"
;
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
{
Box
,
Button
,
Grid
,
TextField
,
Typography
}
from
"
@mui/material
"
;
import
{
getProfiles
,
importProfile
,
putProfiles
}
from
"
../services/cmds
"
;
import
{
import
{
getProxies
}
from
"
../services/api
"
;
getProfiles
,
putProfiles
,
setProfiles
,
importProfile
,
}
from
"
../services/cmds
"
;
import
{
getProxies
,
updateProxy
}
from
"
../services/api
"
;
import
ProfileItemComp
from
"
../components/profile-item
"
;
import
ProfileItemComp
from
"
../components/profile-item
"
;
import
useNotice
from
"
../utils/use-notice
"
;
import
useNotice
from
"
../utils/use-notice
"
;
import
noop
from
"
../utils/noop
"
;
import
noop
from
"
../utils/noop
"
;
...
@@ -15,6 +20,43 @@ const ProfilePage = () => {
...
@@ -15,6 +20,43 @@ const ProfilePage = () => {
const
{
mutate
}
=
useSWRConfig
();
const
{
mutate
}
=
useSWRConfig
();
const
{
data
:
profiles
=
{}
}
=
useSWR
(
"
getProfiles
"
,
getProfiles
);
const
{
data
:
profiles
=
{}
}
=
useSWR
(
"
getProfiles
"
,
getProfiles
);
useEffect
(()
=>
{
if
(
profiles
.
current
==
null
)
return
;
const
profile
=
profiles
.
items
!
[
profiles
.
current
];
if
(
!
profile
)
return
;
getProxies
().
then
((
proxiesData
)
=>
{
mutate
(
"
getProxies
"
,
proxiesData
);
// init selected array
const
{
selected
=
[]
}
=
profile
;
const
selectedMap
=
Object
.
fromEntries
(
selected
.
map
((
each
)
=>
[
each
.
name
!
,
each
.
now
!
])
);
// todo: enhance error handle
let
hasChange
=
false
;
proxiesData
.
groups
.
forEach
((
group
)
=>
{
const
{
name
,
now
}
=
group
;
if
(
!
now
||
selectedMap
[
name
]
===
now
)
return
;
if
(
selectedMap
[
name
]
==
null
)
{
selectedMap
[
name
]
=
now
!
;
}
else
{
hasChange
=
true
;
updateProxy
(
name
,
selectedMap
[
name
]);
}
});
// update profile selected list
profile
.
selected
=
Object
.
entries
(
selectedMap
).
map
(([
name
,
now
])
=>
({
name
,
now
,
}));
setProfiles
(
profiles
.
current
!
,
profile
).
catch
(
console
.
error
);
// update proxies cache
if
(
hasChange
)
mutate
(
"
getProxies
"
,
getProxies
());
});
},
[
profiles
]);
const
onImport
=
async
()
=>
{
const
onImport
=
async
()
=>
{
if
(
!
url
)
return
;
if
(
!
url
)
return
;
setUrl
(
""
);
setUrl
(
""
);
...
@@ -39,7 +81,6 @@ const ProfilePage = () => {
...
@@ -39,7 +81,6 @@ const ProfilePage = () => {
putProfiles
(
index
)
putProfiles
(
index
)
.
then
(()
=>
{
.
then
(()
=>
{
mutate
(
"
getProfiles
"
,
{
...
profiles
,
current
:
index
},
true
);
mutate
(
"
getProfiles
"
,
{
...
profiles
,
current
:
index
},
true
);
mutate
(
"
getProxies
"
,
getProxies
());
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
console
.
error
(
err
);
console
.
error
(
err
);
...
...
This diff is collapsed.
Click to expand it.
src/pages/proxy.tsx
+
2
−
2
View file @
14bda4f3
...
@@ -4,8 +4,8 @@ import { getProxies } from "../services/api";
...
@@ -4,8 +4,8 @@ import { getProxies } from "../services/api";
import
ProxyGroup
from
"
../components/proxy-group
"
;
import
ProxyGroup
from
"
../components/proxy-group
"
;
const
ProxyPage
=
()
=>
{
const
ProxyPage
=
()
=>
{
const
{
data
}
=
useSWR
(
"
getProxies
"
,
getProxies
);
const
{
data
:
proxiesData
}
=
useSWR
(
"
getProxies
"
,
getProxies
);
const
{
groups
=
[]
}
=
d
ata
??
{};
const
{
groups
=
[]
}
=
proxiesD
ata
??
{};
return
(
return
(
<
Box
sx
=
{
{
width
:
0.9
,
maxWidth
:
"
850px
"
,
mx
:
"
auto
"
,
mb
:
2
}
}
>
<
Box
sx
=
{
{
width
:
0.9
,
maxWidth
:
"
850px
"
,
mx
:
"
auto
"
,
mb
:
2
}
}
>
...
...
This diff is collapsed.
Click to expand it.
src/services/cmds.ts
+
2
−
5
View file @
14bda4f3
...
@@ -25,11 +25,8 @@ export async function getProfiles() {
...
@@ -25,11 +25,8 @@ export async function getProfiles() {
return
(
await
invoke
<
CmdType
.
ProfilesConfig
>
(
"
get_profiles
"
))
??
{};
return
(
await
invoke
<
CmdType
.
ProfilesConfig
>
(
"
get_profiles
"
))
??
{};
}
}
export
async
function
setProfiles
(
export
async
function
setProfiles
(
index
:
number
,
profile
:
CmdType
.
ProfileItem
)
{
current
:
number
,
return
invoke
<
void
>
(
"
set_profiles
"
,
{
index
,
profile
});
profile
:
CmdType
.
ProfileItem
)
{
return
invoke
<
void
>
(
"
set_profiles
"
,
{
current
,
profile
});
}
}
export
async
function
putProfiles
(
current
:
number
)
{
export
async
function
putProfiles
(
current
:
number
)
{
...
...
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