Files
patcher/patches/settings_urls.py
wowlikon 5ff882a8d5 Рефакторинг патчей, реализация Список патчей:
settings_urls: ✔ enabled
  disable_ad: ✔ enabled
  disable_beta_banner: ✔ enabled
  insert_new: ✔ enabled
  color_theme: ✔ enabled
  change_server: ✘ disabled
  package_name: ✔ enabled
  replace_navbar: ✔ enabled
  compress: ✔ enabled, обновление описаний
2025-09-20 23:00:00 +03:00

81 lines
2.7 KiB
Python

"""
Добавляет в настройки ссылки и добвляет текст к версии приложения
"settings_urls": {
"enabled": true,
"menu": {
"Раздел": [
{
"title": "Заголовок",
"description": "Описание",
"url": "ссылка",
"icon": "@drawable/ic_custom_telegram",
"icon_space_reserved": "false"
},
...
],
...
]
},
"version": " by wowlikon"
}
"""
priority = 0
# imports
from lxml import etree
# Patch
def make_category(ns, name, items):
cat = etree.Element("PreferenceCategory", nsmap=ns)
cat.set(f"{{{ns['android']}}}title", name)
cat.set(f"{{{ns['app']}}}iconSpaceReserved", "false")
for item in items:
pref = etree.SubElement(cat, "Preference", nsmap=ns)
pref.set(f"{{{ns['android']}}}title", item["title"])
pref.set(f"{{{ns['android']}}}summary", item["description"])
pref.set(f"{{{ns['app']}}}icon", item["icon"])
pref.set(f"{{{ns['app']}}}iconSpaceReserved", item["icon_space_reserved"])
intent = etree.SubElement(pref, "intent", nsmap=ns)
intent.set(f"{{{ns['android']}}}action", "android.intent.action.VIEW")
intent.set(f"{{{ns['android']}}}data", item["url"])
intent.set(f"{{{ns['app']}}}iconSpaceReserved", item["icon_space_reserved"])
return cat
def apply(config: dict) -> bool:
file_path = "./decompiled/res/xml/preference_main.xml"
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(file_path, parser)
root = tree.getroot()
# Insert new PreferenceCategory before the last element
last = root[-1] # last element
pos = root.index(last)
for section, items in config["menu"].items():
root.insert(pos, make_category(config["xml_ns"], section, items))
pos += 1
# Save back
tree.write(file_path, pretty_print=True, xml_declaration=True, encoding="utf-8")
filepaths = [
"./decompiled/smali_classes2/com/swiftsoft/anixartd/ui/activity/UpdateActivity.smali",
"./decompiled/smali_classes2/com/swiftsoft/anixartd/ui/fragment/main/preference/MainPreferenceFragment.smali",
]
for filepath in filepaths:
content = ""
with open(filepath, "r", encoding="utf-8") as file:
for line in file.readlines():
if '"\u0412\u0435\u0440\u0441\u0438\u044f'.encode("unicode_escape").decode() in line:
content += line[:line.rindex('"')] + config["version"] + line[line.rindex('"'):]
else:
content += line
with open(filepath, "w", encoding="utf-8") as file:
file.write(content)
return True