60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
# build.py
|
|
import os
|
|
import shutil
|
|
import sys
|
|
import subprocess
|
|
from PIL import Image, ImageDraw
|
|
|
|
_IS_WINDOWS = sys.platform == "win32"
|
|
_PLATFORM_TAG = "windows" if _IS_WINDOWS else "linux"
|
|
|
|
|
|
def _make_icon_image(size: int) -> Image.Image:
|
|
"""Create a green-dot icon at the given size."""
|
|
img = Image.new("RGBA", (size, size), (0, 0, 0, 0))
|
|
d = ImageDraw.Draw(img)
|
|
margin = max(1, size // 16)
|
|
d.ellipse([margin, margin, size - margin, size - margin], fill=(40, 200, 80))
|
|
return img
|
|
|
|
|
|
def generate_icon():
|
|
"""Generate platform-appropriate icon files."""
|
|
sizes = [16, 32, 48, 256]
|
|
frames = [_make_icon_image(s) for s in sizes]
|
|
if _IS_WINDOWS:
|
|
frames[0].save("icon.ico", format="ICO", sizes=[(s, s) for s in sizes],
|
|
append_images=frames[1:])
|
|
print("icon.ico generated.")
|
|
else:
|
|
frames[-1].save("icon.png", format="PNG")
|
|
print("icon.png generated.")
|
|
|
|
|
|
def build():
|
|
generate_icon()
|
|
subprocess.run([sys.executable, "-m", "PyInstaller", "whisper-dictation.spec",
|
|
"--noconfirm"], check=True)
|
|
|
|
dist_dir = os.path.join("dist", "whisper-dictation-" + _PLATFORM_TAG)
|
|
for fname in ["config.json", "vocabulary.json"]:
|
|
dest = os.path.join(dist_dir, fname)
|
|
if not os.path.exists(dest):
|
|
shutil.copy(fname, dest)
|
|
print(f"Copied {fname} -> {dist_dir}/")
|
|
else:
|
|
print(f"Skipped {fname} (already exists in dist — preserving user edits)")
|
|
|
|
# Copy icon.png into dist for Linux .desktop files
|
|
if not _IS_WINDOWS:
|
|
icon_dest = os.path.join(dist_dir, "icon.png")
|
|
if not os.path.exists(icon_dest):
|
|
shutil.copy("icon.png", icon_dest)
|
|
print(f"Copied icon.png -> {dist_dir}/")
|
|
|
|
print(f"\nBuild complete: {dist_dir}/")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
build()
|