mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 01:23:43 +08:00
feat: add error prompt for loading initial config file
This commit is contained in:
parent
d54a765bd6
commit
a9cccc7b97
@ -14,8 +14,9 @@
|
|||||||
- Linux 在系统服务模式下无法拉起 Mihomo 内核
|
- Linux 在系统服务模式下无法拉起 Mihomo 内核
|
||||||
|
|
||||||
#### 新增了:
|
#### 新增了:
|
||||||
- ClashVergeRev 从现在开始不再强依赖系统服务和管理权限
|
- Clash Verge Rev 从现在开始不再强依赖系统服务和管理权限
|
||||||
- 支持根据用户偏好选择Sidecar(用户空间)模式或安装服务
|
- 支持根据用户偏好选择Sidecar(用户空间)模式或安装服务
|
||||||
|
- 增加载入初始配置文件的错误提示
|
||||||
|
|
||||||
#### 优化了:
|
#### 优化了:
|
||||||
- 重构了后端内核管理逻辑,更轻量化和有效的管理内核,提高了性能和稳定性
|
- 重构了后端内核管理逻辑,更轻量化和有效的管理内核,提高了性能和稳定性
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
use super::{prfitem::PrfItem, PrfOption};
|
use super::{prfitem::PrfItem, PrfOption};
|
||||||
use crate::utils::{dirs, help};
|
use crate::utils::{dirs, help};
|
||||||
|
use crate::{logging, utils::logging::Type};
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_yaml::Mapping;
|
use serde_yaml::Mapping;
|
||||||
|
use serde_yaml::Value;
|
||||||
use std::{fs, io::Write};
|
use std::{fs, io::Write};
|
||||||
|
|
||||||
/// Define the `profiles.yaml` schema
|
/// Define the `profiles.yaml` schema
|
||||||
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct IProfiles {
|
pub struct IProfiles {
|
||||||
@ -382,16 +383,92 @@ impl IProfiles {
|
|||||||
pub fn current_mapping(&self) -> Result<Mapping> {
|
pub fn current_mapping(&self) -> Result<Mapping> {
|
||||||
match (self.current.as_ref(), self.items.as_ref()) {
|
match (self.current.as_ref(), self.items.as_ref()) {
|
||||||
(Some(current), Some(items)) => {
|
(Some(current), Some(items)) => {
|
||||||
|
logging!(
|
||||||
|
info,
|
||||||
|
Type::Config,
|
||||||
|
true,
|
||||||
|
"开始获取当前配置文件 current_uid={}",
|
||||||
|
current
|
||||||
|
);
|
||||||
|
logging!(info, Type::Core, true, "服务可用,直接使用服务模式");
|
||||||
if let Some(item) = items.iter().find(|e| e.uid.as_ref() == Some(current)) {
|
if let Some(item) = items.iter().find(|e| e.uid.as_ref() == Some(current)) {
|
||||||
let file_path = match item.file.as_ref() {
|
let file_path = match item.file.as_ref() {
|
||||||
Some(file) => dirs::app_profiles_dir()?.join(file),
|
Some(file) => {
|
||||||
None => bail!("failed to get the file field"),
|
let path = dirs::app_profiles_dir()?.join(file);
|
||||||
|
logging!(
|
||||||
|
info,
|
||||||
|
Type::Config,
|
||||||
|
true,
|
||||||
|
"找到配置文件路径: {}",
|
||||||
|
path.display()
|
||||||
|
);
|
||||||
|
path
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
logging!(
|
||||||
|
error,
|
||||||
|
Type::Config,
|
||||||
|
true,
|
||||||
|
"配置项缺少file字段 uid={}",
|
||||||
|
current
|
||||||
|
);
|
||||||
|
bail!("failed to get the file field");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return help::read_mapping(&file_path);
|
if !file_path.exists() {
|
||||||
|
logging!(
|
||||||
|
error,
|
||||||
|
Type::Config,
|
||||||
|
true,
|
||||||
|
"配置文件不存在: {}",
|
||||||
|
file_path.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
match help::read_mapping(&file_path) {
|
||||||
|
Ok(mapping) => {
|
||||||
|
let key_count = mapping.len();
|
||||||
|
logging!(
|
||||||
|
info,
|
||||||
|
Type::Config,
|
||||||
|
true,
|
||||||
|
"成功读取配置文件, 包含{}个键值对",
|
||||||
|
key_count
|
||||||
|
);
|
||||||
|
// 打印主要的配置键
|
||||||
|
let important_keys = ["proxies", "proxy-groups", "rules"];
|
||||||
|
for key in important_keys.iter() {
|
||||||
|
if mapping.contains_key(&Value::from(*key)) {
|
||||||
|
logging!(info, Type::Config, true, "配置包含关键字段: {}", key);
|
||||||
|
} else {
|
||||||
|
logging!(warn, Type::Config, true, "配置缺少关键字段: {}", key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Ok(mapping);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
logging!(error, Type::Config, true, "读取配置文件失败: {}", e);
|
||||||
|
// 将错误发送到前端显示
|
||||||
|
crate::core::handle::Handle::notice_message(
|
||||||
|
"config_validate::yaml_syntax_error",
|
||||||
|
&format!("{}", e),
|
||||||
|
);
|
||||||
|
return Err(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
logging!(
|
||||||
|
error,
|
||||||
|
Type::Config,
|
||||||
|
true,
|
||||||
|
"未找到当前配置项 uid={}",
|
||||||
|
current
|
||||||
|
);
|
||||||
bail!("failed to find the current profile \"uid:{current}\"");
|
bail!("failed to find the current profile \"uid:{current}\"");
|
||||||
}
|
}
|
||||||
_ => Ok(Mapping::new()),
|
_ => {
|
||||||
|
logging!(warn, Type::Config, true, "没有当前配置项,返回空配置");
|
||||||
|
Ok(Mapping::new())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,13 +13,13 @@ use crate::{
|
|||||||
const LIGHT_WEIGHT_TASK_UID: &str = "light_weight_task";
|
const LIGHT_WEIGHT_TASK_UID: &str = "light_weight_task";
|
||||||
|
|
||||||
pub fn enable_auto_light_weight_mode() {
|
pub fn enable_auto_light_weight_mode() {
|
||||||
logging!(info, Type::Lightweight, True, "开启自动轻量模式");
|
logging!(info, Type::Lightweight, true, "开启自动轻量模式");
|
||||||
setup_window_close_listener();
|
setup_window_close_listener();
|
||||||
setup_webview_focus_listener();
|
setup_webview_focus_listener();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn disable_auto_light_weight_mode() {
|
pub fn disable_auto_light_weight_mode() {
|
||||||
logging!(info, Type::Lightweight, True, "关闭自动轻量模式");
|
logging!(info, Type::Lightweight, true, "关闭自动轻量模式");
|
||||||
let _ = cancel_light_weight_timer();
|
let _ = cancel_light_weight_timer();
|
||||||
cancel_window_close_listener();
|
cancel_window_close_listener();
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ pub fn entry_lightweight_mode() {
|
|||||||
}
|
}
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
AppHandleManager::global().set_activation_policy_accessory();
|
AppHandleManager::global().set_activation_policy_accessory();
|
||||||
logging!(info, Type::Lightweight, True, "轻量模式已开启");
|
logging!(info, Type::Lightweight, true, "轻量模式已开启");
|
||||||
}
|
}
|
||||||
let _ = cancel_light_weight_timer();
|
let _ = cancel_light_weight_timer();
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ fn setup_window_close_listener() -> u32 {
|
|||||||
logging!(
|
logging!(
|
||||||
info,
|
info,
|
||||||
Type::Lightweight,
|
Type::Lightweight,
|
||||||
True,
|
true,
|
||||||
"监听到关闭请求,开始轻量模式计时"
|
"监听到关闭请求,开始轻量模式计时"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -62,7 +62,7 @@ fn setup_webview_focus_listener() -> u32 {
|
|||||||
logging!(
|
logging!(
|
||||||
info,
|
info,
|
||||||
Type::Lightweight,
|
Type::Lightweight,
|
||||||
True,
|
true,
|
||||||
"监听到窗口获得焦点,取消轻量模式计时"
|
"监听到窗口获得焦点,取消轻量模式计时"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -74,7 +74,7 @@ fn setup_webview_focus_listener() -> u32 {
|
|||||||
fn cancel_window_close_listener() {
|
fn cancel_window_close_listener() {
|
||||||
if let Some(window) = handle::Handle::global().get_window() {
|
if let Some(window) = handle::Handle::global().get_window() {
|
||||||
window.unlisten(setup_window_close_listener());
|
window.unlisten(setup_window_close_listener());
|
||||||
logging!(info, Type::Lightweight, True, "取消了窗口关闭监听");
|
logging!(info, Type::Lightweight, true, "取消了窗口关闭监听");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ fn setup_light_weight_timer() -> Result<()> {
|
|||||||
.set_maximum_parallel_runnable_num(1)
|
.set_maximum_parallel_runnable_num(1)
|
||||||
.set_frequency_once_by_minutes(once_by_minutes)
|
.set_frequency_once_by_minutes(once_by_minutes)
|
||||||
.spawn_async_routine(move || async move {
|
.spawn_async_routine(move || async move {
|
||||||
logging!(info, Type::Timer, True, "计时器到期,开始进入轻量模式");
|
logging!(info, Type::Timer, true, "计时器到期,开始进入轻量模式");
|
||||||
entry_lightweight_mode();
|
entry_lightweight_mode();
|
||||||
})
|
})
|
||||||
.context("failed to create timer task")?;
|
.context("failed to create timer task")?;
|
||||||
@ -118,7 +118,7 @@ fn setup_light_weight_timer() -> Result<()> {
|
|||||||
logging!(
|
logging!(
|
||||||
info,
|
info,
|
||||||
Type::Timer,
|
Type::Timer,
|
||||||
True,
|
true,
|
||||||
"计时器已设置,{} 分钟后将自动进入轻量模式",
|
"计时器已设置,{} 分钟后将自动进入轻量模式",
|
||||||
once_by_minutes
|
once_by_minutes
|
||||||
);
|
);
|
||||||
@ -134,7 +134,7 @@ fn cancel_light_weight_timer() -> Result<()> {
|
|||||||
delay_timer
|
delay_timer
|
||||||
.remove_task(task.task_id)
|
.remove_task(task.task_id)
|
||||||
.context("failed to remove timer task")?;
|
.context("failed to remove timer task")?;
|
||||||
logging!(info, Type::Timer, True, "计时器已取消");
|
logging!(info, Type::Timer, true, "计时器已取消");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user