Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
App icons for the iPhone: eight alternate icons plus a hand-made Halloween one, drawn by scripts/app-icons.mjs (iOS sets and previews, no Android files in 1.4.3)
Duarte Santos0060b6949c7e
diff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Halloween.appiconset/Contents.json b/frontend/ios/App/App/Assets.xcassets/AppIcon-Halloween.appiconset/Contents.jsonnew file mode 100644index 000000000..27a4f3814--- /dev/null+++ b/frontend/ios/App/App/Assets.xcassets/AppIcon-Halloween.appiconset/Contents.json@@ -0,0 +1,14 @@+{+ "images" : [+ {+ "filename" : "icon-1024.png",+ "idiom" : "universal",+ "platform" : "ios",+ "size" : "1024x1024"+ }+ ],+ "info" : {+ "author" : "xcode",+ "version" : 1+ }+}diff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Halloween.appiconset/icon-1024.png b/frontend/ios/App/App/Assets.xcassets/AppIcon-Halloween.appiconset/icon-1024.pngnew file mode 100644index 000000000..713b3b957Binary files /dev/null and b/frontend/ios/App/App/Assets.xcassets/AppIcon-Halloween.appiconset/icon-1024.png differdiff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Light.appiconset/Contents.json b/frontend/ios/App/App/Assets.xcassets/AppIcon-Light.appiconset/Contents.jsonnew file mode 100644index 000000000..27a4f3814--- /dev/null+++ b/frontend/ios/App/App/Assets.xcassets/AppIcon-Light.appiconset/Contents.json@@ -0,0 +1,14 @@+{+ "images" : [+ {+ "filename" : "icon-1024.png",+ "idiom" : "universal",+ "platform" : "ios",+ "size" : "1024x1024"+ }+ ],+ "info" : {+ "author" : "xcode",+ "version" : 1+ }+}diff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Light.appiconset/icon-1024.png b/frontend/ios/App/App/Assets.xcassets/AppIcon-Light.appiconset/icon-1024.pngnew file mode 100644index 000000000..dfa5f2a13Binary files /dev/null and b/frontend/ios/App/App/Assets.xcassets/AppIcon-Light.appiconset/icon-1024.png differdiff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Mono.appiconset/Contents.json b/frontend/ios/App/App/Assets.xcassets/AppIcon-Mono.appiconset/Contents.jsonnew file mode 100644index 000000000..27a4f3814--- /dev/null+++ b/frontend/ios/App/App/Assets.xcassets/AppIcon-Mono.appiconset/Contents.json@@ -0,0 +1,14 @@+{+ "images" : [+ {+ "filename" : "icon-1024.png",+ "idiom" : "universal",+ "platform" : "ios",+ "size" : "1024x1024"+ }+ ],+ "info" : {+ "author" : "xcode",+ "version" : 1+ }+}diff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Mono.appiconset/icon-1024.png b/frontend/ios/App/App/Assets.xcassets/AppIcon-Mono.appiconset/icon-1024.pngnew file mode 100644index 000000000..c72de5283Binary files /dev/null and b/frontend/ios/App/App/Assets.xcassets/AppIcon-Mono.appiconset/icon-1024.png differdiff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Neon.appiconset/Contents.json b/frontend/ios/App/App/Assets.xcassets/AppIcon-Neon.appiconset/Contents.jsonnew file mode 100644index 000000000..27a4f3814--- /dev/null+++ b/frontend/ios/App/App/Assets.xcassets/AppIcon-Neon.appiconset/Contents.json@@ -0,0 +1,14 @@+{+ "images" : [+ {+ "filename" : "icon-1024.png",+ "idiom" : "universal",+ "platform" : "ios",+ "size" : "1024x1024"+ }+ ],+ "info" : {+ "author" : "xcode",+ "version" : 1+ }+}diff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Neon.appiconset/icon-1024.png b/frontend/ios/App/App/Assets.xcassets/AppIcon-Neon.appiconset/icon-1024.pngnew file mode 100644index 000000000..3d0b09cefBinary files /dev/null and b/frontend/ios/App/App/Assets.xcassets/AppIcon-Neon.appiconset/icon-1024.png differdiff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Orange.appiconset/Contents.json b/frontend/ios/App/App/Assets.xcassets/AppIcon-Orange.appiconset/Contents.jsonnew file mode 100644index 000000000..27a4f3814--- /dev/null+++ b/frontend/ios/App/App/Assets.xcassets/AppIcon-Orange.appiconset/Contents.json@@ -0,0 +1,14 @@+{+ "images" : [+ {+ "filename" : "icon-1024.png",+ "idiom" : "universal",+ "platform" : "ios",+ "size" : "1024x1024"+ }+ ],+ "info" : {+ "author" : "xcode",+ "version" : 1+ }+}diff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Orange.appiconset/icon-1024.png b/frontend/ios/App/App/Assets.xcassets/AppIcon-Orange.appiconset/icon-1024.pngnew file mode 100644index 000000000..93ff7794cBinary files /dev/null and b/frontend/ios/App/App/Assets.xcassets/AppIcon-Orange.appiconset/icon-1024.png differdiff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Pink.appiconset/Contents.json b/frontend/ios/App/App/Assets.xcassets/AppIcon-Pink.appiconset/Contents.jsonnew file mode 100644index 000000000..27a4f3814--- /dev/null+++ b/frontend/ios/App/App/Assets.xcassets/AppIcon-Pink.appiconset/Contents.json@@ -0,0 +1,14 @@+{+ "images" : [+ {+ "filename" : "icon-1024.png",+ "idiom" : "universal",+ "platform" : "ios",+ "size" : "1024x1024"+ }+ ],+ "info" : {+ "author" : "xcode",+ "version" : 1+ }+}diff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Pink.appiconset/icon-1024.png b/frontend/ios/App/App/Assets.xcassets/AppIcon-Pink.appiconset/icon-1024.pngnew file mode 100644index 000000000..d8b1458a4Binary files /dev/null and b/frontend/ios/App/App/Assets.xcassets/AppIcon-Pink.appiconset/icon-1024.png differdiff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Sky.appiconset/Contents.json b/frontend/ios/App/App/Assets.xcassets/AppIcon-Sky.appiconset/Contents.jsonnew file mode 100644index 000000000..27a4f3814--- /dev/null+++ b/frontend/ios/App/App/Assets.xcassets/AppIcon-Sky.appiconset/Contents.json@@ -0,0 +1,14 @@+{+ "images" : [+ {+ "filename" : "icon-1024.png",+ "idiom" : "universal",+ "platform" : "ios",+ "size" : "1024x1024"+ }+ ],+ "info" : {+ "author" : "xcode",+ "version" : 1+ }+}diff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Sky.appiconset/icon-1024.png b/frontend/ios/App/App/Assets.xcassets/AppIcon-Sky.appiconset/icon-1024.pngnew file mode 100644index 000000000..9af66adb6Binary files /dev/null and b/frontend/ios/App/App/Assets.xcassets/AppIcon-Sky.appiconset/icon-1024.png differdiff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Violet.appiconset/Contents.json b/frontend/ios/App/App/Assets.xcassets/AppIcon-Violet.appiconset/Contents.jsonnew file mode 100644index 000000000..27a4f3814--- /dev/null+++ b/frontend/ios/App/App/Assets.xcassets/AppIcon-Violet.appiconset/Contents.json@@ -0,0 +1,14 @@+{+ "images" : [+ {+ "filename" : "icon-1024.png",+ "idiom" : "universal",+ "platform" : "ios",+ "size" : "1024x1024"+ }+ ],+ "info" : {+ "author" : "xcode",+ "version" : 1+ }+}diff --git a/frontend/ios/App/App/Assets.xcassets/AppIcon-Violet.appiconset/icon-1024.png b/frontend/ios/App/App/Assets.xcassets/AppIcon-Violet.appiconset/icon-1024.pngnew file mode 100644index 000000000..063aa08b0Binary files /dev/null and b/frontend/ios/App/App/Assets.xcassets/AppIcon-Violet.appiconset/icon-1024.png differdiff --git a/frontend/public/app-icons/default.png b/frontend/public/app-icons/default.pngnew file mode 100644index 000000000..b52f65a46Binary files /dev/null and b/frontend/public/app-icons/default.png differdiff --git a/frontend/public/app-icons/halloween.png b/frontend/public/app-icons/halloween.pngnew file mode 100644index 000000000..9a232b644Binary files /dev/null and b/frontend/public/app-icons/halloween.png differdiff --git a/frontend/public/app-icons/light.png b/frontend/public/app-icons/light.pngnew file mode 100644index 000000000..126c76b56Binary files /dev/null and b/frontend/public/app-icons/light.png differdiff --git a/frontend/public/app-icons/mono.png b/frontend/public/app-icons/mono.pngnew file mode 100644index 000000000..a058dce90Binary files /dev/null and b/frontend/public/app-icons/mono.png differdiff --git a/frontend/public/app-icons/neon.png b/frontend/public/app-icons/neon.pngnew file mode 100644index 000000000..fed49e47fBinary files /dev/null and b/frontend/public/app-icons/neon.png differdiff --git a/frontend/public/app-icons/orange.png b/frontend/public/app-icons/orange.pngnew file mode 100644index 000000000..e4dd1a192Binary files /dev/null and b/frontend/public/app-icons/orange.png differdiff --git a/frontend/public/app-icons/pink.png b/frontend/public/app-icons/pink.pngnew file mode 100644index 000000000..0e325f573Binary files /dev/null and b/frontend/public/app-icons/pink.png differdiff --git a/frontend/public/app-icons/sky.png b/frontend/public/app-icons/sky.pngnew file mode 100644index 000000000..ac14c52b9Binary files /dev/null and b/frontend/public/app-icons/sky.png differdiff --git a/frontend/public/app-icons/violet.png b/frontend/public/app-icons/violet.pngnew file mode 100644index 000000000..62097eeebBinary files /dev/null and b/frontend/public/app-icons/violet.png differdiff --git a/frontend/resources/icons/halloween.svg b/frontend/resources/icons/halloween.svgnew file mode 100644index 000000000..aaa4a0d0d--- /dev/null+++ b/frontend/resources/icons/halloween.svg@@ -0,0 +1,61 @@+<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 512 512">+ <!-- openGym app icon "halloween", drawn by hand (the only one not written by scripts/app-icons.mjs,+ which renders it). The dumbbell is the glyph of resources/icon.svg in pumpkin orange; around+ it a purple night, a crescent moon, a cobweb in the corner and its spider. Only rect, circle,+ line, polyline, polygon and one radialGradient: what the script knows how to draw. -->+ <defs>+ <radialGradient id="night" gradientUnits="userSpaceOnUse" cx="256" cy="300" r="380">+ <stop offset="0" stop-color="#3d1a63"/>+ <stop offset="1" stop-color="#0d0517"/>+ </radialGradient>+ </defs>+ <rect width="512" height="512" fill="url(#night)"/>+ <!-- the moon: a pale disc with the night bitten out of it -->+ <circle cx="112" cy="110" r="50" fill="#f7e8b4"/>+ <circle cx="136" cy="92" r="46" fill="url(#night)"/>+ <g fill="#f7e8b4">+ <circle cx="222" cy="72" r="6"/>+ <circle cx="300" cy="118" r="4"/>+ <circle cx="66" cy="230" r="4"/>+ </g>+ <!-- the cobweb, hung from the top right corner -->+ <g stroke="#b7a2de" stroke-width="7">+ <line x1="512" y1="0" x2="448" y2="159"/>+ <line x1="512" y1="0" x2="390" y2="122"/>+ <line x1="512" y1="0" x2="353" y2="64"/>+ <polyline points="512,54 508,50 505,47 501,47 497,48 492,50 490,45 487,41 484,39 479,38 474,38 474,33 473,28 471,25 467,22 462,20 464,15 465,11 465,7 462,4 458,0"/>+ <polyline points="512,102 505,95 498,89 491,88 483,90 474,95 470,85 465,77 459,73 451,72 440,72 440,61 439,53 435,47 427,42 417,38 422,29 424,21 423,14 417,7 410,0"/>+ <polyline points="512,148 501,137 492,130 482,128 470,131 457,137 450,123 444,112 435,106 423,105 407,105 407,89 406,77 400,68 389,62 375,55 381,42 384,30 382,20 375,11 364,0"/>+ </g>+ <!-- its spider, on a thread, inside the corner iOS rounds off -->+ <line x1="456" y1="132" x2="456" y2="150" stroke="#b7a2de" stroke-width="4"/>+ <g stroke="#ecdfff" stroke-width="4.5">+ <polyline points="449.6,156.4 438.4,148.4 433.6,156.4"/>+ <polyline points="462.4,156.4 473.6,148.4 478.4,156.4"/>+ <polyline points="449.6,161.2 435.2,159.6 430.4,169.2"/>+ <polyline points="462.4,161.2 476.8,159.6 481.6,169.2"/>+ <polyline points="450.4,166 438.4,170.8 436.8,180.4"/>+ <polyline points="461.6,166 473.6,170.8 475.2,180.4"/>+ </g>+ <g fill="#ecdfff">+ <circle cx="456" cy="153.2" r="7.2"/>+ <circle cx="456" cy="166" r="10.4"/>+ </g>+ <!-- the dumbbell, pumpkin orange -->+ <g fill="#ff7a1a">+ <rect x="80" y="242" width="352" height="28"/>+ <rect x="80" y="199" width="36" height="114"/>+ <rect x="131" y="169" width="47" height="174"/>+ <rect x="334" y="169" width="47" height="174"/>+ <rect x="396" y="199" width="36" height="114"/>+ </g>+ <!-- the big plates carved like jack-o'-lanterns: two eyes and a grin each, lit from inside -->+ <g fill="#ffd166">+ <polygon points="136,214 151,214 143.5,198"/>+ <polygon points="158,214 173,214 165.5,198"/>+ <polygon points="136,292 154.5,302 173,292 170,310 164,304 154.5,316 145,304 139,310"/>+ <polygon points="339,214 354,214 346.5,198"/>+ <polygon points="361,214 376,214 368.5,198"/>+ <polygon points="339,292 357.5,302 376,292 373,310 367,304 357.5,316 348,304 342,310"/>+ </g>+</svg>diff --git a/frontend/resources/icons/light.svg b/frontend/resources/icons/light.svgnew file mode 100644index 000000000..8522f3e78--- /dev/null+++ b/frontend/resources/icons/light.svg@@ -0,0 +1,11 @@+<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 512 512">+ <!-- openGym app icon "light", written by scripts/app-icons.mjs (the glyph of resources/icon.svg). -->+ <rect width="512" height="512" fill="#ffffff"/>+ <g fill="#65a30d">+ <rect x="80" y="242" width="352" height="28"/>+ <rect x="80" y="199" width="36" height="114"/>+ <rect x="131" y="169" width="47" height="174"/>+ <rect x="334" y="169" width="47" height="174"/>+ <rect x="396" y="199" width="36" height="114"/>+ </g>+</svg>diff --git a/frontend/resources/icons/mono.svg b/frontend/resources/icons/mono.svgnew file mode 100644index 000000000..7783b52a0--- /dev/null+++ b/frontend/resources/icons/mono.svg@@ -0,0 +1,11 @@+<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 512 512">+ <!-- openGym app icon "mono", written by scripts/app-icons.mjs (the glyph of resources/icon.svg). -->+ <rect width="512" height="512" fill="#0c0e12"/>+ <g fill="#f2f2f7">+ <rect x="80" y="242" width="352" height="28"/>+ <rect x="80" y="199" width="36" height="114"/>+ <rect x="131" y="169" width="47" height="174"/>+ <rect x="334" y="169" width="47" height="174"/>+ <rect x="396" y="199" width="36" height="114"/>+ </g>+</svg>diff --git a/frontend/resources/icons/neon.svg b/frontend/resources/icons/neon.svgnew file mode 100644index 000000000..cd3853510--- /dev/null+++ b/frontend/resources/icons/neon.svg@@ -0,0 +1,11 @@+<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 512 512">+ <!-- openGym app icon "neon", written by scripts/app-icons.mjs (the glyph of resources/icon.svg). -->+ <rect width="512" height="512" fill="#a3e635"/>+ <g fill="#0c0e12">+ <rect x="80" y="242" width="352" height="28"/>+ <rect x="80" y="199" width="36" height="114"/>+ <rect x="131" y="169" width="47" height="174"/>+ <rect x="334" y="169" width="47" height="174"/>+ <rect x="396" y="199" width="36" height="114"/>+ </g>+</svg>diff --git a/frontend/resources/icons/orange.svg b/frontend/resources/icons/orange.svgnew file mode 100644index 000000000..5a6019507--- /dev/null+++ b/frontend/resources/icons/orange.svg@@ -0,0 +1,11 @@+<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 512 512">+ <!-- openGym app icon "orange", written by scripts/app-icons.mjs (the glyph of resources/icon.svg). -->+ <rect width="512" height="512" fill="#ff9f0a"/>+ <g fill="#0c0e12">+ <rect x="80" y="242" width="352" height="28"/>+ <rect x="80" y="199" width="36" height="114"/>+ <rect x="131" y="169" width="47" height="174"/>+ <rect x="334" y="169" width="47" height="174"/>+ <rect x="396" y="199" width="36" height="114"/>+ </g>+</svg>diff --git a/frontend/resources/icons/pink.svg b/frontend/resources/icons/pink.svgnew file mode 100644index 000000000..472d9f01f--- /dev/null+++ b/frontend/resources/icons/pink.svg@@ -0,0 +1,11 @@+<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 512 512">+ <!-- openGym app icon "pink", written by scripts/app-icons.mjs (the glyph of resources/icon.svg). -->+ <rect width="512" height="512" fill="#ff375f"/>+ <g fill="#ffffff">+ <rect x="80" y="242" width="352" height="28"/>+ <rect x="80" y="199" width="36" height="114"/>+ <rect x="131" y="169" width="47" height="174"/>+ <rect x="334" y="169" width="47" height="174"/>+ <rect x="396" y="199" width="36" height="114"/>+ </g>+</svg>diff --git a/frontend/resources/icons/sky.svg b/frontend/resources/icons/sky.svgnew file mode 100644index 000000000..a72335d94--- /dev/null+++ b/frontend/resources/icons/sky.svg@@ -0,0 +1,11 @@+<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 512 512">+ <!-- openGym app icon "sky", written by scripts/app-icons.mjs (the glyph of resources/icon.svg). -->+ <rect width="512" height="512" fill="#0a84ff"/>+ <g fill="#ffffff">+ <rect x="80" y="242" width="352" height="28"/>+ <rect x="80" y="199" width="36" height="114"/>+ <rect x="131" y="169" width="47" height="174"/>+ <rect x="334" y="169" width="47" height="174"/>+ <rect x="396" y="199" width="36" height="114"/>+ </g>+</svg>diff --git a/frontend/resources/icons/violet.svg b/frontend/resources/icons/violet.svgnew file mode 100644index 000000000..b816c642b--- /dev/null+++ b/frontend/resources/icons/violet.svg@@ -0,0 +1,11 @@+<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 512 512">+ <!-- openGym app icon "violet", written by scripts/app-icons.mjs (the glyph of resources/icon.svg). -->+ <rect width="512" height="512" fill="#bf5af2"/>+ <g fill="#ffffff">+ <rect x="80" y="242" width="352" height="28"/>+ <rect x="80" y="199" width="36" height="114"/>+ <rect x="131" y="169" width="47" height="174"/>+ <rect x="334" y="169" width="47" height="174"/>+ <rect x="396" y="199" width="36" height="114"/>+ </g>+</svg>diff --git a/frontend/scripts/app-icons.mjs b/frontend/scripts/app-icons.mjsnew file mode 100644index 000000000..f94fe71b8--- /dev/null+++ b/frontend/scripts/app-icons.mjs@@ -0,0 +1,260 @@+#!/usr/bin/env node+/* The alternate home-screen icons (Settings → Look & Home → App icon), drawn from+ * src/lib/app-icon-variants.js and the dumbbell in resources/icon.svg.+ *+ * The glyph is five rectangles, so this draws them itself (4x4 to 8x8 samples per pixel for the+ * edges) and writes the PNGs with node:zlib: no sharp or resvg to install, and the same bytes on+ * every machine, which the test checks. A variant with `art` (Halloween) is a hand-made SVG+ * instead, drawn by the small renderer below (rect, circle, line, polyline, polygon, one radial+ * gradient). Written per variant:+ * resources/icons/<id>.svg the source (the glyph ones only)+ * public/app-icons/<id>.png 112 px preview for the settings row+ * ios/App/App/Assets.xcassets/AppIcon-<Name>.appiconset/ 1024 px, opaque (Apple refuses alpha)+ * In 1.4.3 the picker is on the iPhone only, so there are no Android launcher files here (1.4.4+ * adds them). The default icon keeps the files @capacitor/assets made for it (docs/MOBILE.md);+ * only its preview comes from here.+ *+ * Usage: node scripts/app-icons.mjs write everything+ * node scripts/app-icons.mjs --check exit 1 when a committed file differs from a fresh draw */+import { deflateSync } from 'node:zlib'+import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'+import { dirname, join } from 'node:path'+import { fileURLToPath } from 'node:url'+import { APP_ICON_VARIANTS } from '../src/lib/app-icon-variants.js'++export const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')+export const PREVIEW = 112+export const IOS_SIZE = 1024++/** The glyph's rectangles, in the 512 grid of resources/icon.svg: one source for every icon. */+export function glyph(svg = readFileSync(join(ROOT, 'resources/icon.svg'), 'utf8')) {+ const g = svg.match(/<g[^>]*>([\s\S]*?)<\/g>/)?.[1] || ''+ return [...g.matchAll(/<rect\s+x="(\d+)"\s+y="(\d+)"\s+width="(\d+)"\s+height="(\d+)"/g)]+ .map(m => m.slice(1, 5).map(Number))+}++const rgb = hex => [1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16))++/** One icon `size` px square: the background, the glyph on it, optionally cut to a circle. */+export function draw(v, size, { round = false, rects = glyph() } = {}) {+ if (v.art) return drawArt(readFileSync(join(ROOT, v.art), 'utf8'), size)+ const k = size <= 256 ? 8 : 4+ const bg = rgb(v.bg), fg = rgb(v.fg)+ const ch = round ? 4 : 3+ const out = Buffer.alloc(size * size * ch)+ const scale = 512 / size+ // Per sample row, the glyph's spans across it: the inner loop then only compares numbers.+ const spans = []+ for (let s = 0; s < size * k; s++) {+ const gy = (s + 0.5) / k * scale+ spans.push(rects.filter(([, ry, , rh]) => gy >= ry && gy < ry + rh).map(([rx, , rw]) => [rx, rx + rw]))+ }+ for (let y = 0; y < size; y++) for (let x = 0; x < size; x++) {+ let inside = 0, on = 0+ for (let sy = 0; sy < k; sy++) {+ const py = y + (sy + 0.5) / k+ const row = spans[y * k + sy]+ for (let sx = 0; sx < k; sx++) {+ const px = x + (sx + 0.5) / k+ if (round) {+ const dx = px - size / 2, dy = py - size / 2+ if (dx * dx + dy * dy > (size / 2) * (size / 2)) continue+ }+ inside+++ const gx = px * scale+ for (const [a, b] of row) if (gx >= a && gx < b) { on++; break }+ }+ }+ const o = (y * size + x) * ch+ const a = inside ? on / inside : 0+ for (let c = 0; c < 3; c++) out[o + c] = Math.round(bg[c] + (fg[c] - bg[c]) * a)+ if (round) out[o + 3] = Math.round(255 * inside / (k * k))+ }+ return png(size, size, out, ch)+}++// --- the hand-made icons: a renderer for the little SVG they are allowed to use ---+// Painted back to front like SVG: each sample takes the colour of the topmost shape covering it.+// Strokes are capsules (round caps and joins), polygons fill even-odd, and a fill may be the one+// userSpaceOnUse radialGradient with two stops. Coordinates in the 512 viewBox.++const num = (a, k, d = 0) => (a[k] === undefined ? d : Number(a[k]))+const attrs = tag => Object.fromEntries([...tag.matchAll(/([\w:-]+)="([^"]*)"/g)].map(m => [m[1], m[2]]))+const pts = s => s.trim().split(/[\s,]+/).map(Number).reduce((o, n, i) => (i % 2 ? o[o.length - 1].push(n) : o.push([n]), o), [])++/** The SVG as a list of shapes, each { hit(x, y), color(x, y), box }: what drawArt paints. */+export function scene(svg) {+ const grads = {}+ for (const m of svg.matchAll(/<radialGradient\b([^>]*)>([\s\S]*?)<\/radialGradient>/g)) {+ const a = attrs(m[1])+ const stops = [...m[2].matchAll(/<stop\b([^>]*)\/>/g)].map(s => attrs(s[1]))+ grads[a.id] = { cx: num(a, 'cx'), cy: num(a, 'cy'), r: num(a, 'r'), c0: rgb(stops[0]['stop-color']), c1: rgb(stops[stops.length - 1]['stop-color']) }+ }+ const paint = f => {+ const g = /^url\(#(.+)\)$/.exec(f)+ if (!g) { const c = rgb(f); return () => c }+ const { cx, cy, r, c0, c1 } = grads[g[1]]+ return (x, y) => {+ const t = Math.min(1, Math.hypot(x - cx, y - cy) / r)+ return [0, 1, 2].map(i => c0[i] + (c1[i] - c0[i]) * t)+ }+ }+ const body = svg.replace(/<defs>[\s\S]*?<\/defs>/g, '').replace(/<!--[\s\S]*?-->/g, '')+ const stack = [{}]+ const shapes = []+ for (const m of body.matchAll(/<(\/?)(\w+)\b([^>]*?)(\/?)>/g)) {+ const [, close, name, raw, self] = m+ if (name === 'svg') continue+ if (name === 'g') { close ? stack.pop() : stack.push({ ...stack[stack.length - 1], ...attrs(raw) }); continue }+ if (close) continue+ const a = { ...stack[stack.length - 1], ...attrs(raw) }+ if (!self) throw new Error(`app icon art: <${name}> must close itself`)+ if (name === 'rect') {+ const x = num(a, 'x'), y = num(a, 'y'), w = num(a, 'width'), h = num(a, 'height')+ shapes.push({ box: [x, y, x + w, y + h], hit: (px, py) => px >= x && px < x + w && py >= y && py < y + h, color: paint(a.fill) })+ } else if (name === 'circle') {+ const cx = num(a, 'cx'), cy = num(a, 'cy'), r = num(a, 'r')+ shapes.push({ box: [cx - r, cy - r, cx + r, cy + r], hit: (px, py) => (px - cx) ** 2 + (py - cy) ** 2 <= r * r, color: paint(a.fill) })+ } else if (name === 'line' || name === 'polyline') {+ const p = name === 'line' ? [[num(a, 'x1'), num(a, 'y1')], [num(a, 'x2'), num(a, 'y2')]] : pts(a.points)+ const hw = num(a, 'stroke-width', 1) / 2+ const segs = p.slice(1).map((q, i) => [p[i], q])+ const xs = p.map(q => q[0]), ys = p.map(q => q[1])+ shapes.push({+ box: [Math.min(...xs) - hw, Math.min(...ys) - hw, Math.max(...xs) + hw, Math.max(...ys) + hw],+ hit: (px, py) => segs.some(([[x1, y1], [x2, y2]]) => {+ const dx = x2 - x1, dy = y2 - y1+ const t = Math.max(0, Math.min(1, ((px - x1) * dx + (py - y1) * dy) / (dx * dx + dy * dy || 1)))+ return (px - x1 - t * dx) ** 2 + (py - y1 - t * dy) ** 2 <= hw * hw+ }),+ color: paint(a.stroke),+ })+ } else if (name === 'polygon') {+ const p = pts(a.points)+ const xs = p.map(q => q[0]), ys = p.map(q => q[1])+ shapes.push({+ box: [Math.min(...xs), Math.min(...ys), Math.max(...xs), Math.max(...ys)],+ hit: (px, py) => {+ let inside = false+ for (let i = 0, j = p.length - 1; i < p.length; j = i++) {+ const [xi, yi] = p[i], [xj, yj] = p[j]+ if ((yi > py) !== (yj > py) && px < (xj - xi) * (py - yi) / (yj - yi) + xi) inside = !inside+ }+ return inside+ },+ color: paint(a.fill),+ })+ } else throw new Error(`app icon art: no <${name}> in the renderer`)+ }+ return shapes.reverse() // topmost first+}++/** A hand-made icon `size` px square, opaque (iOS), 4x4 samples per pixel. */+export function drawArt(svg, size) {+ const shapes = scene(svg)+ const k = 4, scale = 512 / size+ const out = Buffer.alloc(size * size * 3)+ for (let y = 0; y < size; y++) {+ // Only the shapes this pixel row can touch.+ const y0 = y * scale, y1 = (y + 1) * scale+ const row = shapes.filter(s => s.box[1] <= y1 && s.box[3] >= y0)+ for (let x = 0; x < size; x++) {+ const x0 = x * scale, x1 = (x + 1) * scale+ const here = row.filter(s => s.box[0] <= x1 && s.box[2] >= x0)+ const sum = [0, 0, 0]+ for (let sy = 0; sy < k; sy++) for (let sx = 0; sx < k; sx++) {+ const px = (x + (sx + 0.5) / k) * scale, py = (y + (sy + 0.5) / k) * scale+ const s = here.find(sh => sh.hit(px, py))+ const c = s ? s.color(px, py) : [0, 0, 0]+ sum[0] += c[0]; sum[1] += c[1]; sum[2] += c[2]+ }+ const o = (y * size + x) * 3+ for (let c = 0; c < 3; c++) out[o + c] = Math.round(sum[c] / (k * k))+ }+ }+ return png(size, size, out, 3)+}++// --- PNG, the bare minimum: IHDR, one IDAT, IEND; filter 0 on every row ---+const CRC = new Uint32Array(256).map((_, n) => {+ let c = n+ for (let i = 0; i < 8; i++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1+ return c >>> 0+})+const crc32 = buf => { let c = 0xffffffff; for (const b of buf) c = CRC[(c ^ b) & 0xff] ^ (c >>> 8); return (c ^ 0xffffffff) >>> 0 }+const chunk = (type, data) => {+ const len = Buffer.alloc(4); len.writeUInt32BE(data.length)+ const body = Buffer.concat([Buffer.from(type, 'ascii'), data])+ const crc = Buffer.alloc(4); crc.writeUInt32BE(crc32(body))+ return Buffer.concat([len, body, crc])+}+function png(w, h, pixels, ch) {+ const ihdr = Buffer.alloc(13)+ ihdr.writeUInt32BE(w, 0); ihdr.writeUInt32BE(h, 4)+ ihdr[8] = 8; ihdr[9] = ch === 4 ? 6 : 2 // 8 bit, RGBA or RGB+ const raw = Buffer.alloc(h * (w * ch + 1))+ for (let y = 0; y < h; y++) pixels.copy(raw, y * (w * ch + 1) + 1, y * w * ch, (y + 1) * w * ch)+ return Buffer.concat([Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]), chunk('IHDR', ihdr), chunk('IDAT', deflateSync(raw, { level: 9 })), chunk('IEND', Buffer.alloc(0))])+}++/** Width, height and whether the PNG has an alpha channel, read from its header. */+export function pngInfo(buf) {+ return { width: buf.readUInt32BE(16), height: buf.readUInt32BE(20), alpha: buf[25] === 6 || buf[25] === 4 }+}++const svgOf = (v, rects) => `<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 512 512">+ <!-- openGym app icon "${v.id}", written by scripts/app-icons.mjs (the glyph of resources/icon.svg). -->+ <rect width="512" height="512" fill="${v.bg}"/>+ <g fill="${v.fg}">+${rects.map(([x, y, w, h]) => ` <rect x="${x}" y="${y}" width="${w}" height="${h}"/>`).join('\n')}+ </g>+</svg>+`++const iosContents = `{+ "images" : [+ {+ "filename" : "icon-1024.png",+ "idiom" : "universal",+ "platform" : "ios",+ "size" : "1024x1024"+ }+ ],+ "info" : {+ "author" : "xcode",+ "version" : 1+ }+}+`++/** Every file this script owns, as [path relative to frontend/, () => contents]: drawn on demand. */+export function files(rects = glyph()) {+ const out = []+ for (const v of APP_ICON_VARIANTS) {+ out.push([`public/app-icons/${v.id}.png`, () => draw(v, PREVIEW, { rects })])+ if (v.id === 'default') continue+ if (!v.art) out.push([`resources/icons/${v.id}.svg`, () => svgOf(v, rects)])+ const set = `ios/App/App/Assets.xcassets/${v.ios}.appiconset`+ out.push([`${set}/Contents.json`, () => iosContents])+ out.push([`${set}/icon-1024.png`, () => draw(v, IOS_SIZE, { rects })])+ }+ return out+}++if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {+ const check = process.argv.includes('--check')+ const bad = []+ for (const [rel, make] of files()) {+ const p = join(ROOT, rel)+ const body = make()+ const buf = Buffer.isBuffer(body) ? body : Buffer.from(body)+ if (check) {+ if (!existsSync(p) || !readFileSync(p).equals(buf)) bad.push(rel)+ continue+ }+ mkdirSync(dirname(p), { recursive: true })+ writeFileSync(p, buf)+ }+ if (bad.length) { console.error('app icons out of date (run node scripts/app-icons.mjs):\n ' + bad.join('\n ')); process.exit(1) }+ console.log(check ? 'app icons up to date' : 'app icons written')+}diff --git a/frontend/scripts/app-icons.test.mjs b/frontend/scripts/app-icons.test.mjsnew file mode 100644index 000000000..416bc5d90--- /dev/null+++ b/frontend/scripts/app-icons.test.mjs@@ -0,0 +1,99 @@+/* The alternate home-screen icons: every file scripts/app-icons.mjs owns is there, the size iOS+ * wants, and drawn the way the script draws it today; and the iOS project lists the same icons as+ * src/lib/app-icon-variants.js, or the picker would offer one the phone has not got. In 1.4.3 the+ * picker is iPhone only: Android keeps its one launcher icon (1.4.4 has the alias tests). */+import { describe, expect, it } from 'vitest'+import { execFileSync } from 'node:child_process'+import { existsSync, readFileSync, statSync } from 'node:fs'+import { join } from 'node:path'+import { IOS_SIZE, PREVIEW, ROOT, draw, files, pngInfo, scene } from './app-icons.mjs'+import { APP_ICON_VARIANTS } from '../src/lib/app-icon-variants.js'++const read = rel => readFileSync(join(ROOT, rel), 'utf8')+const ALT = APP_ICON_VARIANTS.filter(v => v.id !== 'default')++describe('generated icon files', () => {+ it('are all committed', () => {+ const missing = files().map(([rel]) => rel).filter(rel => !existsSync(join(ROOT, rel)))+ expect(missing).toEqual([])+ })++ it('have the sizes each platform wants', () => {+ for (const v of APP_ICON_VARIANTS) {+ const preview = join(ROOT, `public/app-icons/${v.id}.png`)+ expect(pngInfo(readFileSync(preview))).toMatchObject({ width: PREVIEW, height: PREVIEW })+ expect(statSync(preview).size, v.id).toBeLessThanOrEqual(30 * 1024)+ }+ for (const v of ALT) {+ // Apple turns down an app icon with an alpha channel.+ const ios = readFileSync(join(ROOT, `ios/App/App/Assets.xcassets/${v.ios}.appiconset/icon-1024.png`))+ expect(pngInfo(ios)).toEqual({ width: IOS_SIZE, height: IOS_SIZE, alpha: false })+ const set = JSON.parse(read(`ios/App/App/Assets.xcassets/${v.ios}.appiconset/Contents.json`))+ expect(set.images).toEqual([{ filename: 'icon-1024.png', idiom: 'universal', platform: 'ios', size: '1024x1024' }])+ }+ })++ it('match a fresh draw (the small ones; --check compares them all)', () => {+ for (const v of APP_ICON_VARIANTS) {+ expect(readFileSync(join(ROOT, `public/app-icons/${v.id}.png`)).equals(draw(v, PREVIEW)), v.id).toBe(true)+ }+ })+})++describe('node scripts/app-icons.mjs --check', () => {+ // Every committed icon against a fresh draw, the 1024s too (about 20 s, so it runs once, here).+ it('finds nothing out of date', () => {+ const out = execFileSync(process.execPath, [join(ROOT, 'scripts/app-icons.mjs'), '--check'], { encoding: 'utf8' })+ expect(out).toContain('app icons up to date')+ }, 120_000)+})++describe('the Halloween icon', () => {+ const v = APP_ICON_VARIANTS.find(x => x.id === 'halloween')++ it('is a hand-made SVG the renderer knows every piece of', () => {+ expect(v).toMatchObject({ name: 'Halloween', ios: 'AppIcon-Halloween', art: 'resources/icons/halloween.svg' })+ // scene() throws on any element it cannot draw.+ expect(scene(read(v.art)).length).toBeGreaterThan(10)+ })++ it('is dark at the edges, orange on the dumbbell, pale on the moon', () => {+ const shapes = scene(read(v.art))+ const at = (x, y) => shapes.find(s => s.hit(x, y)).color(x, y).map(Math.round)+ expect(at(256, 256)).toEqual([255, 122, 26]) // the bar+ expect(at(90, 110)).toEqual([247, 232, 180]) // the moon's lit side+ const corner = at(10, 500)+ expect(Math.max(...corner)).toBeLessThan(40)+ })+})++describe('Android in 1.4.3', () => {+ it('keeps MainActivity as the one launcher entry: no aliases, no icon plugin', () => {+ const manifest = read('android/app/src/main/AndroidManifest.xml')+ expect(manifest).not.toMatch(/<activity-alias\b[^>]*Icon/)+ const main = manifest.match(/<activity\b[\s\S]*?android:name="\.MainActivity"[\s\S]*?<\/activity>/)[0]+ expect(main).toMatch(/android\.intent\.category\.LAUNCHER/)+ expect(existsSync(join(ROOT, 'android/app/src/main/java/ch/duartesantos/opengym/AppIconPlugin.java'))).toBe(false)+ expect(files().map(([rel]) => rel).filter(rel => rel.startsWith('android/'))).toEqual([])+ })+})++describe('iOS alternate icons', () => {+ const pbx = read('ios/App/App.xcodeproj/project.pbxproj')++ it('every App build configuration names all alternate icon sets', () => {+ const names = [...pbx.matchAll(/ASSETCATALOG_COMPILER_ALTERNATE_APPICON_NAMES = "([^"]*)";/g)].map(m => m[1].split(' '))+ expect(names.length).toBe((pbx.match(/ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;/g) || []).length)+ for (const n of names) expect(n).toEqual(ALT.map(v => v.ios))+ expect(names[0]).toContain('AppIcon-Halloween')+ })++ it('the plugin is compiled, registered and knows the same sets', () => {+ expect(pbx).toMatch(/\/\* AppIconPlugin\.swift in Sources \*\/,/)+ expect(pbx).toMatch(/\/\* AppIconPlugin\.swift \*\/ = \{isa = PBXFileReference;[^}]*path = AppIconPlugin\.swift;/)+ expect(read('ios/App/App/MainViewController.swift')).toContain('bridge?.registerPluginInstance(AppIconPlugin())')+ const swift = read('ios/App/App/AppIconPlugin.swift')+ const pairs = [...swift.matchAll(/"(\w+)": "(AppIcon-\w+)"/g)].map(m => [m[1], m[2]])+ expect(pairs).toEqual(ALT.map(v => [v.id, v.ios]))+ })+})diff --git a/frontend/src/lib/app-icon-variants.js b/frontend/src/lib/app-icon-variants.jsnew file mode 100644index 000000000..4d3fe83b4--- /dev/null+++ b/frontend/src/lib/app-icon-variants.js@@ -0,0 +1,22 @@+// The home-screen icons a phone can switch to (Settings → Look & Home → App icon). Plain data, no+// imports: scripts/app-icons.mjs draws every icon file from this list and the settings row lists+// the same ids, so the picker can never offer an icon the native projects do not have.+//+// `name` is the English key the row passes to t(). `ios` is the AppIcon set in the asset catalog+// (null: the primary icon) and `android` the activity-alias 1.4.4 adds to AndroidManifest.xml (1.4.3+// has the picker on the iPhone only, so nothing reads it here yet). `art` is a hand-made SVG the+// script renders instead of the glyph; `bg`/`fg` are then just its main colours.+export const APP_ICON_VARIANTS = [+ { id: 'default', name: 'Original', bg: '#0c0e12', fg: '#a3e635', ios: null, android: 'IconDefault' },+ { id: 'light', name: 'Light', bg: '#ffffff', fg: '#65a30d', ios: 'AppIcon-Light', android: 'IconLight' },+ { id: 'mono', name: 'Mono', bg: '#0c0e12', fg: '#f2f2f7', ios: 'AppIcon-Mono', android: 'IconMono' },+ { id: 'neon', name: 'Green', bg: '#a3e635', fg: '#0c0e12', ios: 'AppIcon-Neon', android: 'IconNeon' },+ { id: 'sky', name: 'Blue', bg: '#0a84ff', fg: '#ffffff', ios: 'AppIcon-Sky', android: 'IconSky' },+ { id: 'orange', name: 'Orange', bg: '#ff9f0a', fg: '#0c0e12', ios: 'AppIcon-Orange', android: 'IconOrange' },+ { id: 'pink', name: 'Pink', bg: '#ff375f', fg: '#ffffff', ios: 'AppIcon-Pink', android: 'IconPink' },+ { id: 'violet', name: 'Purple', bg: '#bf5af2', fg: '#ffffff', ios: 'AppIcon-Violet', android: 'IconViolet' },+ // All year, Halloween theme or not: some people are spooky in March.+ { id: 'halloween', name: 'Halloween', bg: '#0d0517', fg: '#ff7a1a', art: 'resources/icons/halloween.svg', ios: 'AppIcon-Halloween', android: 'IconHalloween' },+]++export const APP_ICON_IDS = APP_ICON_VARIANTS.map(v => v.id)