Skip to content

Open source CapCut alternative.

TypeScript

Create custom Mac DMG installer

David Lef5c0e8bee933
diff --git a/apps/Donkey/Package.swift b/apps/Donkey/Package.swift
index 4f4912b4..a8c7cf4a 100644
--- a/apps/Donkey/Package.swift
+++ b/apps/Donkey/Package.swift
@@ -55,6 +55,10 @@ let package = Package(
"DonkeyUI",
.product(name: "Sparkle", package: "Sparkle")
],
+ exclude: [
+ "Resources/Donkey.icns",
+ "Resources/Donkey.iconset"
+ ],
resources: [
.copy("Resources/theme.json")
]
diff --git a/docs/guides/install-donkey.md b/docs/guides/install-donkey.md
index dc4606c5..622710c2 100644
--- a/docs/guides/install-donkey.md
+++ b/docs/guides/install-donkey.md
@@ -8,6 +8,9 @@ From the repo root:
./scripts/package-donkey-app.sh
```
+The drag-to-Applications background is rendered from SVG, so local packaging
+requires ImageMagick's `magick` command.
+
The script builds the release executable, creates `dist/Donkey.app`, copies bundled resources and embedded frameworks, ensures the executable can load those frameworks from the app bundle, applies an ad-hoc signature when `codesign` is available, and creates `dist/Donkey.dmg`.
The app bundle version defaults to `0.1.0` build `1`. Override it for local release testing:
@@ -31,7 +34,15 @@ For distribution through the site, publish the disk image:
dist/Donkey.dmg
```
-Opening the disk image mounts a `Donkey` volume with `Donkey.app` and an `Applications` shortcut, matching the standard drag-to-Applications macOS install flow. The user installs Donkey by dragging the app onto the shortcut, which copies it into `/Applications`.
+Opening the disk image mounts a `Donkey` volume with a custom Finder installer
+window: `Donkey.app` sits on the left, the `Applications` shortcut sits on the
+right, and the background arrow points users through the drag-to-Applications
+flow. The installer artwork lives in `scripts/assets/donkey-dmg-background.svg`;
+the package script renders that SVG into the Finder background and writes the
+Finder layout into the compressed disk image so users see the install screen
+immediately after opening `Donkey.dmg`.
+The user installs Donkey by dragging the app onto the shortcut, which copies it
+into `/Applications`.
To launch the packaged app:
diff --git a/scripts/assets/donkey-dmg-background.svg b/scripts/assets/donkey-dmg-background.svg
new file mode 100644
index 00000000..0af7d3b4
--- /dev/null
+++ b/scripts/assets/donkey-dmg-background.svg
@@ -0,0 +1,7 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="760" height="480" viewBox="0 0 760 480">
+ <rect width="760" height="480" fill="#f2f0e9"/>
+ <g fill="none" stroke-linecap="round" stroke-linejoin="round">
+ <path d="M344 225h64" stroke="#3d3a33" stroke-opacity="1" stroke-width="6"/>
+ <path d="M386 203l24 22-24 22" stroke="#3d3a33" stroke-opacity="1" stroke-width="6"/>
+ </g>
+</svg>
diff --git a/scripts/package-donkey-app.sh b/scripts/package-donkey-app.sh
index f7b4669c..b34bff44 100755
--- a/scripts/package-donkey-app.sh
+++ b/scripts/package-donkey-app.sh
@@ -4,6 +4,7 @@ set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
APP_DIR="$ROOT_DIR/dist/Donkey.app"
DMG_PATH="$ROOT_DIR/dist/Donkey.dmg"
+DMG_RW_PATH="$ROOT_DIR/dist/Donkey-rw.dmg"
DMG_ROOT="$ROOT_DIR/dist/DonkeyInstaller"
RUNTIME_PACKAGE_DIR="$ROOT_DIR/dist/LocalRuntimePackages"
APP_VERSION="${DONKEY_APP_VERSION:-0.1.0}"
@@ -20,6 +21,128 @@ BUILD_DIR="$ROOT_DIR/apps/Donkey"
EXECUTABLE="$BUILD_DIR/.build/release/Donkey"
CACHE_DIR="$BUILD_DIR/.build/package-cache"
APP_ICON_SOURCE="$BUILD_DIR/Sources/Donkey/Resources/Donkey.icns"
+DMG_BACKGROUND_SOURCE="$ROOT_DIR/scripts/assets/donkey-dmg-background.svg"
+DMG_BACKGROUND_RENDERED="$ROOT_DIR/dist/donkey-dmg-background.png"
+DMG_WINDOW_WIDTH=760
+DMG_WINDOW_HEIGHT=480
+DMG_WINDOW_LEFT=160
+DMG_WINDOW_TOP=120
+DMG_WINDOW_RIGHT=$((DMG_WINDOW_LEFT + DMG_WINDOW_WIDTH))
+DMG_WINDOW_BOTTOM=$((DMG_WINDOW_TOP + DMG_WINDOW_HEIGHT))
+DMG_APP_ICON_X=220
+DMG_APP_ICON_Y=225
+DMG_APPLICATIONS_ICON_X=540
+DMG_APPLICATIONS_ICON_Y=225
+
+render_dmg_background() {
+ if [ ! -f "$DMG_BACKGROUND_SOURCE" ]; then
+ echo "Missing DMG background image: $DMG_BACKGROUND_SOURCE" >&2
+ exit 1
+ fi
+ if ! command -v magick >/dev/null 2>&1; then
+ echo "ImageMagick is required to render $DMG_BACKGROUND_SOURCE for the Finder installer background." >&2
+ exit 1
+ fi
+
+ mkdir -p "$(dirname "$DMG_BACKGROUND_RENDERED")"
+ magick "$DMG_BACKGROUND_SOURCE" "PNG24:$DMG_BACKGROUND_RENDERED"
+}
+
+set_dmg_volume_icon() {
+ local volume_dir="$1"
+
+ if [ -f "$APP_ICON_SOURCE" ]; then
+ cp "$APP_ICON_SOURCE" "$volume_dir/.VolumeIcon.icns"
+ SetFile -t icns -c icnC "$volume_dir/.VolumeIcon.icns"
+ SetFile -a V "$volume_dir/.VolumeIcon.icns"
+ SetFile -a C "$volume_dir"
+ fi
+}
+
+configure_dmg_window() {
+ local mount_dir="$1"
+
+ SetFile -a V "$mount_dir/.background" >/dev/null 2>&1 || true
+
+ osascript <<APPLESCRIPT
+tell application "Finder"
+ set mountedFolder to POSIX file "$mount_dir" as alias
+ set backgroundFile to POSIX file "$mount_dir/.background/donkey-dmg-background.png" as alias
+ open mountedFolder
+ delay 0.2
+ set installerWindow to front Finder window
+ set current view of installerWindow to icon view
+ try
+ set toolbar visible of installerWindow to false
+ end try
+ try
+ set statusbar visible of installerWindow to false
+ end try
+ set bounds of installerWindow to {$DMG_WINDOW_LEFT, $DMG_WINDOW_TOP, $DMG_WINDOW_RIGHT, $DMG_WINDOW_BOTTOM}
+ set theViewOptions to icon view options of installerWindow
+ set arrangement of theViewOptions to not arranged
+ set icon size of theViewOptions to 144
+ set background picture of theViewOptions to backgroundFile
+ set position of item "Donkey.app" of installerWindow to {$DMG_APP_ICON_X, $DMG_APP_ICON_Y}
+ set position of item "Applications" of installerWindow to {$DMG_APPLICATIONS_ICON_X, $DMG_APPLICATIONS_ICON_Y}
+ update mountedFolder without registering applications
+ delay 1
+ close installerWindow
+end tell
+APPLESCRIPT
+
+ set_dmg_volume_icon "$mount_dir"
+}
+
+create_drag_to_applications_dmg() {
+ local mount_dir
+ local mounted=0
+
+ render_dmg_background
+
+ mount_dir="$(mktemp -d "${TMPDIR:-/tmp}/donkey-dmg.XXXXXX")"
+ cleanup_dmg_mount() {
+ trap - RETURN
+ if [ "$mounted" = "1" ]; then
+ hdiutil detach "$mount_dir" -force >/dev/null 2>&1 || true
+ fi
+ rm -rf "$mount_dir"
+ }
+ trap cleanup_dmg_mount RETURN
+
+ rm -rf "$DMG_ROOT" "$DMG_PATH" "$DMG_RW_PATH"
+ mkdir -p "$DMG_ROOT/.background"
+ cp -R "$APP_DIR" "$DMG_ROOT/Donkey.app"
+ ln -s /Applications "$DMG_ROOT/Applications"
+ cp "$DMG_BACKGROUND_RENDERED" "$DMG_ROOT/.background/donkey-dmg-background.png"
+
+ hdiutil create \
+ -volname "Donkey" \
+ -srcfolder "$DMG_ROOT" \
+ -ov \
+ -format UDRW \
+ -fs HFS+ \
+ "$DMG_RW_PATH" >/dev/null
+
+ hdiutil attach "$DMG_RW_PATH" \
+ -readwrite \
+ -noverify \
+ -noautoopen \
+ -mountpoint "$mount_dir" >/dev/null
+ mounted=1
+
+ configure_dmg_window "$mount_dir"
+ sync
+ hdiutil detach "$mount_dir" >/dev/null
+ mounted=0
+
+ hdiutil convert "$DMG_RW_PATH" \
+ -format UDZO \
+ -imagekey zlib-level=9 \
+ -o "$DMG_PATH" >/dev/null
+
+ rm -rf "$DMG_ROOT" "$DMG_RW_PATH"
+}
mkdir -p "$CACHE_DIR/clang" "$CACHE_DIR/swiftpm" "$CACHE_DIR/home"
export CLANG_MODULE_CACHE_PATH="$CACHE_DIR/clang"
@@ -126,17 +249,7 @@ if command -v codesign >/dev/null 2>&1; then
codesign --force --deep --sign - "$APP_DIR" >/dev/null
fi
-rm -rf "$DMG_ROOT" "$DMG_PATH"
-mkdir -p "$DMG_ROOT"
-cp -R "$APP_DIR" "$DMG_ROOT/Donkey.app"
-ln -s /Applications "$DMG_ROOT/Applications"
-hdiutil create \
- -volname "Donkey" \
- -srcfolder "$DMG_ROOT" \
- -ov \
- -format UDZO \
- "$DMG_PATH" >/dev/null
-rm -rf "$DMG_ROOT"
+create_drag_to_applications_dmg
echo "Packaged $APP_DIR"
echo "Created drag-to-Applications disk image: $DMG_PATH"