From e00dc144a0afda98fa6fdc52e5113e4d7f6a7198 Mon Sep 17 00:00:00 2001
From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com>
Date: Fri, 20 Nov 2026 13:34:48 +0000
Subject: [PATCH] chore: Modify readme generator to handle no app icon is
available
---
.github/assets/blank-app-icon.svg | 3 +
.github/assets/universal-icon.svg | 11 ++
.github/scripts/generate_patches_readme.py | 136 +++++++++++++++++++--
README.md | 3 +-
4 files changed, 140 insertions(+), 13 deletions(-)
create mode 100644 .github/assets/blank-app-icon.svg
create mode 100644 .github/assets/universal-icon.svg
diff --git a/.github/assets/blank-app-icon.svg b/.github/assets/blank-app-icon.svg
new file mode 100644
index 000000000..b32568407
--- /dev/null
+++ b/.github/assets/blank-app-icon.svg
@@ -0,0 +1,3 @@
+
diff --git a/.github/assets/universal-icon.svg b/.github/assets/universal-icon.svg
new file mode 100644
index 000000000..4f9ac0de2
--- /dev/null
+++ b/.github/assets/universal-icon.svg
@@ -0,0 +1,11 @@
+
diff --git a/.github/scripts/generate_patches_readme.py b/.github/scripts/generate_patches_readme.py
index a892347ec..7c0c2d051 100644
--- a/.github/scripts/generate_patches_readme.py
+++ b/.github/scripts/generate_patches_readme.py
@@ -13,7 +13,10 @@ python3 generate_patches_readme.py [patches-list.json] [RE
import json
import re
import sys
-from html import escape
+import urllib.error
+import urllib.request
+from concurrent.futures import ThreadPoolExecutor
+from html import escape, unescape
from pathlib import Path
#
@@ -22,6 +25,18 @@ from pathlib import Path
#
INCLUDE_APP_ICONS = False
+#
+# Icons to use instead of the Play Store icon, keyed by package name.
+# Add an icon here for apps that have no icon, such as apps not on the Play Store,
+# or to replace an icon. The icon can be a URL, or a path relative to README.md
+# and PATCHES.md such as ".github/assets/my-app-icon.svg".
+# The "universal" entry is the icon of the universal patches.
+#
+ICON_OVERRIDES = {
+ "universal": ".github/assets/universal-icon.svg",
+ # "com.example.app": "https://example.com/icon.png",
+}
+
if len(sys.argv) < 3:
print("Usage: generate_patches_readme.py [json] [README] [PATCHES]")
@@ -41,6 +56,9 @@ owner, repo = repo_full.split("/", 1)
# Redirects / to the Play Store icon of the app, a 404 if the Play Store does not have it.
PLAY_STORE_ICON_URL = "https://publicmetadata.co.uk"
+# Icon of apps the Play Store does not have. Relative to README.md and PATCHES.md.
+BLANK_ICON_PATH = ".github/assets/blank-app-icon.svg"
+
with open(json_path, encoding="utf-8") as f:
data = json.load(f)
@@ -92,13 +110,93 @@ def play_store_link(package_name):
def app_icon(package_name, size):
- """Play Store icon of the app.
+ """Icon of the app, the "universal" override for the universal patches (no package
+ name), or an empty string if icons are off or there is no icon.
- The alt text is empty because the app name is always next to the icon, and so an
- app the Play Store does not have shows an empty space instead of a broken image.
+ The alt text is empty because the app name is always next to the icon.
"""
- src = escape(f"{PLAY_STORE_ICON_URL}/{package_name}")
- return f''
+ if not INCLUDE_APP_ICONS:
+ return ""
+ src = icons.get(package_name) if package_name else ICON_OVERRIDES.get("universal")
+ if not src:
+ return ""
+ return f''
+
+
+class _NoRedirectHandler(urllib.request.HTTPRedirectHandler):
+ """Makes a redirect raise an HTTPError instead of being followed."""
+
+ def redirect_request(self, *args, **kwargs):
+ return None
+
+
+_no_redirect_opener = urllib.request.build_opener(_NoRedirectHandler)
+
+
+def icon_api_status(url):
+ """HTTP status of the icon API for a URL, or None if the request failed."""
+ # Cloudflare rejects the default Python user agent with a 403.
+ request = urllib.request.Request(
+ url, method="HEAD", headers={"User-Agent": "patches-readme-generator"}
+ )
+ try:
+ with _no_redirect_opener.open(request, timeout=15) as response:
+ return response.status
+ except urllib.error.HTTPError as ex:
+ # Redirects and error responses are raised, the status is the result.
+ return ex.code
+ except OSError as ex:
+ # Network failures, including timeouts.
+ sys.stderr.write(f"Icon lookup failed for {url}: {ex}\n")
+ return None
+
+
+def existing_icons(readme_text):
+ """Icon of each package in the README index table, keyed by package name."""
+ found = {}
+ for line in readme_text.splitlines():
+ img = re.search(r' and .
START_PATTERN = r""
END_MARKER = ""
diff --git a/README.md b/README.md
index a3189772e..b85a035b1 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,8 @@ To start using this template, follow these steps:
patches after yourself ("UserXYZ Morphe patches"). See the [NOTICE](NOTICE) for details.
7. (Optional): Add `patches-bundle.png` to the project if you want a custom icon to show in
Morphe Manager instead of your GitHub profile avatar.
-8. (Optional): Sign your releases, so Morphe Manager refuses a release that was changed or swapped after you published it:
+8. (Optional): Set `INCLUDE_APP_ICONS = True` in [generate_patches_readme.py](.github/scripts/generate_patches_readme.py) to show app icons in the generated patches list.
+9. (Optional): Sign your releases, so Morphe Manager refuses a release that was changed or swapped after you published it:
1. Run `./gradlew generateSigningKey`. It creates `morphe-signing.pub` and `morphe-signing.key`.
2. Commit `morphe-signing.pub`. Never commit `morphe-signing.key`, it is already ignored by git.
3. Add the content of `morphe-signing.key` as the `MORPHE_SIGNING_KEY` secret in your repo