Files
notification-service/Scripts/gen_icon.sh
T
2026-07-06 01:17:30 +08:00

50 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Regenerate Sources/NotificationService/AppIcon.swift from bell-logo.avif:
# removes the bottom black bar, trims white padding, centers the bell on a
# transparent 1024x1024 square, and embeds the PNG as base64 in Swift.
set -euo pipefail
cd "$(dirname "$0")/.."
SRC="${1:-bell-logo.avif}"
OUT_SWIFT="Sources/NotificationService/AppIcon.swift"
if [ ! -f "$SRC" ]; then
echo "source image not found: $SRC" >&2
exit 1
fi
PNG="$(mktemp -t bellicon).png"
trap 'rm -f "$PNG"' EXIT
swift Scripts/process_icon.swift "$SRC" "$PNG" >/dev/null
B64="$(base64 -i "$PNG" | tr -d '\n')"
cat > "$OUT_SWIFT" <<'EOF'
import Foundation
import AppKit
// Auto-generated from bell-logo.avif (bottom black bar removed, bell centered
// on a transparent square). Regenerate via `just icon`. DO NOT edit by hand.
enum AppIcon {
static let base64EncodedPNG = "__BASE64__"
static let image: NSImage? = {
guard let data = Data(base64Encoded: base64EncodedPNG),
let img = NSImage(data: data) else { return nil }
return img
}()
}
EOF
python3 - "$B64" "$OUT_SWIFT" <<'PY'
import sys
b64, path = sys.argv[1], sys.argv[2]
s = open(path).read().replace("__BASE64__", b64)
open(path, "w").write(s)
PY
echo "Generated $OUT_SWIFT ($(wc -c < "$OUT_SWIFT") bytes) from $SRC"