From 3b52cd4c1bded09d5a4d9b2dc17ff1736ea89b3d Mon Sep 17 00:00:00 2001 From: Karolis Stasaitis Date: Fri, 22 Nov 2024 21:34:28 +0100 Subject: [PATCH] desktopToDarwinBundle: fix 16x, 32x app icons Changes the script to produce rgb+mask images for 16x and 32x icons instead of png. Using icns files containing 16x and 32x png images for app bundles results in Finder misrendering icons for these sizes (even though the icns files are rendered correctly when viewed by themselves) --- .../setup-hooks/desktop-to-darwin-bundle.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh index d7cab0e81a60..4fbef4baa512 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -92,6 +92,7 @@ convertIconTheme() { echo "desktopToDarwinBundle: resizing icon $in to $out, size $dim" >&2 magick convert -scale "${dim}x${dim}" -density "$density" -units PixelsPerInch "$in" "$out" + convertIfUnsupportedIcon "$out" "$iconSize" "$scale" } function synthesizeIcon() { @@ -107,11 +108,27 @@ convertIconTheme() { echo "desktopToDarwinBundle: rasterizing svg $in to $out, size $dim" >&2 rsvg-convert --keep-aspect-ratio --width "$dim" --height "$dim" "$in" --output "$out" magick convert -density "$density" -units PixelsPerInch "$out" "$out" + convertIfUnsupportedIcon "$out" "$iconSize" "$scale" else return 1 fi } + # macOS does not correctly display 16x and 32x png icons on app bundles + # they need to be converted to rgb+mask (argb is supported only from macOS 11) + function convertIfUnsupportedIcon() { + local -r in=$1 + local -r iconSize=$2 + local -r scale=$3 + local -r out=${in%.png}.rgb + + if [[ ($scale -eq 1) && ($iconSize -eq 32 || $iconSize -eq 16) ]]; then + echo "desktopToDarwinBundle: converting ${iconSize}x icon to rgb" >&2 + icnsutil convert "$out" "$in" + rm "$in" + fi + } + function getIcons() { local -r sharePath=$1 local -r iconname=$2 @@ -151,6 +168,7 @@ convertIconTheme() { fixed) local density=$((72 * scale))x$((72 * scale)) magick convert -density "$density" -units PixelsPerInch "$icon" "$result" + convertIfUnsupportedIcon "$result" "$iconSize" "$scale" foundIcon=OTHER ;; threshold)