Skip to content

Commit

Permalink
feat: windows环境强制使用sc
Browse files Browse the repository at this point in the history
  • Loading branch information
SerenitySir committed Jul 26, 2024
1 parent fdd1745 commit a4bfc31
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/util/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;
use std::ffi::OsString;
use std::path::PathBuf;
use log::{error, info};
use service_manager::{ServiceInstallCtx, ServiceLabel, ServiceManager, ServiceStartCtx, ServiceStopCtx, ServiceUninstallCtx};
use service_manager::{ScServiceManager, ServiceInstallCtx, ServiceLabel, ServiceManager, ServiceStartCtx, ServiceStopCtx, ServiceUninstallCtx};

/// 系统服务
pub struct Service {
Expand All @@ -26,11 +26,17 @@ impl Service {
/// let service = Service::new("nal");
/// ```
pub fn new(name: &str) -> anyhow::Result<Self> {
let service_manager = if cfg!(windows) {
Box::new(ScServiceManager::system())
} else {
<dyn ServiceManager>::native()?
};

Ok(Self {
name: name.parse()?,
path: env::current_exe()?,
// 通过检测平台上可用的内容来获得通用服务
service_manage: <dyn ServiceManager>::native()?,
service_manage: service_manager,
})
}

Expand Down

0 comments on commit a4bfc31

Please sign in to comment.