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
7d878d25
There was an error fetching the commit references. Please try again later.
Commit
7d878d25
authored
3 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
chore: something
parent
a35cd285
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/main.rs
+38
-49
38 additions, 49 deletions
src-tauri/src/main.rs
with
38 additions
and
49 deletions
src-tauri/src/main.rs
+
38
−
49
View file @
7d878d25
...
...
@@ -21,7 +21,6 @@ use crate::{
use
std
::
sync
::{
Arc
,
Mutex
};
use
tauri
::{
api
,
CustomMenuItem
,
Manager
,
SystemTray
,
SystemTrayEvent
,
SystemTrayMenu
,
SystemTrayMenuItem
,
SystemTraySubmenu
,
};
fn
main
()
->
std
::
io
::
Result
<
()
>
{
...
...
@@ -30,23 +29,34 @@ fn main() -> std::io::Result<()> {
return
Ok
(());
}
let
sub_menu
=
SystemTraySubmenu
::
new
(
"出站规则"
,
SystemTrayMenu
::
new
()
.add_item
(
CustomMenuItem
::
new
(
"rway_global"
,
"全局连接"
))
.add_item
(
CustomMenuItem
::
new
(
"rway_rule"
,
"规则连接"
)
.selected
())
.add_item
(
CustomMenuItem
::
new
(
"rway_direct"
,
"直接连接"
)),
);
let
menu
=
SystemTrayMenu
::
new
()
.add_submenu
(
sub_menu
)
.add_native_item
(
SystemTrayMenuItem
::
Separator
)
.add_item
(
CustomMenuItem
::
new
(
"syste_proxy"
,
"设置为系统代理"
))
.add_item
(
CustomMenuItem
::
new
(
"self_startup"
,
"开机启动"
)
.selected
())
.add_item
(
CustomMenuItem
::
new
(
"open_window"
,
"显示应用"
))
.add_native_item
(
SystemTrayMenuItem
::
Separator
)
.add_item
(
CustomMenuItem
::
new
(
"quit"
,
"退出"
)
.accelerator
(
"CmdOrControl+Q"
));
let
app
=
tauri
::
Builder
::
default
()
tauri
::
Builder
::
default
()
.setup
(|
app
|
{
// a simple http server
embed_server
(
&
app
.handle
());
// init app config
utils
::
init
::
init_app
(
app
.package_info
());
// run clash sidecar
let
info
=
utils
::
clash
::
run_clash_bin
(
&
app
.handle
());
// update the profile
let
info_copy
=
info
.clone
();
tauri
::
async_runtime
::
spawn
(
async
move
{
match
put_clash_profile
(
&
info_copy
)
.await
{
Ok
(
_
)
=>
{}
Err
(
err
)
=>
log
::
error!
(
"failed to put config for `{}`"
,
err
),
};
});
app
.manage
(
state
::
VergeConfLock
(
Arc
::
new
(
Mutex
::
new
(
read_verge
()))));
app
.manage
(
state
::
ClashInfoState
(
Arc
::
new
(
Mutex
::
new
(
info
))));
app
.manage
(
state
::
ProfileLock
::
default
());
Ok
(())
})
.system_tray
(
SystemTray
::
new
()
.with_menu
(
menu
))
.on_system_tray_event
(
move
|
app
,
event
|
match
event
{
SystemTrayEvent
::
MenuItemClick
{
id
,
..
}
=>
match
id
.as_str
()
{
...
...
@@ -83,42 +93,21 @@ fn main() -> std::io::Result<()> {
cmds
::
profile
::
put_profiles
,
])
.build
(
tauri
::
generate_context!
())
.expect
(
"error while running tauri application"
);
// a simple http server
embed_server
(
&
app
.handle
());
// init app config
utils
::
init
::
init_app
(
app
.package_info
());
// run clash sidecar
let
info
=
utils
::
clash
::
run_clash_bin
(
&
app
.handle
());
// update the profile
let
info_copy
=
info
.clone
();
tauri
::
async_runtime
::
spawn
(
async
move
{
match
put_clash_profile
(
&
info_copy
)
.await
{
Ok
(
_
)
=>
{}
Err
(
err
)
=>
log
::
error!
(
"failed to put config for `{}`"
,
err
),
};
});
app
.manage
(
state
::
VergeConfLock
(
Arc
::
new
(
Mutex
::
new
(
read_verge
()))));
app
.manage
(
state
::
ClashInfoState
(
Arc
::
new
(
Mutex
::
new
(
info
))));
app
.manage
(
state
::
ProfileLock
::
default
());
app
.run
(|
app_handle
,
e
|
match
e
{
tauri
::
Event
::
CloseRequested
{
label
,
api
,
..
}
=>
{
let
app_handle
=
app_handle
.clone
();
api
.prevent_close
();
app_handle
.get_window
(
&
label
)
.unwrap
()
.hide
()
.unwrap
();
}
tauri
::
Event
::
ExitRequested
{
api
,
..
}
=>
{
api
.prevent_exit
();
}
tauri
::
Event
::
Exit
=>
{
api
::
process
::
kill_children
();
}
_
=>
{}
});
.expect
(
"error while running tauri application"
)
.run
(|
app_handle
,
e
|
match
e
{
tauri
::
Event
::
CloseRequested
{
label
,
api
,
..
}
=>
{
let
app_handle
=
app_handle
.clone
();
api
.prevent_close
();
app_handle
.get_window
(
&
label
)
.unwrap
()
.hide
()
.unwrap
();
}
tauri
::
Event
::
ExitRequested
{
api
,
..
}
=>
{
api
.prevent_exit
();
}
tauri
::
Event
::
Exit
=>
{
api
::
process
::
kill_children
();
}
_
=>
{}
});
Ok
(())
}
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