Skip to content

Commit

Permalink
feat: Save current background in a file
Browse files Browse the repository at this point in the history
This allows to not depend on feh for getting the current background.
We still need it for setting the background, but we can use other
programs for that.
  • Loading branch information
Yag000 committed Dec 23, 2023
1 parent 3ffd461 commit 27e44c3
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions src/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,11 @@ use crate::{
/// Panics if the file $HOME/.fehbg does not exist.
///
pub fn get_current_wallpaper() -> Option<File> {
let feh_raw = read_to_string(format!(
"{}/.fehbg",
home::home_dir()
.expect("Unable to get home path")
.to_str()
.unwrap()
let wallpaper_path = read_to_string(format!(
"{}/.local/share/wallshift/.current_wallpaper",
home::home_dir()?.to_str()?
))
.expect("failed to open .fehbg file");

let wallpaper_path = feh_raw
.lines()
// We take the second line because the first line is the shebang
.nth(1)
.expect("failed to parse .fehbg file, it should contain at least 2 lines")
// We take the last word
.split(' ')
.nth(3)
.expect("failed to parse .fehbg file, it should contain at least 4 words")
// Remove the single quotes
.trim_matches('\'')
.to_string();
.ok()?;

File::try_from(wallpaper_path).ok()
}
Expand Down Expand Up @@ -222,4 +206,21 @@ pub fn update_wallpaper(settings: &Settings, path: &str) {
.output()
.expect("failed to call betterlockscreen");
}

// Saves the current wallpaper

std::fs::create_dir_all(format!(
"{}/.local/share/wallshift",
home::home_dir().unwrap().to_str().unwrap()
))
.expect("failed to create directory");

std::fs::write(
format!(
"{}/.local/share/wallshift/.current_wallpaper",
home::home_dir().unwrap().to_str().unwrap()
),
path,
)
.expect("failed to save current wallpaper");
}

0 comments on commit 27e44c3

Please sign in to comment.