Files
FunConnect/scripts/generate-icons.sh

85 lines
3.3 KiB
Bash
Raw Normal View History

#!/bin/bash
# FunMC 图标生成脚本 (Linux/macOS)
# 需要安装 ImageMagick 或使用 cargo tauri icon 命令
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(dirname "$SCRIPT_DIR")"
ICONS_DIR="$ROOT_DIR/client/icons"
SVG_PATH="$ICONS_DIR/icon.svg"
echo -e "\033[33mFunMC 图标生成脚本\033[0m"
echo "==================="
# 检查 SVG 源文件
if [ ! -f "$SVG_PATH" ]; then
echo -e "\033[31m错误: 未找到 SVG 源文件: $SVG_PATH\033[0m"
exit 1
fi
# 方法 1: 使用 cargo tauri icon (推荐)
echo -e "\n\033[36m尝试使用 cargo tauri icon...\033[0m"
cd "$ROOT_DIR/client"
if cargo tauri icon "$SVG_PATH" 2>/dev/null; then
echo -e "\033[32m图标生成成功!\033[0m"
else
echo -e "\033[33mcargo tauri icon 失败,尝试使用 ImageMagick...\033[0m"
# 方法 2: 使用 ImageMagick
if command -v convert &> /dev/null; then
echo "使用 ImageMagick 生成图标..."
mkdir -p "$ICONS_DIR"
# PNG 图标
convert -background none "$SVG_PATH" -resize 32x32 "$ICONS_DIR/32x32.png"
convert -background none "$SVG_PATH" -resize 128x128 "$ICONS_DIR/128x128.png"
convert -background none "$SVG_PATH" -resize 256x256 "$ICONS_DIR/128x128@2x.png"
# ICO (Windows)
convert -background none "$SVG_PATH" -resize 256x256 \
-define icon:auto-resize=256,128,96,64,48,32,16 \
"$ICONS_DIR/icon.ico"
# ICNS (macOS) - 需要 png2icns 或 iconutil
if command -v png2icns &> /dev/null; then
convert -background none "$SVG_PATH" -resize 1024x1024 "$ICONS_DIR/icon_1024.png"
png2icns "$ICONS_DIR/icon.icns" "$ICONS_DIR/icon_1024.png"
rm "$ICONS_DIR/icon_1024.png"
elif command -v iconutil &> /dev/null; then
ICONSET_DIR="$ICONS_DIR/icon.iconset"
mkdir -p "$ICONSET_DIR"
for size in 16 32 64 128 256 512 1024; do
convert -background none "$SVG_PATH" -resize ${size}x${size} "$ICONSET_DIR/icon_${size}x${size}.png"
done
# 生成 @2x 版本
convert -background none "$SVG_PATH" -resize 32x32 "$ICONSET_DIR/icon_16x16@2x.png"
convert -background none "$SVG_PATH" -resize 64x64 "$ICONSET_DIR/icon_32x32@2x.png"
convert -background none "$SVG_PATH" -resize 256x256 "$ICONSET_DIR/icon_128x128@2x.png"
convert -background none "$SVG_PATH" -resize 512x512 "$ICONSET_DIR/icon_256x256@2x.png"
convert -background none "$SVG_PATH" -resize 1024x1024 "$ICONSET_DIR/icon_512x512@2x.png"
iconutil -c icns "$ICONSET_DIR"
rm -rf "$ICONSET_DIR"
else
echo -e "\033[33m警告: 无法生成 .icns 文件 (需要 png2icns 或 iconutil)\033[0m"
fi
echo -e "\033[32m图标生成完成!\033[0m"
else
echo -e "\033[31m错误: 未找到 ImageMagick\033[0m"
echo "请安装 ImageMagick 后重试:"
echo " Ubuntu/Debian: sudo apt install imagemagick"
echo " macOS: brew install imagemagick"
echo " 或者使用: cargo install tauri-cli && cargo tauri icon"
exit 1
fi
fi
echo -e "\n图标目录: $ICONS_DIR"
ls -la "$ICONS_DIR"