diff --git a/.github/scripts/generate_patches_readme.py b/.github/scripts/generate_patches_readme.py
index 6b1ccc16a..367b2a00f 100644
--- a/.github/scripts/generate_patches_readme.py
+++ b/.github/scripts/generate_patches_readme.py
@@ -63,10 +63,18 @@ with open(json_path, encoding="utf-8") as f:
data = json.load(f)
-# Group patches by package; patches with no compatiblePackages are universal.
+# App name suffix of each form factor. Mobile and unspecified have no suffix.
+FORM_FACTORS = {
+ "TV": "Android TV",
+ "WEARABLE": "Wear OS",
+ "AUTOMOTIVE": "Android Automotive",
+}
+
+# Group patches by package and form factor; patches with no compatiblePackages are universal.
+# The same package name can be used by different apps for each form factor.
# JSON structure: compatiblePackages is a list of objects with
-# { packageName, name, targets: [{ version, isExperimental, description }] }
-by_pkg = {} # packageName -> { name, patches, targets }
+# { packageName, name, formFactor, targets: [{ version, isExperimental, description }] }
+by_pkg = {} # (packageName, form factor suffix) -> { name, package, patches, targets }
universal = {}
for patch in data["patches"]:
@@ -80,16 +88,19 @@ for patch in data["patches"]:
for pkg_entry in compatible_packages:
package_name = pkg_entry["packageName"]
app_name = pkg_entry.get("name") or package_name
- if package_name not in by_pkg:
- by_pkg[package_name] = {
- "name": app_name,
+ suffix = FORM_FACTORS.get(pkg_entry.get("formFactor"))
+ key = (package_name, suffix)
+ if key not in by_pkg:
+ by_pkg[key] = {
+ "name": f"{app_name} ({suffix})" if suffix else app_name,
+ "package": package_name,
"patches": {},
- "targets": pkg_entry.get("targets", []),
+ "targets": pkg_entry.get("targets") or [],
}
# Deduplicate patches that appear across multiple packages.
- if patch["name"] not in by_pkg[package_name]["patches"]:
- by_pkg[package_name]["patches"][patch["name"]] = patch
+ if patch["name"] not in by_pkg[key]["patches"]:
+ by_pkg[key]["patches"][patch["name"]] = patch
def anchor(name):
@@ -217,6 +228,19 @@ def version_labels(targets):
return labels
+def count_label(count, singular, plural):
+ """Count followed by its noun, such as "1 patch" or "2 patches"."""
+ return f"{count} {singular if count == 1 else plural}"
+
+
+def totals_label():
+ """Total patch and app counts."""
+ return (
+ f"**{count_label(total, 'patch', 'patches')}** across "
+ f"**{count_label(len(sorted_packages), 'app', 'apps')}**"
+ )
+
+
def clean_description(text):
"""Collapse all whitespace in a description into single spaces."""
return re.sub(r"\s+", " ", (text or "")).strip()
@@ -237,7 +261,7 @@ def options_summary(options, visible=3):
shown = titles[:visible]
remaining = len(titles) - len(shown)
- summary = ", ".join(escape(title, quote=False) for title in shown)
+ summary = ", ".join(markdown_cell(clean_description(title)) for title in shown)
if remaining > 0:
summary += f", +{remaining} more"
return f"
Options: {summary}"
@@ -253,7 +277,7 @@ def patches_table(patches):
for patch in sorted(patches, key=lambda p: p["name"]):
description = clean_description(patch.get("description") or "")
details = markdown_cell(description) + options_summary(patch.get("options") or [])
- rows.append(f"| **{escape(patch['name'], quote=False)}** | {details} |")
+ rows.append(f"| **{markdown_cell(patch['name'])}** | {details} |")
return "\n".join(rows)
@@ -268,7 +292,7 @@ def versions_line(targets):
def index_row(index, app_name, package_name, count, labels):
"""One row of the compact README index table."""
- app_cell = f"[**{escape(app_name, quote=False)}**](PATCHES.md#{app_anchor(app_name, package_name)})"
+ app_cell = f"[**{markdown_cell(app_name)}**](PATCHES.md#{app_anchor(app_name, package_name)})"
icon = app_icon(package_name, 24)
if icon:
app_cell = f"{icon} {app_cell}"
@@ -286,20 +310,20 @@ def build_readme_section():
lines = [
f"> **[v{ver}](https://github.com/{owner}/{repo}/releases/tag/v{ver})**"
f" · `{branch}` · "
- f"**{total} patches** across **{len(sorted_packages)} apps**"
+ f"{totals_label()}"
f" · [Full details](PATCHES.md)",
"",
"| # | App | Patches | Version | Package |",
"|---|---|---|---|---|",
]
- for index, (package_name, entry) in enumerate(sorted_packages, start=1):
+ for index, entry in enumerate(sorted_packages, start=1):
patches = list(entry["patches"].values())
lines.append(
index_row(
index,
entry["name"],
- package_name,
+ entry["package"],
len(patches),
version_labels(entry["targets"]),
)
@@ -326,14 +350,15 @@ def build_patches_doc():
"# Patches",
"",
f"> Generated from `patches-list.json` — **v{ver}** (`{branch}`) · "
- f"**{total} patches** across **{len(sorted_packages)} apps** · "
+ f"{totals_label()} · "
f"back to [README](README.md)",
"",
"---",
"",
]
- for package_name, entry in sorted_packages:
+ for entry in sorted_packages:
+ package_name = entry["package"]
patches = list(entry["patches"].values())
sections.append(f"## {entry['name']} ({package_name})")
sections.append("")
@@ -363,27 +388,45 @@ def build_patches_doc():
raw_ver = data["version"]
ver = raw_ver.lstrip("v")
total = sum(len(entry["patches"]) for entry in by_pkg.values()) + len(universal)
-sorted_packages = sorted(by_pkg.items(), key=lambda item: item[1]["name"].lower())
+sorted_packages = sorted(by_pkg.values(), key=lambda entry: entry["name"].lower())
readme = readme_path.read_text(encoding="utf-8")
+# Replace the template links if present.
+readme = readme.replace(
+ "https://morphe.software/add-source?github=xyz-user/xyz-patches",
+ f"https://morphe.software/add-source?github={repo_full}",
+)
+readme = readme.replace("https://github.com/xyz-user/xyz-patches", f"https://github.com/{repo_full}")
+
icons = (
- resolve_icons([package_name for package_name, _ in sorted_packages], existing_icons(readme))
+ resolve_icons(
+ # The same package can be listed for more than one form factor.
+ list(dict.fromkeys(entry["package"] for entry in sorted_packages)),
+ existing_icons(readme),
+ )
if INCLUDE_APP_ICONS
else {}
)
-# Marker pattern matches both and .
+# EXPANDED has no effect, but the README of older projects can still have it.
START_PATTERN = r""
END_MARKER = ""
marker_match = re.search(START_PATTERN, readme)
+if not marker_match and END_MARKER not in readme:
+ # Both markers were removed, so the README patches list is updated by hand.
+ readme_path.write_text(readme, encoding="utf-8")
+ patches_path.write_text(build_patches_doc(), encoding="utf-8")
+ print(f"No patches list markers in {readme_path}, only wrote {patches_path}")
+ sys.exit(0)
+
if not marker_match or END_MARKER not in readme:
- # Fallback: print to stdout so CI can catch the issue.
+ # Only one marker is present. Print to stdout so CI can catch the issue.
print(build_readme_section())
sys.stderr.write(
- f"Markers / {END_MARKER} not found in {readme_path}. "
+ f"Markers / {END_MARKER} not found in {readme_path}. "
"Printed to stdout instead.\n"
)
sys.exit(1)
diff --git a/README.md b/README.md
index b85a035b1..aa0737580 100644
--- a/README.md
+++ b/README.md
@@ -18,11 +18,12 @@ Click the button below, or manually add this repo url to Morphe Manager: https:/
## 🩹 Patches list
-
+
@@ -80,7 +81,7 @@ To develop and release your Patches using this template:
If you need something custom with your releases then modify the existing `release.yml`
and `.releaserc` instead of writing everything new from scratch.
- Do not manually edit or manually commit any generated files such as: `patches-list.json`,
- `patches-bundle.json`, `CHANGELOG.md`. These files will be automatically updated by `release.yml`.
+ `patches-bundle.json`, `PATCHES.md`, `CHANGELOG.md`. These files will be automatically updated by `release.yml`.
- Do not force push any semantic release commits as that will break all future releases.
If you need to fix a broken release, it's always easiest to create a new release instead of
fixing an existing release.
diff --git a/patches/src/main/kotlin/app/template/patches/example/ExamplePatch.kt b/patches/src/main/kotlin/app/template/patches/example/ExamplePatch.kt
index c49b8e9d0..795c43d8a 100644
--- a/patches/src/main/kotlin/app/template/patches/example/ExamplePatch.kt
+++ b/patches/src/main/kotlin/app/template/patches/example/ExamplePatch.kt
@@ -1,3 +1,7 @@
+//
+// TODO: Delete this patch and the example patch extension code.
+//
+
package app.template.patches.example
import app.morphe.patcher.extensions.InstructionExtensions.addInstructions