feat: 项目基础框架搭建 - Phase 1 Issue #1
- 创建 Cargo.toml 依赖配置 - 实现配置管理模块 (config/) - 实现核心服务模块 (core/) - 文档处理引擎 - 翻译服务 - 实现基础设施模块 (infrastructure/) - 存储模块 - 实现 UI 模块 (ui/) - 集成 logging (tracing) 项目结构: ├── Cargo.toml ├── src/ │ ├── main.rs │ ├── config/mod.rs │ ├── core/ │ │ ├── mod.rs │ │ ├── document.rs │ │ └── translation.rs │ ├── infrastructure/ │ │ ├── mod.rs │ │ └── storage.rs │ └── ui/ │ └── mod.rs
This commit is contained in:
69
src/config/mod.rs
Normal file
69
src/config/mod.rs
Normal file
@@ -0,0 +1,69 @@
|
||||
//! 配置管理模块
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub theme: ThemeConfig,
|
||||
pub reader: ReaderConfig,
|
||||
pub translation: TranslationConfig,
|
||||
pub storage: StorageConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ThemeConfig {
|
||||
pub mode: String, // "light" or "dark"
|
||||
pub font_size: u32,
|
||||
pub font_family: String,
|
||||
pub line_height: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ReaderConfig {
|
||||
pub default_format: String,
|
||||
pub scroll_smooth: bool,
|
||||
pub show_toc: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct TranslationConfig {
|
||||
pub provider: String, // "google", "deepl", "ollama"
|
||||
pub api_key: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct StorageConfig {
|
||||
pub library_path: String,
|
||||
pub cache_path: String,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
theme: ThemeConfig {
|
||||
mode: "light".to_string(),
|
||||
font_size: 16,
|
||||
font_family: "system".to_string(),
|
||||
line_height: 1.5,
|
||||
},
|
||||
reader: ReaderConfig {
|
||||
default_format: "pdf".to_string(),
|
||||
scroll_smooth: true,
|
||||
show_toc: true,
|
||||
},
|
||||
translation: TranslationConfig {
|
||||
provider: "ollama".to_string(),
|
||||
api_key: None,
|
||||
},
|
||||
storage: StorageConfig {
|
||||
library_path: "./library".to_string(),
|
||||
cache_path: "./cache".to_string(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load() -> Config {
|
||||
// 后续从文件加载配置
|
||||
Config::default()
|
||||
}
|
||||
Reference in New Issue
Block a user