Add app name display

try to display app name in webui
This commit is contained in:
KOWX712
2024-11-20 00:44:28 +08:00
parent ff8a768a00
commit 0736f4ea38
3 changed files with 76 additions and 67 deletions

View File

@@ -1,19 +0,0 @@
#!/system/bin/sh
if [ -f "/data/adb/apd" ] || [ -f "/data/adb/ksud" ]; then
exit 1
fi
MODPATH=${0%/*}
OUTPUT="$MODPATH/denylist"
# Get Magisk denylist
magisk --denylist ls 2>/dev/null | \
awk -F'|' '{print $1}' | \
grep -v "isolated" | \
sort | uniq > "$OUTPUT"
if [ ! -s "$OUTPUT" ]; then
echo "Failed to retrieve Magisk denylist or no packages found." > "$OUTPUT"
exit 1
fi

View File

@@ -96,7 +96,7 @@
</div> </div>
<template id="app-template"> <template id="app-template">
<div class="card" onclick="toggleCheckbox(event)"> <div class="card" onclick="toggleCheckbox(event)">
<div class="content"> <div class="content" data-package="">
<p class="name"></p> <p class="name"></p>
<input type="checkbox" class="checkbox" checked> <input type="checkbox" class="checkbox" checked>
</div> </div>

View File

@@ -56,33 +56,49 @@ function isExcluded(appName) {
return excludeList.some(excludeItem => appName.includes(excludeItem)); return excludeList.some(excludeItem => appName.includes(excludeItem));
} }
// Function to fetch, sort, and render the app list // Function to fetch, sort, and render the app list with app names
async function fetchAppList() { async function fetchAppList() {
try { try {
await readExcludeFile(); await readExcludeFile();
const result = await execCommand("pm list packages -3 </dev/null 2>&1 | cat"); const result = await execCommand(`
const packageList = result.split("\n").map(line => line.replace("package:", "").trim()).filter(Boolean); pm list packages -3 | while read -r line; do
const sortedApps = packageList.sort((a, b) => { PACKAGE=$(echo "$line" | awk -F: '{print $2}')
const aInExclude = isExcluded(a); APK_PATH=$(pm path "$PACKAGE" | grep "base.apk" | awk -F: '{print $2}' | tr -d '\\r')
const bInExclude = isExcluded(b); if [ -n "$APK_PATH" ]; then
return aInExclude === bInExclude ? a.localeCompare(b) : aInExclude ? 1 : -1; APP_NAME=$( ${basePath}aapt dump badging "$APK_PATH" 2>/dev/null | grep "application-label:" | sed "s/application-label://; s/'//g" )
echo "$APP_NAME|$PACKAGE"
else
echo "Unknown App|$PACKAGE"
fi
done
`);
const appEntries = result.split("\n").map(line => {
const [appName, packageName] = line.split("|").map(item => item.trim());
return { appName, packageName };
}).filter(entry => entry.packageName); // Remove invalid entries
const sortedApps = appEntries.sort((a, b) => {
const aInExclude = isExcluded(a.packageName);
const bInExclude = isExcluded(b.packageName);
return aInExclude === bInExclude ? a.appName.localeCompare(b.appName) : aInExclude ? 1 : -1;
}); });
appListContainer.innerHTML = ""; appListContainer.innerHTML = ""; // Clear the container before rendering
sortedApps.forEach(appName => { sortedApps.forEach(({ appName, packageName }) => {
const appElement = document.importNode(appTemplate, true); const appElement = document.importNode(appTemplate, true);
appElement.querySelector(".name").textContent = appName; const contentElement = appElement.querySelector(".content");
contentElement.setAttribute("data-package", packageName);
const nameElement = appElement.querySelector(".name");
nameElement.innerHTML = `<strong>${appName || "Unknown App"}</strong><br>${packageName}`;
const checkbox = appElement.querySelector(".checkbox"); const checkbox = appElement.querySelector(".checkbox");
checkbox.checked = !isExcluded(appName); checkbox.checked = !isExcluded(packageName);
appListContainer.appendChild(appElement); appListContainer.appendChild(appElement);
}); });
console.log("App list fetched, sorted, and rendered successfully."); console.log("App list with names and packages rendered successfully.");
} catch (error) { } catch (error) {
console.error("Failed to fetch or render app list:", error); console.error("Failed to fetch or render app list with names:", error);
} }
floatingBtn.style.transform = 'translateY(-100px)'; floatingBtn.style.transform = "translateY(-100px)";
} }
// Function to refresh app list // Function to refresh app list
async function refreshAppList() { async function refreshAppList() {
isRefreshing = true; isRefreshing = true;
@@ -117,17 +133,18 @@ async function runXposedScript() {
} }
} }
// Function to read the xposed list and uncheck corresponding apps // Function to read the Xposed list and uncheck corresponding apps
async function deselectXposedApps() { async function deselectXposedApps() {
try { try {
const result = await execCommand(`cat ${basePath}exclude-list`); const result = await execCommand(`cat ${basePath}exclude-list`);
const xposedApps = result.split("\n").map(app => app.trim()).filter(Boolean); const xposedApps = result.split("\n").map(app => app.trim()).filter(Boolean);
const apps = document.querySelectorAll(".card"); const apps = document.querySelectorAll(".card");
apps.forEach(app => { apps.forEach(app => {
const appName = app.querySelector(".name").textContent.trim(); const contentElement = app.querySelector(".content");
const packageName = contentElement.getAttribute("data-package");
const checkbox = app.querySelector(".checkbox"); const checkbox = app.querySelector(".checkbox");
if (xposedApps.includes(appName)) { if (xposedApps.includes(packageName)) {
checkbox.checked = false; // Uncheck if found in exclude-list checkbox.checked = false; // Uncheck if found in Xposed list
} }
}); });
console.log("Xposed apps deselected successfully."); console.log("Xposed apps deselected successfully.");
@@ -136,30 +153,43 @@ async function deselectXposedApps() {
} }
} }
// Function to run the Denylist script // Function to check if Magisk
async function runDenylistScript() { async function checkMagisk() {
try { try {
const denylistScriptPath = `${basePath}get_denylist.sh`; const hasDenylistCondition = await execCommand(`
await execCommand(denylistScriptPath); if [ ! -f "/data/adb/apd" ] && [ ! -f "/data/adb/ksud" ]; then
console.log('Denylist element displayed successfully.'); echo "OK"
selectDenylistElement.style.display = "flex"; else
echo ""
fi
`);
if (hasDenylistCondition.trim() === "OK") {
console.log("Denylist conditions met, displaying element.");
selectDenylistElement.style.display = "flex";
} else {
console.log("ksud or apd detected, leaving denylist element hidden.");
}
} catch (error) { } catch (error) {
console.error("Failed to execute Denylist script:", error); console.error("Error while checking denylist conditions:", error);
} }
} }
// Function to read the denylist and check corresponding apps // Function to read the denylist and check corresponding apps
async function selectDenylistApps() { async function selectDenylistApps() {
try { try {
const result = await execCommand(`cat ${basePath}denylist`); const result = await execCommand(`
const denylistApps = result.split("\n") magisk --denylist ls 2>/dev/null | \
.map(app => app.trim()) awk -F'|' '{print $1}' | \
.filter(Boolean); grep -v "isolated" | \
sort | uniq
`);
const denylistApps = result.split("\n").map(app => app.trim()).filter(Boolean);
const apps = document.querySelectorAll(".card"); const apps = document.querySelectorAll(".card");
apps.forEach(app => { apps.forEach(app => {
const appName = app.querySelector(".name").textContent.trim(); const contentElement = app.querySelector(".content");
const packageName = contentElement.getAttribute("data-package");
const checkbox = app.querySelector(".checkbox"); const checkbox = app.querySelector(".checkbox");
if (denylistApps.includes(appName)) { if (denylistApps.includes(packageName)) {
checkbox.checked = true; // Select the app if found in denylist checkbox.checked = true; // Select the app if found in denylist
} }
}); });
@@ -169,7 +199,6 @@ async function selectDenylistApps() {
} }
} }
// Function to select all visible apps // Function to select all visible apps
function selectAllApps() { function selectAllApps() {
document.querySelectorAll(".card").forEach(card => { document.querySelectorAll(".card").forEach(card => {
@@ -312,26 +341,25 @@ clearBtn.addEventListener("click", () => {
document.getElementById("save").addEventListener("click", async () => { document.getElementById("save").addEventListener("click", async () => {
await readExcludeFile(); await readExcludeFile();
const deselectedApps = Array.from(appListContainer.querySelectorAll(".checkbox:not(:checked)")) const deselectedApps = Array.from(appListContainer.querySelectorAll(".checkbox:not(:checked)"))
.map(checkbox => checkbox.closest(".card").querySelector(".name").textContent); .map(checkbox => checkbox.closest(".card").querySelector(".content").getAttribute("data-package"));
const selectedApps = Array.from(appListContainer.querySelectorAll(".checkbox:checked")) const selectedApps = Array.from(appListContainer.querySelectorAll(".checkbox:checked"))
.map(checkbox => checkbox.closest(".card").querySelector(".name").textContent); .map(checkbox => checkbox.closest(".card").querySelector(".content").getAttribute("data-package"));
// Add deselected apps to EXCLUDE list
for (const app of deselectedApps) { for (const packageName of deselectedApps) {
if (!excludeList.includes(app)) { if (!excludeList.includes(packageName)) {
excludeList.push(app); excludeList.push(packageName);
console.log("Added to EXCLUDE list:", app); console.log("Added to EXCLUDE list:", packageName);
} else { } else {
console.log("App already in EXCLUDE file, skipping:", app); console.log("Package already in EXCLUDE file, skipping:", packageName);
} }
} }
// Remove selected apps from EXCLUDE list
if (selectedApps.length > 0) { if (selectedApps.length > 0) {
selectedApps.forEach(app => { selectedApps.forEach(packageName => {
excludeList = excludeList.filter(excludedApp => excludedApp !== app); excludeList = excludeList.filter(excludedPackage => excludedPackage !== packageName);
console.log("Removed from EXCLUDE list:", app); console.log("Removed from EXCLUDE list:", packageName);
}); });
} }
try { try {
// Save the EXCLUDE file // Save the EXCLUDE file
const updatedExcludeContent = excludeList.join("\n"); const updatedExcludeContent = excludeList.join("\n");
@@ -363,7 +391,7 @@ document.addEventListener('DOMContentLoaded', async () => {
document.getElementById("select-denylist").addEventListener("click", selectDenylistApps); document.getElementById("select-denylist").addEventListener("click", selectDenylistApps);
document.getElementById("deselect-xposed").addEventListener("click", deselectXposedApps); document.getElementById("deselect-xposed").addEventListener("click", deselectXposedApps);
await fetchAppList(); await fetchAppList();
runDenylistScript(); checkMagisk();
runXposedScript(); runXposedScript();
loadingIndicator.style.display = "none"; loadingIndicator.style.display = "none";
}); });