write-darwin-bundle: Invert squircle logic

Older macOS cannot interpret the `CFBundleIconFiles` key so we cannot
rewrite the `CFBundleIconFile` entry without special consideration. I
opted to fix this by inverting the squircle logic. We always add both
the `CFBundleIconFile` and `CFBundleIconFiles` keys. The former is
necessary for at least macOS 10.13 and probably 10.12. The latter seems
to be ignored on those versions and overrides the former on newer
versions of macOS.

Inverting the logic also allows us to rely on the `toPlist` generator to
generate the XML syntax, which is a nice bonus.
This commit is contained in:
toonn 2022-03-21 12:35:42 +01:00
parent e5e8e1d926
commit 7a40437bdd
No known key found for this signature in database
GPG key ID: 44FF902A66DF4576

View file

@ -5,6 +5,7 @@ let
CFBundleDevelopmentRegion = "English";
CFBundleExecutable = "$name";
CFBundleIconFile = "$icon";
CFBundleIconFiles = [ "$icon" ];
CFBundleIdentifier = "org.nixos.$name";
CFBundleInfoDictionaryVersion = "6.0";
CFBundleName = "$name";
@ -25,11 +26,8 @@ in writeScriptBin "write-darwin-bundle" ''
${pListText}
EOF
if [[ $squircle != 0 && $squircle != "false" ]]; then
sed "
s|CFBundleIconFile|CFBundleIconFiles|;
s|<string>$icon</string>|<array><string>$icon</string></array>|
" -i "$plist"
if [[ $squircle == 0 || $squircle == "false" ]]; then
sed '/CFBundleIconFiles/,\|</array>|d' -i "$plist"
fi
cat > "$prefix/Applications/$name.app/Contents/MacOS/$name" <<EOF