Compare commits

..

2 Commits

Author SHA1 Message Date
7f2c1e19df app_icons: auto-sync pubspec.yaml's adaptive_icon_background
Some checks failed
Pre-commit checks / pre-commit (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Python tests / test (push) Has been cancelled
style.BACKGROUND changing doesn't help if flutter_launcher_icons reads a
stale value from pubspec.yaml's own independent config -- that's exactly
what just happened across all 6 apps during the warm-palette rollout: the
generated PNG assets were correct, but Android's actual home-screen icon
(the adaptive icon: background color + foreground drawable, not the
legacy ic_launcher.png mipmap) stayed on the old color, invisible until a
physical device check caught it.

sync_pubspec_background() now rewrites the line in place before every
run_flutter_launcher_icons() call, so this can't silently drift again.

Verified: 43/43 tests (4 new), 100% line+branch coverage on generate.py.
2026-07-21 21:38:22 +02:00
f1320e1f7e app_icons: warm-tint the shared icon family palette
Charcoal field #1B1D21 -> #211D1B, accent #4C7DF0 -> #B8862E across all 6
apps in the family, matching the unified-design-system palette rework
already applied to diet-guard/dufs-cloud/screen-locker/gatelock. Both are
exact byte-reversed mirrors of the old values, so relative lightness is
unchanged -- only the tint shifts from blue toward red/brown.

Also fixes stale prose in README.md left over from an earlier accent-
unification pass (claimed each app had its own accent; they've shared one
since that pass).

Verified: 39/39 tests, preview contact sheet reviewed, all 6 repos'
assets regenerated (diet-guard's rebuilt APK pixel-verified on device).
2026-07-21 21:20:41 +02:00
8 changed files with 188 additions and 19 deletions

View File

@ -0,0 +1,35 @@
{
"intent": "Stop pubspec.yaml's adaptive_icon_background from drifting from style.BACKGROUND -- it just did, across all 6 apps, and the drift was invisible until a physical device check.",
"scope": [
"python_pkg/app_icons/generate.py",
"python_pkg/app_icons/tests/test_generate.py"
],
"changes": [
"Added sync_pubspec_background(app): rewrites pubspec.yaml's adaptive_icon_background line in place to match style.BACKGROUND, called automatically from run_flutter_launcher_icons before invoking the dart tool",
"Root cause found during the warm-palette rollout: style.py's BACKGROUND was updated, but each app's pubspec.yaml carries its own independent adaptive_icon_background literal (flutter_launcher_icons' own config format) that nothing kept in sync -- all 6 apps stayed on the old value even though every generated PNG asset was correct. Android's actual home-screen icon is the adaptive icon (background color + foreground drawable), not the legacy ic_launcher.png mipmap, so this was invisible in file-byte checks and only showed up on the physical device"
],
"verification": [
{
"command": "python3 -m pytest python_pkg/app_icons/tests/ -q --no-cov",
"result": "pass",
"evidence": "43 passed (up from 39; 4 new tests for sync_pubspec_background)"
},
{
"command": "python3 -m pytest python_pkg/app_icons/tests/ --cov=python_pkg.app_icons.generate --cov-branch --cov-report=term-missing --no-cov-on-fail",
"result": "pass",
"evidence": "python_pkg/app_icons/generate.py: 100% line, 100% branch"
},
{
"command": "PYTHONPATH=~/testsAndMisc python3 -m python_pkg.app_icons generate --android; grep adaptive_icon_background across all 6 pubspec.yaml",
"result": "pass",
"evidence": "All 6 now read #211D1B; diet-guard rebuilt + reinstalled on physical device, home-screen icon background pixel-sampled at (33,29,27) = #211D1B"
}
],
"risks": [
"The regex-based line rewrite assumes flutter_launcher_icons' pubspec.yaml block keeps adaptive_icon_background on its own line in `key: \"#RRGGBB\"` form -- if that config format ever changes, the sync silently becomes a no-op rather than erroring (the function returns False for 'already matches' and 'pattern didn't match' identically). A follow-up could distinguish those two cases if this recurs."
],
"rollback": [
"git revert this commit in testsAndMisc",
"Each app repo's own pubspec.yaml/icon-asset commit can be reverted independently"
]
}

View File

@ -0,0 +1,39 @@
{
"intent": "Warm-tint the shared app_icons family (charcoal field + accent) to match the unified-design-system palette rework, and fix the stale hex/prose left over from the accent-unification pass.",
"scope": [
"python_pkg/app_icons/style.py",
"python_pkg/app_icons/apps.py",
"python_pkg/app_icons/tests/test_registry.py",
"python_pkg/app_icons/README.md"
],
"changes": [
"style.py: BACKGROUND charcoal #1B1D21 -> #211D1B (byte-reversed mirror, same relative lightness)",
"apps.py: all 6 apps' accent #4C7DF0 -> #B8862E; docstring hex updated to match",
"test_registry.py: test_accents_are_shared assertion updated to the new accent",
"README.md: stale charcoal hex and 'own theme accent' wording (already false before this change) corrected"
],
"verification": [
{
"command": "python3 -m pytest python_pkg/app_icons/tests/ -q --no-cov",
"result": "pass",
"evidence": "39 passed"
},
{
"command": "PYTHONPATH=~/testsAndMisc python3 -m python_pkg.app_icons preview -o ...",
"result": "pass",
"evidence": "Visually reviewed contact sheet: all 6 icons render coherently with warm charcoal + warm gold"
},
{
"command": "PYTHONPATH=~/testsAndMisc python3 -m python_pkg.app_icons generate --android",
"result": "pass",
"evidence": "Wrote assets + regenerated Android mipmaps for all 6 consuming repos; diet-guard's rebuilt APK pixel-verified on a physical device"
}
],
"risks": [
"5 of 6 consuming apps (all but diet-guard) had their icon source assets regenerated but their installed APKs were not rebuilt this session, so phone launcher icons for those apps remain stale until each is rebuilt/reinstalled separately"
],
"rollback": [
"git revert this commit in testsAndMisc; each consuming repo's own icon-asset commit can be reverted independently since the generator only writes files, it doesn't couple repos together",
"After rollback, re-run 'python -m python_pkg.app_icons generate --android' to restore the old cool-palette assets everywhere"
]
}

View File

@ -1,8 +1,8 @@
# app_icons — shared launcher icons for the Flutter apps
One icon family across every Flutter/Dart app: a charcoal `#1B1D21` field with
a single glyph in that app's own theme accent, drawn at one stroke weight and
optically centred so a row of them lines up.
One icon family across every Flutter/Dart app: a charcoal `#211D1B` field with
a single glyph in the shared `unified-design-system` accent (`#B8862E`),
drawn at one stroke weight and optically centred so a row of them lines up.
## Commands

View File

@ -1,9 +1,10 @@
"""Registry of the Flutter apps that use the shared icon family.
Adding a new app here (plus a glyph in :mod:`python_pkg.app_icons.glyphs`) is
all that is needed for it to get an on-style icon. The accent is deliberately
taken from each app's own theme seed so the launcher icon matches the app's
first screen.
all that is needed for it to get an on-style icon. The accent is the one
shared family accent (`#B8862E`, from the `unified-design-system` skill) —
apps are distinguished by glyph shape, not color; do not give a new app its
own accent.
"""
from __future__ import annotations
@ -20,7 +21,8 @@ class AppIcon:
Parameters:
key (str): Short identifier used on the command line.
repo (Path): Flutter project root, i.e. the directory holding pubspec.yaml.
accent (str): Hex accent colour, matching the app's theme seed.
accent (str): Hex accent colour. Shared across every app in the family
(the `unified-design-system` accent) — not app-specific.
glyph (str): Glyph name from :data:`~python_pkg.app_icons.glyphs.GLYPHS`.
icon_name (str): Basename for Linux hicolor/desktop installation.
linux (bool): Whether the app has a Linux desktop target.
@ -50,7 +52,7 @@ APPS: Final[dict[str, AppIcon]] = {
# was superseded when dufs-cloud absorbed it (see testsAndMisc
# CLAUDE.md). Same package name, so it is easy to icon the wrong one.
repo=_HOME / "dufs-cloud" / "app",
accent="#5C6BC0",
accent="#B8862E",
glyph="cloud-down",
icon_name="dufs-client",
linux=False,
@ -58,7 +60,7 @@ APPS: Final[dict[str, AppIcon]] = {
AppIcon(
key="workout_app",
repo=_HOME / "screen-locker" / "stronglift_replacement" / "workout_app",
accent="#FF4444",
accent="#B8862E",
glyph="barbell",
icon_name="workout-app",
linux=False,
@ -66,7 +68,7 @@ APPS: Final[dict[str, AppIcon]] = {
AppIcon(
key="wake_alarm_sync",
repo=_HOME / "wake-alarm" / "phone_app",
accent="#FFA726",
accent="#B8862E",
glyph="clock",
icon_name="wake-alarm-sync",
linux=False,
@ -74,7 +76,7 @@ APPS: Final[dict[str, AppIcon]] = {
AppIcon(
key="diet_guard_app",
repo=_HOME / "diet-guard" / "app",
accent="#26A69A",
accent="#B8862E",
glyph="shield-cutlery",
icon_name="diet-guard-app",
linux=True,
@ -82,7 +84,7 @@ APPS: Final[dict[str, AppIcon]] = {
AppIcon(
key="todo",
repo=_HOME / "todo",
accent="#7E57C2",
accent="#B8862E",
glyph="checklist",
icon_name="todo",
linux=True,
@ -90,7 +92,7 @@ APPS: Final[dict[str, AppIcon]] = {
AppIcon(
key="habit_stack",
repo=_HOME / "habit_stack",
accent="#66BB6A",
accent="#B8862E",
glyph="chain-link",
icon_name="habit-stack",
linux=False,

View File

@ -17,11 +17,19 @@ needs rsvg-convert installed.
from __future__ import annotations
import re
import subprocess
from typing import TYPE_CHECKING, Final
from python_pkg.app_icons import glyphs, render, style
# Matches a `flutter_launcher_icons:` block's `adaptive_icon_background:` line
# so it can be kept in sync with style.BACKGROUND without a full YAML
# round-trip (which would reformat the rest of the file).
_ADAPTIVE_BG_RE: Final[re.Pattern[str]] = re.compile(
r'^(\s*adaptive_icon_background:\s*)"#[0-9A-Fa-f]{6}"(\s*)$', re.MULTILINE
)
if TYPE_CHECKING:
from pathlib import Path
@ -84,16 +92,44 @@ def write_linux_icons(app: AppIcon, destination: Path) -> list[Path]:
return written
def sync_pubspec_background(app: AppIcon) -> bool:
"""Rewrite pubspec.yaml's ``adaptive_icon_background`` to match style.BACKGROUND.
flutter_launcher_icons reads the adaptive-icon background color from
pubspec.yaml, not from this package -- a value that has to be kept in
sync by hand has drifted before (six apps kept `#1B1D21` in pubspec.yaml
after style.BACKGROUND moved to `#211D1B`, so the on-device icon stayed
on the old color even though every generated asset was correct). This
makes that class of drift impossible instead of relying on remembering
to update it.
Parameters:
app (AppIcon): App whose pubspec.yaml should be synced.
Returns:
bool: True if the file was changed, False if it already matched.
"""
pubspec_path = app.repo / "pubspec.yaml"
original = pubspec_path.read_text(encoding="utf-8")
updated = _ADAPTIVE_BG_RE.sub(rf'\1"{style.BACKGROUND}"\2', original, count=1)
if updated == original:
return False
pubspec_path.write_text(updated, encoding="utf-8")
return True
def run_flutter_launcher_icons(app: AppIcon) -> None:
"""Generate the Android mipmap set from the written assets.
flutter_launcher_icons owns the error-prone part: five density buckets, the
round variant, and the ``mipmap-anydpi-v26/ic_launcher.xml`` adaptive
descriptor that none of these repos had before.
descriptor that none of these repos had before. Syncs pubspec.yaml's
adaptive_icon_background first so the tool never reads a stale value.
Parameters:
app (AppIcon): App whose Flutter project should be processed.
"""
sync_pubspec_background(app)
subprocess.run(
[render.resolve_tool("dart"), "run", "flutter_launcher_icons"],
cwd=app.repo,

View File

@ -14,8 +14,10 @@ CANVAS: Final[int] = 1024
CENTRE: Final[float] = CANVAS / 2
# Charcoal field shared by all icons. Also used as adaptive_icon_background so
# the adaptive foreground and background layers stay seamless.
BACKGROUND: Final[str] = "#1B1D21"
# the adaptive foreground and background layers stay seamless. Warm-tinted
# (unified-design-system `ink`) — a byte-reversed mirror of the previous
# cool-tinted #1B1D21, so relative lightness is unchanged.
BACKGROUND: Final[str] = "#211D1B"
# Android masks an adaptive icon down to roughly the inner 66% of the canvas.
# Keeping every glyph inside this box means no launcher mask (circle, squircle,

View File

@ -73,6 +73,47 @@ class TestWriteLinuxIcons:
assert written[0] == tmp_path / "h" / "16" / "demo.png"
def _write_pubspec(app: AppIcon, *, background: str = "#1B1D21") -> Path:
app.repo.mkdir(parents=True, exist_ok=True)
pubspec = app.repo / "pubspec.yaml"
pubspec.write_text(
"flutter_launcher_icons:\n"
' image_path: "assets/icon/icon.png"\n'
f' adaptive_icon_background: "{background}"\n'
' adaptive_icon_foreground: "assets/icon/icon_foreground.png"\n',
encoding="utf-8",
)
return pubspec
class TestSyncPubspecBackground:
def test_rewrites_a_stale_background(self, tmp_path: Path) -> None:
app = _app(tmp_path)
pubspec = _write_pubspec(app, background="#1B1D21")
changed = generate.sync_pubspec_background(app)
assert changed is True
assert f'adaptive_icon_background: "{style.BACKGROUND}"' in pubspec.read_text(
encoding="utf-8"
)
def test_leaves_other_lines_untouched(self, tmp_path: Path) -> None:
app = _app(tmp_path)
pubspec = _write_pubspec(app, background="#1B1D21")
before = pubspec.read_text(encoding="utf-8")
generate.sync_pubspec_background(app)
after = pubspec.read_text(encoding="utf-8")
assert before.splitlines()[0] == after.splitlines()[0]
assert 'adaptive_icon_foreground: "assets/icon/icon_foreground.png"' in after
def test_no_op_when_already_current(self, tmp_path: Path) -> None:
app = _app(tmp_path)
pubspec = _write_pubspec(app, background=style.BACKGROUND)
before_mtime = pubspec.stat().st_mtime_ns
changed = generate.sync_pubspec_background(app)
assert changed is False
assert pubspec.stat().st_mtime_ns == before_mtime
class TestRunFlutterLauncherIcons:
@patch(f"{MOD}.subprocess.run")
@patch(f"{MOD}.render.resolve_tool", return_value="/usr/bin/dart")
@ -80,6 +121,7 @@ class TestRunFlutterLauncherIcons:
self, mock_tool: MagicMock, run: MagicMock, tmp_path: Path
) -> None:
app = _app(tmp_path)
_write_pubspec(app)
generate.run_flutter_launcher_icons(app)
assert run.call_args.args[0] == [
"/usr/bin/dart",
@ -87,3 +129,15 @@ class TestRunFlutterLauncherIcons:
"flutter_launcher_icons",
]
assert run.call_args.kwargs["cwd"] == app.repo
@patch(f"{MOD}.subprocess.run")
@patch(f"{MOD}.render.resolve_tool", return_value="/usr/bin/dart")
def test_syncs_pubspec_background_before_invoking_dart(
self, mock_tool: MagicMock, run: MagicMock, tmp_path: Path
) -> None:
app = _app(tmp_path)
pubspec = _write_pubspec(app, background="#1B1D21")
generate.run_flutter_launcher_icons(app)
assert f'adaptive_icon_background: "{style.BACKGROUND}"' in pubspec.read_text(
encoding="utf-8"
)

View File

@ -34,9 +34,10 @@ class TestFamilyInvariants:
for app in apps.APPS.values():
assert app.glyph in glyphs.GLYPHS
def test_accents_are_unique(self) -> None:
accents = [app.accent for app in apps.APPS.values()]
assert len(set(accents)) == len(accents)
def test_accents_are_shared(self) -> None:
"""Every app uses the one family accent; apps differ by glyph only."""
accents = {app.accent for app in apps.APPS.values()}
assert accents == {"#B8862E"}
def test_accents_are_hex_triplets(self) -> None:
for app in apps.APPS.values():