fix: windows service mode
This commit is contained in:
parent
40c041031e
commit
1550d528bd
@ -79,15 +79,22 @@ impl CoreManager {
|
|||||||
pub async fn run_core(&self) -> Result<()> {
|
pub async fn run_core(&self) -> Result<()> {
|
||||||
let config_path = Config::generate_file(ConfigType::Run)?;
|
let config_path = Config::generate_file(ConfigType::Run)?;
|
||||||
|
|
||||||
let should_kill = match self.sidecar.lock().take() {
|
let mut should_kill = match self.sidecar.lock().take() {
|
||||||
Some(child) => {
|
Some(child) => {
|
||||||
log::debug!(target: "app", "stop the core sidecar");
|
log::debug!(target: "app", "stop the core by sidecar");
|
||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
None => false,
|
None => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
if *self.use_service_mode.lock() {
|
||||||
|
log::debug!(target: "app", "stop the core by service");
|
||||||
|
log_err!(super::win_service::stop_core_by_service().await);
|
||||||
|
should_kill = true;
|
||||||
|
}
|
||||||
|
|
||||||
// 这里得等一会儿
|
// 这里得等一会儿
|
||||||
if should_kill {
|
if should_kill {
|
||||||
sleep(Duration::from_millis(500)).await;
|
sleep(Duration::from_millis(500)).await;
|
||||||
@ -98,10 +105,8 @@ impl CoreManager {
|
|||||||
use super::win_service;
|
use super::win_service;
|
||||||
|
|
||||||
// 服务模式
|
// 服务模式
|
||||||
let enable = {
|
let enable = { Config::verge().latest().enable_service_mode.clone() };
|
||||||
let enable = Config::verge().data().enable_service_mode.clone();
|
let enable = enable.unwrap_or(false);
|
||||||
enable.unwrap_or(false)
|
|
||||||
};
|
|
||||||
|
|
||||||
*self.use_service_mode.lock() = enable;
|
*self.use_service_mode.lock() = enable;
|
||||||
|
|
||||||
@ -189,7 +194,7 @@ impl CoreManager {
|
|||||||
pub fn stop_core(&self) -> Result<()> {
|
pub fn stop_core(&self) -> Result<()> {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
if *self.use_service_mode.lock() {
|
if *self.use_service_mode.lock() {
|
||||||
log::debug!(target: "app", "stop core by service");
|
log::debug!(target: "app", "stop the core by service");
|
||||||
tauri::async_runtime::block_on(async move {
|
tauri::async_runtime::block_on(async move {
|
||||||
log_err!(super::win_service::stop_core_by_service().await);
|
log_err!(super::win_service::stop_core_by_service().await);
|
||||||
});
|
});
|
||||||
@ -198,6 +203,7 @@ impl CoreManager {
|
|||||||
|
|
||||||
let mut sidecar = self.sidecar.lock();
|
let mut sidecar = self.sidecar.lock();
|
||||||
if let Some(child) = sidecar.take() {
|
if let Some(child) = sidecar.take() {
|
||||||
|
log::debug!(target: "app", "stop the core by sidecar");
|
||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -44,7 +44,7 @@ pub async fn install_service() -> Result<()> {
|
|||||||
let level = token.privilege_level()?;
|
let level = token.privilege_level()?;
|
||||||
|
|
||||||
let status = match level {
|
let status = match level {
|
||||||
PrivilegeLevel::NotPrivileged => RunasCommand::new(install_path).status()?,
|
PrivilegeLevel::NotPrivileged => RunasCommand::new(install_path).show(false).status()?,
|
||||||
_ => StdCommand::new(install_path)
|
_ => StdCommand::new(install_path)
|
||||||
.creation_flags(0x08000000)
|
.creation_flags(0x08000000)
|
||||||
.status()?,
|
.status()?,
|
||||||
@ -74,7 +74,7 @@ pub async fn uninstall_service() -> Result<()> {
|
|||||||
let level = token.privilege_level()?;
|
let level = token.privilege_level()?;
|
||||||
|
|
||||||
let status = match level {
|
let status = match level {
|
||||||
PrivilegeLevel::NotPrivileged => RunasCommand::new(uninstall_path).status()?,
|
PrivilegeLevel::NotPrivileged => RunasCommand::new(uninstall_path).show(false).status()?,
|
||||||
_ => StdCommand::new(uninstall_path)
|
_ => StdCommand::new(uninstall_path)
|
||||||
.creation_flags(0x08000000)
|
.creation_flags(0x08000000)
|
||||||
.status()?,
|
.status()?,
|
||||||
|
@ -212,6 +212,8 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> {
|
|||||||
let service_mode = patch.enable_service_mode;
|
let service_mode = patch.enable_service_mode;
|
||||||
|
|
||||||
if service_mode.is_some() {
|
if service_mode.is_some() {
|
||||||
|
log::debug!(target: "app", "change service mode to {}", service_mode.unwrap());
|
||||||
|
|
||||||
Config::generate()?;
|
Config::generate()?;
|
||||||
CoreManager::global().run_core().await?;
|
CoreManager::global().run_core().await?;
|
||||||
} else if tun_mode.is_some() {
|
} else if tun_mode.is_some() {
|
||||||
|
@ -48,7 +48,7 @@ export const ServiceViewer = forwardRef<DialogRef, Props>((props, ref) => {
|
|||||||
|
|
||||||
const onUninstall = useLockFn(async () => {
|
const onUninstall = useLockFn(async () => {
|
||||||
try {
|
try {
|
||||||
if (state === "active" && enable) {
|
if (enable) {
|
||||||
await patchVergeConfig({ enable_service_mode: false });
|
await patchVergeConfig({ enable_service_mode: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user