From c7cb9dad4e782ee0ff99773c3607ec3b7792c723 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 11 Sep 2026 16:57:14 +0200 Subject: refactor(accent): resolve the wallpaper path, finish the atomic-write helper colors.json recorded whatever path it was handed, so it read either the real wallpaper or ~/.cache/wal/wpaper, the symlink to it, depending on the caller. wallp passes the resolved file; a manual run usually passes the symlink. Same wallpaper either way, so record one spelling. write_atomic arrived with the quickshell palette but only write_border used it. The other four writers kept their own copy of the same write-then-rename, which is the duplication the helper was added to remove, so they use it now. No behaviour change: the temp file was already created by mkstemp in every case, so the resulting modes are the same. Verified by running the script before and after: udt-palette.qml, udt-accent.rasi and udt-border.lua are byte-identical, and colors.json differs only in the wallpaper field this commit intends to change. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_015gbjA2bmswN8jyPDKzrvqe --- bin/udt-accent | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/bin/udt-accent b/bin/udt-accent index 4294347..7949597 100755 --- a/bin/udt-accent +++ b/bin/udt-accent @@ -153,18 +153,9 @@ def write_accent(name): f"* {{ accent: {hexval}ff; }}\n" ) - OUTPUT.parent.mkdir(parents=True, exist_ok=True) # Write-then-rename: a rofi launch during a wallpaper change must never # read a half-written file. - fd, tmp = tempfile.mkstemp(dir=str(OUTPUT.parent), suffix=".tmp") - try: - with os.fdopen(fd, "w") as handle: - handle.write(content) - os.replace(tmp, OUTPUT) - except BaseException: - if os.path.exists(tmp): - os.unlink(tmp) - raise + write_atomic(OUTPUT, content) def hue_neighbours(name): @@ -270,7 +261,10 @@ def write_colors_json(name, image): colors[4] = colors[12] = hexval doc = { - "wallpaper": str(image), + # Resolved, not as passed: wallp gives the real file but a caller may + # give ~/.cache/wal/wpaper, the symlink to it. Same wallpaper either + # way, so record one spelling. + "wallpaper": os.path.realpath(image), "alpha": "100", "special": { "background": MACCHIATO["background"], @@ -280,16 +274,7 @@ def write_colors_json(name, image): "colors": {f"color{i}": c for i, c in enumerate(colors)}, } - fd, tmp = tempfile.mkstemp(dir=str(COLORS_JSON.parent), suffix=".tmp") - try: - with os.fdopen(fd, "w") as handle: - json.dump(doc, handle, indent=4) - handle.write("\n") - os.replace(tmp, COLORS_JSON) - except BaseException: - if os.path.exists(tmp): - os.unlink(tmp) - raise + write_atomic(COLORS_JSON, json.dumps(doc, indent=4) + "\n") # Firefox only picks the new colours up when pywalfox pushes them. Never # fatal: pywalfox may not be installed, and the desktop theme is unaffected. @@ -310,15 +295,7 @@ def write_dunst(name): if "@ACCENT@" not in text: return - fd, tmp = tempfile.mkstemp(dir=str(DUNSTRC.parent), suffix=".tmp") - try: - with os.fdopen(fd, "w") as handle: - handle.write(text.replace("@ACCENT@", ACCENTS[name])) - os.replace(tmp, DUNSTRC) - except BaseException: - if os.path.exists(tmp): - os.unlink(tmp) - raise + write_atomic(DUNSTRC, text.replace("@ACCENT@", ACCENTS[name])) # Restart dunst so it rereads the file. It must be started again, not just # killed: nothing else respawns it, and a dead dunst means no notifications -- cgit v1.2.3