mirror of
https://git-qiuchenly.yltfspace.com/QiuChenly/corepatch
synced 2025-11-25 10:08:20 +08:00
Fix: Failed to search for apps when packageName is list.
This commit is contained in:
53
main.py
53
main.py
@@ -13,10 +13,17 @@ def read_input(prompt):
|
||||
def search_apps(app_list, install_apps, keyword):
|
||||
keyword = keyword.lower()
|
||||
installed_apps = {app['CFBundleIdentifier']: app['CFBundleName'].lower() for app in install_apps}
|
||||
def is_match(pn): return any(keyword in p.lower() for p in (pn if isinstance(pn, list) else [pn]))
|
||||
return [{**app, "packageName": pn} for app in app_list
|
||||
if (pn := app.get("packageName")) and is_match(pn) and any(pid == pn and keyword in name for pid, name in installed_apps.items())]
|
||||
|
||||
def is_match(pn):
|
||||
return keyword in (pn.lower() if isinstance(pn, str) else any(keyword in p.lower() for p in pn))
|
||||
matched_apps = []
|
||||
for app in app_list:
|
||||
pn_list = app.get("packageName")
|
||||
if isinstance(pn_list, list):
|
||||
matched = [pn for pn in pn_list if is_match(pn) and any(pid == pn and keyword in name for pid, name in installed_apps.items())]
|
||||
matched_apps.extend({**app, "packageName": pn} for pn in matched)
|
||||
elif pn_list and is_match(pn_list):
|
||||
matched_apps.append({**app, "packageName": pn_list})
|
||||
return matched_apps
|
||||
|
||||
def parse_app_info(app_base_locate, app_info_file):
|
||||
with open(app_info_file, "rb") as f:
|
||||
@@ -157,20 +164,32 @@ def main():
|
||||
matched_apps = search_apps(app_list, install_apps, keyword)
|
||||
if not matched_apps:
|
||||
print("未找到匹配的应用程序。")
|
||||
exit(0)
|
||||
|
||||
print("找到以下匹配的应用程序:")
|
||||
for i, app in enumerate(matched_apps, 1):
|
||||
package_name = app.get("packageName")
|
||||
print(f"{i}. {' / '.join(package_name) if isinstance(package_name, list) else package_name}")
|
||||
|
||||
choice = input("请输入要注入的应用程序编号,或输入0退出: ").strip()
|
||||
if choice.isdigit() and 0 < int(choice) <= len(matched_apps):
|
||||
selected_app = matched_apps[int(choice) - 1]
|
||||
app_Lst = [selected_app.copy() | {"packageName": name} for name in (selected_app["packageName"] if isinstance(selected_app["packageName"], list) else [selected_app["packageName"]])]
|
||||
else:
|
||||
print("已退出程序。")
|
||||
exit(0)
|
||||
app_Lst = []
|
||||
selected = set()
|
||||
while len(selected) < len(matched_apps):
|
||||
print("找到以下匹配的应用程序:")
|
||||
for i, app in enumerate(matched_apps, 1):
|
||||
status = " ✅[已选中]" if i-1 in selected else ""
|
||||
print(f"{i}. {app.get('packageName')}{status}")
|
||||
if len(selected) == len(matched_apps):
|
||||
print("所有应用已选中,即将开始处理...")
|
||||
break
|
||||
choice = input("请输入要注入的应用程序编号,输入0退出,或按回车继续: ").strip()
|
||||
if choice == '0':
|
||||
print("已退出程序。")
|
||||
exit(0)
|
||||
elif choice.isdigit() and 0 < int(choice) <= len(matched_apps):
|
||||
index = int(choice) - 1
|
||||
if index not in selected:
|
||||
app_Lst.append(matched_apps[index])
|
||||
selected.add(index)
|
||||
if len(selected) == len(matched_apps): print("所有应用已选中,即将开始处理...")
|
||||
else: print(f"应用 {matched_apps[index].get('packageName')} 已经被选择,请选择其他应用。")
|
||||
elif choice == '':
|
||||
if not app_Lst: print("未选择任何应用,请至少选择一个应用。")
|
||||
else: break
|
||||
else: print("无效的输入,请重新选择。")
|
||||
else:
|
||||
app_Lst = [app.copy() | {"packageName": name} for app in app_list
|
||||
if not (app.get("forQiuChenly") and not os.path.exists("/Users/qiuchenly"))
|
||||
|
||||
Reference in New Issue
Block a user