From 7cae88c2efcc54f987885b63c66e4d1f8db11767 Mon Sep 17 00:00:00 2001 From: Radiquum Date: Thu, 4 Sep 2025 14:12:41 +0500 Subject: [PATCH] feat: [R] Include enabled patches, developer and more info in settings Fixes #4 --- patches/add_settings_menu_items.config.json | 23 ++++- patches/add_settings_menu_items.py | 87 +++++++++++++++++-- patches/resources/icons-night/github_mark.xml | 5 ++ patches/resources/icons/github_mark.xml | 5 ++ patches/resources/icons/solar_code_2_bold.xml | 5 ++ 5 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 patches/resources/icons-night/github_mark.xml create mode 100644 patches/resources/icons/github_mark.xml create mode 100644 patches/resources/icons/solar_code_2_bold.xml diff --git a/patches/add_settings_menu_items.config.json b/patches/add_settings_menu_items.config.json index 3c8312d..e340672 100644 --- a/patches/add_settings_menu_items.config.json +++ b/patches/add_settings_menu_items.config.json @@ -1,3 +1,24 @@ { - "add_patch_info": true + "add_patch_info": true, + "main_settings_categories": [ + { + "title": "anixart-patcher", + "items": [ + { + "title": "Radiquum", + "summary": "Разработчик", + "url": "https://radiquum.wah.su/", + "icon": "@drawable/solar_code_2_bold", + "icon_space_reserved": false + }, + { + "title": "Репозиторий", + "summary": "https://github.com/Radiquum/anixart-patcher", + "url": "https://github.com/Radiquum/anixart-patcher", + "icon": "@drawable/github_mark", + "icon_space_reserved": false + } + ] + } + ] } \ No newline at end of file diff --git a/patches/add_settings_menu_items.py b/patches/add_settings_menu_items.py index 153c70c..febcd39 100644 --- a/patches/add_settings_menu_items.py +++ b/patches/add_settings_menu_items.py @@ -1,4 +1,5 @@ """Adds used patches and custom menu items to app settings""" + # Developer: Radiquum # URL: @@ -9,6 +10,7 @@ priority = -95 # imports ## bundled import os +import shutil import random import string from typing import TypedDict @@ -21,9 +23,23 @@ from config import config, log # Patch +class PatchConfig_AddSettingsMenuItemsCategoryItem(TypedDict): + title: str + summary: str | None + url: str | None + icon: str | None + icon_space_reserved: bool + + +class PatchConfig_AddSettingsMenuItemsCategory(TypedDict): + title: str + items: list[PatchConfig_AddSettingsMenuItemsCategoryItem] + + class PatchConfig_AddSettingsMenuItems(TypedDict): _internal_all_patch_statuses: list add_patch_info: bool + main_settings_categories: list[PatchConfig_AddSettingsMenuItemsCategory] def random_key(): @@ -53,14 +69,14 @@ def create_intent( def create_Preference( title: str, - description: str | None = None, + summary: str | None = None, icon: str | None = None, icon_space_reserved: bool = False, ): ns = config["xml_ns"] item = etree.Element("Preference", nsmap=ns) item.set(f"{{{ns['android']}}}title", title) - item.set(f"{{{ns['android']}}}summary", description or "") + item.set(f"{{{ns['android']}}}summary", summary or "") if icon: item.set(f"{{{ns['app']}}}icon", icon) item.set(f"{{{ns['app']}}}iconSpaceReserved", str(icon_space_reserved).lower()) @@ -77,6 +93,23 @@ def create_PreferenceCategory(title: str): return category +def add_icons(): + src_icon_path = f"{config["folders"]["patches"]}/resources/icons" + src_icon_night_path = f"{config["folders"]["patches"]}/resources/icons-night" + dst_icon_path = f"{config["folders"]["decompiled"]}/res/drawable" + dst_icon_night_path = f"{config["folders"]["decompiled"]}/res/drawable-night" + icons = os.listdir(src_icon_path) + if len(icons) == 0: + return + + for icon in icons: + shutil.copy(f"{src_icon_path}/{icon}", f"{dst_icon_path}/{icon}") + if os.path.exists(f"{src_icon_night_path}/{icon}"): + shutil.copy( + f"{src_icon_night_path}/{icon}", f"{dst_icon_night_path}/{icon}" + ) + + def add_patch_info(patch_statuses: list): category = create_PreferenceCategory("Использованные патчи") for patch in patch_statuses: @@ -91,23 +124,48 @@ def add_patch_info(patch_statuses: list): ) as f: line = f.readline() if line.startswith('"""'): - description.append(line.strip().removeprefix('"""').removesuffix('"""').strip()) + description.append( + line.strip().removeprefix('"""').removesuffix('"""').strip() + ) line = f.readline() if line.startswith("# Developer:"): description.append("by") - description.append(line.strip().removeprefix("# Developer:").strip()) + description.append( + line.strip().removeprefix("# Developer:").strip() + ) line = f.readline() if line.startswith("# URL:"): url = line.strip().removeprefix("# URL:").strip() - item = create_Preference(patch["name"].replace("_", " ").strip().title(), description=" ".join(description)) + item = create_Preference( + patch["name"].replace("_", " ").strip().title(), + description=" ".join(description), + ) if url: - item.append(create_intent(data = url)) + item.append(create_intent(data=url)) category.append(item) return category +def add_custom_category( + title: str, items: list[PatchConfig_AddSettingsMenuItemsCategoryItem] +): + category = create_PreferenceCategory(title) + for item in items: + new_item = create_Preference( + item["title"], + item["summary"], + item["icon"], + item["icon_space_reserved"], + ) + if item["url"]: + new_item.append(create_intent(data=item["url"])) + category.append(new_item) + return category + + def apply(patch_conf: PatchConfig_AddSettingsMenuItems) -> bool: + parser = etree.XMLParser(remove_blank_text=True) preference_main_xml = ( f"{config['folders']['decompiled']}/res/xml/preference_main.xml" ) @@ -115,7 +173,22 @@ def apply(patch_conf: PatchConfig_AddSettingsMenuItems) -> bool: f"{config['folders']['decompiled']}/res/xml/preference_additional.xml" ) - parser = etree.XMLParser(remove_blank_text=True) + add_icons() + + if os.path.exists(preference_main_xml): + tree = etree.parse(preference_main_xml, parser) + root = tree.getroot() + + last = root[-1]; pos = root.index(last) + for item in patch_conf["main_settings_categories"]: + root.insert(pos, add_custom_category(item["title"], item["items"])); pos += 1 + + tree.write( + preference_main_xml, + pretty_print=True, + xml_declaration=True, + encoding="utf-8", + ) if os.path.exists(preference_additional_xml): tree = etree.parse(preference_additional_xml, parser) diff --git a/patches/resources/icons-night/github_mark.xml b/patches/resources/icons-night/github_mark.xml new file mode 100644 index 0000000..42c9d27 --- /dev/null +++ b/patches/resources/icons-night/github_mark.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/patches/resources/icons/github_mark.xml b/patches/resources/icons/github_mark.xml new file mode 100644 index 0000000..ce12ac8 --- /dev/null +++ b/patches/resources/icons/github_mark.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/patches/resources/icons/solar_code_2_bold.xml b/patches/resources/icons/solar_code_2_bold.xml new file mode 100644 index 0000000..8f42ffc --- /dev/null +++ b/patches/resources/icons/solar_code_2_bold.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file