opt: dynamically adjust basePath in js

This commit is contained in:
KOWX712
2025-03-21 18:57:52 +08:00
parent 530f006154
commit e704bda0f7
6 changed files with 27 additions and 19 deletions

View File

@@ -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"

View File

@@ -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,

View File

@@ -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();

View File

@@ -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.");

View File

@@ -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);

View File

@@ -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";