diff --git a/module/common/get_WebUI.sh b/module/common/get_WebUI.sh index b9cfcb5..1e5b61f 100644 --- a/module/common/get_WebUI.sh +++ b/module/common/get_WebUI.sh @@ -1,7 +1,6 @@ URL="https://github.com/5ec1cff/KsuWebUIStandalone/releases/download/v1.0/KsuWebUI-1.0-34-release.apk" APK_DIR="$COMPATH" -find_busybox check_wget echo "- Downloading the WebUI apk..." diff --git a/module/common/get_extra.sh b/module/common/get_extra.sh index 78cb68a..7b7f442 100644 --- a/module/common/get_extra.sh +++ b/module/common/get_extra.sh @@ -7,35 +7,33 @@ KBOUTPUT="$MODPATH/.extra" . $MODPATH/util_func.sh -find_busybox check_wget -# Fetch additional package names -wget --no-check-certificate -q -O - "https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/more-excldue.json" 2>/dev/null | \ -grep -o '"package-name": *"[^"]*"' | \ -awk -F'"' '{print $4}' > "$OUTPUT" - -if [ ! -s "$OUTPUT" ]; then - rm -f "$KBOUTPUT" - skipfetch=true -fi - -# Find xposed package name -pm list packages -3 &1 | cat | awk -F: '{print $2}' | while read -r PACKAGE; do - if ! grep -Fq "$PACKAGE" "$SKIPLIST"; then - pm path "$PACKAGE" | grep "base.apk" | awk -F: '{print $2}' | tr -d '\r' | while read -r APK_PATH; do - aapt dump xmltree "$APK_PATH" AndroidManifest.xml 2>/dev/null | grep -qE "xposed.category|xposeddescription" && echo "$PACKAGE" >> "$OUTPUT" - done - fi -done - -if [ "$skipfetch" != "true" ]; then +get_kb() { wget --no-check-certificate -qO "$KBOUTPUT" "https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/.extra" + [ -s "$KBOUTPUT" ] || rm -f "$KBOUTPUT" +} - if [ ! -s "$KBOUTPUT" ]; then - rm -f "$KBOUTPUT" +get_unnecessary() { + if [ ! -s "$OUTPUT" ] || [ ! -f "$OUTPUT" ]; then + wget --no-check-certificate -q -O - "https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/more-excldue.json" 2>/dev/null | \ + grep -o '"package-name": *"[^"]*"' | \ + awk -F'"' '{print $4}' > "$OUTPUT" fi + get_xposed +} +get_xposed() { + pm list packages -3 | awk -F: '{print $2}' | while read -r PACKAGE; do + if ! grep -Fq "$PACKAGE" "$SKIPLIST" && ! grep -Fq "$PACKAGE" "$OUTPUT"; then + pm path "$PACKAGE" | grep "base.apk" | awk -F: '{print $2}' | tr -d '\r' | while read -r APK_PATH; do + aapt dump xmltree "$APK_PATH" AndroidManifest.xml 2>/dev/null | grep -qE "xposed.category|xposeddescription" && echo "$PACKAGE" >> "$OUTPUT" + done + fi + done +} + +check_update() { if [ -d "$MODPATH/temp" ]; then JSON=$(wget --no-check-certificate -q -O - "https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/main/update.json") REMOTE_VERSION=$(echo "$JSON" | grep -o '"versionCode": *[0-9]*' | awk -F: '{print $2}' | tr -d ' ') @@ -44,6 +42,11 @@ if [ "$skipfetch" != "true" ]; then echo "update" fi fi -else - exit 1 -fi +} + +case "$1" in + --kb) get_kb; exit ;; + --unnecessary) get_unnecessary; exit ;; + --xposed) get_xposed; exit ;; + --update) check_update; exit ;; +esac \ No newline at end of file diff --git a/module/common/util_func.sh b/module/common/util_func.sh index 9ffdb9b..42fadf9 100644 --- a/module/common/util_func.sh +++ b/module/common/util_func.sh @@ -1,26 +1,18 @@ PACKAGE_NAME="io.github.a13e300.ksuwebui" MODID="set-id" -BBPATH="/data/adb/modules/busybox-ndk/system/*/busybox \ -/data/adb/magisk/busybox \ +BBPATH="/data/adb/magisk/busybox \ /data/adb/ksu/bin/busybox \ -/data/adb/ap/bin/busybox" - -find_busybox() { - for path in $BBPATH; do - if [ -f "$path" ]; then - BUSYBOX="$path" - return 0 - fi - done - return 1 -} +/data/adb/ap/bin/busybox \ +/data/adb/modules/busybox-ndk/system/*/busybox" check_wget() { + for path in $BBPATH; do + [ -f "$path" ] && BUSYBOX="$path" && break + done if ! command -v wget >/dev/null || grep -q "wget-curl" "$(command -v wget)"; then - if find_busybox; then + if [ -n "$BUSYBOX" ]; then wget() { "$BUSYBOX" wget "$@"; } else - echo "Error: busybox not found." > "$OUTPUT" exit 1 fi fi diff --git a/module/webroot/index.js b/module/webroot/index.js index 9d73ec0..4d5dba9 100644 --- a/module/webroot/index.js +++ b/module/webroot/index.js @@ -318,7 +318,7 @@ async function refreshAppList() { await new Promise(resolve => setTimeout(resolve, 500)); window.scrollTo(0, 0); if (noConnection.style.display === "flex") { - await runExtraScript(); + await updateCheck(); } await fetchAppList(); loadingIndicator.style.display = 'none'; @@ -344,34 +344,46 @@ function deselectAllApps() { }); } -// Function to run the extra script -async function runExtraScript() { - try { - const scriptPath = `${basePath}common/get_extra.sh`; - const output = await execCommand(scriptPath); - console.log("Extra script executed successfully."); - noConnection.style.display = "none"; - if (output.includes("update")) { - console.log("Update detected from extra script."); - showPrompt("new_update"); - updateCard.style.display = "flex"; - await execCommand(` +// Function to run the update check +async function updateCheck() { + try { + const scriptPath = `sh ${basePath}common/get_extra.sh --update`; + const output = await execCommand(scriptPath); + console.log("update script executed successfully."); + noConnection.style.display = "none"; + if (output.includes("update")) { + console.log("Update detected from extra script."); + showPrompt("new_update"); + updateCard.style.display = "flex"; + await execCommand(` su -c "mkdir -p '/data/adb/modules/TA_utl' && cp -rf '${basePath}common/temp/'* '/data/adb/modules/TA_utl/'" `); - } else { - console.log("No update detected from extra script."); + } else { + console.log("No update detected from extra script."); + } + } catch (error) { + console.error("Failed to execute update script:", error); + showPrompt("no_internet", false); + noConnection.style.display = "flex"; } - } catch (error) { - console.error("Failed to execute Extra script:", error); - showPrompt("no_internet", false); - noConnection.style.display = "flex"; - } } // Function to read the exclude list and uncheck corresponding apps async function deselectUnnecessaryApps() { try { + const fileCheck = await execCommand(`test -f ${basePath}common/exclude-list && echo "exists" || echo "not found"`); + if (fileCheck.trim() === "not found") { + setTimeout(async () => { + await execCommand(`sh ${basePath}common/get_extra.sh --unnecessary`); + }, 100); + console.log("Exclude list not found. Running the unnecessary apps script."); + } else { + setTimeout(async () => { + await execCommand(`sh ${basePath}common/get_extra.sh --xposed`); + }, 100); + console.log("Exclude list found. Running xposed script."); + } const result = await execCommand(`cat ${basePath}common/exclude-list`); const UnnecessaryApps = result.split("\n").map(app => app.trim()).filter(Boolean); const apps = document.querySelectorAll(".card"); @@ -380,10 +392,10 @@ async function deselectUnnecessaryApps() { const packageName = contentElement.getAttribute("data-package"); const checkbox = app.querySelector(".checkbox"); if (UnnecessaryApps.includes(packageName)) { - checkbox.checked = false; // Uncheck if found in more-exclude list + checkbox.checked = false; } }); - console.log("unnecessary apps deselected successfully."); + console.log("Unnecessary apps deselected successfully."); } catch (error) { console.error("Failed to deselect unnecessary apps:", error); } @@ -452,6 +464,9 @@ async function aospkb() { // Function to replace valid kb async function extrakb() { + setTimeout(async () => { + await execCommand(`sh ${basePath}common/get_extra.sh --kb`); + }, 100); const sourcePath = `${basePath}common/.extra`; const destinationPath = "/data/adb/tricky_store/keybox.xml"; try { @@ -469,7 +484,6 @@ async function extrakb() { } } - // Function to handle Verified Boot Hash async function setBootHash() { const showCard = () => { @@ -563,7 +577,7 @@ async function fetchAppList() { } catch (error) { console.error("Failed to read target.txt file:", error); } - + let applistMap = {}; try { const applistResult = await execCommand(`cat ${basePath}common/applist`); @@ -769,11 +783,11 @@ document.addEventListener('DOMContentLoaded', async () => { checkMagisk(); loadingIndicator.style.display = "none"; document.querySelector('.uninstall-container').classList.remove('hidden-uninstall'); - runExtraScript(); + setTimeout(updateCheck, 0); }); // Redirect to GitHub release page -updateCard.addEventListener('click', async() => { +updateCard.addEventListener('click', async () => { try { await execCommand('am start -a android.intent.action.VIEW -d https://github.com/KOWX712/Tricky-Addon-Update-Target-List/releases/latest'); } catch (error) { @@ -782,19 +796,19 @@ updateCard.addEventListener('click', async() => { }); telegramLink.addEventListener('click', async () => { - try { - await execCommand('am start -a android.intent.action.VIEW -d https://t.me/kowchannel'); - } catch (error) { - console.error('Error opening Telegram link:', error); - } + try { + await execCommand('am start -a android.intent.action.VIEW -d https://t.me/kowchannel'); + } catch (error) { + console.error('Error opening Telegram link:', error); + } }); githubLink.addEventListener('click', async () => { - try { - await execCommand('am start -a android.intent.action.VIEW -d https://github.com/KOWX712/Tricky-Addon-Update-Target-List'); - } catch (error) { - console.error('Error opening GitHub link:', error); - } + try { + await execCommand('am start -a android.intent.action.VIEW -d https://github.com/KOWX712/Tricky-Addon-Update-Target-List'); + } catch (error) { + console.error('Error opening GitHub link:', error); + } }); // Function to execute shell commands