mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
fix: improve Service connection method and permissions for Windows and Unix
This commit is contained in:
@@ -144,21 +144,6 @@ pub fn service_path() -> Result<PathBuf> {
|
||||
Ok(res_dir.join("clash-verge-service.exe"))
|
||||
}
|
||||
|
||||
// TODO 迁移 Service日志后删除
|
||||
pub fn service_log_file() -> Result<PathBuf> {
|
||||
use chrono::Local;
|
||||
|
||||
let log_dir = app_logs_dir()?.join("service");
|
||||
|
||||
let local_time = Local::now().format("%Y-%m-%d-%H%M").to_string();
|
||||
let log_file = format!("{local_time}.log");
|
||||
let log_file = log_dir.join(log_file);
|
||||
|
||||
let _ = std::fs::create_dir_all(&log_dir);
|
||||
|
||||
Ok(log_file)
|
||||
}
|
||||
|
||||
pub fn sidecar_log_dir() -> Result<PathBuf> {
|
||||
let log_dir = app_logs_dir()?.join("sidecar");
|
||||
let _ = std::fs::create_dir_all(&log_dir);
|
||||
@@ -207,7 +192,7 @@ pub fn get_encryption_key() -> Result<Vec<u8>> {
|
||||
|
||||
#[cfg(unix)]
|
||||
pub fn ensure_mihomo_safe_dir() -> Option<PathBuf> {
|
||||
["/var/tmp", "/tmp"]
|
||||
["/tmp"]
|
||||
.iter()
|
||||
.map(PathBuf::from)
|
||||
.find(|path| path.exists())
|
||||
|
||||
@@ -93,8 +93,6 @@ pub async fn sidecar_writer() -> Result<FileLogWriter> {
|
||||
.try_build()?)
|
||||
}
|
||||
|
||||
// TODO 后续迁移新 service 时使用
|
||||
#[allow(dead_code)]
|
||||
pub async fn service_writer_config() -> Result<WriterConfig> {
|
||||
let (log_max_size, log_max_count) = {
|
||||
let verge_guard = Config::verge().await;
|
||||
|
||||
@@ -3,7 +3,11 @@ use anyhow::Result;
|
||||
use crate::{
|
||||
config::Config,
|
||||
core::{
|
||||
CoreManager, Timer, handle, hotkey::Hotkey, service::SERVICE_MANAGER, sysopt, tray::Tray,
|
||||
CoreManager, Timer, handle,
|
||||
hotkey::Hotkey,
|
||||
service::{SERVICE_MANAGER, ServiceManager, is_service_ipc_path_exists},
|
||||
sysopt,
|
||||
tray::Tray,
|
||||
},
|
||||
logging, logging_error,
|
||||
module::lightweight::{auto_lightweight_mode_init, run_once_auto_lightweight},
|
||||
@@ -46,7 +50,7 @@ pub fn resolve_setup_async() {
|
||||
"Version: {}",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
);
|
||||
init_service_manager().await;
|
||||
futures::join!(init_service_manager());
|
||||
|
||||
futures::join!(
|
||||
init_work_config(),
|
||||
@@ -189,7 +193,18 @@ pub(super) async fn init_verge_config() {
|
||||
|
||||
pub(super) async fn init_service_manager() {
|
||||
logging!(info, Type::Setup, "Initializing service manager...");
|
||||
logging_error!(Type::Setup, SERVICE_MANAGER.lock().await.refresh().await);
|
||||
clash_verge_service_ipc::set_config(ServiceManager::config()).await;
|
||||
if !is_service_ipc_path_exists() {
|
||||
logging!(
|
||||
warn,
|
||||
Type::Setup,
|
||||
"Service IPC path does not exist, service may be unavailable"
|
||||
);
|
||||
return;
|
||||
}
|
||||
if SERVICE_MANAGER.lock().await.init().await.is_ok() {
|
||||
logging_error!(Type::Setup, SERVICE_MANAGER.lock().await.refresh().await);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn init_core_manager() {
|
||||
|
||||
Reference in New Issue
Block a user