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
f88989bd
There was an error fetching the commit references. Please try again later.
Unverified
Commit
f88989bd
authored
2 years ago
by
GyDi
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: change service installer and uninstaller
parent
77ef3847
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
scripts/check.mjs
+14
-8
14 additions, 8 deletions
scripts/check.mjs
src-tauri/src/cmds.rs
+6
-6
6 additions, 6 deletions
src-tauri/src/cmds.rs
src-tauri/src/core/service.rs
+37
-34
37 additions, 34 deletions
src-tauri/src/core/service.rs
with
57 additions
and
48 deletions
scripts/check.mjs
+
14
−
8
View file @
f88989bd
...
@@ -143,20 +143,26 @@ async function resolveService() {
...
@@ -143,20 +143,26 @@ async function resolveService() {
if
(
platform
!==
"
win32
"
)
return
;
if
(
platform
!==
"
win32
"
)
return
;
const
url
=
const
resDir
=
path
.
join
(
cwd
,
"
src-tauri/resources
"
);
"
https://github.com/zzzgydi/clash-verge-service/releases/download/latest/clash-verge-service.exe
"
;
const
binName
=
"
clash-verge-service.exe
"
;
const
repo
=
"
https://github.com/zzzgydi/clash-verge-service/releases/download/latest
"
;
const
resDir
=
path
.
join
(
cwd
,
"
src-tauri/resources
"
);
async
function
help
(
bin
)
{
const
targetPath
=
path
.
join
(
resDir
,
bin
Name
);
const
targetPath
=
path
.
join
(
resDir
,
bin
);
if
(
!
FORCE
&&
(
await
fs
.
pathExists
(
targetPath
)))
return
;
if
(
!
FORCE
&&
(
await
fs
.
pathExists
(
targetPath
)))
return
;
const
url
=
`
${
repo
}
/
${
bin
}
`
;
await
downloadFile
(
url
,
targetPath
);
}
await
fs
.
mkdirp
(
resDir
);
await
fs
.
mkdirp
(
resDir
);
await
downloadFile
(
url
,
targetPath
);
await
help
(
"
clash-verge-service.exe
"
);
await
help
(
"
install-service.exe
"
);
await
help
(
"
uninstall-service.exe
"
);
console
.
log
(
`[INFO]: resolve
${
binName
}
finished`
);
console
.
log
(
`[INFO]: resolve
Service
finished`
);
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
src-tauri/src/cmds.rs
+
6
−
6
View file @
f88989bd
...
@@ -258,20 +258,20 @@ pub mod service {
...
@@ -258,20 +258,20 @@ pub mod service {
#[tauri::command]
#[tauri::command]
pub
async
fn
check_service
()
->
Result
<
JsonResponse
,
String
>
{
pub
async
fn
check_service
()
->
Result
<
JsonResponse
,
String
>
{
wrap_err!
(
crate
::
core
::
Service
::
check_service
()
.await
)
// no log
match
crate
::
core
::
Service
::
check_service
()
.await
{
Ok
(
res
)
=>
Ok
(
res
),
Err
(
err
)
=>
Err
(
err
.to_string
()),
}
}
}
#[tauri::command]
#[tauri::command]
pub
async
fn
install_service
()
->
Result
<
(),
String
>
{
pub
async
fn
install_service
()
->
Result
<
(),
String
>
{
log_if_err!
(
crate
::
core
::
Service
::
install_service
()
.await
);
wrap_err!
(
crate
::
core
::
Service
::
install_service
()
.await
)
let
ret
=
wrap_err!
(
crate
::
core
::
Service
::
start_service
()
.await
);
log
::
info!
(
"clash verge service started successfully"
);
ret
}
}
#[tauri::command]
#[tauri::command]
pub
async
fn
uninstall_service
()
->
Result
<
(),
String
>
{
pub
async
fn
uninstall_service
()
->
Result
<
(),
String
>
{
log_if_err!
(
crate
::
core
::
Service
::
stop_service
()
.await
);
wrap_err!
(
crate
::
core
::
Service
::
uninstall_service
()
.await
)
wrap_err!
(
crate
::
core
::
Service
::
uninstall_service
()
.await
)
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src-tauri/src/core/service.rs
+
37
−
34
View file @
f88989bd
...
@@ -191,8 +191,9 @@ pub mod win_service {
...
@@ -191,8 +191,9 @@ pub mod win_service {
use
super
::
*
;
use
super
::
*
;
use
anyhow
::
Context
;
use
anyhow
::
Context
;
use
deelevate
::{
PrivilegeLevel
,
Token
};
use
deelevate
::{
PrivilegeLevel
,
Token
};
use
runas
::
Command
as
RunasCommond
;
use
runas
::
Command
as
RunasCommand
;
use
std
::{
env
::
current_exe
,
process
::
Command
as
StdCommond
};
use
std
::
os
::
windows
::
process
::
CommandExt
;
use
std
::{
env
::
current_exe
,
process
::
Command
as
StdCommand
};
const
SERVICE_NAME
:
&
str
=
"clash_verge_service"
;
const
SERVICE_NAME
:
&
str
=
"clash_verge_service"
;
...
@@ -217,61 +218,63 @@ pub mod win_service {
...
@@ -217,61 +218,63 @@ pub mod win_service {
/// 该函数应该在协程或者线程中执行,避免UAC弹窗阻塞主线程
/// 该函数应该在协程或者线程中执行,避免UAC弹窗阻塞主线程
pub
async
fn
install_service
()
->
Result
<
()
>
{
pub
async
fn
install_service
()
->
Result
<
()
>
{
let
binary_path
=
dirs
::
service_path
();
let
binary_path
=
dirs
::
service_path
();
let
arg
=
format!
(
"binpath={}"
,
binary_path
.as_os_str
()
.to_string_lossy
());
let
install_path
=
binary_path
.with_file_name
(
"install-service.exe"
);
if
!
install_path
.exists
()
{
bail!
(
"installer exe not found"
);
}
let
token
=
Token
::
with_current_process
()
?
;
let
token
=
Token
::
with_current_process
()
?
;
let
level
=
token
.privilege_level
()
?
;
let
level
=
token
.privilege_level
()
?
;
let
args
=
[
"create"
,
SERVICE_NAME
,
arg
.as_str
(),
"type=own"
,
"start=AUTO"
,
"displayname=Clash Verge Service"
,
];
let
status
=
match
level
{
let
status
=
match
level
{
PrivilegeLevel
::
NotPrivileged
=>
RunasCommond
::
new
(
"sc"
)
.args
(
&
args
)
.status
()
?
,
PrivilegeLevel
::
NotPrivileged
=>
RunasCommand
::
new
(
install_path
)
.status
()
?
,
_
=>
StdCommond
::
new
(
"sc"
)
.args
(
&
args
)
.status
()
?
,
_
=>
StdCommand
::
new
(
install_path
)
.creation_flags
(
0x08000000
)
.status
()
?
,
};
};
if
status
.success
()
{
if
!
status
.success
()
{
return
Ok
(());
bail!
(
}
"failed to install service with status {}"
,
status
.code
()
.unwrap
()
if
status
.code
()
==
Some
(
1073i32
)
{
);
bail!
(
"clash verge service is installed"
);
}
}
bail!
(
Ok
(())
"failed to install service with status {}"
,
status
.code
()
.unwrap
()
)
}
}
/// Uninstall the Clash Verge Service
/// Uninstall the Clash Verge Service
/// 该函数应该在协程或者线程中执行,避免UAC弹窗阻塞主线程
/// 该函数应该在协程或者线程中执行,避免UAC弹窗阻塞主线程
pub
async
fn
uninstall_service
()
->
Result
<
()
>
{
pub
async
fn
uninstall_service
()
->
Result
<
()
>
{
let
binary_path
=
dirs
::
service_path
();
let
uninstall_path
=
binary_path
.with_file_name
(
"uninstall-service.exe"
);
if
!
uninstall_path
.exists
()
{
bail!
(
"uninstaller exe not found"
);
}
let
token
=
Token
::
with_current_process
()
?
;
let
token
=
Token
::
with_current_process
()
?
;
let
level
=
token
.privilege_level
()
?
;
let
level
=
token
.privilege_level
()
?
;
let
args
=
[
"delete"
,
SERVICE_NAME
];
let
status
=
match
level
{
let
status
=
match
level
{
PrivilegeLevel
::
NotPrivileged
=>
RunasCommond
::
new
(
"sc"
)
.args
(
&
args
)
.status
()
?
,
PrivilegeLevel
::
NotPrivileged
=>
RunasCommand
::
new
(
uninstall_path
)
.status
()
?
,
_
=>
StdCommond
::
new
(
"sc"
)
.args
(
&
args
)
.status
()
?
,
_
=>
StdCommand
::
new
(
uninstall_path
)
.creation_flags
(
0x08000000
)
.status
()
?
,
};
};
match
status
.success
()
{
if
!
status
.success
()
{
true
=>
Ok
(()),
bail!
(
false
=>
bail!
(
"failed to uninstall service with status {}"
,
"failed to uninstall service with status {}"
,
status
.code
()
.unwrap
()
status
.code
()
.unwrap
()
)
,
)
;
}
}
Ok
(())
}
}
/// [deprecated]
/// start service
/// start service
/// 该函数应该在协程或者线程中执行,避免UAC弹窗阻塞主线程
/// 该函数应该在协程或者线程中执行,避免UAC弹窗阻塞主线程
pub
async
fn
start_service
()
->
Result
<
()
>
{
pub
async
fn
start_service
()
->
Result
<
()
>
{
...
@@ -281,8 +284,8 @@ pub mod win_service {
...
@@ -281,8 +284,8 @@ pub mod win_service {
let
args
=
[
"start"
,
SERVICE_NAME
];
let
args
=
[
"start"
,
SERVICE_NAME
];
let
status
=
match
level
{
let
status
=
match
level
{
PrivilegeLevel
::
NotPrivileged
=>
RunasComm
o
nd
::
new
(
"sc"
)
.args
(
&
args
)
.status
()
?
,
PrivilegeLevel
::
NotPrivileged
=>
RunasComm
a
nd
::
new
(
"sc"
)
.args
(
&
args
)
.status
()
?
,
_
=>
StdComm
o
nd
::
new
(
"sc"
)
.args
(
&
args
)
.status
()
?
,
_
=>
StdComm
a
nd
::
new
(
"sc"
)
.args
(
&
args
)
.status
()
?
,
};
};
match
status
.success
()
{
match
status
.success
()
{
...
...
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