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" cp "$MODPATH/uninstall.sh" "$COMPATH/update/uninstall.sh"
fi 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 # Set aapt binary
cp "$MODPATH/module.prop" "$COMPATH/update/module.prop" cp "$MODPATH/module.prop" "$COMPATH/update/module.prop"
mv "$MODPATH/bin/$(getprop ro.product.cpu.abi)/aapt" "$COMPATH/aapt" 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(` const appName = await execCommand(`
base_apk=$(pm path ${packageName} | grep "base.apk" | awk -F: '{print $2}') 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}') [ -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 { return {
appName: appName.trim() || packageName, appName: appName.trim() || packageName,

View File

@@ -17,7 +17,7 @@ const prompt = document.getElementById('prompt');
const floatingCard = document.querySelector('.floating-card'); const floatingCard = document.querySelector('.floating-card');
const floatingBtn = document.querySelector('.floating-btn'); const floatingBtn = document.querySelector('.floating-btn');
export const basePath = "set-path"; export let basePath;
export const appsWithExclamation = []; export const appsWithExclamation = [];
export const appsWithQuestion = []; 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 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 isRefreshing = false;
let MMRL_API = true; 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 // Function to load the version from module.prop
async function getModuleVersion() { async function getModuleVersion() {
const moduleVersion = document.getElementById('module-version'); const moduleVersion = document.getElementById('module-version');
try { 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; moduleVersion.textContent = version;
} catch (error) { } catch (error) {
console.error("Failed to read version from module.prop:", error); console.error("Failed to read version from module.prop:", error);
@@ -55,7 +65,7 @@ export async function refreshAppList() {
if (noConnection.style.display === "flex") { if (noConnection.style.display === "flex") {
try { try {
updateCheck(); 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) { } catch (error) {
toast("Failed!"); toast("Failed!");
console.error("Error occurred:", error); console.error("Error occurred:", error);
@@ -204,7 +214,7 @@ document.querySelector(".uninstall-container").addEventListener("click", () => {
}); });
async function uninstallWebUI() { async function uninstallWebUI() {
try { 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."); console.log("uninstall script executed successfully.");
showPrompt("prompt.uninstall_prompt"); showPrompt("prompt.uninstall_prompt");
} catch (error) { } catch (error) {
@@ -352,6 +362,7 @@ document.addEventListener('DOMContentLoaded', async () => {
await loadTranslations(userLang); await loadTranslations(userLang);
await checkMMRL(); await checkMMRL();
if (!MMRL_API) return; if (!MMRL_API) return;
await getBasePath();
hideFloatingBtn(); hideFloatingBtn();
getModuleVersion(); getModuleVersion();
setupMenuToggle(); setupMenuToggle();

View File

@@ -57,7 +57,7 @@ document.getElementById("deselect-unnecessary").addEventListener("click", async
toast("Failed to download unnecessary apps!"); toast("Failed to download unnecessary apps!");
throw error; 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 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"); const apps = document.querySelectorAll(".card");
apps.forEach(app => { apps.forEach(app => {
@@ -192,7 +192,7 @@ async function setKeybox(content) {
// Function to replace aosp kb // Function to replace aosp kb
export async function aospkb() { 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); const result = await setKeybox(source);
if (result) { if (result) {
console.log("AOSP keybox copied successfully."); console.log("AOSP keybox copied successfully.");

View File

@@ -225,7 +225,7 @@ export function securityPatch() {
// Auto config button // Auto config button
autoButton.addEventListener('click', async () => { autoButton.addEventListener('click', async () => {
try { 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") { if (output.trim() === "not set") {
showPrompt('security_patch.auto_failed', false); showPrompt('security_patch.auto_failed', false);
} else { } else {
@@ -318,7 +318,7 @@ export function securityPatch() {
try { try {
showPrompt('security_patch.fetching'); showPrompt('security_patch.fetching');
await new Promise(resolve => setTimeout(resolve, 200)); 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); showPrompt('security_patch.fetched', true, 1000);
checkAdvanced(true); checkAdvanced(true);

View File

@@ -26,7 +26,7 @@ function downloadFile(targetURL, fileName) {
reader.onload = async function() { reader.onload = async function() {
const base64Data = reader.result.split(',')[1]; const base64Data = reader.result.split(',')[1];
try { try {
await execCommand(`echo ${base64Data} | base64 -d > ${basePath}common/tmp/${fileName}`); await execCommand(`echo ${base64Data} | base64 -d > ${basePath}/common/tmp/${fileName}`);
resolve(); resolve();
} catch (error) { } catch (error) {
reject(error); reject(error);
@@ -52,7 +52,7 @@ export async function updateCheck() {
zipURL = data.zipUrl; zipURL = data.zipUrl;
changelogURL = data.changelog; 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")) { if (updateAvailable.includes("update")) {
showPrompt("prompt.new_update", true, 1500); showPrompt("prompt.new_update", true, 1500);
updateCard.style.display = "flex"; updateCard.style.display = "flex";
@@ -67,7 +67,7 @@ export async function updateCheck() {
// Function to render changelog // Function to render changelog
async function renderChangelog() { 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; window.linkRedirect = linkRedirect;
marked.setOptions({ marked.setOptions({
sanitize: true, sanitize: true,
@@ -111,8 +111,8 @@ function setupUpdateMenu() {
updateCard.addEventListener('click', async () => { updateCard.addEventListener('click', async () => {
try { try {
const module = await execCommand(` const module = await execCommand(`
[ -f ${basePath}common/tmp/module.zip ] || echo "noModule" [ -f ${basePath}/common/tmp/module.zip ] || echo "noModule"
[ -f ${basePath}common/tmp/changelog.md ] || echo "noChangelog" [ -f ${basePath}/common/tmp/changelog.md ] || echo "noChangelog"
[ ! -f /data/adb/modules/TA_utl/update ] || echo "updated" [ ! -f /data/adb/modules/TA_utl/update ] || echo "updated"
`); `);
if (module.trim().includes("updated")) { if (module.trim().includes("updated")) {
@@ -131,7 +131,7 @@ function setupUpdateMenu() {
if (downloading) return; if (downloading) return;
downloading = true; downloading = true;
try { 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"); showPrompt("prompt.downloaded");
installButton.style.display = "flex"; installButton.style.display = "flex";
downloading = false; downloading = false;
@@ -161,7 +161,7 @@ function setupUpdateMenu() {
try { try {
showPrompt("prompt.installing"); showPrompt("prompt.installing");
await new Promise(resolve => setTimeout(resolve, 300)); 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"); showPrompt("prompt.installed");
installButton.style.display = "none"; installButton.style.display = "none";
rebootButton.style.display = "flex"; rebootButton.style.display = "flex";