feat: windows service mode ui

This commit is contained in:
GyDi
2022-04-25 16:12:04 +08:00
committed by GitHub
parent 2d0b63c29d
commit 6b368953f4
8 changed files with 234 additions and 14 deletions

View File

@@ -251,6 +251,11 @@ pub mod service {
wrap_err!(crate::core::Service::start_service().await)
}
#[tauri::command]
pub async fn stop_service() -> Result<(), String> {
wrap_err!(crate::core::Service::stop_service().await)
}
#[tauri::command]
pub async fn check_service() -> Result<JsonResponse, String> {
wrap_err!(crate::core::Service::check_service().await)
@@ -258,11 +263,13 @@ pub mod service {
#[tauri::command]
pub async fn install_service() -> Result<(), String> {
wrap_err!(crate::core::Service::install_service().await)
wrap_err!(crate::core::Service::install_service().await)?;
wrap_err!(crate::core::Service::start_service().await)
}
#[tauri::command]
pub async fn uninstall_service() -> Result<(), String> {
log_if_err!(crate::core::Service::stop_service().await);
wrap_err!(crate::core::Service::uninstall_service().await)
}
}
@@ -276,6 +283,11 @@ pub mod service {
Ok(())
}
#[tauri::command]
pub async fn stop_service() -> Result<(), String> {
Ok(())
}
#[tauri::command]
pub async fn check_service() -> Result<(), String> {
Ok(())

View File

@@ -294,15 +294,32 @@ pub mod win_service {
}
}
/// stop service
pub async fn stop_service() -> Result<()> {
let url = format!("{SERVICE_URL}/stop_service");
let res = reqwest::Client::new()
.post(url)
.send()
.await?
.json::<JsonResponse>()
.await
.context("failed to connect to the Clash Verge Service")?;
if res.code != 0 {
bail!(res.msg);
}
Ok(())
}
/// check the windows service status
pub async fn check_service() -> Result<JsonResponse> {
let url = format!("{SERVICE_URL}/get_clash");
let response = reqwest::get(url)
.await
.context("failed to connect to the Clash Verge Service")?
.await?
.json::<JsonResponse>()
.await
.context("failed to parse the Clash Verge Service response")?;
.context("failed to connect to the Clash Verge Service")?;
Ok(response)
}
@@ -335,11 +352,10 @@ pub mod win_service {
.post(url)
.json(&map)
.send()
.await
.context("failed to connect to the Clash Verge Service")?
.await?
.json::<JsonResponse>()
.await
.context("failed to parse the Clash Verge Service response")?;
.context("failed to connect to the Clash Verge Service")?;
if res.code != 0 {
bail!(res.msg);
@@ -354,11 +370,10 @@ pub mod win_service {
let res = reqwest::Client::new()
.post(url)
.send()
.await
.context("failed to connect to the Clash Verge Service")?
.await?
.json::<JsonResponse>()
.await
.context("failed to parse the Clash Verge Service response")?;
.context("failed to connect to the Clash Verge Service")?;
if res.code != 0 {
bail!(res.msg);

View File

@@ -129,6 +129,7 @@ fn main() -> std::io::Result<()> {
cmds::save_profile_file,
// service mode
cmds::service::start_service,
cmds::service::stop_service,
cmds::service::check_service,
cmds::service::install_service,
cmds::service::uninstall_service,