-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
73 lines (60 loc) · 2.01 KB
/
build.py
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
import os
import platform
from pathlib import Path
import PyInstaller.__main__
import cairosvg
def convert_svg_icons():
"""将SVG图标转换为各平台所需格式"""
svg_path = Path("resources/icon.svg")
if platform.system() == "Darwin":
# macOS需要ICNS
sizes = [16, 32, 64, 128, 256, 512, 1024]
png_files = []
for size in sizes:
output_file = f"icon_{size}x{size}.png"
cairosvg.svg2png(
url=str(svg_path),
write_to=output_file,
output_width=size,
output_height=size
)
png_files.append(output_file)
os.makedirs("icon.iconset", exist_ok=True)
for size, png_file in zip(sizes, png_files):
os.rename(png_file, f"icon.iconset/icon_{size}x{size}.png")
os.system("iconutil -c icns icon.iconset")
os.system("rm -rf icon.iconset")
def build_app():
"""构建WatchCat应用程序"""
# 转换图标
convert_svg_icons()
# 基础配置
app_name = "WatchCat"
entry_point = "src/main.py"
icon_file = "icon.icns"
# PyInstaller 参数
args = [
entry_point,
"--name=%s" % app_name,
"--windowed",
"--clean",
f"--icon={icon_file}",
"--add-data=resources:resources",
"--collect-submodules=src",
"--noupx", # 禁用UPX压缩以提升启动速度
"--noconfirm", # 自动覆盖输出目录
]
# macOS 特定配置
if platform.system() == "Darwin":
args.extend([
"--osx-bundle-identifier=com.cs-magic.watchcat",
"--codesign-identity=", # 空字符串表示跳过签名
"--osx-entitlements-file=", # 空字符串表示不使用授权文件
])
# 运行 PyInstaller
PyInstaller.__main__.run(args)
# 清理临时文件
if os.path.exists(icon_file):
os.remove(icon_file)
if __name__ == "__main__":
build_app()