Skip to content

Commit fd68a3d

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

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/wallpaper.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ 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+
104105
match path {
105106
File::Image(img) => {
106107
let max_index = read_dir(format!("{}/{name}", settings.wallpaper_dir))?.count();
@@ -120,11 +121,21 @@ pub fn get_next_animated_wallpaper(settings: &Settings, path: &File) -> Result<O
120121
}
121122
}
122123

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-
))))
124+
let base_name = format!("{name}{}", next_index);
125+
126+
let a = read_dir(format!("{}/{name}", settings.wallpaper_dir))?.find(|s| {
127+
if let Ok(s) = s {
128+
if let Some(s) = s.path().file_stem() {
129+
return s.to_str() == Some(&base_name);
130+
}
131+
}
132+
false
133+
});
134+
135+
match a {
136+
Some(Err(e)) => Err(anyhow!(e)),
137+
_ => Ok(a.map(|s| ImagePath::from(s.unwrap().path().to_str().unwrap().to_string()))),
138+
}
128139
}
129140

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

180+
// Saves the current wallpaper
181+
save_wallpaper(path)?;
182+
169183
// Updates the betterlockscreen wallpaper
170184
if settings.betterlockscreen {
171185
Command::new("betterlockscreen")
@@ -174,9 +188,6 @@ pub fn update_wallpaper(settings: &Settings, path: &str) -> Result<()> {
174188
.output()?;
175189
}
176190

177-
// Saves the current wallpaper
178-
save_wallpaper(path)?;
179-
180191
Ok(())
181192
}
182193

0 commit comments

Comments
 (0)