-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-dmg.sh
More file actions
executable file
·172 lines (153 loc) · 6.28 KB
/
Copy pathmake-dmg.sh
File metadata and controls
executable file
·172 lines (153 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bash
# make-dmg.sh — Build 方言语音输入.app and package into a .dmg
# Usage: ./make-dmg.sh [output-dir]
# Output: 方言语音输入.dmg in output-dir (default: ./dist/)
#
# v2.0: Native Qwen3-ASR engine (no Python dependency)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUTPUT_DIR="${1:-$SCRIPT_DIR/dist}"
APP_DISPLAY_NAME="Dialect Voice Input"
APP_BUNDLE="$OUTPUT_DIR/$APP_DISPLAY_NAME.app"
MACOS_APP_DIR="$SCRIPT_DIR"
BUNDLE_ID="com.fangyan.voiceinput"
EXECUTABLE_NAME="SichuanVoiceInput"
DMG_NAME="$APP_DISPLAY_NAME"
DMG_PATH="$OUTPUT_DIR/$DMG_NAME.dmg"
VERSION="2.0.0"
echo "=== 方言语音输入 DMG Packager (v2 — Native Qwen3-ASR) ==="
echo "Output: $DMG_PATH"
echo ""
mkdir -p "$OUTPUT_DIR"
# ── Step 1: Build C static library ────────────────────────────────────────
echo "[1/6] Building libqwen_asr.a..."
bash "$MACOS_APP_DIR/build-lib.sh" 2>&1 | tail -3
# ── Step 2: Build Swift binary (release, universal) ───────────────────────
echo "[2/6] Building Universal Binary (arm64 + x86_64, release)..."
cd "$MACOS_APP_DIR"
swift build -c release --arch arm64 --arch x86_64 2>&1 | tail -5
SWIFT_BINARY="$(swift build -c release --arch arm64 --arch x86_64 --show-bin-path)/SichuanVoiceInput"
if [[ ! -f "$SWIFT_BINARY" ]]; then
echo "ERROR: Swift binary not found at $SWIFT_BINARY"
exit 1
fi
echo " Binary: $SWIFT_BINARY ($(lipo -info "$SWIFT_BINARY" 2>&1 | tail -1))"
cd "$SCRIPT_DIR"
# ── Step 3: Generate app icon ─────────────────────────────────────────────
echo "[3/6] Generating app icon..."
ICON_WORK_DIR="$OUTPUT_DIR/.icon_tmp"
mkdir -p "$ICON_WORK_DIR"
swift "$SCRIPT_DIR/generate-icon.swift" "$ICON_WORK_DIR" 2>/dev/null || {
echo "WARNING: Icon generation failed, continuing without custom icon"
}
ICNS_PATH=""
if [[ -d "$ICON_WORK_DIR/AppIcon.iconset" ]]; then
iconutil --convert icns "$ICON_WORK_DIR/AppIcon.iconset" --output "$ICON_WORK_DIR/AppIcon.icns" 2>/dev/null && {
ICNS_PATH="$ICON_WORK_DIR/AppIcon.icns"
echo " Icon: $ICNS_PATH"
}
fi
rm -rf "$ICON_WORK_DIR/AppIcon.iconset"
# ── Step 4: Create .app bundle ────────────────────────────────────────────
echo "[4/6] Creating .app bundle..."
rm -rf "$APP_BUNDLE"
mkdir -p "$APP_BUNDLE/Contents/MacOS"
mkdir -p "$APP_BUNDLE/Contents/Resources"
# Copy binary
cp "$SWIFT_BINARY" "$APP_BUNDLE/Contents/MacOS/$EXECUTABLE_NAME"
# Copy icon
if [[ -n "$ICNS_PATH" && -f "$ICNS_PATH" ]]; then
cp "$ICNS_PATH" "$APP_BUNDLE/Contents/Resources/AppIcon.icns"
fi
rm -rf "$ICON_WORK_DIR"
# ── Step 5: Write Info.plist ──────────────────────────────────────────────
echo "[5/6] Writing Info.plist..."
ICON_ENTRY=""
if [[ -f "$APP_BUNDLE/Contents/Resources/AppIcon.icns" ]]; then
ICON_ENTRY="<key>CFBundleIconFile</key><string>AppIcon</string>"
fi
cat > "$APP_BUNDLE/Contents/Info.plist" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>$EXECUTABLE_NAME</string>
<key>CFBundleIdentifier</key>
<string>$BUNDLE_ID</string>
<key>CFBundleName</key>
<string>$APP_DISPLAY_NAME</string>
<key>CFBundleDisplayName</key>
<string>$APP_DISPLAY_NAME</string>
<key>CFBundleVersion</key>
<string>$VERSION</string>
<key>CFBundleShortVersionString</key>
<string>$VERSION</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>LSUIElement</key>
<true/>
<key>NSMicrophoneUsageDescription</key>
<string>Dialect Voice Input needs microphone access to record speech for transcription.</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>14.0</string>
$ICON_ENTRY
</dict>
</plist>
PLIST
# ── Step 6: Code sign & create DMG ───────────────────────────────────────
echo "[6/6] Code signing & creating DMG..."
codesign --force --deep --sign - "$APP_BUNDLE" 2>&1 || {
echo "WARNING: codesign failed (non-fatal — app will still run via Gatekeeper bypass)"
}
rm -f "$DMG_PATH"
DMG_TMP="$OUTPUT_DIR/.dmg_tmp"
rm -rf "$DMG_TMP"
mkdir -p "$DMG_TMP"
cp -R "$APP_BUNDLE" "$DMG_TMP/"
ln -s /Applications "$DMG_TMP/Applications"
cat > "$DMG_TMP/.README.txt" <<'README'
Installation:
1. Drag "Dialect Voice Input" to the "Applications" folder
2. First launch: right-click → Open → Open (Gatekeeper bypass)
3. The ASR model (~1.7GB) downloads automatically on first launch
4. A microphone icon appears in the menu bar when ready
5. Hold Right Option key to talk, release to transcribe
README
hdiutil create \
-volname "$APP_DISPLAY_NAME" \
-srcfolder "$DMG_TMP" \
-ov \
-format UDZO \
-imagekey zlib-level=9 \
"$DMG_PATH"
rm -rf "$DMG_TMP"
APP_SIZE=$(du -sh "$APP_BUNDLE" | cut -f1)
DMG_SIZE=$(du -sh "$DMG_PATH" | cut -f1)
echo ""
echo "======================================"
echo " Done!"
echo "======================================"
echo ""
echo " App: $APP_BUNDLE ($APP_SIZE)"
echo " DMG: $DMG_PATH ($DMG_SIZE)"
echo ""
echo " 安装说明(发给用户):"
echo " ─────────────────────"
echo " 1. 双击 $DMG_NAME.dmg"
echo " 2. 将「$APP_DISPLAY_NAME」拖入「Applications」文件夹"
echo " 3. 首次打开:右键点击 app → 打开 → 打开"
echo " 或运行:xattr -cr /Applications/$APP_DISPLAY_NAME.app"
echo " 4. 首次启动自动下载 Qwen3-ASR 模型(约 1.9GB,需几分钟)"
echo " 5. 菜单栏出现麦克风图标后即可使用"
echo " 6. 按住右 Option 键说话,松开自动转写输入"
echo ""
echo " 系统要求:"
echo " ─────────"
echo " - macOS 14 (Sonoma) 或更高"
echo " - 约 2GB 磁盘空间(模型 ~1.9GB)"
echo " - 麦克风权限 + 辅助功能权限"
echo " - 无需 Python"
echo ""