Files
komorebi/komorebi-recorder/assets/generate.py
T
LGUG2Z 8a203f0da7 feat(icon): a watermelon for every window
The recorder window and the viewer carry an icon of their own: a slice of
watermelon, drawn as komorebi-recorder/assets/watermelon.svg. `just icon`
(assets/generate.py, with resvg from the devShell) renders the PNG the windows
set and the ICO that Windows embeds. Until now eframe's default egui icon
showed.

macOS: eframe sets the PNG as the Dock icon while a window is open. The program
is a bare executable and not an app bundle, so Finder is unchanged.

Windows: eframe sets the same PNG as the window and taskbar icon. build.rs
compiles the ICO into both executables with embed-resource (rc.exe on Windows,
llvm-rc when cross-building from a Mac), and the installer shows it in Apps &
features through ARPPRODUCTICON. The taskbar, Explorer and the installer have
not been looked at on Windows: W4 and W5 in docs/dev/windows-checkpoints.md now
say what to check.

embed-resource adds seven crates to the lockfile and moves toml_datetime and
toml_parser up by a patch release.
2026-10-27 22:22:56 -07:00

45 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""Renders watermelon.svg into the two files the program uses.
watermelon.png (256 by 256) is the icon every window sets while the program runs, and
watermelon.ico is the icon Windows shows for the executables and for the installer. Needs
`resvg` on PATH, which `nix develop` provides; run it with `just icon`.
"""
import struct
import subprocess
import tempfile
from pathlib import Path
HERE = Path(__file__).resolve().parent
SIZES = [16, 24, 32, 48, 64, 128, 256]
def render(size, directory):
out = Path(directory) / f"{size}.png"
subprocess.run(
["resvg", "-w", str(size), "-h", str(size), str(HERE / "watermelon.svg"), str(out)],
check=True,
)
return out.read_bytes()
def ico(images):
"""An ICO file whose entries are PNGs, which Windows has read since Vista. A size of 256 is
written as 0."""
offset = 6 + 16 * len(images)
entries, data = b"", b""
for size, png in images:
entries += struct.pack(
"<BBBBHHII", size % 256, size % 256, 0, 0, 1, 32, len(png), offset + len(data)
)
data += png
return struct.pack("<HHH", 0, 1, len(images)) + entries + data
with tempfile.TemporaryDirectory() as directory:
images = [(size, render(size, directory)) for size in SIZES]
(HERE / "watermelon.png").write_bytes(images[-1][1])
(HERE / "watermelon.ico").write_bytes(ico(images))