Upload fastsearch-tauri/create_icons.py
Browse files- fastsearch-tauri/create_icons.py +101 -0
fastsearch-tauri/create_icons.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Create minimal placeholder icon files for Tauri Windows build.
|
| 3 |
+
|
| 4 |
+
Tauri v2's tauri-build requires icons/ directory with at least icon.ico
|
| 5 |
+
for Windows resource embedding. Run this script before building.
|
| 6 |
+
|
| 7 |
+
Usage:
|
| 8 |
+
cd fastsearch-tauri
|
| 9 |
+
python create_icons.py
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import struct
|
| 13 |
+
import os
|
| 14 |
+
import zlib
|
| 15 |
+
|
| 16 |
+
def create_png(width, height):
|
| 17 |
+
"""Create a minimal valid transparent PNG."""
|
| 18 |
+
# IHDR
|
| 19 |
+
ihdr_data = struct.pack('>IIBBBBB', width, height, 8, 6, 0, 0, 0)
|
| 20 |
+
ihdr_crc = struct.pack('>I', zlib.crc32(b'IHDR' + ihdr_data) & 0xffffffff)
|
| 21 |
+
ihdr = struct.pack('>I', 13) + b'IHDR' + ihdr_data + ihdr_crc
|
| 22 |
+
|
| 23 |
+
# IDAT - transparent black RGBA
|
| 24 |
+
raw = b''
|
| 25 |
+
for _ in range(height):
|
| 26 |
+
raw += b'\x00' # Filter: None
|
| 27 |
+
raw += b'\x00\x00\x00\x00' * width # Transparent RGBA
|
| 28 |
+
|
| 29 |
+
compressed = zlib.compress(raw)
|
| 30 |
+
idat_crc = struct.pack('>I', zlib.crc32(b'IDAT' + compressed) & 0xffffffff)
|
| 31 |
+
idat = struct.pack('>I', len(compressed)) + b'IDAT' + compressed + idat_crc
|
| 32 |
+
|
| 33 |
+
# IEND
|
| 34 |
+
iend_crc = struct.pack('>I', zlib.crc32(b'IEND') & 0xffffffff)
|
| 35 |
+
iend = struct.pack('>I', 0) + b'IEND' + iend_crc
|
| 36 |
+
|
| 37 |
+
return b'\x89PNG\r\n\x1a\n' + ihdr + idat + iend
|
| 38 |
+
|
| 39 |
+
def create_ico(width=32, height=32):
|
| 40 |
+
"""Create a minimal valid transparent ICO file."""
|
| 41 |
+
# ICO header
|
| 42 |
+
header = struct.pack('<HHH', 0, 1, 1)
|
| 43 |
+
|
| 44 |
+
# BITMAPINFOHEADER (40 bytes)
|
| 45 |
+
infoheader = struct.pack('<IiiHHIIiiII', 40, width, height * 2, 1, 32, 0, 0, 0, 0, 0, 0)
|
| 46 |
+
|
| 47 |
+
# XOR mask (BGRA pixels) + AND mask (1bpp)
|
| 48 |
+
xor_pixels = b'\x00\x00\x00\x00' * (width * height)
|
| 49 |
+
|
| 50 |
+
row_bytes = (width + 7) // 8
|
| 51 |
+
pad = (4 - (row_bytes % 4)) % 4
|
| 52 |
+
and_mask = b''
|
| 53 |
+
for _ in range(height):
|
| 54 |
+
and_mask += b'\x00' * row_bytes + b'\x00' * pad
|
| 55 |
+
|
| 56 |
+
img_data = infoheader + xor_pixels + and_mask
|
| 57 |
+
img_size = len(img_data)
|
| 58 |
+
|
| 59 |
+
# ICONDIRENTRY
|
| 60 |
+
entry = struct.pack('<BBBBHHII',
|
| 61 |
+
width if width < 256 else 0,
|
| 62 |
+
height if height < 256 else 0,
|
| 63 |
+
0, 0, 1, 32,
|
| 64 |
+
img_size,
|
| 65 |
+
22 # Offset = header(6) + entry(16)
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
return header + entry + img_data
|
| 69 |
+
|
| 70 |
+
def main():
|
| 71 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 72 |
+
out_dir = os.path.join(script_dir, 'src-tauri', 'icons')
|
| 73 |
+
os.makedirs(out_dir, exist_ok=True)
|
| 74 |
+
|
| 75 |
+
# Create PNG icons
|
| 76 |
+
for size in [32, 128]:
|
| 77 |
+
data = create_png(size, size)
|
| 78 |
+
path = os.path.join(out_dir, f'{size}x{size}.png')
|
| 79 |
+
with open(path, 'wb') as f:
|
| 80 |
+
f.write(data)
|
| 81 |
+
print(f"Created {path}")
|
| 82 |
+
|
| 83 |
+
# Create 128@2x (256x256)
|
| 84 |
+
data = create_png(256, 256)
|
| 85 |
+
path = os.path.join(out_dir, '128x128@2x.png')
|
| 86 |
+
with open(path, 'wb') as f:
|
| 87 |
+
f.write(data)
|
| 88 |
+
print(f"Created {path}")
|
| 89 |
+
|
| 90 |
+
# Create ICO
|
| 91 |
+
data = create_ico(32, 32)
|
| 92 |
+
path = os.path.join(out_dir, 'icon.ico')
|
| 93 |
+
with open(path, 'wb') as f:
|
| 94 |
+
f.write(data)
|
| 95 |
+
print(f"Created {path}")
|
| 96 |
+
|
| 97 |
+
print(f"\nAll placeholder icons created in {out_dir}")
|
| 98 |
+
print("Replace these with real icons for production.")
|
| 99 |
+
|
| 100 |
+
if __name__ == '__main__':
|
| 101 |
+
main()
|