mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 20:50:06 +00:00
fix(clean): improve loading feedback and spinner output
This commit is contained in:
@@ -7,7 +7,17 @@ clean_tool_cache() {
|
||||
local description="$1"
|
||||
shift
|
||||
if [[ "$DRY_RUN" != "true" ]]; then
|
||||
local command_succeeded=false
|
||||
if [[ -t 1 ]]; then
|
||||
start_section_spinner "Cleaning $description..."
|
||||
fi
|
||||
if "$@" > /dev/null 2>&1; then
|
||||
command_succeeded=true
|
||||
fi
|
||||
if [[ -t 1 ]]; then
|
||||
stop_section_spinner
|
||||
fi
|
||||
if [[ "$command_succeeded" == "true" ]]; then
|
||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} $description"
|
||||
fi
|
||||
else
|
||||
|
||||
@@ -5,6 +5,7 @@ set -euo pipefail
|
||||
clean_deep_system() {
|
||||
stop_section_spinner
|
||||
local cache_cleaned=0
|
||||
start_section_spinner "Cleaning system caches..."
|
||||
# Optimized: Single pass for /Library/Caches (3 patterns in 1 scan)
|
||||
if sudo test -d "/Library/Caches" 2> /dev/null; then
|
||||
while IFS= read -r -d '' file; do
|
||||
@@ -20,6 +21,7 @@ clean_deep_system() {
|
||||
\( -name "*.log" -mtime "+$MOLE_LOG_AGE_DAYS" \) \
|
||||
\) -print0 2> /dev/null || true)
|
||||
fi
|
||||
stop_section_spinner
|
||||
[[ $cache_cleaned -eq 1 ]] && log_success "System caches"
|
||||
start_section_spinner "Cleaning system temporary files..."
|
||||
local tmp_cleaned=0
|
||||
@@ -147,7 +149,7 @@ clean_deep_system() {
|
||||
done
|
||||
stop_section_spinner
|
||||
[[ $installer_cleaned -gt 0 ]] && debug_log "Cleaned $installer_cleaned macOS installer(s)"
|
||||
start_section_spinner "Scanning system caches..."
|
||||
start_section_spinner "Scanning browser code signature caches..."
|
||||
local code_sign_cleaned=0
|
||||
while IFS= read -r -d '' cache_dir; do
|
||||
if safe_sudo_remove "$cache_dir"; then
|
||||
@@ -158,11 +160,16 @@ clean_deep_system() {
|
||||
[[ $code_sign_cleaned -gt 0 ]] && log_success "Browser code signature caches, $code_sign_cleaned items"
|
||||
|
||||
local diag_base="/private/var/db/diagnostics"
|
||||
start_section_spinner "Cleaning system diagnostic logs..."
|
||||
safe_sudo_find_delete "$diag_base" "*" "$MOLE_LOG_AGE_DAYS" "f" || true
|
||||
safe_sudo_find_delete "$diag_base" "*.tracev3" "30" "f" || true
|
||||
safe_sudo_find_delete "/private/var/db/DiagnosticPipeline" "*" "$MOLE_LOG_AGE_DAYS" "f" || true
|
||||
stop_section_spinner
|
||||
log_success "System diagnostic logs"
|
||||
|
||||
start_section_spinner "Cleaning power logs..."
|
||||
safe_sudo_find_delete "/private/var/db/powerlog" "*" "$MOLE_LOG_AGE_DAYS" "f" || true
|
||||
stop_section_spinner
|
||||
log_success "Power logs"
|
||||
start_section_spinner "Cleaning memory exception reports..."
|
||||
local mem_reports_dir="/private/var/db/reportmemoryexception/MemoryLimitViolations"
|
||||
|
||||
@@ -76,8 +76,13 @@ _clean_mail_downloads() {
|
||||
)
|
||||
local count=0
|
||||
local cleaned_kb=0
|
||||
local spinner_active=false
|
||||
for target_path in "${mail_dirs[@]}"; do
|
||||
if [[ -d "$target_path" ]]; then
|
||||
if [[ "$spinner_active" == "false" && -t 1 ]]; then
|
||||
start_section_spinner "Cleaning old Mail attachments..."
|
||||
spinner_active=true
|
||||
fi
|
||||
local dir_size_kb=0
|
||||
dir_size_kb=$(get_path_size_kb "$target_path")
|
||||
if ! [[ "$dir_size_kb" =~ ^[0-9]+$ ]]; then
|
||||
@@ -102,6 +107,9 @@ _clean_mail_downloads() {
|
||||
done < <(command find "$target_path" -type f -mtime +"$mail_age_days" -print0 2> /dev/null || true)
|
||||
fi
|
||||
done
|
||||
if [[ "$spinner_active" == "true" ]]; then
|
||||
stop_section_spinner
|
||||
fi
|
||||
if [[ $count -gt 0 ]]; then
|
||||
local cleaned_mb
|
||||
cleaned_mb=$(echo "$cleaned_kb" | awk '{printf "%.1f", $1/1024}' || echo "0.0")
|
||||
@@ -832,8 +840,12 @@ clean_application_support_logs() {
|
||||
local current_time
|
||||
current_time=$(get_epoch_seconds)
|
||||
if [[ "$current_time" =~ ^[0-9]+$ ]] && ((current_time - last_progress_update >= 1)); then
|
||||
local app_label="$app_name"
|
||||
if [[ ${#app_label} -gt 24 ]]; then
|
||||
app_label="${app_label:0:21}..."
|
||||
fi
|
||||
stop_section_spinner
|
||||
start_section_spinner "Scanning Application Support... $app_count/$total_apps ($app_name: $candidate_item_count items)"
|
||||
start_section_spinner "Scanning Application Support... $app_count/$total_apps [$app_label, $candidate_item_count items]"
|
||||
last_progress_update=$current_time
|
||||
fi
|
||||
fi
|
||||
@@ -883,8 +895,12 @@ clean_application_support_logs() {
|
||||
local current_time
|
||||
current_time=$(get_epoch_seconds)
|
||||
if [[ "$current_time" =~ ^[0-9]+$ ]] && ((current_time - last_progress_update >= 1)); then
|
||||
local container_label="$container"
|
||||
if [[ ${#container_label} -gt 24 ]]; then
|
||||
container_label="${container_label:0:21}..."
|
||||
fi
|
||||
stop_section_spinner
|
||||
start_section_spinner "Scanning Application Support... group container ($container: $candidate_item_count items)"
|
||||
start_section_spinner "Scanning Application Support... group [$container_label, $candidate_item_count items]"
|
||||
last_progress_update=$current_time
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user