Skip to content

Commit d35907c

Browse files
committed
feat: ignore image format of animated wallpapers
1 parent c984231 commit d35907c

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/wallpaper.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ pub fn get_random_wallpaper(settings: &Settings) -> Result<File> {
101101
pub fn get_next_animated_wallpaper(settings: &Settings, path: &File) -> Result<Option<ImagePath>> {
102102
let name = path.get_animated_wallpaper_name();
103103
let next_index;
104+
105+
println!("{name}");
104106
match path {
105107
File::Image(img) => {
106108
let max_index = read_dir(format!("{}/{name}", settings.wallpaper_dir))?.count();
@@ -120,11 +122,21 @@ pub fn get_next_animated_wallpaper(settings: &Settings, path: &File) -> Result<O
120122
}
121123
}
122124

123-
//TODO: Add support for other file formats
124-
Ok(Some(ImagePath::from(format!(
125-
"{}/{name}/{name}{}.png",
126-
settings.wallpaper_dir, next_index
127-
))))
125+
let base_name = format!("{name}{}", next_index);
126+
127+
let a = read_dir(format!("{}/{name}", settings.wallpaper_dir))?.find(|s| {
128+
if let Ok(s) = s {
129+
if let Some(s) = s.path().file_stem() {
130+
return s.to_str() == Some(&base_name);
131+
}
132+
}
133+
false
134+
});
135+
136+
match a {
137+
Some(Err(e)) => Err(anyhow!(e)),
138+
_ => Ok(a.map(|s| ImagePath::from(s.unwrap().path().to_str().unwrap().to_string()))),
139+
}
128140
}
129141

130142
/// Gets the next wallpaper.
@@ -166,6 +178,9 @@ pub fn update_wallpaper(settings: &Settings, path: &str) -> Result<()> {
166178
// TODO: allow user to choose other wallpaper setter
167179
Command::new("feh").arg("--bg-fill").arg(path).output()?;
168180

181+
// Saves the current wallpaper
182+
save_wallpaper(path)?;
183+
169184
// Updates the betterlockscreen wallpaper
170185
if settings.betterlockscreen {
171186
Command::new("betterlockscreen")
@@ -174,9 +189,6 @@ pub fn update_wallpaper(settings: &Settings, path: &str) -> Result<()> {
174189
.output()?;
175190
}
176191

177-
// Saves the current wallpaper
178-
save_wallpaper(path)?;
179-
180192
Ok(())
181193
}
182194

0 commit comments

Comments
 (0)