Skip to content

fix(dmg): preserve image quality and @2x Retina in background padding#164

Merged
kdroidFilter merged 1 commit intomainfrom
fix/dmg-background-padding-quality
Mar 28, 2026
Merged

fix(dmg): preserve image quality and @2x Retina in background padding#164
kdroidFilter merged 1 commit intomainfrom
fix/dmg-background-padding-quality

Conversation

@kdroidFilter
Copy link
Copy Markdown
Owner

Summary

Fixes the DMG background image rendering issue introduced in v1.5.0 (#26 fix).

The previous padDmgBackgroundForTitleBar implementation had three bugs:

  • Renamed output to background-padded.png, breaking electron-builder's @2x auto-detection (transformBackgroundFileIfNeed looks for <name>@2x.<ext> next to the source)
  • Ignored @2x Retina variants, so only the 1x image was padded — Retina displays showed blurry/unpadded backgrounds
  • Used the source image type for the padded canvas, which produced black padding instead of transparent when the source had no alpha channel (e.g. TYPE_3BYTE_BGR)

Changes

  • Preserve the original filename so electron-builder discovers @2x variants
  • Explicitly pad @2x files with 2× MACOS_DMG_TITLE_BAR_HEIGHT pixels (56px for Retina)
  • Always use TYPE_INT_ARGB + AlphaComposite.Clear for guaranteed transparent padding
  • Add 14 unit tests (dimensions, pixel verification, transparency, @2x, idempotency, edge cases)

Closes #163

Test plan

  • 14 unit tests pass (DmgBackgroundPaddingTest)
  • Pixel-level verification: original colors preserved, padding fully transparent
  • Visual inspection of generated images (1x and @2x)
  • ktlint + detekt pass without cache
  • Gradle cache (up-to-date) works correctly on re-run
  • Manual: build a DMG with a background image and verify it displays correctly

The previous padding implementation used Java ImageIO with issues:
- Renamed output to background-padded.png, breaking electron-builder's
  @2x auto-detection (transformBackgroundFileIfNeed)
- Did not pad @2x Retina variants, causing blurry backgrounds
- Used original image type which could produce black padding instead
  of transparent when the source lacked an alpha channel

Fix by preserving the original filename, explicitly handling @2x
variants with 2x pixel padding, and always using TYPE_INT_ARGB with
AlphaComposite.Clear for guaranteed transparent padding.

Add 14 unit tests covering dimensions, transparency, @2x handling,
idempotency, and edge cases.

Closes #163
@kdroidFilter kdroidFilter merged commit 37c1102 into main Mar 28, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DMG installer doesn't show background correctly

1 participant