summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2022-03-21 13:26:19 +0100
committertoonn <toonn@toonn.io>2022-03-21 14:20:03 +0100
commit6aa5c537483e9cc9cbd66ac28fef8800ba306f97 (patch)
tree8b52abbfe17564e6dc043280d5d13476cd57fd22 /pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh
parent08a2b83c9630fb191022dda93d62cc1c0f9e5aa4 (diff)
downloadnixpkgs-6aa5c537483e9cc9cbd66ac28fef8800ba306f97.tar
nixpkgs-6aa5c537483e9cc9cbd66ac28fef8800ba306f97.tar.gz
nixpkgs-6aa5c537483e9cc9cbd66ac28fef8800ba306f97.tar.bz2
nixpkgs-6aa5c537483e9cc9cbd66ac28fef8800ba306f97.tar.lz
nixpkgs-6aa5c537483e9cc9cbd66ac28fef8800ba306f97.tar.xz
nixpkgs-6aa5c537483e9cc9cbd66ac28fef8800ba306f97.tar.zst
nixpkgs-6aa5c537483e9cc9cbd66ac28fef8800ba306f97.zip
desktopToDarwinBundle: Fall back to scaling available
Sometimes scalable icons or icons within the thresholds from the desired
resolutions aren't available. In this case it's still nicer to end up
with a blocky scaled icon rather than the generic default.
Diffstat (limited to 'pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh')
-rw-r--r--pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh33
1 files changed, 32 insertions, 1 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 0519d183ba9..d54af90b688 100644
--- a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh
+++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh
@@ -50,8 +50,10 @@ convertIconTheme() {
                     else
                         echo "threshold $icon"
                     fi
-                    return 0
+                elif [[ -a $icon ]]; then
+                  echo "fallback $icon"
                 fi
+                return 0
             done
         done
         echo "scalable"
@@ -101,6 +103,17 @@ convertIconTheme() {
             scalableIcon=('-')
         fi
 
+        # Tri-state variable, NONE means no icons have been found, an empty
+        # icns file will be generated, not sure that's necessary because macOS
+        # will default to a generic icon if no icon can be found.
+        #
+        # OTHER means an appropriate icon was found.
+        #
+        # Any other value is a path to an icon file that isn't scalable or
+        # within the threshold. This is used as a fallback in case no better
+        # icon can be found and will be scaled as much as
+        # necessary to result in appropriate icon sizes.
+        local foundIcon=NONE
         for iconSize in "${iconSizes[@]}"; do
             for scale in "${!scales[@]}"; do
                 local iconResult=$(findIcon $iconSize $scale)
@@ -112,6 +125,7 @@ convertIconTheme() {
                     fixed)
                         local density=$((72 * scale))x$((72 * scale))
                         magick convert -density "$density" -units PixelsPerInch "$icon" "$result"
+                        foundIcon=OTHER
                         ;;
                     threshold)
                         # Synthesize an icon of the exact size if a scalable icon is available
@@ -119,15 +133,32 @@ convertIconTheme() {
                         if ! synthesizeIcon "${scalableIcon[0]}" "$result" "$iconSize" "$scale"; then
                             resizeIcon "$icon" "$result" "$iconSize" "$scale"
                         fi
+                        foundIcon=OTHER
                         ;;
                     scalable)
                         synthesizeIcon "${scalableIcon[0]}" "$result" "$iconSize" "$scale" || true
+                        foundIcon=OTHER
+                        ;;
+                    fallback)
+                        # Use the largest size available to scale to
+                        # appropriate sizes.
+                        if [[ $foundIcon != OTHER ]]; then
+                          foundIcon=$icon
+                        fi
                         ;;
                     *)
                         ;;
                 esac
             done
         done
+        if [[ $foundIcon != NONE && $foundIcon != OTHER ]]; then
+            # Ideally we'd only resize to whatever the closest sizes are,
+            # starting from whatever icon sizes are available.
+            for iconSize in 16 32 128 256 512; do
+              local result=${resultdir}/${iconSize}x${iconSize}.png
+              resizeIcon "$foundIcon" "$result" "$iconSize" 1
+            done
+        fi
         echo "$resultdir"
     }