From c126b638666f750134f7113946d3599816de5643 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Tue, 21 Oct 2025 20:06:26 +0800 Subject: [PATCH 1/2] Clean loading --- bin/clean.sh | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/bin/clean.sh b/bin/clean.sh index 3ea5510..ebbdf58 100755 --- a/bin/clean.sh +++ b/bin/clean.sh @@ -251,13 +251,15 @@ safe_clean() { # Show progress indicator for potentially slow operations if [[ ${#existing_paths[@]} -gt 3 ]]; then - if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Checking items with whitelist safety..."; fi + local total_paths=${#existing_paths[@]} + if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning $total_paths items..."; fi local temp_dir temp_dir=$(create_temp_dir) # Parallel processing (bash 3.2 compatible) local -a pids=() local idx=0 + local completed=0 for path in "${existing_paths[@]}"; do ( local size @@ -275,11 +277,18 @@ safe_clean() { if ((${#pids[@]} >= MAX_PARALLEL_JOBS)); then wait "${pids[0]}" 2> /dev/null || true pids=("${pids[@]:1}") + ((completed++)) + # Update progress every 10 items for smoother display + if [[ -t 1 ]] && ((completed % 10 == 0)); then + stop_inline_spinner + MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning items ($completed/$total_paths)..." + fi fi done for pid in "${pids[@]}"; do wait "$pid" 2> /dev/null || true + ((completed++)) done # Read results using same index @@ -303,7 +312,8 @@ safe_clean() { # Temp dir will be auto-cleaned by cleanup_temp_files else # Show progress for small batches too (simpler jobs) - if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Checking items with whitelist safety..."; fi + local total_paths=${#existing_paths[@]} + if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning $total_paths items..."; fi for path in "${existing_paths[@]}"; do local size_bytes @@ -658,7 +668,25 @@ perform_cleanup() { safe_clean /usr/local/var/homebrew/locks/* "Homebrew lock files (Intel)" if command -v brew > /dev/null 2>&1; then if [[ "$DRY_RUN" != "true" ]]; then - MOLE_CMD_TIMEOUT=300 clean_tool_cache "Homebrew cleanup" brew cleanup -s --prune=all + if [[ -t 1 ]]; then MOLE_SPINNER_PREFIX=" " start_inline_spinner "Homebrew cleanup..."; fi + # Run brew cleanup and capture output + local brew_output + brew_output=$(brew cleanup -s --prune=all 2>&1) + if [[ -t 1 ]]; then stop_inline_spinner; fi + + # Show summary of what was cleaned + local removed_count=$(echo "$brew_output" | grep -c "Removing:" || echo "0") + local freed_space=$(echo "$brew_output" | grep -o "[0-9.]*[KMGT]B freed" | tail -1 || echo "") + + if [[ $removed_count -gt 0 ]] || [[ -n "$freed_space" ]]; then + if [[ -n "$freed_space" ]]; then + echo -e " ${GREEN}${ICON_SUCCESS}${NC} Homebrew cleanup ${GREEN}($freed_space)${NC}" + else + echo -e " ${GREEN}${ICON_SUCCESS}${NC} Homebrew cleanup (${removed_count} items)" + fi + else + echo -e " ${GREEN}${ICON_SUCCESS}${NC} Homebrew cleanup" + fi else echo -e " ${YELLOW}→${NC} Homebrew (would cleanup)" fi From 9a3d5c11aa751f3d850fdfc9b03199226fffa06e Mon Sep 17 00:00:00 2001 From: Tw93 Date: Wed, 22 Oct 2025 10:04:12 +0800 Subject: [PATCH 2/2] Incremental check when app is uninstalled --- bin/uninstall.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/bin/uninstall.sh b/bin/uninstall.sh index 4b346e8..47e91bd 100755 --- a/bin/uninstall.sh +++ b/bin/uninstall.sh @@ -104,10 +104,18 @@ scan_applications() { local cache_dir="$HOME/.cache/mole" local cache_file="$cache_dir/app_scan_cache" local cache_meta="$cache_dir/app_scan_meta" + local cache_dir_mtime="$cache_dir/app_dir_mtime" local cache_ttl=86400 # 24 hours cache validity (app count change will trigger refresh) mkdir -p "$cache_dir" 2> /dev/null + # Get modification time of app directories to detect new installations + local sys_app_mtime + sys_app_mtime=$(stat -f%m "/Applications" 2> /dev/null || echo "0") + local user_app_mtime + user_app_mtime=$(stat -f%m "$HOME/Applications" 2> /dev/null || echo "0") + local combined_mtime=$((sys_app_mtime + user_app_mtime)) + # Quick count of current apps (system + user directories) local current_app_count current_app_count=$( @@ -118,13 +126,15 @@ scan_applications() { ) # Check if cache is valid unless explicitly disabled - if [[ -f "$cache_file" && -f "$cache_meta" ]]; then + if [[ -f "$cache_file" && -f "$cache_meta" && -f "$cache_dir_mtime" ]]; then local cache_age=$(($(date +%s) - $(stat -f%m "$cache_file" 2> /dev/null || echo 0))) local cached_app_count cached_app_count=$(cat "$cache_meta" 2> /dev/null || echo "0") + local cached_dir_mtime + cached_dir_mtime=$(cat "$cache_dir_mtime" 2> /dev/null || echo "0") - # Cache is valid if: age < TTL AND app count matches - if [[ $cache_age -lt $cache_ttl && "$cached_app_count" == "$current_app_count" ]]; then + # Cache is valid if: age < TTL AND app count matches AND directory not modified + if [[ $cache_age -lt $cache_ttl && "$cached_app_count" == "$current_app_count" && "$cached_dir_mtime" == "$combined_mtime" ]]; then # Silent - cache hit, return immediately without any output echo "$cache_file" return 0 @@ -371,9 +381,10 @@ scan_applications() { } rm -f "$temp_file" - # Update cache with app count metadata + # Update cache with app count metadata and directory modification time cp "${temp_file}.sorted" "$cache_file" 2> /dev/null || true echo "$current_app_count" > "$cache_meta" 2> /dev/null || true + echo "$combined_mtime" > "$cache_dir_mtime" 2> /dev/null || true # Verify sorted file exists before returning if [[ -f "${temp_file}.sorted" ]]; then