8f841eac by 柴进

:art: DMG 背景图: PIL 生成箭头 + 中文提示, 布局对齐

之前只有两个图标并排, 用户看不出来要拖拽. 现在在 DMG 挂载打开时:
- 中间一根灰箭头从 .app 指向 Applications
- 底部中文提示 "将左侧应用拖到右侧 Applications 即完成安装"
- 窗口/图标/箭头三者坐标对齐

实现:
- 用 PIL 在 staging 阶段生成 600x400 PNG, 放 .background/bg.png
  (dot 前缀让 Finder 默认隐藏)
- AppleScript 里 set background picture 用 HFS path (冒号分隔)
- 图标位置 {150,200} / {450,200} 与背景图箭头两端对齐

PIL 字体查找: PingFang (默认中文) -> STHeiti -> Helvetica -> 兜底,
在打包机上都会命中至少一个.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 063d58aa
......@@ -92,12 +92,54 @@ TMP_DMG="dist/.tmp_rw.dmg"
STAGE="dist/.dmg_stage"
VOL_NAME="ZB100ImageGenerator"
# 1. 准备 staging: .app + Applications 快捷方式
# 1. 准备 staging: .app + Applications 快捷方式 + 背景图
rm -rf "$STAGE"
mkdir -p "$STAGE"
mkdir -p "$STAGE/.background"
cp -R "dist/ZB100ImageGenerator.app" "$STAGE/"
ln -s /Applications "$STAGE/Applications"
# 用 PIL 生成带箭头+中文提示的背景图 (600x400, 跟 DMG 窗口尺寸匹配)
DMG_BG_PATH="$STAGE/.background/bg.png" python3 <<'PYEOF'
import os
from PIL import Image, ImageDraw, ImageFont
W, H = 600, 400
img = Image.new('RGB', (W, H), color=(248, 248, 250))
d = ImageDraw.Draw(img)
# 中间箭头 (从 .app 指向 Applications)
arrow_y = 200
arrow_color = (120, 120, 125)
d.line([(260, arrow_y), (425, arrow_y)], fill=arrow_color, width=5)
d.polygon(
[(425, arrow_y - 14), (455, arrow_y), (425, arrow_y + 14)],
fill=arrow_color,
)
# 底部提示文字
def load_font(size):
for path in (
"/System/Library/Fonts/PingFang.ttc",
"/System/Library/Fonts/STHeiti Medium.ttc",
"/System/Library/Fonts/Helvetica.ttc",
):
if os.path.exists(path):
try:
return ImageFont.truetype(path, size)
except Exception:
continue
return ImageFont.load_default()
font = load_font(22)
text = "将左侧应用拖到右侧 Applications 即完成安装"
bbox = d.textbbox((0, 0), text, font=font)
tw = bbox[2] - bbox[0]
d.text(((W - tw) // 2, 320), text, fill=(90, 90, 95), font=font)
img.save(os.environ['DMG_BG_PATH'])
print(f"[dmg] 背景图已生成: {os.environ['DMG_BG_PATH']}")
PYEOF
# 2. 先卸载可能残留的同名卷, 防止上次失败留下的挂载
hdiutil detach "/Volumes/$VOL_NAME" -force >/dev/null 2>&1 || true
......@@ -121,12 +163,16 @@ tell application "Finder"
set current view of container window to icon view
set toolbar visible of container window to false
set statusbar visible of container window to false
set the bounds of container window to {200, 120, 800, 470}
-- 窗口尺寸匹配背景图 600x400, 坐标系从屏幕左上角算
set the bounds of container window to {200, 120, 800, 520}
set theViewOptions to the icon view options of container window
set arrangement of theViewOptions to not arranged
set icon size of theViewOptions to 128
set position of item "ZB100ImageGenerator.app" of container window to {160, 170}
set position of item "Applications" of container window to {440, 170}
-- 设置背景图 (HFS path, 冒号分隔)
set background picture of theViewOptions to file ".background:bg.png"
-- 图标位置要跟背景图里的箭头对齐
set position of item "ZB100ImageGenerator.app" of container window to {150, 200}
set position of item "Applications" of container window to {450, 200}
update without registering applications
delay 1
close
......