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
acc6e05b
There was an error fetching the commit references. Please try again later.
Unverified
Commit
acc6e05b
authored
3 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
feat: system tray supports system proxy setting
parent
4ce15577
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-tauri/src/cmds.rs
+11
-0
11 additions, 0 deletions
src-tauri/src/cmds.rs
src-tauri/src/main.rs
+35
-7
35 additions, 7 deletions
src-tauri/src/main.rs
src-tauri/src/utils/resolve.rs
+7
-0
7 additions, 0 deletions
src-tauri/src/utils/resolve.rs
src/pages/_layout.tsx
+3
-0
3 additions, 0 deletions
src/pages/_layout.tsx
with
56 additions
and
7 deletions
src-tauri/src/cmds.rs
+
11
−
0
View file @
acc6e05b
...
@@ -280,11 +280,13 @@ pub fn get_verge_config(verge_state: State<'_, VergeState>) -> Result<VergeConfi
...
@@ -280,11 +280,13 @@ pub fn get_verge_config(verge_state: State<'_, VergeState>) -> Result<VergeConfi
#[tauri::command]
#[tauri::command]
pub
fn
patch_verge_config
(
pub
fn
patch_verge_config
(
payload
:
VergeConfig
,
payload
:
VergeConfig
,
app_handle
:
tauri
::
AppHandle
,
clash_state
:
State
<
'_
,
ClashState
>
,
clash_state
:
State
<
'_
,
ClashState
>
,
verge_state
:
State
<
'_
,
VergeState
>
,
verge_state
:
State
<
'_
,
VergeState
>
,
profiles_state
:
State
<
'_
,
ProfilesState
>
,
profiles_state
:
State
<
'_
,
ProfilesState
>
,
)
->
Result
<
(),
String
>
{
)
->
Result
<
(),
String
>
{
let
tun_mode
=
payload
.enable_tun_mode
.clone
();
let
tun_mode
=
payload
.enable_tun_mode
.clone
();
let
system_proxy
=
payload
.enable_system_proxy
.clone
();
// change tun mode
// change tun mode
if
tun_mode
.is_some
()
{
if
tun_mode
.is_some
()
{
...
@@ -299,6 +301,15 @@ pub fn patch_verge_config(
...
@@ -299,6 +301,15 @@ pub fn patch_verge_config(
let
mut
verge
=
verge_state
.0
.lock
()
.unwrap
();
let
mut
verge
=
verge_state
.0
.lock
()
.unwrap
();
wrap_err!
(
verge
.patch_config
(
payload
))
?
;
wrap_err!
(
verge
.patch_config
(
payload
))
?
;
// change system tray
if
system_proxy
.is_some
()
{
app_handle
.tray_handle
()
.get_item
(
"system_proxy"
)
.set_selected
(
system_proxy
.unwrap
())
.unwrap
();
}
Ok
(())
Ok
(())
}
}
...
...
This diff is collapsed.
Click to expand it.
src-tauri/src/main.rs
+
35
−
7
View file @
acc6e05b
...
@@ -8,7 +8,10 @@ mod core;
...
@@ -8,7 +8,10 @@ mod core;
mod
states
;
mod
states
;
mod
utils
;
mod
utils
;
use
crate
::
utils
::{
resolve
,
server
};
use
crate
::{
core
::
VergeConfig
,
utils
::{
resolve
,
server
},
};
use
tauri
::{
use
tauri
::{
api
,
CustomMenuItem
,
Manager
,
SystemTray
,
SystemTrayEvent
,
SystemTrayMenu
,
SystemTrayMenuItem
,
api
,
CustomMenuItem
,
Manager
,
SystemTray
,
SystemTrayEvent
,
SystemTrayMenu
,
SystemTrayMenuItem
,
};
};
...
@@ -21,6 +24,7 @@ fn main() -> std::io::Result<()> {
...
@@ -21,6 +24,7 @@ fn main() -> std::io::Result<()> {
let
tray_menu
=
SystemTrayMenu
::
new
()
let
tray_menu
=
SystemTrayMenu
::
new
()
.add_item
(
CustomMenuItem
::
new
(
"open_window"
,
"Show"
))
.add_item
(
CustomMenuItem
::
new
(
"open_window"
,
"Show"
))
.add_item
(
CustomMenuItem
::
new
(
"system_proxy"
,
"System Proxy"
))
.add_item
(
CustomMenuItem
::
new
(
"restart_clash"
,
"Restart Clash"
))
.add_item
(
CustomMenuItem
::
new
(
"restart_clash"
,
"Restart Clash"
))
.add_native_item
(
SystemTrayMenuItem
::
Separator
)
.add_native_item
(
SystemTrayMenuItem
::
Separator
)
.add_item
(
CustomMenuItem
::
new
(
"quit"
,
"Quit"
)
.accelerator
(
"CmdOrControl+Q"
));
.add_item
(
CustomMenuItem
::
new
(
"quit"
,
"Quit"
)
.accelerator
(
"CmdOrControl+Q"
));
...
@@ -40,6 +44,31 @@ fn main() -> std::io::Result<()> {
...
@@ -40,6 +44,31 @@ fn main() -> std::io::Result<()> {
window
.show
()
.unwrap
();
window
.show
()
.unwrap
();
window
.set_focus
()
.unwrap
();
window
.set_focus
()
.unwrap
();
}
}
"system_proxy"
=>
{
let
verge_state
=
app_handle
.state
::
<
states
::
VergeState
>
();
let
mut
verge
=
verge_state
.0
.lock
()
.unwrap
();
let
old_value
=
verge
.config.enable_system_proxy
.clone
()
.unwrap_or
(
false
);
let
new_value
=
!
old_value
;
match
verge
.patch_config
(
VergeConfig
{
enable_system_proxy
:
Some
(
new_value
),
..
VergeConfig
::
default
()
})
{
Ok
(
_
)
=>
{
app_handle
.tray_handle
()
.get_item
(
id
.as_str
())
.set_selected
(
new_value
)
.unwrap
();
// update verge config
let
window
=
app_handle
.get_window
(
"main"
)
.unwrap
();
window
.emit
(
"verge://refresh-verge-config"
,
"yes"
)
.unwrap
();
}
Err
(
err
)
=>
log
::
error!
(
"{err}"
),
}
}
"restart_clash"
=>
{
"restart_clash"
=>
{
let
clash_state
=
app_handle
.state
::
<
states
::
ClashState
>
();
let
clash_state
=
app_handle
.state
::
<
states
::
ClashState
>
();
let
profiles_state
=
app_handle
.state
::
<
states
::
ProfilesState
>
();
let
profiles_state
=
app_handle
.state
::
<
states
::
ProfilesState
>
();
...
@@ -55,13 +84,12 @@ fn main() -> std::io::Result<()> {
...
@@ -55,13 +84,12 @@ fn main() -> std::io::Result<()> {
}
}
_
=>
{}
_
=>
{}
},
},
#[cfg(target_os
=
"windows"
)]
SystemTrayEvent
::
LeftClick
{
..
}
=>
{
SystemTrayEvent
::
LeftClick
{
..
}
=>
{
if
cfg!
[
target_os
=
"windows"
]
{
let
window
=
app_handle
.get_window
(
"main"
)
.unwrap
();
let
window
=
app_handle
.get_window
(
"main"
)
.unwrap
();
window
.unminimize
()
.unwrap
();
window
.unminimize
()
.unwrap
();
window
.show
()
.unwrap
();
window
.show
()
.unwrap
();
window
.set_focus
()
.unwrap
();
window
.set_focus
()
.unwrap
();
}
}
}
_
=>
{}
_
=>
{}
})
})
...
...
This diff is collapsed.
Click to expand it.
src-tauri/src/utils/resolve.rs
+
7
−
0
View file @
acc6e05b
...
@@ -39,6 +39,13 @@ pub fn resolve_setup(app: &App) {
...
@@ -39,6 +39,13 @@ pub fn resolve_setup(app: &App) {
}
}
log_if_err!
(
verge
.init_launch
());
log_if_err!
(
verge
.init_launch
());
verge
.config.enable_system_proxy
.map
(|
enable
|
{
log_if_err!
(
app
.tray_handle
()
.get_item
(
"system_proxy"
)
.set_selected
(
enable
));
});
}
}
/// reset system proxy
/// reset system proxy
...
...
This diff is collapsed.
Click to expand it.
src/pages/_layout.tsx
+
3
−
0
View file @
acc6e05b
...
@@ -41,6 +41,9 @@ const Layout = () => {
...
@@ -41,6 +41,9 @@ const Layout = () => {
mutate
(
"
getProxies
"
);
mutate
(
"
getProxies
"
);
mutate
(
"
getClashConfig
"
);
mutate
(
"
getClashConfig
"
);
});
});
// update the verge config
listen
(
"
verge://refresh-verge-config
"
,
()
=>
mutate
(
"
getVergeConfig
"
));
},
[]);
},
[]);
useEffect
(()
=>
{
useEffect
(()
=>
{
...
...
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