From 12e8bd2b923040b052fce253721d8c3e6d51ade4 Mon Sep 17 00:00:00 2001 From: fromost Date: Sun, 14 Dec 2025 21:34:34 +0800 Subject: [PATCH] Remove unused types --- src/config/mod.rs | 60 --------------------------------------------- src/config/types.rs | 19 -------------- 2 files changed, 79 deletions(-) delete mode 100755 src/config/mod.rs delete mode 100755 src/config/types.rs diff --git a/src/config/mod.rs b/src/config/mod.rs deleted file mode 100755 index 7b623ca..0000000 --- a/src/config/mod.rs +++ /dev/null @@ -1,60 +0,0 @@ -use crate::config::types::{ApplicationConfig, BasicConfig, PathConfig}; -use crate::constants::{APP_CONIFG_FILE_PATH, CACHE_MAP}; -use color_eyre::Result; -use std::path::PathBuf; -use language_tags::LanguageTag; -use ratatui::widgets::ListState; -use serde::Deserialize; -use serde_json; - -pub mod types; - -const CONFIG_KEY: &str = "app_conf"; - -impl ApplicationConfig { - pub fn get_config() -> Result { - if CACHE_MAP.contains_key(CONFIG_KEY) && - let Some(cached_config) = CACHE_MAP.get(CONFIG_KEY) - { - Ok(serde_json::from_value(cached_config.clone())?) - } else if APP_CONIFG_FILE_PATH.exists() { - ApplicationConfig::from_file(&APP_CONIFG_FILE_PATH) - } else { - ApplicationConfig::new() - } - } - - fn from_file(path: &PathBuf) -> Result { - let reader = std::fs::File::open(path)?; - let result: serde_json::Value = serde_json::from_reader(reader)?; - CACHE_MAP.insert(CONFIG_KEY.to_string(), result.clone()); - Ok(serde_json::from_value(result)?) - } - - fn new() -> Result { - let default_locale = sys_locale::get_locale().unwrap_or(String::from("ja-JP")); - let conf = Self { - basic_config: BasicConfig { - tick_rate: 250, - locale: LanguageTag::parse(&default_locale)?, - }, - path_config: PathConfig { - dlsite_paths: vec![], - }, - }; - conf.clone().write_to_file(APP_CONIFG_FILE_PATH.to_path_buf())?; - Ok(conf) - } - - fn write_to_file(self, path: PathBuf) -> Result<()> { - let writer = std::fs::File::create(path)?; - serde_json::to_writer_pretty(writer, &self)?; - Ok(()) - } - - pub fn save(self) -> Result<()> { - let current_value = serde_json::to_value(&self)?; - CACHE_MAP.alter(CONFIG_KEY, |_, _| current_value); - self.write_to_file(APP_CONIFG_FILE_PATH.to_path_buf()) - } -} diff --git a/src/config/types.rs b/src/config/types.rs deleted file mode 100755 index 8f20552..0000000 --- a/src/config/types.rs +++ /dev/null @@ -1,19 +0,0 @@ -use language_tags::LanguageTag; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct ApplicationConfig { - pub basic_config: BasicConfig, - pub path_config: PathConfig, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub(crate) struct BasicConfig { - pub locale: LanguageTag, - pub tick_rate: u64, -} - -#[derive(Clone, Debug, Serialize, Deserialize)] -pub struct PathConfig { - pub dlsite_paths: Vec -} \ No newline at end of file