From b48f6118c489beda224223dc66589195b387a9d0 Mon Sep 17 00:00:00 2001 From: Marco Rebhan Date: Mon, 21 Nov 2022 19:37:02 +0100 Subject: [PATCH 1/3] desktopToDarwinBundle: Return at most 1 literal match from desktop file This fixes multiple entries being returned from getDesktopParam, e.g. in the case of localized key names: 'Name', 'Name[de]', and makes this function to match this key exactly instead of a pattern for the same reason. --- .../setup-hooks/desktop-to-darwin-bundle.sh | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) 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 83ea7de3ee21..f52b50608f94 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -2,12 +2,25 @@ fixupOutputHooks+=('convertDesktopFiles $prefix') # Get a param out of a desktop file. First parameter is the file and the second -# is a pattern of the key who's value we should fetch. +# is the key who's value we should fetch. getDesktopParam() { - local file="$1"; - local pattern="$2"; + local file="$1" + local key="$2" + local line k v - awk -F "=" "/${pattern}/ {print \$2}" "${file}" + while read -r line; do + if [[ "$line" = *=* ]]; then + k="${line%%=*}" + v="${line#*=}" + + if [[ "$k" = "$key" ]]; then + echo "$v" + return + fi + fi + done < "$file" + + return 1 } # Convert a freedesktop.org icon theme for a given app to a .icns file. When possible, missing @@ -190,14 +203,14 @@ processExecFieldCodes() { convertDesktopFile() { local -r file=$1 local -r sharePath=$(dirname "$(dirname "$file")") - local -r name=$(getDesktopParam "${file}" "^Name") + local -r name=$(getDesktopParam "${file}" "Name") local -r macOSExec=$(getDesktopParam "${file}" "X-macOS-Exec") if [[ "$macOSExec" ]]; then local -r exec="$macOSExec" else local -r exec=$(processExecFieldCodes "${file}") fi - local -r iconName=$(getDesktopParam "${file}" "^Icon") + local -r iconName=$(getDesktopParam "${file}" "Icon") local -r squircle=$(getDesktopParam "${file}" "X-macOS-SquircleIcon") mkdir -p "${!outputBin}/Applications/${name}.app/Contents/MacOS" From d9a07bcd41135f2b9653ba934fc5867856196f78 Mon Sep 17 00:00:00 2001 From: Marco Rebhan Date: Sat, 25 Mar 2023 22:09:41 +0100 Subject: [PATCH 2/3] desktopToDarwinBundle: Add debug outputs for icon conversion --- pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh | 4 ++++ 1 file changed, 4 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 f52b50608f94..f05a8fb5140b 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -81,6 +81,7 @@ convertIconTheme() { local density=$((72 * scale))x$((72 * scale)) local dim=$((iconSize * scale)) + echo "desktopToDarwinBundle: resizing icon $in to $out, size $dim" >&2 magick convert -scale "${dim}x${dim}" -density "$density" -units PixelsPerInch "$in" "$out" } @@ -93,6 +94,8 @@ convertIconTheme() { if [[ $in != '-' ]]; then local density=$((72 * scale))x$((72 * scale)) local dim=$((iconSize * scale)) + + 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" else @@ -134,6 +137,7 @@ convertIconTheme() { local icon=${iconResult#* } local scaleSuffix=${scales[$scale]} local result=${resultdir}/${iconSize}x${iconSize}${scales[$scale]}${scaleSuffix:+x}.png + echo "desktopToDarwinBundle: using $type icon $icon for size $iconSize$scaleSuffix" >&2 case $type in fixed) local density=$((72 * scale))x$((72 * scale)) From f78175ad35e0fa7eb5183b756cfa988b783fed77 Mon Sep 17 00:00:00 2001 From: Marco Rebhan Date: Sat, 25 Mar 2023 22:09:57 +0100 Subject: [PATCH 3/3] desktopToDarwinBundle: Fix icon selection algorithm Now, the fallback icon is only used after considering all possible icons instead of only the first one. --- .../setup-hooks/desktop-to-darwin-bundle.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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 f05a8fb5140b..e4e7fba84770 100644 --- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh +++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh @@ -54,21 +54,30 @@ convertIconTheme() { $((iconSize - 2))x$((iconSize - 2))${scaleSuffix} ) + local fallbackIcon= + for iconIndex in "${!candidateIcons[@]}"; do for maybeSize in "${validSizes[@]}"; do icon=${candidateIcons[$iconIndex]} if [[ $icon = */$maybeSize/* ]]; then if [[ $maybeSize = $exactSize ]]; then echo "fixed $icon" + return 0 else echo "threshold $icon" + return 0 fi - elif [[ -a $icon ]]; then - echo "fallback $icon" + elif [[ -a $icon && -z "$fallbackIcon" ]]; then + fallbackIcon="$icon" fi - return 0 done done + + if [[ -n "$fallbackIcon" ]]; then + echo "fallback $fallbackIcon" + return 0 + fi + echo "scalable" }