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
57d23eb0
There was an error fetching the commit references. Please try again later.
Unverified
Commit
57d23eb0
authored
2 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
fix(macos): set auto launch path to application
parent
5ebd9be8
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/core/sysopt.rs
+45
-13
45 additions, 13 deletions
src-tauri/src/core/sysopt.rs
with
45 additions
and
13 deletions
src-tauri/src/core/sysopt.rs
+
45
−
13
View file @
57d23eb0
use
crate
::{
data
::
*
,
log_if_err
};
use
anyhow
::{
bail
,
Result
};
use
anyhow
::{
anyhow
,
bail
,
Result
};
use
auto_launch
::{
AutoLaunch
,
AutoLaunchBuilder
};
use
std
::
sync
::
Arc
;
use
sysproxy
::
Sysproxy
;
...
...
@@ -133,30 +133,62 @@ impl Sysopt {
let
verge
=
data
.verge
.lock
();
let
enable
=
verge
.enable_auto_launch
.clone
()
.unwrap_or
(
false
);
if
!
enable
{
return
Ok
(());
}
let
app_exe
=
current_exe
()
?
;
let
app_exe
=
dunce
::
canonicalize
(
app_exe
)
?
;
let
app_name
=
app_exe
.file_stem
()
.and_then
(|
f
|
f
.to_str
())
.ok_or
(
anyhow!
(
"failed to get file stem"
))
?
;
let
app_exe
=
current_exe
()
.unwrap
();
let
app_exe
=
dunce
::
canonicalize
(
app_exe
)
.unwrap
();
let
app_name
=
app_exe
.file_stem
()
.unwrap
()
.to_str
()
.unwrap
();
let
app_path
=
app_exe
.as_os_str
()
.to_str
()
.unwrap
();
let
app_path
=
app_exe
.as_os_str
()
.to_str
()
.ok_or
(
anyhow!
(
"failed to get app_path"
))
?
.to_string
();
// fix issue #26
#[cfg(target_os
=
"windows"
)]
let
app_path
=
format!
(
"
\"
{app_path}
\"
"
);
#[cfg(target_os
=
"windows"
)]
let
app_path
=
app_path
.as_str
();
// use the /Applications/Clash Verge.app path
#[cfg(target_os
=
"macos"
)]
let
app_path
=
(||
->
Option
<
String
>
{
let
path
=
std
::
path
::
PathBuf
::
from
(
&
app_path
);
let
path
=
path
.parent
()
?
.parent
()
?
.parent
()
?
;
let
extension
=
path
.extension
()
?
.to_str
()
?
;
match
extension
==
"app"
{
true
=>
Some
(
path
.as_os_str
()
.to_str
()
?
.to_string
()),
false
=>
None
,
}
})()
.unwrap_or
(
app_path
);
let
auto
=
AutoLaunchBuilder
::
new
()
.set_app_name
(
app_name
)
.set_app_path
(
app_path
)
.set_app_path
(
&
app_path
)
.build
()
?
;
// fix issue #26
auto
.enable
()
?
;
self
.auto_launch
=
Some
(
auto
);
let
auto
=
self
.auto_launch
.as_ref
()
.unwrap
();
// macos每次启动都更新登录项,避免重复设置登录项
#[cfg(target_os
=
"macos"
)]
{
let
_
=
auto
.disable
();
if
enable
{
auto
.enable
()
?
;
}
}
#[cfg(not(target_os
=
"macos"
))]
{
match
enable
{
true
=>
auto
.enable
()
?
,
false
=>
auto
.disable
()
?
,
};
}
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