Skip to content

Commit

Permalink
Merge pull request #31 from TC999/wake
Browse files Browse the repository at this point in the history
yaml函数移位
  • Loading branch information
TC999 authored Jan 5, 2025
2 parents 04f467f + 5d1e3b9 commit 6f3cf85
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ Cargo.lock
*.log
adcignore.txt
/rules

# yaml 规则文件
*.yaml
15 changes: 3 additions & 12 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::move_module; // 导入移动模块
use crate::open;
use crate::scanner;
use crate::utils;
use crate::yaml_loader::FolderDescriptions;
use crate::yaml_loader::{FolderDescriptions, load_folder_descriptions};
use eframe::egui::{self, Grid, ScrollArea};
use std::collections::HashSet;
use std::sync::mpsc::{Receiver, Sender};
Expand Down Expand Up @@ -80,16 +80,7 @@ impl eframe::App for AppDataCleaner {

// 加载描述文件
if self.folder_descriptions.is_none() {
match FolderDescriptions::load_from_yaml("folders_description.yaml") {
Ok(descriptions) => self.folder_descriptions = Some(descriptions),
Err(e) => {
if !self.yaml_error_logged {
eprintln!("加载 YAML 文件失败: {}", e);
logger::log_error(&format!("加载 YAML 文件失败: {}", e));
self.yaml_error_logged = true; // 记录错误,避免重复输出
}
}
}
self.folder_descriptions = load_folder_descriptions("folders_description.yaml", &mut self.yaml_error_logged);
}

if self.is_logging_enabled != self.previous_logging_state {
Expand Down Expand Up @@ -248,4 +239,4 @@ impl eframe::App for AppDataCleaner {
// 显示移动窗口
self.move_module.show_move_window(ctx);
}
}
}
15 changes: 15 additions & 0 deletions src/yaml_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,18 @@ impl FolderDescriptions {
}
}
}

// 新增函数,用于加载文件夹描述
pub fn load_folder_descriptions(file_path: &str, yaml_error_logged: &mut bool) -> Option<FolderDescriptions> {
match FolderDescriptions::load_from_yaml(file_path) {
Ok(descriptions) => Some(descriptions),
Err(e) => {
if !*yaml_error_logged {
eprintln!("加载 YAML 文件失败: {}", e);
crate::logger::log_error(&format!("加载 YAML 文件失败: {}", e));
*yaml_error_logged = true; // 记录错误,避免重复输出
}
None
}
}
}

0 comments on commit 6f3cf85

Please sign in to comment.