diff --git a/CLAUDE.md b/CLAUDE.md index b827f99..5d34f09 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1328,6 +1328,15 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal When a feature needs a shape the fixture lacks, **add it to the generator** rather than reaching for the real library. +- **One app icon** (Round 121): `packaging/lint.jpg`, corners rounded at + wave's radius (16 % of the side), rendered by `scripts/make_icons.py` into + `packaging/lintunes.png` (desktop, 512 px, installed by + `packaging/install-desktop.sh`) and andTunes' `ic_launcher.png` — the same + icon on both. There is no swap-a-PNG customization any more; after + remaking it, `andtunes/build.py --ship`. +- **Quitting ends with `main.leave`** (`os._exit` after `aboutToQuit` has + saved everything): a normal `sys.exit` let Python free the QApplication's + wrapper in random order and sip segfaulted on every quit. - `scripts/` holds one-off maintenance tools (`audit_artwork.py`, `recover_artwork.py`, `clear_computed_ratings.py`) run manually against a data dir; most default to dry-run and need `--write` to mutate files. diff --git a/andtunes/app/src/main/res/drawable-nodpi/ic_launcher.png b/andtunes/app/src/main/res/drawable-nodpi/ic_launcher.png index b8f3649..8895894 100644 Binary files a/andtunes/app/src/main/res/drawable-nodpi/ic_launcher.png and b/andtunes/app/src/main/res/drawable-nodpi/ic_launcher.png differ diff --git a/andtunes/build.py b/andtunes/build.py index 2dc1225..dd3fb2f 100644 --- a/andtunes/build.py +++ b/andtunes/build.py @@ -26,8 +26,8 @@ import sys import zipfile from pathlib import Path -VERSION_NAME = "0.4.1" -VERSION_CODE = 8 +VERSION_NAME = "0.4.2" +VERSION_CODE = 9 PACKAGE = "me.teafry.andtunes" MIN_SDK = 26 diff --git a/andtunes/tools/make_buttons.py b/andtunes/tools/make_buttons.py index bb7dc97..f9ec615 100644 --- a/andtunes/tools/make_buttons.py +++ b/andtunes/tools/make_buttons.py @@ -171,21 +171,6 @@ def toggle_icon(name: str, color="black", size=ICON) -> QImage: return image -def launcher() -> QImage: - size = 192 - image, p = _canvas(size, size) - path = QPainterPath() - path.addRoundedRect(QRectF(8, 8, size - 16, size - 16), 36, 36) - p.fillPath(path, QColor("black")) - p.setPen(Qt.PenStyle.NoPen) - p.setBrush(QColor("white")) - p.drawPolygon(_tri(70, 50, 142, 96)) - p.drawPolygon(QPolygonF([QPointF(70, 96), QPointF(142, 96), - QPointF(70, 142)])) - p.end() - return image - - def save(image: QImage, name: str, *dirs: Path): for d in dirs: d.mkdir(parents=True, exist_ok=True) @@ -201,7 +186,7 @@ def main(): save(transport(name), name, RES, SHIP) for name in TOGGLES: save(toggle_icon(name), name, RES, SHIP) - save(launcher(), "ic_launcher", RES) + # The launcher icon is LinTunes' own: scripts/make_icons.py. # Status-bar icons must be white-on-transparent; Android tints by alpha. save(transport("play", "white", 96), "ic_notify", RES) print(f"wrote {len(MENU) + len(TRANSPORT) + len(TOGGLES)} buttons to {RES} and {SHIP}") diff --git a/extra-docs.md b/extra-docs.md index 96457ef..4ab836a 100644 --- a/extra-docs.md +++ b/extra-docs.md @@ -106,12 +106,10 @@ dock icon, uses the synced library automatically.) ## App icon _(written by LLM, cleaned up by me)_ -You can change the app icon if you want. - `packaging/install-desktop.sh` installs the launcher entry and icon for your -user (lets you pin LinTunes to the GNOME dash). The icon is just a file — -replace `packaging/lintunes.png` (256×256 PNG) and re-run the script to use -your own. GNOME caches icons, so if the old one lingers, log out and back in. +user (lets you pin LinTunes to the GNOME dash). The icon is the same on the +desktop and the Rabbit; GNOME caches icons, so if an old one lingers after +re-running the script, log out and back in. Unpinning from the dash does **not** uninstall LinTunes — it's still in the GNOME app grid (open Activities and search "LinTunes"). Right-click it there → diff --git a/lintunes/__init__.py b/lintunes/__init__.py index 54fe534..302fd27 100644 --- a/lintunes/__init__.py +++ b/lintunes/__init__.py @@ -1,3 +1,3 @@ """LinTunes — iTunes-style music library manager and player for Linux.""" -__version__ = "0.87.0" +__version__ = "0.87.1" diff --git a/lintunes/android/andTunes.apk b/lintunes/android/andTunes.apk index a087664..9b4c880 100644 Binary files a/lintunes/android/andTunes.apk and b/lintunes/android/andTunes.apk differ diff --git a/lintunes/android/andTunes.json b/lintunes/android/andTunes.json index 5ba1f85..b9492a0 100644 --- a/lintunes/android/andTunes.json +++ b/lintunes/android/andTunes.json @@ -1 +1 @@ -{"version_name": "0.4.1", "version_code": 8} +{"version_name": "0.4.2", "version_code": 9} diff --git a/lintunes/main.py b/lintunes/main.py index 44fff22..71b1a86 100644 --- a/lintunes/main.py +++ b/lintunes/main.py @@ -191,7 +191,24 @@ def run_gui(data_dir: Path, files: list[Path], exit_code = app.exec() if window.restart_requested: return True # caller re-execs the updated code - sys.exit(exit_code) + leave(exit_code) + + +def leave(exit_code: int): + """End the process once the event loop is done, without Python tearing + down the Qt objects. Everything is already saved by then (aboutToQuit + flushed the library, the player shut down), but a normal exit then + frees the QApplication's wrapper in no particular order, and sip touched + a QObject Qt had already deleted: a segfault and a core dump on every + quit (2026-10-27, 2026-11-06; four out of four on the dev library).""" + import logging + logging.shutdown() + for stream in (sys.stdout, sys.stderr): + try: + stream.flush() + except (OSError, ValueError): + pass + os._exit(exit_code) if __name__ == "__main__": diff --git a/packaging/install-desktop.sh b/packaging/install-desktop.sh index 657dd6d..ba9a0a8 100755 --- a/packaging/install-desktop.sh +++ b/packaging/install-desktop.sh @@ -1,15 +1,16 @@ #!/usr/bin/env bash # Install the lintunes .desktop entry and icon for the current user, so GNOME # shows a proper icon and the app can be pinned to the dash. -# Re-run after swapping packaging/lintunes.png to update the icon. set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" APPS_DIR="$HOME/.local/share/applications" -ICON_DIR="$HOME/.local/share/icons/hicolor/256x256/apps" +ICON_DIR="$HOME/.local/share/icons/hicolor/512x512/apps" mkdir -p "$APPS_DIR" "$ICON_DIR" cp "$HERE/lintunes.png" "$ICON_DIR/lintunes.png" +# The icon used to install at 256x256; an old copy there would shadow this one. +rm -f "$HOME/.local/share/icons/hicolor/256x256/apps/lintunes.png" # If lintunes isn't on PATH, point Exec at this checkout's module instead. # We must NOT rely on the working directory: GNOME's dash launches apps via a diff --git a/packaging/lint.jpg b/packaging/lint.jpg new file mode 100755 index 0000000..3ed4f04 Binary files /dev/null and b/packaging/lint.jpg differ diff --git a/packaging/lintunes.png b/packaging/lintunes.png index 4c219bf..5388db6 100644 Binary files a/packaging/lintunes.png and b/packaging/lintunes.png differ diff --git a/scripts/make_icons.py b/scripts/make_icons.py new file mode 100644 index 0000000..57b3964 --- /dev/null +++ b/scripts/make_icons.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +"""Make LinTunes' one app icon from packaging/lint.jpg: the picture squared +from its centre with its corners rounded at wave's radius (16 % of the +side), as packaging/lintunes.png (desktop, 512 px) and andTunes' launcher +(andtunes/app/src/main/res/drawable-nodpi/ic_launcher.png, 192 px) — the +same icon on both. Re-run after changing lint.jpg; the outputs are +committed, and the APK needs `andtunes/build.py --ship` to carry it.""" +from pathlib import Path + +from PIL import Image, ImageDraw + +HERE = Path(__file__).resolve().parent.parent +SOURCE = HERE / "packaging" / "lint.jpg" +CORNER = 0.16 # corner radius, as a fraction of the side +DESKTOP = HERE / "packaging" / "lintunes.png" +ANDROID = (HERE / "andtunes" / "app" / "src" / "main" / "res" + / "drawable-nodpi" / "ic_launcher.png") + + +def rounded(img: Image.Image, size: int) -> Image.Image: + img = img.convert("RGB").resize((size, size), Image.LANCZOS) + # Drawn at 4x and shrunk, so the corners are smooth rather than stepped. + big = size * 4 + mask = Image.new("L", (big, big), 0) + ImageDraw.Draw(mask).rounded_rectangle( + (0, 0, big - 1, big - 1), radius=big * CORNER, fill=255) + out = img.convert("RGBA") + out.putalpha(mask.resize((size, size), Image.LANCZOS)) + return out + + +def main() -> None: + src = Image.open(SOURCE) + side = min(src.size) # square it up from the centre + left, top = (src.width - side) // 2, (src.height - side) // 2 + src = src.crop((left, top, left + side, top + side)) + rounded(src, 512).save(DESKTOP) + rounded(src, 192).save(ANDROID) + print(f"Wrote {DESKTOP.relative_to(HERE)} and {ANDROID.relative_to(HERE)}.") + + +if __name__ == "__main__": + main() diff --git a/tests/test_round121.py b/tests/test_round121.py new file mode 100644 index 0000000..5373be9 --- /dev/null +++ b/tests/test_round121.py @@ -0,0 +1,51 @@ +"""Round 121: one app icon (packaging/lint.jpg, wave's corner radius) on the +desktop and the Rabbit, and quitting no longer segfaults.""" +from pathlib import Path +from unittest.mock import patch + +from PyQt6.QtGui import QImage + +from lintunes import main + +ROOT = Path(__file__).resolve().parents[1] +DESKTOP = ROOT / "packaging" / "lintunes.png" +ANDROID = (ROOT / "andtunes" / "app" / "src" / "main" / "res" + / "drawable-nodpi" / "ic_launcher.png") + + +def _alpha(img: QImage, x: int, y: int) -> int: + return img.pixelColor(x, y).alpha() + + +def test_both_icons_are_the_same_picture_with_round_corners(qapp): + desktop, android = QImage(str(DESKTOP)), QImage(str(ANDROID)) + assert (desktop.width(), desktop.height()) == (512, 512) + assert (android.width(), android.height()) == (192, 192) + for img in (desktop, android): + side = img.width() + for x, y in ((0, 0), (side - 1, 0), (0, side - 1), (side - 1, side - 1)): + assert _alpha(img, x, y) == 0 # corners cut away + assert _alpha(img, side // 2, 0) == 255 # edges kept + assert _alpha(img, side // 2, side // 2) == 255 + # Wave's radius, 16 % of the side: inside it the corner is still + # clear just off the diagonal, past it the picture is solid. + r = round(side * 0.16) + assert _alpha(img, round(r * 0.2), round(r * 0.2)) == 0 + assert _alpha(img, r, 1) == 255 + small = desktop.scaled(192, 192).convertToFormat(QImage.Format.Format_ARGB32) + a = android.convertToFormat(QImage.Format.Format_ARGB32) + mid = small.pixelColor(96, 96), a.pixelColor(96, 96) + assert all(abs(c1 - c2) < 24 for c1, c2 in zip(mid[0].getRgb(), mid[1].getRgb())) + + +def test_the_launcher_is_not_drawn_by_make_buttons(): + src = (ROOT / "andtunes" / "tools" / "make_buttons.py").read_text() + assert "def launcher" not in src + + +def test_leave_flushes_and_skips_python_teardown(): + with patch.object(main.os, "_exit") as hard_exit, \ + patch("logging.shutdown") as log_shutdown: + main.leave(3) + log_shutdown.assert_called_once() + hard_exit.assert_called_once_with(3)