Check the app's icon: say when it can't be used, refuse it on publish
An icon.png that's missing, a link, over 1 MB or not a PNG used to become the default silently. The installer and coreapp deploy now say so (and note icons that aren't square or are small); coreapp publish refuses an unusable or uncommitted one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+39
-9
@@ -41,6 +41,7 @@ import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -560,16 +561,39 @@ def write(path, text, mode=0o644):
|
||||
os.chmod(path, mode)
|
||||
|
||||
|
||||
def icon_from(folder):
|
||||
"""The app's icon.png if it's a reasonable PNG, else the default."""
|
||||
ICON_LIMIT = 1024 * 1024
|
||||
|
||||
|
||||
def icon_check(folder):
|
||||
"""The app's icon.png: ("ok", "missing" or "bad", a note for the
|
||||
developer or "")."""
|
||||
path = os.path.join(folder, "icon.png")
|
||||
try:
|
||||
if not os.path.islink(path) and os.path.getsize(path) <= 1024 * 1024:
|
||||
with open(path, "rb") as f:
|
||||
if f.read(8) == b"\x89PNG\r\n\x1a\n":
|
||||
return path
|
||||
except OSError:
|
||||
pass
|
||||
default = "the Core shows the default icon instead"
|
||||
if os.path.islink(path):
|
||||
return "bad", f"icon.png is a link, so {default}. Make it a file."
|
||||
if not os.path.isfile(path):
|
||||
return "missing", f"No icon.png (a PNG file up to 1 MB), so {default}."
|
||||
if os.path.getsize(path) > ICON_LIMIT:
|
||||
return "bad", f"icon.png is bigger than 1 MB, so {default}."
|
||||
with open(path, "rb") as f:
|
||||
head = f.read(24)
|
||||
if head[:8] != b"\x89PNG\r\n\x1a\n" or head[12:16] != b"IHDR":
|
||||
return "bad", f"icon.png isn't a PNG, so {default}."
|
||||
width, height = struct.unpack(">II", head[16:24])
|
||||
notes = []
|
||||
if width != height:
|
||||
notes.append(f"icon.png is {width}x{height}; the dashboard shows it in a "
|
||||
"square, so a square one looks best.")
|
||||
if min(width, height) < 80:
|
||||
notes.append(f"icon.png is small ({width}x{height}): the dashboard shows it "
|
||||
"at 40x40 (80x80 pixels on sharp screens); 256x256 looks good.")
|
||||
return "ok", " ".join(notes)
|
||||
|
||||
|
||||
def icon_from(folder):
|
||||
"""The app's icon.png if it's usable, else the default."""
|
||||
if icon_check(folder)[0] == "ok":
|
||||
return os.path.join(folder, "icon.png")
|
||||
return os.path.join(TEMPLATES, "icon.png")
|
||||
|
||||
|
||||
@@ -752,6 +776,9 @@ def install_app(m, p, folder, origin, addon_ok, recreate):
|
||||
say(f"{m['title']} {m['version']} from {origin['source']} ({origin['tag']}, "
|
||||
f"commit {origin['commit'][:12]})")
|
||||
ensure_image(m, pull=bool(origin))
|
||||
state, note = icon_check(folder)
|
||||
if state != "ok":
|
||||
say(f"Note: {note}")
|
||||
|
||||
if p["state"] == "new":
|
||||
make_service_folder(m, p, folder, origin)
|
||||
@@ -1099,6 +1126,9 @@ def main(args):
|
||||
"health", "docs", "dbname"):
|
||||
print(f"{key}={m[key]}")
|
||||
print(f"needs={' '.join(m['needs'])}")
|
||||
state, note = icon_check(rest[0])
|
||||
print(f"icon={state}")
|
||||
print(f"icon_note={note}")
|
||||
return 0
|
||||
if os.geteuid() != 0:
|
||||
raise Refused("Run coreapps as root on the Core.")
|
||||
|
||||
Reference in New Issue
Block a user