mirror of
https://github.com/tw93/Mole.git
synced 2026-02-14 18:47:28 +00:00
Scanning application acceleration
This commit is contained in:
@@ -98,22 +98,47 @@ clean_orphaned_app_data() {
|
|||||||
"$HOME/Applications"
|
"$HOME/Applications"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Create a temp dir for parallel results to avoid write contention
|
||||||
|
local scan_tmp_dir=$(create_temp_dir)
|
||||||
|
|
||||||
|
# Parallel scan for applications
|
||||||
|
local pids=()
|
||||||
|
local dir_idx=0
|
||||||
for app_dir in "${app_dirs[@]}"; do
|
for app_dir in "${app_dirs[@]}"; do
|
||||||
[[ -d "$app_dir" ]] || continue
|
[[ -d "$app_dir" ]] || continue
|
||||||
run_with_timeout 10 sh -c "find '$app_dir' -name '*.app' -maxdepth 3 -type d 2> /dev/null" | while IFS= read -r app_path; do
|
(
|
||||||
local bundle_id
|
run_with_timeout 10 sh -c "find '$app_dir' -name '*.app' -maxdepth 3 -type d 2> /dev/null" | while IFS= read -r app_path; do
|
||||||
bundle_id=$(defaults read "$app_path/Contents/Info.plist" CFBundleIdentifier 2> /dev/null || echo "")
|
local bundle_id
|
||||||
[[ -n "$bundle_id" ]] && echo "$bundle_id"
|
bundle_id=$(defaults read "$app_path/Contents/Info.plist" CFBundleIdentifier 2> /dev/null || echo "")
|
||||||
done >> "$installed_bundles"
|
[[ -n "$bundle_id" ]] && echo "$bundle_id"
|
||||||
|
done > "$scan_tmp_dir/apps_${dir_idx}.txt"
|
||||||
|
) &
|
||||||
|
pids+=($!)
|
||||||
|
((dir_idx++))
|
||||||
done
|
done
|
||||||
|
|
||||||
# Get running applications and LaunchAgents with timeout protection
|
# Get running applications and LaunchAgents in parallel
|
||||||
local running_apps=$(run_with_timeout 5 osascript -e 'tell application "System Events" to get bundle identifier of every application process' 2> /dev/null || echo "")
|
(
|
||||||
echo "$running_apps" | tr ',' '\n' | sed -e 's/^ *//;s/ *$//' -e '/^$/d' >> "$installed_bundles"
|
local running_apps=$(run_with_timeout 5 osascript -e 'tell application "System Events" to get bundle identifier of every application process' 2> /dev/null || echo "")
|
||||||
|
echo "$running_apps" | tr ',' '\n' | sed -e 's/^ *//;s/ *$//' -e '/^$/d' > "$scan_tmp_dir/running.txt"
|
||||||
|
) &
|
||||||
|
pids+=($!)
|
||||||
|
|
||||||
run_with_timeout 5 find ~/Library/LaunchAgents /Library/LaunchAgents \
|
(
|
||||||
-name "*.plist" -type f 2> /dev/null |
|
run_with_timeout 5 find ~/Library/LaunchAgents /Library/LaunchAgents \
|
||||||
xargs -I {} basename {} .plist >> "$installed_bundles" 2> /dev/null || true
|
-name "*.plist" -type f 2> /dev/null |
|
||||||
|
xargs -I {} basename {} .plist > "$scan_tmp_dir/agents.txt" 2> /dev/null || true
|
||||||
|
) &
|
||||||
|
pids+=($!)
|
||||||
|
|
||||||
|
# Wait for all background scans to complete
|
||||||
|
for pid in "${pids[@]}"; do
|
||||||
|
wait "$pid" 2> /dev/null || true
|
||||||
|
done
|
||||||
|
|
||||||
|
# Merge all results
|
||||||
|
cat "$scan_tmp_dir"/*.txt >> "$installed_bundles" 2> /dev/null || true
|
||||||
|
rm -rf "$scan_tmp_dir"
|
||||||
|
|
||||||
# Deduplicate
|
# Deduplicate
|
||||||
sort -u "$installed_bundles" -o "$installed_bundles"
|
sort -u "$installed_bundles" -o "$installed_bundles"
|
||||||
|
|||||||
Reference in New Issue
Block a user