Emit bread.paper.changed after a successful set
All checks were successful
check / check (push) Successful in 23s
dev release / build (push) Successful in 25s

Link bread-utils v0.7.1 (bread-client) and publish
{ "path": "<wallpaper>" } once awww + wal + bread-theme reload
all succeed. Silent no-op if breadd is down. breadpaper is
CLI-only — no watch subscriber; modules should bread.exec
("breadpaper set …"). See EVENTS.md.
This commit is contained in:
Breadway 2026-08-15 22:15:29 +08:00
parent 7a3a54c6f0
commit 54210ddc93
5 changed files with 452 additions and 20 deletions

View file

@ -4,7 +4,12 @@ mod wallpaper;
use std::path::{Path, PathBuf};
use anyhow::{Context, Result, bail};
use anyhow::{bail, Context, Result};
use bread_utils::bread_client::BreadClient;
/// App id in bread's sibling-app registry (`KNOWN_APPS`). Events publish as
/// `bread.paper.*`. See `EVENTS.md`.
const APP_ID: &str = "paper";
const IMAGE_EXTENSIONS: &[&str] = &["png", "jpg", "jpeg", "webp", "gif", "bmp"];
@ -13,9 +18,19 @@ pub fn set(path: &Path) -> Result<()> {
apply_wallpaper(&path)?;
generate_palette(&path)?;
reload_theme()?;
emit_changed(&path);
Ok(())
}
/// Fire-and-forget `bread.paper.changed`. Silent no-op if breadd is down
/// (`BreadClient::emit` never blocks or errors the caller).
fn emit_changed(path: &Path) {
BreadClient::connect(APP_ID).emit(
"bread.paper.changed",
serde_json::json!({ "path": path.to_string_lossy() }),
);
}
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");
@ -59,3 +74,15 @@ fn validate(path: &Path) -> Result<PathBuf> {
Ok(canonical)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn emit_changed_is_silent_without_breadd() {
// BreadClient::emit must never panic or error just because the
// socket is missing — this is the fail-silent contract.
emit_changed(Path::new("/tmp/wallpaper.png"));
}
}