fix: use a struct for clarity

This commit is contained in:
silver 2025-06-07 21:24:59 +01:00
parent b4f6835704
commit a7423959dc
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D

View file

@ -94,26 +94,33 @@ async fn update_icon_main(ctx: Arc<Context>) {
let logos = get_logos(&config_global, &config_toml); let logos = get_logos(&config_global, &config_toml);
} }
fn get_festival(config_toml: &ConfigToml)-> (Option<String>, Vec<String>){ struct FestivalData{
current: Option<String>,
exclusions: Vec<String>,
}
fn get_festival(config_toml: &ConfigToml)-> FestivalData {
let today = Utc::now(); let today = Utc::now();
let day = today.day(); let day = today.day();
let month = today.month(); let month = today.month();
let year = today.year(); let year = today.year();
let mut festival_current = None; let mut result = FestivalData {
let mut festival_not = vec![]; current: None,
exclusions: vec![],
};
for festival in &config_toml.festivals { for festival in &config_toml.festivals {
if (day >= festival.start.day && day <= festival.end.day) if (day >= festival.start.day && day <= festival.end.day)
&& (month >= festival.start.month && month <= festival.end.month ) && (month >= festival.start.month && month <= festival.end.month )
&& (year >= festival.start.year && year <= festival.end.year) { && (year >= festival.start.year && year <= festival.end.year) {
festival_current = Some(festival.name.to_owned()); result.current = Some(festival.name.to_owned());
} else if !festival.all_year { } else if !festival.all_year {
festival_not.push(festival.name.to_owned()); result.exclusions.push(festival.name.to_owned());
} }
} }
(festival_current, festival_not) result
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -184,7 +191,11 @@ fn convert_svg_to_png(original: &PathBuf, out: &PathBuf){
fs::write(out, &bytes).expect("TODO: panic message"); fs::write(out, &bytes).expect("TODO: panic message");
} }
fn get_logos(config: &Config, config_toml: &ConfigToml) -> Vec<(OsString, PathBuf)> { struct LogoData {
name: OsString,
path: PathBuf,
}
fn get_logos(config: &Config, config_toml: &ConfigToml) -> Vec<LogoData> {
let folder = format!("{}/open-governance/{}", &config.home, &config_toml.source.directory); let folder = format!("{}/open-governance/{}", &config.home, &config_toml.source.directory);
let folder_path = PathBuf::from(&folder); let folder_path = PathBuf::from(&folder);
let paths = fs::read_dir(folder).unwrap(); let paths = fs::read_dir(folder).unwrap();
@ -203,8 +214,8 @@ fn get_logos(config: &Config, config_toml: &ConfigToml) -> Vec<(OsString, PathB
for tmp in paths.flatten() { for tmp in paths.flatten() {
let path_local = tmp.path().to_owned(); let path_local = tmp.path().to_owned();
let path_local2 = tmp.path().to_owned(); let path_local2 = tmp.path().to_owned();
let temp2 = path_local2.file_name().unwrap(); let name = path_local2.file_name().unwrap().to_owned();
let mut file_path = tmp.path(); let mut path = tmp.path();
match tmp.path().extension() { match tmp.path().extension() {
None => {} None => {}
@ -220,12 +231,15 @@ fn get_logos(config: &Config, config_toml: &ConfigToml) -> Vec<(OsString, PathB
log::error!("Failed to render {path_local:?}: {}", e) log::error!("Failed to render {path_local:?}: {}", e)
} }
} }
file_path = path_new; path = path_new;
} }
} }
}; };
logos.push((temp2.to_owned(), file_path.to_owned())); logos.push(LogoData{
name,
path,
});
println!("Name: {}", &tmp.path().display()); println!("Name: {}", &tmp.path().display());
} }