From 410629fad5fc3f2e0e3eade128f5c0101a61c286 Mon Sep 17 00:00:00 2001 From: KOWX712 Date: Sat, 22 Feb 2025 19:17:53 +0800 Subject: [PATCH] opt: move unnecessary list download to JS --- module/common/get_extra.sh | 17 ++---------- module/webui/scripts/menu_option.js | 40 ++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/module/common/get_extra.sh b/module/common/get_extra.sh index f44fe61..4c012f9 100644 --- a/module/common/get_extra.sh +++ b/module/common/get_extra.sh @@ -2,7 +2,6 @@ MODPATH=${0%/*} ORG_PATH="$PATH" SKIPLIST="$MODPATH/tmp/skiplist" -OUTPUT="$MODPATH/tmp/exclude-list" if [ "$MODPATH" = "/data/adb/modules/.TA_utl/common" ]; then MODDIR="/data/adb/modules/.TA_utl" @@ -39,24 +38,16 @@ download() { } get_xposed() { - pm list packages -3 | cut -d':' -f2 | grep -vxF -f "$SKIPLIST" | grep -vxF -f "$OUTPUT" | while read -r PACKAGE; do + pm list packages -3 | cut -d':' -f2 | grep -vxF -f "$SKIPLIST" | while read -r PACKAGE; do APK_PATH=$(pm path "$PACKAGE" | grep "base.apk" | cut -d':' -f2 | tr -d '\r') if [ -n "$APK_PATH" ]; then if aapt dump xmltree "$APK_PATH" AndroidManifest.xml 2>/dev/null | grep -qE "xposed.category|xposeddescription"; then - echo "$PACKAGE" >>"$OUTPUT" + echo "$PACKAGE" fi fi done } -get_unnecessary() { - if [ ! -s "$OUTPUT" ] || [ ! -f "$OUTPUT" ]; then - JSON=$(download --fetch "https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/more-exclude.json") || exit 1 - echo "$JSON" | grep -o '"package-name": *"[^"]*"' | awk -F'"' '{print $4}' >"$OUTPUT" - fi - get_xposed -} - check_update() { [ -f "$MODDIR/disable" ] && rm -f "$MODDIR/disable" LOCAL_VERSION=$(grep '^versionCode=' "$MODPATH/update/module.prop" | awk -F= '{print $2}') @@ -146,10 +137,6 @@ get_latest_security_patch() { } case "$1" in ---unnecessary) - get_unnecessary - exit - ;; --xposed) get_xposed exit diff --git a/module/webui/scripts/menu_option.js b/module/webui/scripts/menu_option.js index 87bb788..6eb8b7b 100644 --- a/module/webui/scripts/menu_option.js +++ b/module/webui/scripts/menu_option.js @@ -40,17 +40,33 @@ document.getElementById("select-denylist").addEventListener("click", async () => // Function to read the exclude list and uncheck corresponding apps document.getElementById("deselect-unnecessary").addEventListener("click", async () => { try { - const fileCheck = await execCommand(`test -f ${basePath}common/tmp/exclude-list && echo "exists" || echo "not found"`); - if (fileCheck.trim() === "not found") { - setTimeout(async () => { - await execCommand(`sh ${basePath}common/get_extra.sh --unnecessary`); - }, 0); - console.log("Exclude list not found. Running the unnecessary apps script."); + const fileCheck = await execCommand(`[ -f ${basePath}common/tmp/exclude-list ] || echo "false"`); + if (fileCheck.trim() === "false") { + fetch("https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/more-exclude.json") + .then(response => { + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + return response.json(); + }) + .then(data => { + const excludeList = data.data + .flatMap(category => category.apps) + .map(app => app['package-name']) + .join('\n'); + return excludeList; + }) + .then(async excludeList => { + await execCommand(` + echo "${excludeList}" > ${basePath}common/tmp/exclude-list + sh ${basePath}common/get_extra.sh --xposed + `); + }) + .catch(error => { + toast("Failed to download unnecessary apps!"); + }); } else { - setTimeout(async () => { - await execCommand(`sh ${basePath}common/get_extra.sh --xposed`); - }, 0); - console.log("Exclude list found. Running xposed script."); + await execCommand(`sh ${basePath}common/get_extra.sh --xposed`); } await new Promise(resolve => setTimeout(resolve, 100)); const result = await execCommand(`cat ${basePath}common/tmp/exclude-list`); @@ -66,8 +82,8 @@ document.getElementById("deselect-unnecessary").addEventListener("click", async }); console.log("Unnecessary apps deselected successfully."); } catch (error) { - toast("Failed!"); - console.error("Failed to deselect unnecessary apps:", error); + toast("Failed to get unnecessary apps!"); + console.error("Failed to get unnecessary apps:", error); } });