mirror of
https://github.com/MarkusZoppelt/stahl.git
synced 2026-11-22 12:22:57 +01:00
- With the lock on in Settings, the app opens on the vault, and Face ID (or the passcode) turns it open with a knock. Coming back from the background asks again; a cancelled prompt leaves the door with a way to retry. - 120 Hz on ProMotion iPhones, which hold an app to 60 Hz unless it asks. - A swipe in from the left edge goes back. - A light tick for each day a finger crosses on a chart, each slice of the donut, and the point where a pull refreshes; a knock when it does. - Dark and tinted app icons, rendered from the door shader with the rest.
83 lines
3.5 KiB
Shell
Executable file
83 lines
3.5 KiB
Shell
Executable file
#!/usr/bin/env bash
|
|
# Regenerates every icon from the steel door: the app's (assets/icons), the mark it draws inside
|
|
# (assets/door.png), the README's logo and the landing page's. Run it after changing site/door.js:
|
|
#
|
|
# site/render-icons.sh
|
|
#
|
|
# Node, Playwright's Chromium and Pillow come from nixpkgs and npm, in a temporary directory.
|
|
set -euo pipefail
|
|
|
|
root=$(cd "$(dirname "$0")/.." && pwd)
|
|
work=$(mktemp -d /tmp/stahl-icons.XXXX)
|
|
trap 'rm -rf "$work"; kill "$server" 2>/dev/null || true' EXIT
|
|
|
|
# The page's shader, served on loopback as the page would be.
|
|
nix shell nixpkgs#python3 --command python3 -m http.server 8199 --bind 127.0.0.1 -d "$root/site" >/dev/null 2>&1 &
|
|
server=$!
|
|
sleep 1
|
|
|
|
cp "$root/site/render-icons.mjs" "$work/"
|
|
(cd "$work" && nix shell nixpkgs#nodejs --command bash -c \
|
|
'npm init -y >/dev/null && npm install --silent playwright >/dev/null && npx playwright install chromium >/dev/null && node render-icons.mjs http://127.0.0.1:8199/ door.rgba')
|
|
|
|
nix-shell -p "python3.withPackages (p: [ p.pillow ])" --run "python3 -I - '$work' '$root'" <<'EOF'
|
|
import math, sys
|
|
from pathlib import Path
|
|
from PIL import Image, ImageChops
|
|
|
|
work, root = Path(sys.argv[1]), Path(sys.argv[2])
|
|
size = 1024
|
|
door = Image.frombytes("RGBA", (size, size), (work / "door.rgba").read_bytes())
|
|
|
|
# Nothing outside the rim: the page draws a soft shadow there, which an icon must not carry.
|
|
edge = size / 2 - 2
|
|
rim = Image.new("L", (size, size))
|
|
rim.putdata([
|
|
max(0, min(255, round((edge - math.hypot(x + 0.5 - size / 2, y + 0.5 - size / 2) + 0.5) * 255)))
|
|
for y in range(size) for x in range(size)
|
|
])
|
|
door.putalpha(ImageChops.multiply(door.getchannel("A"), rim))
|
|
|
|
def at(px):
|
|
return door.resize((px, px), Image.LANCZOS)
|
|
|
|
icons = root / "assets/icons"
|
|
at(512).save(icons / "icon.png", optimize=True)
|
|
at(32).save(icons / "32x32.png", optimize=True)
|
|
at(64).save(icons / "64x64.png", optimize=True)
|
|
at(128).save(icons / "128x128.png", optimize=True)
|
|
at(256).save(icons / "128x128@2x.png", optimize=True)
|
|
door.save(icons / "icon.ico", sizes=[(16, 16), (24, 24), (32, 32), (48, 48), (64, 64), (256, 256)])
|
|
|
|
iconset = work / "icon.iconset"
|
|
iconset.mkdir()
|
|
for px in (16, 32, 128, 256, 512):
|
|
at(px).save(iconset / f"icon_{px}x{px}.png")
|
|
at(px * 2).save(iconset / f"icon_{px}x{px}@2x.png")
|
|
|
|
# iOS rounds an icon's corners itself and wants no transparency: the door on the steel wall.
|
|
wall = Image.new("RGBA", (size, size), (10, 15, 19, 255))
|
|
inset = round(size * 0.84)
|
|
wall.alpha_composite(at(inset), ((size - inset) // 2, (size - inset) // 2))
|
|
ios = root / "ios/Shell/Assets.xcassets/AppIcon.appiconset"
|
|
ios.mkdir(parents=True, exist_ok=True)
|
|
wall.convert("RGB").save(ios / "icon.png", optimize=True)
|
|
# Its dark appearance: the door alone, which iOS sets on its own dark tile. Tinted: the same in
|
|
# grey, which iOS colours with the Home Screen's tint.
|
|
alone = Image.new("RGBA", (size, size), (0, 0, 0, 0))
|
|
alone.alpha_composite(at(inset), ((size - inset) // 2, (size - inset) // 2))
|
|
alone.save(ios / "icon-dark.png", optimize=True)
|
|
alone.convert("LA").save(ios / "icon-tinted.png", optimize=True)
|
|
|
|
# The app draws the door at up to 168 points, so 2x that with room to spare, mipmapped by Rune.
|
|
at(512).save(root / "assets/door.png", optimize=True)
|
|
at(256).save(root / "site/icon.png", optimize=True)
|
|
at(64).save(root / "site/favicon.png", optimize=True)
|
|
at(180).save(root / "site/apple-touch-icon.png", optimize=True)
|
|
EOF
|
|
|
|
if command -v iconutil >/dev/null; then
|
|
iconutil -c icns "$work/icon.iconset" -o "$root/assets/icons/icon.icns"
|
|
else
|
|
echo "iconutil is macOS only: assets/icons/icon.icns is unchanged" >&2
|
|
fi
|