opt: cache applist in json format

This commit is contained in:
KOWX712
2025-03-10 02:37:58 +08:00
parent a119c58279
commit b4cd5467ef
4 changed files with 78 additions and 82 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
__MACOSX __MACOSX
.DS_Store .DS_Store
applist.json

View File

@@ -78,7 +78,7 @@ if [ ! -d "$TS/webroot" ] && [ ! -L "$TS/webroot" ]; then
fi fi
# Optimization # Optimization
OUTPUT_APP="$MODPATH/common/tmp/applist" OUTPUT_APP="$MODPATH/webui/applist.json"
OUTPUT_SKIP="$MODPATH/common/tmp/skiplist" OUTPUT_SKIP="$MODPATH/common/tmp/skiplist"
OUTPUT_XPOSED="$MODPATH/common/tmp/xposed" OUTPUT_XPOSED="$MODPATH/common/tmp/xposed"
@@ -97,7 +97,7 @@ else
fi fi
# Initialize cache files to save app list and skip list # Initialize cache files to save app list and skip list
echo "# This file is generated from service.sh to speed up load time" > "$OUTPUT_APP" echo "[" > "$OUTPUT_APP"
echo "# This file is generated from service.sh to speed up load time" > "$OUTPUT_SKIP" echo "# This file is generated from service.sh to speed up load time" > "$OUTPUT_SKIP"
# Get list of third party apps and specific system apps, then cache app name # Get list of third party apps and specific system apps, then cache app name
@@ -107,16 +107,12 @@ echo "# This file is generated from service.sh to speed up load time" > "$OUTPUT
pm list packages -s | grep -E "$SYSTEM_APP" 2>/dev/null || true pm list packages -s | grep -E "$SYSTEM_APP" 2>/dev/null || true
} | awk -F: '{print $2}' | while read -r PACKAGE; do } | awk -F: '{print $2}' | while read -r PACKAGE; do
# Get APK path for the package # Get APK path for the package
APK_PATH=$(pm path "$PACKAGE" 2>/dev/null | grep "base.apk" | awk -F: '{print $2}' | tr -d '\r') APK_PATH=$(pm path "$PACKAGE" 2>/dev/null | grep "base.apk" | awk -F: '{print $2}')
[ -z "$APK_PATH" ] && APK_PATH=$(pm path "$PACKAGE" 2>/dev/null | grep ".apk" | awk -F: '{print $2}' | tr -d '\r') [ -z "$APK_PATH" ] && APK_PATH=$(pm path "$PACKAGE" 2>/dev/null | grep ".apk" | awk -F: '{print $2}')
if [ -n "$APK_PATH" ]; then
# Extract app name and save package info
APP_NAME=$(aapt dump badging "$APK_PATH" 2>/dev/null | grep "application-label:" | sed "s/application-label://g; s/'//g") APP_NAME=$(aapt dump badging "$APK_PATH" 2>/dev/null | grep "application-label:" | sed "s/application-label://g; s/'//g")
echo "app-name: $APP_NAME, package-name: $PACKAGE" >> "$OUTPUT_APP" [ -z "$APP_NAME" ] && APP_NAME="$PACKAGE"
else echo " {\"app_name\": \"$APP_NAME\", \"package_name\": \"$PACKAGE\"}," >> "$OUTPUT_APP"
echo "app-name: Unknown App package-name: $PACKAGE" >> "$OUTPUT_APP"
fi
# Check if app is Xposed module and add to skip list if not # Check if app is Xposed module and add to skip list if not
touch "$OUTPUT_XPOSED" touch "$OUTPUT_XPOSED"
@@ -126,3 +122,6 @@ echo "# This file is generated from service.sh to speed up load time" > "$OUTPUT
echo "$PACKAGE" >> "$OUTPUT_SKIP" echo "$PACKAGE" >> "$OUTPUT_SKIP"
fi fi
done done
sed -i '$ s/,$//' "$OUTPUT_APP"
echo "]" >> "$OUTPUT_APP"

View File

@@ -9,6 +9,7 @@ export let modeActive = false;
// Fetch and render applist // Fetch and render applist
export async function fetchAppList() { export async function fetchAppList() {
try { try {
// fetch target list
let targetList = []; let targetList = [];
try { try {
const targetFileContent = await execCommand('cat /data/adb/tricky_store/target.txt'); const targetFileContent = await execCommand('cat /data/adb/tricky_store/target.txt');
@@ -19,56 +20,46 @@ export async function fetchAppList() {
console.error("Failed to read target.txt file:", error); console.error("Failed to read target.txt file:", error);
} }
// fetch applist
let applistMap = {}; let applistMap = {};
try { const response = await fetch('applist.json');
const applistResult = await execCommand(`cat ${basePath}common/tmp/applist`); const appList = await response.json();
applistMap = applistResult const appNameMap = appList.reduce((map, app) => {
.split("\n") map[app.package_name] = app.app_name;
.reduce((map, line) => {
const match = line.match(/app-name:\s*(.+),\s*package-name:\s*(.+)/);
if (match) {
const appName = match[1].trim();
const packageName = match[2].trim();
map[packageName] = appName;
}
return map; return map;
}, {}); }, {});
console.log("Applist loaded successfully.");
} catch (error) {
console.warn("Applist file not found or could not be loaded. Skipping applist lookup.");
}
const result = await execCommand(` // Get installed packages first
pm list packages -3 | awk -F: '{print $2}' let appEntries = [], installedPackages = [];
[ -f "/data/adb/tricky_store/system_app" ] && SYSTEM_APP=$(cat "/data/adb/tricky_store/system_app" | tr '\n' '|' | sed 's/|*$//') || SYSTEM_APP=""
pm list packages -s | awk -F: '{print $2}' | grep -Ex "$SYSTEM_APP" 2>/dev/null || true
`);
const appEntries = result
.split("\n")
.map(line => {
const packageName = line.trim();
const appName = applistMap[packageName] || null;
return { appName, packageName };
})
.filter(entry => entry.packageName);
for (const entry of appEntries) {
if (!entry.appName) {
try { try {
const apkPath = await execCommand(` installedPackages = await execCommand(`
base_apk=$(pm path ${entry.packageName} | grep "base.apk" | awk -F: '{print $2}' | tr -d '\\r') pm list packages -3 | awk -F: '{print $2}'
[ -n "$base_apk" ] || base_apk=$(pm path ${entry.packageName} | grep ".apk" | awk -F: '{print $2}' | tr -d '\\r') [ -s "/data/adb/tricky_store/system_app" ] && SYSTEM_APP=$(cat "/data/adb/tricky_store/system_app" | tr '\n' '|' | sed 's/|*$//') || SYSTEM_APP=""
echo "$base_apk" [ -z "$SYSTEM_APP" ] || pm list packages -s | awk -F: '{print $2}' | grep -Ex "$SYSTEM_APP" 2>/dev/null || true
`)
installedPackages = installedPackages.split("\n").map(line => line.trim()).filter(Boolean);
appEntries = await Promise.all(installedPackages.map(async packageName => {
if (appNameMap[packageName]) {
return {
appName: appNameMap[packageName],
packageName
};
}
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"
`); `);
if (apkPath) { return {
const appName = await execCommand(`${basePath}common/aapt dump badging ${apkPath.trim()} 2>/dev/null | grep "application-label:" | sed "s/application-label://; s/'//g"`); appName: appName.trim() || packageName,
entry.appName = appName.trim() || "Unknown App"; packageName
} else { };
entry.appName = "Unknown App"; }));
}
} catch (error) { } catch (error) {
entry.appName = "Unknown App"; appEntries = appList.map(app => ({
} appName: app.app_name,
} packageName: app.package_name
}));
} }
// Sort // Sort
@@ -108,7 +99,12 @@ export async function fetchAppList() {
} }
const nameElement = appElement.querySelector(".name"); const nameElement = appElement.querySelector(".name");
nameElement.innerHTML = `<strong>${appName || "Unknown App"}</strong><br>${packageName}`; nameElement.innerHTML = `
<div class="app-info">
<div class="app-name"><strong>${appName}</strong></div>
<div class="package-name">${packageName}</div>
</div>
`;
const checkbox = appElement.querySelector(".checkbox"); const checkbox = appElement.querySelector(".checkbox");
checkbox.checked = targetList.includes(packageName); checkbox.checked = targetList.includes(packageName);
appListContainer.appendChild(appElement); appListContainer.appendChild(appElement);