mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 16:14:44 +00:00
perf: improve cleanup UI responsiveness and reduce visual flicker
- Speed up spinner animation from 100ms to 50ms for smoother visuals - Fix spinner flicker by deferring stop until output is ready - Remove unnecessary 'Preparing...' spinner at section start - Hide whitelist-protected items from output (Trash, Finder metadata) - Add spinner feedback for system diagnostic log cleanup - Remove redundant stop_section_spinner calls in cleanup modules The cleanup process now feels significantly faster and more polished, with continuous visual feedback and no jarring gaps between operations.
This commit is contained in:
93
bin/clean.sh
93
bin/clean.sh
@@ -69,10 +69,10 @@ if [[ -f "$HOME/.config/mole/whitelist" ]]; then
|
||||
fi
|
||||
|
||||
case "$line" in
|
||||
/ | /System | /System/* | /bin | /bin/* | /sbin | /sbin/* | /usr/bin | /usr/bin/* | /usr/sbin | /usr/sbin/* | /etc | /etc/* | /var/db | /var/db/*)
|
||||
WHITELIST_WARNINGS+=("Protected system path: $line")
|
||||
continue
|
||||
;;
|
||||
/ | /System | /System/* | /bin | /bin/* | /sbin | /sbin/* | /usr/bin | /usr/bin/* | /usr/sbin | /usr/sbin/* | /etc | /etc/* | /var/db | /var/db/*)
|
||||
WHITELIST_WARNINGS+=("Protected system path: $line")
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
duplicate="false"
|
||||
@@ -86,7 +86,7 @@ if [[ -f "$HOME/.config/mole/whitelist" ]]; then
|
||||
fi
|
||||
[[ "$duplicate" == "true" ]] && continue
|
||||
WHITELIST_PATTERNS+=("$line")
|
||||
done < "$HOME/.config/mole/whitelist"
|
||||
done <"$HOME/.config/mole/whitelist"
|
||||
else
|
||||
WHITELIST_PATTERNS=("${DEFAULT_WHITELIST_PATTERNS[@]}")
|
||||
fi
|
||||
@@ -140,7 +140,7 @@ cleanup() {
|
||||
fi
|
||||
CLEANUP_DONE=true
|
||||
|
||||
stop_inline_spinner 2> /dev/null || true
|
||||
stop_inline_spinner 2>/dev/null || true
|
||||
|
||||
if [[ -t 1 ]]; then
|
||||
printf "\r\033[K" >&2 || true
|
||||
@@ -164,14 +164,10 @@ start_section() {
|
||||
echo ""
|
||||
echo -e "${PURPLE_BOLD}${ICON_ARROW} $1${NC}"
|
||||
|
||||
if [[ -t 1 ]]; then
|
||||
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Preparing..."
|
||||
fi
|
||||
|
||||
if [[ "$DRY_RUN" == "true" ]]; then
|
||||
ensure_user_file "$EXPORT_LIST_FILE"
|
||||
echo "" >> "$EXPORT_LIST_FILE"
|
||||
echo "=== $1 ===" >> "$EXPORT_LIST_FILE"
|
||||
echo "" >>"$EXPORT_LIST_FILE"
|
||||
echo "=== $1 ===" >>"$EXPORT_LIST_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -224,7 +220,7 @@ normalize_paths_for_cleanup() {
|
||||
done
|
||||
fi
|
||||
[[ "$is_child" == "true" ]] || result_paths+=("$path")
|
||||
done <<< "$sorted_paths"
|
||||
done <<<"$sorted_paths"
|
||||
|
||||
if [[ ${#result_paths[@]} -gt 0 ]]; then
|
||||
printf '%s\n' "${result_paths[@]}"
|
||||
@@ -236,9 +232,9 @@ get_cleanup_path_size_kb() {
|
||||
local path="$1"
|
||||
|
||||
if [[ -f "$path" && ! -L "$path" ]]; then
|
||||
if command -v stat > /dev/null 2>&1; then
|
||||
if command -v stat >/dev/null 2>&1; then
|
||||
local bytes
|
||||
bytes=$(stat -f%z "$path" 2> /dev/null || echo "0")
|
||||
bytes=$(stat -f%z "$path" 2>/dev/null || echo "0")
|
||||
if [[ "$bytes" =~ ^[0-9]+$ && "$bytes" -gt 0 ]]; then
|
||||
echo $(((bytes + 1023) / 1024))
|
||||
return 0
|
||||
@@ -247,9 +243,9 @@ get_cleanup_path_size_kb() {
|
||||
fi
|
||||
|
||||
if [[ -L "$path" ]]; then
|
||||
if command -v stat > /dev/null 2>&1; then
|
||||
if command -v stat >/dev/null 2>&1; then
|
||||
local bytes
|
||||
bytes=$(stat -f%z "$path" 2> /dev/null || echo "0")
|
||||
bytes=$(stat -f%z "$path" 2>/dev/null || echo "0")
|
||||
if [[ "$bytes" =~ ^[0-9]+$ && "$bytes" -gt 0 ]]; then
|
||||
echo $(((bytes + 1023) / 1024))
|
||||
else
|
||||
@@ -308,9 +304,6 @@ safe_clean() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Always stop spinner before outputting results
|
||||
stop_section_spinner
|
||||
|
||||
local description
|
||||
local -a targets
|
||||
|
||||
@@ -361,6 +354,7 @@ safe_clean() {
|
||||
local show_scan_feedback=false
|
||||
if [[ ${#targets[@]} -gt 20 && -t 1 ]]; then
|
||||
show_scan_feedback=true
|
||||
stop_section_spinner
|
||||
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Scanning ${#targets[@]} items..."
|
||||
fi
|
||||
|
||||
@@ -467,9 +461,9 @@ safe_clean() {
|
||||
[[ ! "$size" =~ ^[0-9]+$ ]] && size=0
|
||||
|
||||
if [[ "$size" -gt 0 ]]; then
|
||||
echo "$size 1" > "$temp_dir/result_${idx}"
|
||||
echo "$size 1" >"$temp_dir/result_${idx}"
|
||||
else
|
||||
echo "0 0" > "$temp_dir/result_${idx}"
|
||||
echo "0 0" >"$temp_dir/result_${idx}"
|
||||
fi
|
||||
|
||||
((idx++))
|
||||
@@ -494,17 +488,17 @@ safe_clean() {
|
||||
[[ ! "$size" =~ ^[0-9]+$ ]] && size=0
|
||||
local tmp_file="$temp_dir/result_${idx}.$$"
|
||||
if [[ "$size" -gt 0 ]]; then
|
||||
echo "$size 1" > "$tmp_file"
|
||||
echo "$size 1" >"$tmp_file"
|
||||
else
|
||||
echo "0 0" > "$tmp_file"
|
||||
echo "0 0" >"$tmp_file"
|
||||
fi
|
||||
mv "$tmp_file" "$temp_dir/result_${idx}" 2> /dev/null || true
|
||||
mv "$tmp_file" "$temp_dir/result_${idx}" 2>/dev/null || true
|
||||
) &
|
||||
pids+=($!)
|
||||
((idx++))
|
||||
|
||||
if ((${#pids[@]} >= MOLE_MAX_PARALLEL_JOBS)); then
|
||||
wait "${pids[0]}" 2> /dev/null || true
|
||||
wait "${pids[0]}" 2>/dev/null || true
|
||||
pids=("${pids[@]:1}")
|
||||
((completed++))
|
||||
|
||||
@@ -517,7 +511,7 @@ safe_clean() {
|
||||
|
||||
if [[ ${#pids[@]} -gt 0 ]]; then
|
||||
for pid in "${pids[@]}"; do
|
||||
wait "$pid" 2> /dev/null || true
|
||||
wait "$pid" 2>/dev/null || true
|
||||
((completed++))
|
||||
|
||||
if [[ "$show_spinner" == "true" && -t 1 ]]; then
|
||||
@@ -533,11 +527,11 @@ safe_clean() {
|
||||
for path in "${existing_paths[@]}"; do
|
||||
local result_file="$temp_dir/result_${idx}"
|
||||
if [[ -f "$result_file" ]]; then
|
||||
read -r size count < "$result_file" 2> /dev/null || true
|
||||
read -r size count <"$result_file" 2>/dev/null || true
|
||||
local removed=0
|
||||
if [[ "$DRY_RUN" != "true" ]]; then
|
||||
if [[ -L "$path" ]]; then
|
||||
rm "$path" 2> /dev/null && removed=1
|
||||
rm "$path" 2>/dev/null && removed=1
|
||||
else
|
||||
if safe_remove "$path" true; then
|
||||
removed=1
|
||||
@@ -574,7 +568,7 @@ safe_clean() {
|
||||
local removed=0
|
||||
if [[ "$DRY_RUN" != "true" ]]; then
|
||||
if [[ -L "$path" ]]; then
|
||||
rm "$path" 2> /dev/null && removed=1
|
||||
rm "$path" 2>/dev/null && removed=1
|
||||
else
|
||||
if safe_remove "$path" true; then
|
||||
removed=1
|
||||
@@ -614,6 +608,9 @@ safe_clean() {
|
||||
fi
|
||||
|
||||
if [[ $removed_any -eq 1 ]]; then
|
||||
# Stop spinner before output
|
||||
stop_section_spinner
|
||||
|
||||
local size_human=$(bytes_to_human "$((total_size_kb * 1024))")
|
||||
|
||||
local label="$description"
|
||||
@@ -632,9 +629,9 @@ safe_clean() {
|
||||
local size=0
|
||||
|
||||
if [[ -n "${temp_dir:-}" && -f "$temp_dir/result_${idx}" ]]; then
|
||||
read -r size count < "$temp_dir/result_${idx}" 2> /dev/null || true
|
||||
read -r size count <"$temp_dir/result_${idx}" 2>/dev/null || true
|
||||
else
|
||||
size=$(get_cleanup_path_size_kb "$path" 2> /dev/null || echo "0")
|
||||
size=$(get_cleanup_path_size_kb "$path" 2>/dev/null || echo "0")
|
||||
fi
|
||||
|
||||
[[ "$size" == "0" || -z "$size" ]] && {
|
||||
@@ -642,7 +639,7 @@ safe_clean() {
|
||||
continue
|
||||
}
|
||||
|
||||
echo "$(dirname "$path")|$size|$path" >> "$paths_temp"
|
||||
echo "$(dirname "$path")|$size|$path" >>"$paths_temp"
|
||||
((idx++))
|
||||
done
|
||||
fi
|
||||
@@ -673,9 +670,9 @@ safe_clean() {
|
||||
' | while IFS='|' read -r display_path total_size child_count; do
|
||||
local size_human=$(bytes_to_human "$((total_size * 1024))")
|
||||
if [[ $child_count -gt 1 ]]; then
|
||||
echo "$display_path # $size_human ($child_count items)" >> "$EXPORT_LIST_FILE"
|
||||
echo "$display_path # $size_human ($child_count items)" >>"$EXPORT_LIST_FILE"
|
||||
else
|
||||
echo "$display_path # $size_human" >> "$EXPORT_LIST_FILE"
|
||||
echo "$display_path # $size_human" >>"$EXPORT_LIST_FILE"
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -711,7 +708,7 @@ start_cleanup() {
|
||||
SYSTEM_CLEAN=false
|
||||
|
||||
ensure_user_file "$EXPORT_LIST_FILE"
|
||||
cat > "$EXPORT_LIST_FILE" << EOF
|
||||
cat >"$EXPORT_LIST_FILE" <<EOF
|
||||
# Mole Cleanup Preview - $(date '+%Y-%m-%d %H:%M:%S')
|
||||
#
|
||||
# How to protect files:
|
||||
@@ -1001,7 +998,7 @@ perform_cleanup() {
|
||||
echo "# Potential cleanup: ${freed_gb}GB"
|
||||
echo "# Items: $files_cleaned"
|
||||
echo "# Categories: $total_items"
|
||||
} >> "$EXPORT_LIST_FILE"
|
||||
} >>"$EXPORT_LIST_FILE"
|
||||
|
||||
summary_details+=("Detailed file list: ${GRAY}$EXPORT_LIST_FILE${NC}")
|
||||
summary_details+=("Use ${GRAY}mo clean --whitelist${NC} to add protection rules")
|
||||
@@ -1050,17 +1047,17 @@ perform_cleanup() {
|
||||
main() {
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
"--debug")
|
||||
export MO_DEBUG=1
|
||||
;;
|
||||
"--dry-run" | "-n")
|
||||
DRY_RUN=true
|
||||
;;
|
||||
"--whitelist")
|
||||
source "$SCRIPT_DIR/../lib/manage/whitelist.sh"
|
||||
manage_whitelist "clean"
|
||||
exit 0
|
||||
;;
|
||||
"--debug")
|
||||
export MO_DEBUG=1
|
||||
;;
|
||||
"--dry-run" | "-n")
|
||||
DRY_RUN=true
|
||||
;;
|
||||
"--whitelist")
|
||||
source "$SCRIPT_DIR/../lib/manage/whitelist.sh"
|
||||
manage_whitelist "clean"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
Reference in New Issue
Block a user