|
|
|
|
@ -0,0 +1,106 @@
|
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
"""
|
|
|
|
|
简化版macOS应用构建脚本
|
|
|
|
|
专注于正确打包UI.png和图标文件
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
import subprocess
|
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
|
|
def run_command(cmd, cwd=None):
|
|
|
|
|
"""运行命令"""
|
|
|
|
|
print(f"运行: {' '.join(cmd)}")
|
|
|
|
|
result = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
|
|
|
|
|
if result.returncode != 0:
|
|
|
|
|
print(f"错误: {result.stderr}")
|
|
|
|
|
return False
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def build_app():
|
|
|
|
|
"""构建应用"""
|
|
|
|
|
print("=== 开始构建macOS应用 ===")
|
|
|
|
|
|
|
|
|
|
# 清理旧的构建
|
|
|
|
|
print("清理旧构建...")
|
|
|
|
|
for dir_name in ['build', 'dist']:
|
|
|
|
|
if os.path.exists(dir_name):
|
|
|
|
|
shutil.rmtree(dir_name)
|
|
|
|
|
|
|
|
|
|
# PyInstaller命令
|
|
|
|
|
cmd = [
|
|
|
|
|
'pyinstaller',
|
|
|
|
|
'--name', 'MagicWord',
|
|
|
|
|
'--windowed', # 无控制台
|
|
|
|
|
'--icon', 'resources/icons/app_icon_256X256.png', # 256x256图标
|
|
|
|
|
'--add-data', 'src/main.py:.', # 主程序
|
|
|
|
|
'--add-data', 'src:src', # 整个src目录
|
|
|
|
|
'--add-data', 'resources:resources', # 资源目录
|
|
|
|
|
'--add-data', 'src/ui/UI.png:ui', # UI.png图片
|
|
|
|
|
'--add-data', 'src/ui/114514.png:ui', # 其他UI图片
|
|
|
|
|
'--hidden-import', 'PyQt5',
|
|
|
|
|
'--hidden-import', 'PyQt5.QtCore',
|
|
|
|
|
'--hidden-import', 'PyQt5.QtGui',
|
|
|
|
|
'--hidden-import', 'PyQt5.QtWidgets',
|
|
|
|
|
'--hidden-import', 'requests',
|
|
|
|
|
'--hidden-import', 'PIL',
|
|
|
|
|
'--hidden-import', 'PIL.Image',
|
|
|
|
|
'--target-architecture', 'arm64',
|
|
|
|
|
'--noconfirm',
|
|
|
|
|
'--clean',
|
|
|
|
|
'src/main.py'
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
if not run_command(cmd):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
print("=== 构建完成 ===")
|
|
|
|
|
print(f"应用位置: dist/MagicWord.app")
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def verify_resources():
|
|
|
|
|
"""验证资源文件是否正确打包"""
|
|
|
|
|
print("\n=== 验证资源文件 ===")
|
|
|
|
|
|
|
|
|
|
app_path = "dist/MagicWord.app"
|
|
|
|
|
|
|
|
|
|
# 检查UI.png
|
|
|
|
|
ui_path = os.path.join(app_path, "Contents", "Resources", "ui", "UI.png")
|
|
|
|
|
if os.path.exists(ui_path):
|
|
|
|
|
size = os.path.getsize(ui_path)
|
|
|
|
|
print(f"✅ UI.png 已打包: {size} bytes")
|
|
|
|
|
else:
|
|
|
|
|
print("❌ UI.png 未找到")
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
# 检查图标
|
|
|
|
|
icon_path = os.path.join(app_path, "Contents", "Resources", "resources", "icons", "app_icon_256X256.png")
|
|
|
|
|
if os.path.exists(icon_path):
|
|
|
|
|
size = os.path.getsize(icon_path)
|
|
|
|
|
print(f"✅ app_icon_256X256.png 已打包: {size} bytes")
|
|
|
|
|
else:
|
|
|
|
|
print("❌ app_icon_256X256.png 未找到")
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
# 检查应用图标
|
|
|
|
|
app_icon_path = os.path.join(app_path, "Contents", "Resources", "generated-*.icns")
|
|
|
|
|
import glob
|
|
|
|
|
icon_files = glob.glob(app_icon_path)
|
|
|
|
|
if icon_files:
|
|
|
|
|
print(f"✅ 应用图标已生成: {len(icon_files)} 个")
|
|
|
|
|
else:
|
|
|
|
|
print("⚠️ 应用图标未生成")
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
if build_app():
|
|
|
|
|
verify_resources()
|
|
|
|
|
print("\n🎉 macOS应用构建成功!")
|
|
|
|
|
print("应用位置: dist/MagicWord.app")
|
|
|
|
|
print("可以使用: open dist/MagicWord.app 来测试运行")
|
|
|
|
|
else:
|
|
|
|
|
print("\n❌ 构建失败")
|
|
|
|
|
sys.exit(1)
|