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
31c6cbc0
There was an error fetching the commit references. Please try again later.
Unverified
Commit
31c6cbc0
authored
2 years ago
by
GyDi
Browse files
Options
Downloads
Patches
Plain Diff
fix: service mode error
parent
b93284bc
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src-tauri/src/core/service.rs
+14
-4
14 additions, 4 deletions
src-tauri/src/core/service.rs
src/components/setting/service-mode.tsx
+117
-104
117 additions, 104 deletions
src/components/setting/service-mode.tsx
with
131 additions
and
108 deletions
src-tauri/src/core/service.rs
+
14
−
4
View file @
31c6cbc0
...
...
@@ -300,7 +300,9 @@ pub mod win_service {
/// stop service
pub
async
fn
stop_service
()
->
Result
<
()
>
{
let
url
=
format!
(
"{SERVICE_URL}/stop_service"
);
let
res
=
reqwest
::
Client
::
new
()
let
res
=
reqwest
::
ClientBuilder
::
new
()
.no_proxy
()
.build
()
?
.post
(
url
)
.send
()
.await
?
...
...
@@ -318,7 +320,11 @@ pub mod win_service {
/// check the windows service status
pub
async
fn
check_service
()
->
Result
<
JsonResponse
>
{
let
url
=
format!
(
"{SERVICE_URL}/get_clash"
);
let
response
=
reqwest
::
get
(
url
)
let
response
=
reqwest
::
ClientBuilder
::
new
()
.no_proxy
()
.build
()
?
.get
(
url
)
.send
()
.await
?
.json
::
<
JsonResponse
>
()
.await
...
...
@@ -351,7 +357,9 @@ pub mod win_service {
map
.insert
(
"log_file"
,
log_path
);
let
url
=
format!
(
"{SERVICE_URL}/start_clash"
);
let
res
=
reqwest
::
Client
::
new
()
let
res
=
reqwest
::
ClientBuilder
::
new
()
.no_proxy
()
.build
()
?
.post
(
url
)
.json
(
&
map
)
.send
()
...
...
@@ -370,7 +378,9 @@ pub mod win_service {
/// stop the clash by service
pub
(
super
)
async
fn
stop_clash_by_service
()
->
Result
<
()
>
{
let
url
=
format!
(
"{SERVICE_URL}/stop_clash"
);
let
res
=
reqwest
::
Client
::
new
()
let
res
=
reqwest
::
ClientBuilder
::
new
()
.no_proxy
()
.build
()
?
.post
(
url
)
.send
()
.await
?
...
...
This diff is collapsed.
Click to expand it.
src/components/setting/service-mode.tsx
+
117
−
104
View file @
31c6cbc0
import
useSWR
,
{
useSWRConfig
}
from
"
swr
"
;
import
{
useLockFn
}
from
"
ahooks
"
;
import
{
useTranslation
}
from
"
react-i18next
"
;
import
{
Button
,
Dialog
,
DialogContent
,
DialogTitle
,
Stack
,
Typography
,
}
from
"
@mui/material
"
;
import
{
checkService
,
installService
,
uninstallService
,
patchVergeConfig
,
}
from
"
../../services/cmds
"
;
import
Notice
from
"
../base/base-notice
"
;
import
noop
from
"
../../utils/noop
"
;
interface
Props
{
open
:
boolean
;
enable
:
boolean
;
onClose
:
()
=>
void
;
onError
?:
(
err
:
Error
)
=>
void
;
}
const
ServiceMode
=
(
props
:
Props
)
=>
{
const
{
open
,
enable
,
onClose
,
onError
=
noop
}
=
props
;
const
{
t
}
=
useTranslation
();
const
{
mutate
}
=
useSWRConfig
();
const
{
data
:
status
}
=
useSWR
(
"
checkService
"
,
checkService
,
{
revalidateIfStale
:
true
,
shouldRetryOnError
:
false
,
});
const
state
=
status
!=
null
?
status
:
"
pending
"
;
const
onInstall
=
useLockFn
(
async
()
=>
{
try
{
await
installService
();
mutate
(
"
checkService
"
);
onClose
();
Notice
.
success
(
"
Service installed successfully
"
);
}
catch
(
err
:
any
)
{
mutate
(
"
checkService
"
);
onError
(
err
);
}
});
const
onUninstall
=
useLockFn
(
async
()
=>
{
try
{
if
(
state
===
"
active
"
&&
enable
)
{
await
patchVergeConfig
({
enable_service_mode
:
false
});
}
await
uninstallService
();
mutate
(
"
checkService
"
);
onClose
();
Notice
.
success
(
"
Service uninstalled successfully
"
);
}
catch
(
err
:
any
)
{
mutate
(
"
checkService
"
);
onError
(
err
);
}
});
return
(
<
Dialog
open
=
{
open
}
onClose
=
{
onClose
}
>
<
DialogTitle
>
{
t
(
"
Service Mode
"
)
}
</
DialogTitle
>
<
DialogContent
sx
=
{
{
width
:
360
,
userSelect
:
"
text
"
}
}
>
<
Typography
>
Current State:
{
state
}
</
Typography
>
{
(
state
===
"
unknown
"
||
state
===
"
uninstall
"
)
&&
(
<
Typography
>
Infomation: Please make sure the Clash Verge Service is installed
and enabled
</
Typography
>
)
}
<
Stack
direction
=
"row"
spacing
=
{
1
}
sx
=
{
{
mt
:
4
,
justifyContent
:
"
flex-end
"
}
}
>
{
state
===
"
uninstall
"
&&
(
<
Button
variant
=
"contained"
onClick
=
{
onInstall
}
>
Install
</
Button
>
)
}
{
(
state
===
"
active
"
||
state
===
"
installed
"
)
&&
(
<
Button
variant
=
"outlined"
onClick
=
{
onUninstall
}
>
Uninstall
</
Button
>
)
}
</
Stack
>
</
DialogContent
>
</
Dialog
>
);
};
export
default
ServiceMode
;
import
useSWR
,
{
useSWRConfig
}
from
"
swr
"
;
import
{
useLockFn
}
from
"
ahooks
"
;
import
{
useTranslation
}
from
"
react-i18next
"
;
import
{
Button
,
Dialog
,
DialogContent
,
DialogTitle
,
Stack
,
Typography
,
}
from
"
@mui/material
"
;
import
{
checkService
,
installService
,
uninstallService
,
patchVergeConfig
,
}
from
"
../../services/cmds
"
;
import
Notice
from
"
../base/base-notice
"
;
import
noop
from
"
../../utils/noop
"
;
interface
Props
{
open
:
boolean
;
enable
:
boolean
;
onClose
:
()
=>
void
;
onError
?:
(
err
:
Error
)
=>
void
;
}
const
ServiceMode
=
(
props
:
Props
)
=>
{
const
{
open
,
enable
,
onClose
,
onError
=
noop
}
=
props
;
const
{
t
}
=
useTranslation
();
const
{
mutate
}
=
useSWRConfig
();
const
{
data
:
status
}
=
useSWR
(
"
checkService
"
,
checkService
,
{
revalidateIfStale
:
true
,
shouldRetryOnError
:
false
,
});
const
state
=
status
!=
null
?
status
:
"
pending
"
;
const
onInstall
=
useLockFn
(
async
()
=>
{
try
{
await
installService
();
mutate
(
"
checkService
"
);
onClose
();
Notice
.
success
(
"
Service installed successfully
"
);
}
catch
(
err
:
any
)
{
mutate
(
"
checkService
"
);
onError
(
err
);
}
});
const
onUninstall
=
useLockFn
(
async
()
=>
{
try
{
if
(
state
===
"
active
"
&&
enable
)
{
await
patchVergeConfig
({
enable_service_mode
:
false
});
}
await
uninstallService
();
mutate
(
"
checkService
"
);
onClose
();
Notice
.
success
(
"
Service uninstalled successfully
"
);
}
catch
(
err
:
any
)
{
mutate
(
"
checkService
"
);
onError
(
err
);
}
});
// fix unhandle error of the service mode
const
onDisable
=
useLockFn
(
async
()
=>
{
await
patchVergeConfig
({
enable_service_mode
:
false
});
mutate
(
"
checkService
"
);
onClose
();
});
return
(
<
Dialog
open
=
{
open
}
onClose
=
{
onClose
}
>
<
DialogTitle
>
{
t
(
"
Service Mode
"
)
}
</
DialogTitle
>
<
DialogContent
sx
=
{
{
width
:
360
,
userSelect
:
"
text
"
}
}
>
<
Typography
>
Current State:
{
state
}
</
Typography
>
{
(
state
===
"
unknown
"
||
state
===
"
uninstall
"
)
&&
(
<
Typography
>
Infomation: Please make sure the Clash Verge Service is installed
and enabled
</
Typography
>
)
}
<
Stack
direction
=
"row"
spacing
=
{
1
}
sx
=
{
{
mt
:
4
,
justifyContent
:
"
flex-end
"
}
}
>
{
state
===
"
uninstall
"
&&
enable
&&
(
<
Button
variant
=
"contained"
onClick
=
{
onDisable
}
>
Disable Service Mode
</
Button
>
)
}
{
state
===
"
uninstall
"
&&
(
<
Button
variant
=
"contained"
onClick
=
{
onInstall
}
>
Install
</
Button
>
)
}
{
(
state
===
"
active
"
||
state
===
"
installed
"
)
&&
(
<
Button
variant
=
"outlined"
onClick
=
{
onUninstall
}
>
Uninstall
</
Button
>
)
}
</
Stack
>
</
DialogContent
>
</
Dialog
>
);
};
export
default
ServiceMode
;
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