Skip to content

Commit

Permalink
Begin to cache get_config so we can implement debugging feature
Browse files Browse the repository at this point in the history
  • Loading branch information
callmeclover committed May 28, 2024
1 parent b201b67 commit a76cb8e
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 6 deletions.
179 changes: 179 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ rsautogui = "0.2.2"
reqwest = { version = "0.12.3", features = ["blocking"] }
cgisf_lib = "0.2.1"
ping = "0.5.2"
tracing = "0.1.40"
cached = { version = "0.51.3", features = ["async"] }

[dependencies.windows]
version = "0.56.0"
Expand Down
14 changes: 9 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
use dialoguer::{theme::ColorfulTheme, Confirm};
use std::{fs, path::Path};
use toml::{de::Error, from_str, to_string_pretty};

#[derive(Debug, serde::Serialize, serde::Deserialize, Default)]
use cached::{proc_macro::cached, SizedCache};
#[derive(Debug, serde::Serialize, serde::Deserialize, Default, Clone, Eq, Hash, PartialEq)]
pub struct Config {
#[allow(dead_code)] // Disable dead code warning for the entire struct
basic: Basic,
#[allow(dead_code)] // Disable dead code warning for the entire struct
extra: Extra,
}

#[derive(Debug, serde::Serialize, serde::Deserialize)]
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, PartialEq, Eq, Hash)]
struct Basic {
#[allow(dead_code)]
use_mouse: bool,
Expand All @@ -29,7 +29,7 @@ struct Basic {
do_gen_tts: bool,
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Default)]
#[derive(Debug, serde::Serialize, serde::Deserialize, Default, Clone, Hash, PartialEq, Eq)]
struct Extra {
#[allow(dead_code)]
do_debugging: bool,
Expand Down Expand Up @@ -62,7 +62,11 @@ impl Default for Basic {
}
}

pub async fn get_config() -> Config {
#[cached(
ty = "SizedCache<String, Config>",
create = "{ SizedCache::with_size(1) }",
)]
pub fn get_config() -> Config {
loop {
if Path::new("./config.toml").exists() {
loop {
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use tts::*;

#[tokio::main]
async fn main() {
let options: Vec<(&str, usize)> = get_options(get_config().await).await;
let config: Config = get_config().await;
let options: Vec<(&str, usize)> = get_options(config).await;

println!("\nStarting Jerry...");
println!("Jerry has been started!\n");
Expand Down

0 comments on commit a76cb8e

Please sign in to comment.