mirror of
https://github.com/tw93/Mole.git
synced 2026-02-16 08:21:18 +00:00
Improved User Feedback
This commit is contained in:
@@ -190,13 +190,13 @@ scan_applications() {
|
|||||||
# Second pass: process each app with parallel size calculation
|
# Second pass: process each app with parallel size calculation
|
||||||
local app_count=0
|
local app_count=0
|
||||||
local total_apps=${#app_data_tuples[@]}
|
local total_apps=${#app_data_tuples[@]}
|
||||||
# Bound parallelism so small machines stay responsive
|
# Bound parallelism - for metadata queries, can go higher since it's mostly waiting
|
||||||
local max_parallel
|
local max_parallel
|
||||||
max_parallel=$(get_optimal_parallel_jobs "io")
|
max_parallel=$(get_optimal_parallel_jobs "io")
|
||||||
if [[ $max_parallel -lt 4 ]]; then
|
if [[ $max_parallel -lt 8 ]]; then
|
||||||
max_parallel=4
|
max_parallel=8
|
||||||
elif [[ $max_parallel -gt 16 ]]; then
|
elif [[ $max_parallel -gt 32 ]]; then
|
||||||
max_parallel=16
|
max_parallel=32
|
||||||
fi
|
fi
|
||||||
local pids=()
|
local pids=()
|
||||||
local inline_loading=false
|
local inline_loading=false
|
||||||
@@ -222,17 +222,14 @@ scan_applications() {
|
|||||||
app_size=$(bytes_to_human "$((app_size_kb * 1024))")
|
app_size=$(bytes_to_human "$((app_size_kb * 1024))")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get real last used date from macOS metadata
|
# Get last used date - simplified for speed
|
||||||
|
# Note: mdls can be slow (40ms+ per app), so we use file mtime instead
|
||||||
local last_used="Never"
|
local last_used="Never"
|
||||||
local last_used_epoch=0
|
local last_used_epoch=0
|
||||||
|
|
||||||
if [[ -d "$app_path" ]]; then
|
if [[ -d "$app_path" ]]; then
|
||||||
local metadata_date
|
# Use file modification time (much faster than mdls)
|
||||||
metadata_date=$(mdls -name kMDItemLastUsedDate -raw "$app_path" 2> /dev/null)
|
last_used_epoch=$(get_file_mtime "$app_path")
|
||||||
|
|
||||||
if [[ "$metadata_date" != "(null)" && -n "$metadata_date" ]]; then
|
|
||||||
last_used_epoch=$(date -j -f "%Y-%m-%d %H:%M:%S %z" "$metadata_date" "+%s" 2> /dev/null || echo "0")
|
|
||||||
|
|
||||||
if [[ $last_used_epoch -gt 0 ]]; then
|
if [[ $last_used_epoch -gt 0 ]]; then
|
||||||
local days_ago=$(((current_epoch - last_used_epoch) / 86400))
|
local days_ago=$(((current_epoch - last_used_epoch) / 86400))
|
||||||
|
|
||||||
@@ -253,20 +250,6 @@ scan_applications() {
|
|||||||
[[ $years_ago -eq 1 ]] && last_used="1 year ago" || last_used="${years_ago} years ago"
|
[[ $years_ago -eq 1 ]] && last_used="1 year ago" || last_used="${years_ago} years ago"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# Fallback to file modification time
|
|
||||||
last_used_epoch=$(get_file_mtime "$app_path")
|
|
||||||
if [[ $last_used_epoch -gt 0 ]]; then
|
|
||||||
local days_ago=$(((current_epoch - last_used_epoch) / 86400))
|
|
||||||
if [[ $days_ago -lt 30 ]]; then
|
|
||||||
last_used="Recent"
|
|
||||||
elif [[ $days_ago -lt 365 ]]; then
|
|
||||||
last_used="This year"
|
|
||||||
else
|
|
||||||
last_used="Old"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Write to output file atomically
|
# Write to output file atomically
|
||||||
@@ -276,6 +259,31 @@ scan_applications() {
|
|||||||
|
|
||||||
export -f process_app_metadata
|
export -f process_app_metadata
|
||||||
|
|
||||||
|
# Create a temporary file to track progress
|
||||||
|
local progress_file="${temp_file}.progress"
|
||||||
|
echo "0" > "$progress_file"
|
||||||
|
|
||||||
|
# Start a background spinner that reads progress from file
|
||||||
|
local spinner_pid=""
|
||||||
|
(
|
||||||
|
trap 'exit 0' TERM INT EXIT
|
||||||
|
local spinner_chars="|/-\\"
|
||||||
|
local i=0
|
||||||
|
while true; do
|
||||||
|
local completed=$(cat "$progress_file" 2> /dev/null || echo 0)
|
||||||
|
local c="${spinner_chars:$((i % 4)):1}"
|
||||||
|
if [[ $inline_loading == true ]]; then
|
||||||
|
printf "\033[H\033[2K%s Scanning applications... %d/%d" "$c" "$completed" "$total_apps" >&2
|
||||||
|
else
|
||||||
|
echo -ne "\r\033[K%s Scanning applications... %d/%d" "$c" "$completed" "$total_apps" >&2
|
||||||
|
fi
|
||||||
|
((i++))
|
||||||
|
sleep 0.1 2> /dev/null || sleep 1
|
||||||
|
done
|
||||||
|
) &
|
||||||
|
spinner_pid=$!
|
||||||
|
disown 2> /dev/null || true
|
||||||
|
|
||||||
# Process apps in parallel batches
|
# Process apps in parallel batches
|
||||||
for app_data_tuple in "${app_data_tuples[@]}"; do
|
for app_data_tuple in "${app_data_tuples[@]}"; do
|
||||||
((app_count++))
|
((app_count++))
|
||||||
@@ -284,14 +292,8 @@ scan_applications() {
|
|||||||
process_app_metadata "$app_data_tuple" "$temp_file" "$current_epoch" &
|
process_app_metadata "$app_data_tuple" "$temp_file" "$current_epoch" &
|
||||||
pids+=($!)
|
pids+=($!)
|
||||||
|
|
||||||
# Update progress with spinner
|
# Update progress to show scanning progress (use app_count as it increments smoothly)
|
||||||
local spinner_char="${spinner_chars:$((spinner_idx % 4)):1}"
|
echo "$app_count" > "$progress_file"
|
||||||
if [[ $inline_loading == true ]]; then
|
|
||||||
printf "\033[H\033[2K${spinner_char} Scanning applications... %d/%d" "$app_count" "$total_apps" >&2
|
|
||||||
else
|
|
||||||
echo -ne "\r\033[K${spinner_char} Scanning applications... $app_count/$total_apps" >&2
|
|
||||||
fi
|
|
||||||
((spinner_idx++))
|
|
||||||
|
|
||||||
# Wait if we've hit max parallel limit
|
# Wait if we've hit max parallel limit
|
||||||
if ((${#pids[@]} >= max_parallel)); then
|
if ((${#pids[@]} >= max_parallel)); then
|
||||||
@@ -305,22 +307,25 @@ scan_applications() {
|
|||||||
wait "$pid" 2> /dev/null
|
wait "$pid" 2> /dev/null
|
||||||
done
|
done
|
||||||
|
|
||||||
# Check if we found any applications
|
# Stop the spinner and clear the line
|
||||||
if [[ ! -s "$temp_file" ]]; then
|
if [[ -n "$spinner_pid" ]]; then
|
||||||
|
kill -TERM "$spinner_pid" 2> /dev/null || true
|
||||||
|
wait "$spinner_pid" 2> /dev/null || true
|
||||||
|
fi
|
||||||
if [[ $inline_loading == true ]]; then
|
if [[ $inline_loading == true ]]; then
|
||||||
printf "\033[H\033[2K" >&2
|
printf "\033[H\033[2K" >&2
|
||||||
else
|
else
|
||||||
echo -ne "\r\033[K" >&2
|
echo -ne "\r\033[K" >&2
|
||||||
fi
|
fi
|
||||||
|
rm -f "$progress_file"
|
||||||
|
|
||||||
|
# Check if we found any applications
|
||||||
|
if [[ ! -s "$temp_file" ]]; then
|
||||||
echo "No applications found to uninstall" >&2
|
echo "No applications found to uninstall" >&2
|
||||||
rm -f "$temp_file"
|
rm -f "$temp_file"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $inline_loading == true ]]; then
|
|
||||||
printf "\033[H\033[2K" >&2
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Sort by last used (oldest first) and cache the result
|
# Sort by last used (oldest first) and cache the result
|
||||||
sort -t'|' -k1,1n "$temp_file" > "${temp_file}.sorted" || {
|
sort -t'|' -k1,1n "$temp_file" > "${temp_file}.sorted" || {
|
||||||
rm -f "$temp_file"
|
rm -f "$temp_file"
|
||||||
@@ -390,6 +395,15 @@ trap cleanup EXIT INT TERM
|
|||||||
|
|
||||||
# Main function
|
# Main function
|
||||||
main() {
|
main() {
|
||||||
|
# Parse args
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
"--debug")
|
||||||
|
export MO_DEBUG=1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
local use_inline_loading=false
|
local use_inline_loading=false
|
||||||
if [[ -t 1 && -t 2 ]]; then
|
if [[ -t 1 && -t 2 ]]; then
|
||||||
use_inline_loading=true
|
use_inline_loading=true
|
||||||
|
|||||||
Reference in New Issue
Block a user