CLI tool that sets a wallpaper with awww, generates a pywal colour palette, and reloads bread-theme to recolour all running bread GTK apps. Includes CI workflows, bakery metadata, and Arch PKGBUILD.
61 lines
1.4 KiB
Rust
61 lines
1.4 KiB
Rust
mod pywal;
|
|
mod theme;
|
|
mod wallpaper;
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use anyhow::{Context, Result, bail};
|
|
|
|
const IMAGE_EXTENSIONS: &[&str] = &["png", "jpg", "jpeg", "webp", "gif", "bmp"];
|
|
|
|
pub fn set(path: &Path) -> Result<()> {
|
|
let path = validate(path)?;
|
|
apply_wallpaper(&path)?;
|
|
generate_palette(&path)?;
|
|
reload_theme()?;
|
|
Ok(())
|
|
}
|
|
|
|
pub fn get() -> Result<PathBuf> {
|
|
let home = std::env::var("HOME").context("HOME not set")?;
|
|
let wal_file = PathBuf::from(home).join(".cache/wal/wal");
|
|
|
|
let contents = std::fs::read_to_string(&wal_file)
|
|
.with_context(|| format!("no wallpaper set yet ({})", wal_file.display()))?;
|
|
|
|
Ok(PathBuf::from(contents.trim()))
|
|
}
|
|
|
|
pub fn apply_wallpaper(path: &Path) -> Result<()> {
|
|
wallpaper::apply(path)
|
|
}
|
|
|
|
pub fn generate_palette(path: &Path) -> Result<()> {
|
|
pywal::generate(path)
|
|
}
|
|
|
|
pub fn reload_theme() -> Result<()> {
|
|
theme::reload()
|
|
}
|
|
|
|
fn validate(path: &Path) -> Result<PathBuf> {
|
|
let canonical = path
|
|
.canonicalize()
|
|
.with_context(|| format!("not found: {}", path.display()))?;
|
|
|
|
let ext = canonical
|
|
.extension()
|
|
.and_then(|e| e.to_str())
|
|
.unwrap_or("")
|
|
.to_lowercase();
|
|
|
|
if !IMAGE_EXTENSIONS.contains(&ext.as_str()) {
|
|
bail!(
|
|
"unsupported file type '.{}' — expected one of: {}",
|
|
ext,
|
|
IMAGE_EXTENSIONS.join(", ")
|
|
);
|
|
}
|
|
|
|
Ok(canonical)
|
|
}
|