|
| 1 | +#!/bin/sh |
| 2 | +# Cargo's runner on macOS (.cargo/config.toml): runs zbugs-gpui from inside |
| 3 | +# an app bundle, `ZBugs GPUI.app` beside the executable, so it launches as |
| 4 | +# an app with its icon (AppIcon.icon) in the Dock and the app switcher. The |
| 5 | +# bundle stays, to open from Finder. Tests and other executables run as |
| 6 | +# they are. |
| 7 | +set -eu |
| 8 | +exe=$1 |
| 9 | +shift |
| 10 | +[ "$(basename "$exe")" = zbugs-gpui ] || exec "$exe" "$@" |
| 11 | + |
| 12 | +here=$(cd "$(dirname "$0")" && pwd) |
| 13 | +# Absolute: actool takes relative paths from a directory of its own. |
| 14 | +app="$(cd "$(dirname "$exe")" && pwd)/ZBugs GPUI.app" |
| 15 | +res="$app/Contents/Resources" |
| 16 | +mkdir -p "$app/Contents/MacOS" "$res" |
| 17 | + |
| 18 | +# The icon, through Xcode's actool, when it changed: Assets.car for macOS 26 |
| 19 | +# and later, AppIcon.icns for earlier ones. |
| 20 | +if [ ! -e "$res/Assets.car" ] || [ -n "$(find "$here/AppIcon.icon" -newer "$res/Assets.car")" ]; then |
| 21 | + partial=$(mktemp) |
| 22 | + out=$(xcrun actool "$here/AppIcon.icon" --compile "$res" --platform macosx \ |
| 23 | + --minimum-deployment-target 11.0 --app-icon AppIcon \ |
| 24 | + --output-partial-info-plist "$partial" --output-format human-readable-text) || |
| 25 | + { echo "$out" >&2; exit 1; } |
| 26 | + rm -f "$partial" |
| 27 | +fi |
| 28 | + |
| 29 | +cat > "$app/Contents/Info.plist" <<'EOF' |
| 30 | +<?xml version="1.0" encoding="UTF-8"?> |
| 31 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 32 | +<plist version="1.0"> |
| 33 | +<dict> |
| 34 | + <key>CFBundleExecutable</key> |
| 35 | + <string>zbugs-gpui</string> |
| 36 | + <key>CFBundleIdentifier</key> |
| 37 | + <string>dev.rocicorp.zbugs-gpui</string> |
| 38 | + <key>CFBundleName</key> |
| 39 | + <string>ZBugs GPUI</string> |
| 40 | + <key>CFBundlePackageType</key> |
| 41 | + <string>APPL</string> |
| 42 | + <key>CFBundleIconFile</key> |
| 43 | + <string>AppIcon</string> |
| 44 | + <key>CFBundleIconName</key> |
| 45 | + <string>AppIcon</string> |
| 46 | + <key>LSApplicationCategoryType</key> |
| 47 | + <string>public.app-category.developer-tools</string> |
| 48 | + <key>NSHighResolutionCapable</key> |
| 49 | + <true/> |
| 50 | +</dict> |
| 51 | +</plist> |
| 52 | +EOF |
| 53 | + |
| 54 | +# A hard link, not a copy: the executable can be large in a debug build. |
| 55 | +ln -f "$exe" "$app/Contents/MacOS/zbugs-gpui" |
| 56 | +# LaunchServices can see the bundle before it's whole, as when actool runs, |
| 57 | +# and the Dock then shows the app as broken: register it as it is now. |
| 58 | +/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister \ |
| 59 | + -f "$app" |
| 60 | +exec "$app/Contents/MacOS/zbugs-gpui" "$@" |
0 commit comments