From e704bda0f7af796e84e7cf093164aff1d47d361e Mon Sep 17 00:00:00 2001 From: KOWX712 Date: Fri, 21 Mar 2025 18:57:52 +0800 Subject: [PATCH] opt: dynamically adjust basePath in js --- module/install_func.sh | 3 --- module/webui/scripts/applist.js | 2 +- module/webui/scripts/main.js | 19 +++++++++++++++---- module/webui/scripts/menu_option.js | 4 ++-- module/webui/scripts/security_patch.js | 4 ++-- module/webui/scripts/update.js | 14 +++++++------- 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/module/install_func.sh b/module/install_func.sh index f13e9c5..af23c84 100644 --- a/module/install_func.sh +++ b/module/install_func.sh @@ -15,9 +15,6 @@ initialize() { cp "$MODPATH/uninstall.sh" "$COMPATH/update/uninstall.sh" fi - #Set specific path - sed -i "s|\"set-path\"|\"/data/adb/modules/$NEW_MODID/\"|" "$MODPATH/webui/scripts/main.js" || abort "! Failed to set path" - # Set aapt binary cp "$MODPATH/module.prop" "$COMPATH/update/module.prop" mv "$MODPATH/bin/$(getprop ro.product.cpu.abi)/aapt" "$COMPATH/aapt" diff --git a/module/webui/scripts/applist.js b/module/webui/scripts/applist.js index d17fe43..74c8ab2 100644 --- a/module/webui/scripts/applist.js +++ b/module/webui/scripts/applist.js @@ -46,7 +46,7 @@ export async function fetchAppList() { const appName = await execCommand(` base_apk=$(pm path ${packageName} | grep "base.apk" | awk -F: '{print $2}') [ -n "$base_apk" ] || base_apk=$(pm path ${packageName} | grep ".apk" | awk -F: '{print $2}') - ${basePath}common/aapt dump badging $base_apk 2>/dev/null | grep "application-label:" | sed "s/application-label://; s/'//g" + ${basePath}/common/aapt dump badging $base_apk 2>/dev/null | grep "application-label:" | sed "s/application-label://; s/'//g" `); return { appName: appName.trim() || packageName, diff --git a/module/webui/scripts/main.js b/module/webui/scripts/main.js index dd5c451..62d62bf 100644 --- a/module/webui/scripts/main.js +++ b/module/webui/scripts/main.js @@ -17,7 +17,7 @@ const prompt = document.getElementById('prompt'); const floatingCard = document.querySelector('.floating-card'); const floatingBtn = document.querySelector('.floating-btn'); -export const basePath = "set-path"; +export let basePath; export const appsWithExclamation = []; export const appsWithQuestion = []; const ADDITIONAL_APPS = [ "android", "com.android.vending", "com.google.android.gms", "io.github.vvb2060.keyattestation", "io.github.vvb2060.mahoshojo", "icu.nullptr.nativetest" ]; // Always keep default apps in target.txt @@ -27,11 +27,21 @@ let e = 0; let isRefreshing = false; let MMRL_API = true; +// Function to set basePath +async function getBasePath() { + try { + await execCommand('[ -d /data/adb/modules/.TA_utl ]'); + basePath = "/data/adb/modules/.TA_utl" + } catch (error) { + basePath = "/data/adb/modules/TA_utl" + } +} + // Function to load the version from module.prop async function getModuleVersion() { const moduleVersion = document.getElementById('module-version'); try { - const version = await execCommand(`grep '^version=' ${basePath}common/update/module.prop | cut -d'=' -f2`); + const version = await execCommand(`grep '^version=' ${basePath}/common/update/module.prop | cut -d'=' -f2`); moduleVersion.textContent = version; } catch (error) { console.error("Failed to read version from module.prop:", error); @@ -55,7 +65,7 @@ export async function refreshAppList() { if (noConnection.style.display === "flex") { try { updateCheck(); - await execCommand(`[ -f ${basePath}common/tmp/exclude-list ] && rm -f "${basePath}common/tmp/exclude-list"`); + await execCommand(`[ -f ${basePath}/common/tmp/exclude-list ] && rm -f "${basePath}/common/tmp/exclude-list"`); } catch (error) { toast("Failed!"); console.error("Error occurred:", error); @@ -204,7 +214,7 @@ document.querySelector(".uninstall-container").addEventListener("click", () => { }); async function uninstallWebUI() { try { - await execCommand(`sh ${basePath}common/get_extra.sh --uninstall`); + await execCommand(`sh ${basePath}/common/get_extra.sh --uninstall`); console.log("uninstall script executed successfully."); showPrompt("prompt.uninstall_prompt"); } catch (error) { @@ -352,6 +362,7 @@ document.addEventListener('DOMContentLoaded', async () => { await loadTranslations(userLang); await checkMMRL(); if (!MMRL_API) return; + await getBasePath(); hideFloatingBtn(); getModuleVersion(); setupMenuToggle(); diff --git a/module/webui/scripts/menu_option.js b/module/webui/scripts/menu_option.js index 038f91e..9c4f5bf 100644 --- a/module/webui/scripts/menu_option.js +++ b/module/webui/scripts/menu_option.js @@ -57,7 +57,7 @@ document.getElementById("deselect-unnecessary").addEventListener("click", async toast("Failed to download unnecessary apps!"); throw error; }); - const xposed = await execCommand(`sh ${basePath}common/get_extra.sh --xposed`); + const xposed = await execCommand(`sh ${basePath}/common/get_extra.sh --xposed`); const UnnecessaryApps = excludeList.split("\n").map(app => app.trim()).filter(Boolean).concat(xposed.split("\n").map(app => app.trim()).filter(Boolean)); const apps = document.querySelectorAll(".card"); apps.forEach(app => { @@ -192,7 +192,7 @@ async function setKeybox(content) { // Function to replace aosp kb export async function aospkb() { - const source = await execCommand(`xxd -r -p ${basePath}common/.default | base64 -d`); + const source = await execCommand(`xxd -r -p ${basePath}/common/.default | base64 -d`); const result = await setKeybox(source); if (result) { console.log("AOSP keybox copied successfully."); diff --git a/module/webui/scripts/security_patch.js b/module/webui/scripts/security_patch.js index 44fe708..a2a9431 100644 --- a/module/webui/scripts/security_patch.js +++ b/module/webui/scripts/security_patch.js @@ -225,7 +225,7 @@ export function securityPatch() { // Auto config button autoButton.addEventListener('click', async () => { try { - const output = await execCommand(`sh ${basePath}common/get_extra.sh --security-patch`); + const output = await execCommand(`sh ${basePath}/common/get_extra.sh --security-patch`); if (output.trim() === "not set") { showPrompt('security_patch.auto_failed', false); } else { @@ -318,7 +318,7 @@ export function securityPatch() { try { showPrompt('security_patch.fetching'); await new Promise(resolve => setTimeout(resolve, 200)); - const output = await execCommand(`sh ${basePath}common/get_extra.sh --get-security-patch`); + const output = await execCommand(`sh ${basePath}/common/get_extra.sh --get-security-patch`); showPrompt('security_patch.fetched', true, 1000); checkAdvanced(true); diff --git a/module/webui/scripts/update.js b/module/webui/scripts/update.js index a243884..7929784 100644 --- a/module/webui/scripts/update.js +++ b/module/webui/scripts/update.js @@ -26,7 +26,7 @@ function downloadFile(targetURL, fileName) { reader.onload = async function() { const base64Data = reader.result.split(',')[1]; try { - await execCommand(`echo ${base64Data} | base64 -d > ${basePath}common/tmp/${fileName}`); + await execCommand(`echo ${base64Data} | base64 -d > ${basePath}/common/tmp/${fileName}`); resolve(); } catch (error) { reject(error); @@ -52,7 +52,7 @@ export async function updateCheck() { zipURL = data.zipUrl; changelogURL = data.changelog; - const updateAvailable = await execCommand(`sh ${basePath}common/get_extra.sh --check-update ${remoteVersionCode}`); + const updateAvailable = await execCommand(`sh ${basePath}/common/get_extra.sh --check-update ${remoteVersionCode}`); if (updateAvailable.includes("update")) { showPrompt("prompt.new_update", true, 1500); updateCard.style.display = "flex"; @@ -67,7 +67,7 @@ export async function updateCheck() { // Function to render changelog async function renderChangelog() { - const changelog = await execCommand(`sh ${basePath}common/get_extra.sh --release-note ${remoteVersion}`); + const changelog = await execCommand(`sh ${basePath}/common/get_extra.sh --release-note ${remoteVersion}`); window.linkRedirect = linkRedirect; marked.setOptions({ sanitize: true, @@ -111,8 +111,8 @@ function setupUpdateMenu() { updateCard.addEventListener('click', async () => { try { const module = await execCommand(` - [ -f ${basePath}common/tmp/module.zip ] || echo "noModule" - [ -f ${basePath}common/tmp/changelog.md ] || echo "noChangelog" + [ -f ${basePath}/common/tmp/module.zip ] || echo "noModule" + [ -f ${basePath}/common/tmp/changelog.md ] || echo "noChangelog" [ ! -f /data/adb/modules/TA_utl/update ] || echo "updated" `); if (module.trim().includes("updated")) { @@ -131,7 +131,7 @@ function setupUpdateMenu() { if (downloading) return; downloading = true; try { - await execCommand(`sh ${basePath}common/get_extra.sh --get-update ${zipURL}`); + await execCommand(`sh ${basePath}/common/get_extra.sh --get-update ${zipURL}`); showPrompt("prompt.downloaded"); installButton.style.display = "flex"; downloading = false; @@ -161,7 +161,7 @@ function setupUpdateMenu() { try { showPrompt("prompt.installing"); await new Promise(resolve => setTimeout(resolve, 300)); - await execCommand(`sh ${basePath}common/get_extra.sh --install-update`); + await execCommand(`sh ${basePath}/common/get_extra.sh --install-update`); showPrompt("prompt.installed"); installButton.style.display = "none"; rebootButton.style.display = "flex";