Skip to content

Commit

Permalink
Add .icns for proper macOS icon support (#506)
Browse files Browse the repository at this point in the history
* Script to create optimized .icns

* Remove other icons & make a better dmg with create-dmg action
  • Loading branch information
jacksongoode authored Jul 30, 2024
1 parent d895cb9 commit 2d9bdcb
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 11 deletions.
24 changes: 20 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,32 @@ jobs:
target/x86_64-apple-darwin/release/psst-gui \
target/aarch64-apple-darwin/release/psst-gui
- name: Create macOS Disk Image
- name: Install create-dmg
if: runner.os == 'macOS'
run: hdiutil create -volname "Psst" -srcfolder target/release/bundle/osx -ov -format UDZO Psst.dmg
run: brew install create-dmg

- name: Upload macOS Disk Image
- name: Create DMG
if: runner.os == 'macOS'
run: |
create-dmg \
--volname "Psst" \
--volicon "psst-gui/assets/logo.icns" \
--window-pos 200 120 \
--window-size 600 400 \
--icon-size 100 \
--icon "Psst.app" 150 160 \
--hide-extension "Psst.app" \
--app-drop-link 450 160 \
--no-internet-enable \
"Psst.dmg" \
"target/release/bundle/osx/Psst.app"
- name: Upload macOS DMG
uses: actions/upload-artifact@v4
if: runner.os == 'macOS'
with:
name: Psst.dmg
path: ./Psst.dmg
path: Psst.dmg

- name: Make Linux Binary Executable
if: runner.os == 'Linux'
Expand Down
8 changes: 1 addition & 7 deletions psst-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ image = { version = "0.25.1" }
[package.metadata.bundle]
name = "Psst"
identifier = "com.jpochyla.psst"
icon = [
"assets/logo_32.png",
"assets/logo_64.png",
"assets/logo_128.png",
"assets/logo_256.png",
"assets/logo_512.png",
]
icon = ["assets/logo.icns"]
version = "0.1.0"
resources = []
copyright = "Copyright (c) Jan Pochyla 2024. All rights reserved."
Expand Down
Binary file added psst-gui/assets/logo.icns
Binary file not shown.
59 changes: 59 additions & 0 deletions psst-gui/build-icons.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
set -euo pipefail

# Check for required tools
command -v rsvg-convert >/dev/null 2>&1 || {
echo >&2 "rsvg-convert is required but not installed. Aborting."
exit 1
}
command -v iconutil >/dev/null 2>&1 || {
echo >&2 "iconutil is required but not installed. Aborting."
exit 1
}
command -v pngquant >/dev/null 2>&1 || {
echo >&2 "pngquant is required but not installed. Aborting."
exit 1
}
command -v optipng >/dev/null 2>&1 || {
echo >&2 "optipng is required but not installed. Aborting."
exit 1
}

# Temp folder
ICON_DIR="icons"
mkdir -p "$ICON_DIR"

# Generate PNG icons from SVG
SIZES=(16 32 64 128 256 512)
for size in "${SIZES[@]}"; do
rsvg-convert -w $size -h $size assets/logo.svg -o "$ICON_DIR/logo_${size}.png"

# Apply lossy compression with pngquant
pngquant --force --quality=60-80 "$ICON_DIR/logo_${size}.png" --output "$ICON_DIR/logo_${size}.png"

# Further optimize with optipng
optipng -quiet -o5 "$ICON_DIR/logo_${size}.png"

# For smaller sizes, reduce color depth
if [ $size -le 32 ]; then
magick "$ICON_DIR/logo_${size}.png" -colors 256 PNG8:"$ICON_DIR/logo_${size}.png"
fi
done

# Generate ICNS for macOS
ICONSET_DIR="$ICON_DIR/psst.iconset"
mkdir -p "$ICONSET_DIR"
for size in "${SIZES[@]}"; do
cp "$ICON_DIR/logo_${size}.png" "$ICONSET_DIR/icon_${size}x${size}.png"
if [ $size -ne 16 ] && [ $size -ne 32 ]; then
cp "$ICON_DIR/logo_${size}.png" "$ICONSET_DIR/icon_$((size / 2))x$((size / 2))@2x.png"
fi
done

# Create ICNS file
iconutil -c icns "$ICONSET_DIR" -o assets/logo.icns

# Cleanup
rm -r "$ICON_DIR"

echo "Icon generation complete. ICNS file size: $(du -h assets/logo.icns | cut -f1)"

0 comments on commit 2d9bdcb

Please sign in to comment.