#!/usr/bin/env python3 # Regenerates the Windows-only assets: # # python3 scripts/win-assets.py ico -> assets/icon.ico # python3 scripts/win-assets.py spinner -> assets/install-spinner.gif # python3 scripts/win-assets.py -> both # # Source is assets/icon-win.png (1024x1024). Unlike the macOS icon it fills # the canvas with no margin and no drop shadow, which is what Windows expects. # # Needs Pillow (pip install pillow) and, for the spinner, Geist Medium; set # WIN_ASSETS_FONT to its path if it is not in ~/Library/Fonts. # # icon.ico carries every size Windows asks for at 100-200% scaling. 40px and # up are Lanczos downscales of the source; 32px and below are drawn from # scratch (flat red rounded square, white hexagon ring) because a downscaled # glossy icon turns to mush at taskbar size. All entries are 32-bit BGRA with # an alpha channel; the 256px one is PNG-compressed as Vista+ allows. # # install-spinner.gif is Squirrel's whole install UI: shown 1:1 in a # borderless window until the app launches. White background, icon, # one label, one indeterminate bar in the app's primary blue. import io import math import os import struct import sys from PIL import Image, ImageDraw, ImageFilter, ImageFont ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..') ASSETS = os.path.join(ROOT, 'assets') SOURCE = os.path.join(ASSETS, 'icon-win.png') RED = (255, 25, 52) BLUE = (0, 140, 255) # --primary in apps/web/src/index.css, hsla(207, 100%, 50%) WHITE = (255, 255, 255) BACKGROUND = (255, 255, 255) TEXT = (22, 22, 24) TRACK = (224, 224, 224) def source(): im = Image.open(SOURCE).convert('RGBA') if im.size != (1024, 1024): sys.exit(f'{SOURCE} must be 1024x1024, got {im.size}') return im # --- icon.ico --------------------------------------------------------------- ICO_SIZES = [256, 128, 96, 64, 48, 40, 32, 24, 20, 16] def drawn_frame(size): ss = 16 w = size * ss im = Image.new('RGBA', (w, w), (0, 0, 0, 0)) d = ImageDraw.Draw(im) d.rounded_rectangle((0, 0, w - 1, w - 1), radius=0.22 * size * ss, fill=RED + (255,)) stroke = max(2, round(0.10 * size * 2) / 2) * ss radius = (0.38 * size - stroke / ss / 2) * ss c = w / 2 pts = [ (c + radius * math.sin(math.radians(60 * i)), c - radius * math.cos(math.radians(60 * i))) for i in range(6) ] d.line(pts + [pts[0], pts[1]], fill=WHITE + (255,), width=int(stroke), joint='curve') for x, y in pts: d.ellipse((x - stroke / 2, y - stroke / 2, x + stroke / 2, y + stroke / 2), fill=WHITE + (255,)) return im.resize((size, size), Image.LANCZOS) def scaled_frame(src, size): im = src.resize((size, size), Image.LANCZOS) if size <= 128: im = im.filter(ImageFilter.UnsharpMask(radius=0.6, percent=50, threshold=0)) return im def dib(im): w, h = im.size px = im.load() rows = b''.join( bytes(b for x in range(w) for b in (px[x, y][2], px[x, y][1], px[x, y][0], px[x, y][3])) for y in range(h - 1, -1, -1) ) stride = ((w + 31) // 32) * 4 mask = bytes(stride * h) # AND mask all-visible; alpha carries transparency header = struct.pack('= 6: d.rounded_rectangle((a, ty, b, ty + track_h), radius=2, fill=BLUE) frames.append(im) # One shared palette so nothing flickers between frames, taken from a # mid-loop frame where the bar is fully on the track so its colour is kept. palette = frames[n // 2].quantize(colors=128, method=Image.Quantize.MEDIANCUT) quantized = [f.quantize(palette=palette, dither=Image.Dither.NONE) for f in frames] # Median cut averages the background with the icon's antialiased fringe; # pin the slot every background pixel landed in to the exact colour. for q in quantized: entries = list(q.getpalette()) slot = q.getpixel((0, 0)) entries[slot * 3:slot * 3 + 3] = BACKGROUND q.putpalette(entries) path = os.path.join(ASSETS, 'install-spinner.gif') quantized[0].save( path, save_all=True, append_images=quantized[1:], duration=int(1000 / FPS), loop=0, optimize=False, ) print(f'wrote {os.path.relpath(path, ROOT)}') if __name__ == '__main__': what = sys.argv[1:] or ['ico', 'spinner'] for target in what: {'ico': make_ico, 'spinner': make_spinner}[target]()