Files
rustscreen/scripts/make-icon.py
T
Guillaume AssierandClaude Opus 5.5 0c24b2b5d2
CI / Formatting, tests and builds (push) Successful in 3m19s
refactor: code en anglais, rustscreen ouvre l'application de bureau
Code en anglais (#83): identifiants, noms de fichiers et de modules,
commentaires, journal (champ event, noms d'événements anglais),
messages d'erreur, commandes Tauri, types générés, clés de traduction,
sorties de rustscreen-cli, scripts, Nix et CI. Les textes affichés
passent toujours par locales/ (français et anglais); la documentation et
les commits restent en français. AGENTS.md porte la règle.

Ce qui est déjà écrit chez l'utilisateur se relit: anciens noms de
champs des réglages (alias serde), reglages.json à défaut de
settings.json, anciennes clés localStorage dont l'identifiant d'appareil,
jeton de restauration du portail, anciennes options de la ligne de
commande, ancien argument du démarrage automatique.

rustscreen ouvre l'application de bureau (#84): la ligne de commande
devient rustscreen-cli. Le paquet Nix par défaut construit l'application
(interface pnpm, Tauri avec WebKitGTK et PipeWire, icône de barre
système), avec rustscreen-cli et le viewer.

Début du jalon 0.6.0, pas encore essayé en vrai: miroir du viewer
(#29), barres qui s'effacent en fenêtre et en plein écran (#31, #81),
confirmation avant de quitter pendant un partage (#43), démarrage
automatique caché dans la barre système et fichier .desktop réparé au
lancement (#32).

Closes #83, #84
Refs #29, #31, #32, #43, #81

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 11:11:34 +01:00

113 lines
3.5 KiB
Python
Executable File

#!/usr/bin/env python3
"""Generates the rustscreen icon as a PNG, with no graphics dependency.
An AppImage icon must exist before packaging, and the build machine has
neither ImageMagick nor rsvg. Drawing the image here, in pure Python, avoids
adding a system tool to the pipeline for a 256x256 file.
./scripts/make-icon.py assets/rustscreen-256.png
"""
import math
import struct
import sys
import zlib
SIZE = 256
BACKGROUND = (14, 17, 22)
SCREEN = (79, 156, 249)
WAVE = (63, 185, 80)
def blend(a, b, t):
return tuple(round(x + (y - x) * t) for x, y in zip(a, b))
def in_rounded_rect(x, y, x0, y0, x1, y1, radius):
if not (x0 <= x <= x1 and y0 <= y <= y1):
return False
# The four corners are the only places where the radius matters.
for cx, cy in ((x0 + radius, y0 + radius), (x1 - radius, y0 + radius),
(x0 + radius, y1 - radius), (x1 - radius, y1 - radius)):
if (x < x0 + radius or x > x1 - radius) and (y < y0 + radius or y > y1 - radius):
if math.hypot(x - cx, y - cy) > radius:
return False
return True
def arc(x, y, cx, cy, radius, thickness, angle_min, angle_max):
d = math.hypot(x - cx, y - cy)
if abs(d - radius) > thickness / 2:
return False
angle = math.degrees(math.atan2(y - cy, x - cx))
return angle_min <= angle <= angle_max
def draw():
"""Renders the image row by row: rounded background, screen, broadcast waves."""
pixels = []
for y in range(SIZE):
row = []
for x in range(SIZE):
if not in_rounded_rect(x, y, 2, 2, SIZE - 3, SIZE - 3, 44):
row.append((0, 0, 0, 0))
continue
color = BACKGROUND
# Screen: light frame, dark inside, like a shared window.
if in_rounded_rect(x, y, 44, 58, 168, 158, 10):
inside = in_rounded_rect(x, y, 52, 66, 160, 150, 6)
color = BACKGROUND if inside else SCREEN
if inside and y < 96:
# A lighter band at the top of the screen, to suggest an
# image rather than an empty rectangle.
color = blend(SCREEN, BACKGROUND, 0.55)
# Screen stand.
if in_rounded_rect(x, y, 96, 158, 116, 178, 3):
color = SCREEN
if in_rounded_rect(x, y, 74, 178, 138, 190, 5):
color = SCREEN
# Broadcast waves, to the right of the screen.
for radius in (20, 34):
if arc(x, y, 168, 108, radius, 7, -62, 62):
color = WAVE
row.append((*color, 255))
pixels.append(row)
return pixels
def write_png(path, pixels):
raw = bytearray()
for row in pixels:
raw.append(0) # filter 0: none
for r, g, b, a in row:
raw += bytes((r, g, b, a))
def chunk(name, data):
content = name + data
return (
struct.pack(">I", len(data))
+ content
+ struct.pack(">I", zlib.crc32(content) & 0xFFFFFFFF)
)
header = struct.pack(">IIBBBBB", SIZE, SIZE, 8, 6, 0, 0, 0)
png = (
b"\x89PNG\r\n\x1a\n"
+ chunk(b"IHDR", header)
+ chunk(b"IDAT", zlib.compress(bytes(raw), 9))
+ chunk(b"IEND", b"")
)
with open(path, "wb") as f:
f.write(png)
if __name__ == "__main__":
output = sys.argv[1] if len(sys.argv) > 1 else "assets/rustscreen-256.png"
write_png(output, draw())
print(f"icon written: {output}")