1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 15:04:42 +00:00

chore: auto format code

This commit is contained in:
Tw93
2025-12-29 11:07:20 +00:00
parent 580548876a
commit c8b2e3691b
2 changed files with 35 additions and 38 deletions

View File

@@ -60,5 +60,3 @@ fix_broken_preferences() {
echo "$broken_count" echo "$broken_count"
} }

View File

@@ -163,14 +163,14 @@ opt_sqlite_vacuum() {
should_protect_path "$db_file" && continue should_protect_path "$db_file" && continue
# Verify it's a SQLite database # Verify it's a SQLite database
if ! file "$db_file" 2>/dev/null | grep -q "SQLite"; then if ! file "$db_file" 2> /dev/null | grep -q "SQLite"; then
continue continue
fi fi
# Try to vacuum # Try to vacuum
local exit_code=0 local exit_code=0
set +e set +e
run_with_timeout 20 sqlite3 "$db_file" "VACUUM;" 2>/dev/null run_with_timeout 20 sqlite3 "$db_file" "VACUUM;" 2> /dev/null
exit_code=$? exit_code=$?
set -e set -e
@@ -330,14 +330,14 @@ opt_startup_items_cleanup() {
fi fi
if [[ "$need_sudo" == "true" ]]; then if [[ "$need_sudo" == "true" ]]; then
sudo launchctl unload "$plist_file" 2>/dev/null || true sudo launchctl unload "$plist_file" 2> /dev/null || true
if safe_sudo_remove "$plist_file"; then if safe_sudo_remove "$plist_file"; then
((broken_count++)) ((broken_count++))
else else
echo -e " ${YELLOW}!${NC} Failed to remove (sudo) $plist_file" echo -e " ${YELLOW}!${NC} Failed to remove (sudo) $plist_file"
fi fi
else else
launchctl unload "$plist_file" 2>/dev/null || true launchctl unload "$plist_file" 2> /dev/null || true
if safe_remove "$plist_file" true; then if safe_remove "$plist_file" true; then
((broken_count++)) ((broken_count++))
else else
@@ -349,10 +349,10 @@ opt_startup_items_cleanup() {
# Extract program path # Extract program path
local program="" local program=""
program=$(plutil -extract Program raw "$plist_file" 2>/dev/null || echo "") program=$(plutil -extract Program raw "$plist_file" 2> /dev/null || echo "")
if [[ -z "$program" ]]; then if [[ -z "$program" ]]; then
program=$(plutil -extract ProgramArguments.0 raw "$plist_file" 2>/dev/null || echo "") program=$(plutil -extract ProgramArguments.0 raw "$plist_file" 2> /dev/null || echo "")
fi fi
program="${program/#\~/$HOME}" program="${program/#\~/$HOME}"
@@ -363,7 +363,7 @@ opt_startup_items_cleanup() {
fi fi
# Check for orphaned privileged helpers (app uninstalled but helper remains) # Check for orphaned privileged helpers (app uninstalled but helper remains)
local associated_bundle="" local associated_bundle=""
associated_bundle=$(plutil -extract AssociatedBundleIdentifiers.0 raw "$plist_file" 2>/dev/null || echo "") associated_bundle=$(plutil -extract AssociatedBundleIdentifiers.0 raw "$plist_file" 2> /dev/null || echo "")
if [[ -n "$associated_bundle" ]]; then if [[ -n "$associated_bundle" ]]; then
# Check if the associated app exists # Check if the associated app exists
@@ -375,51 +375,51 @@ opt_startup_items_cleanup() {
app_path="$HOME/Applications/$associated_bundle.app" app_path="$HOME/Applications/$associated_bundle.app"
else else
# Fallback to mdfind (slower but comprehensive, with 10s timeout) # Fallback to mdfind (slower but comprehensive, with 10s timeout)
app_path=$(run_with_timeout 10 mdfind "kMDItemCFBundleIdentifier == '$associated_bundle'" 2>/dev/null | head -1 || echo "") app_path=$(run_with_timeout 10 mdfind "kMDItemCFBundleIdentifier == '$associated_bundle'" 2> /dev/null | head -1 || echo "")
fi fi
# If associated app is MISSING, this is an orphan # If associated app is MISSING, this is an orphan
if [[ -z "$app_path" ]]; then if [[ -z "$app_path" ]]; then
if command -v should_protect_path > /dev/null && should_protect_path "$plist_file"; then if command -v should_protect_path > /dev/null && should_protect_path "$plist_file"; then
continue continue
fi fi
# Get the helper tool path # Get the helper tool path
local program="" local program=""
program=$(plutil -extract Program raw "$plist_file" 2>/dev/null || echo "") program=$(plutil -extract Program raw "$plist_file" 2> /dev/null || echo "")
if [[ -z "$program" ]]; then if [[ -z "$program" ]]; then
program=$(plutil -extract ProgramArguments.0 raw "$plist_file" 2>/dev/null || echo "") program=$(plutil -extract ProgramArguments.0 raw "$plist_file" 2> /dev/null || echo "")
fi fi
program="${program/#\~/$HOME}" program="${program/#\~/$HOME}"
# Double check we are not deleting system files # Double check we are not deleting system files
if [[ "$program" == /System/* || if [[ "$program" == /System/* ||
"$program" == /usr/lib/* || "$program" == /usr/lib/* ||
"$program" == /usr/bin/* || "$program" == /usr/bin/* ||
"$program" == /usr/sbin/* || "$program" == /usr/sbin/* ||
"$program" == /Library/Apple/* ]]; then "$program" == /Library/Apple/* ]]; then
continue continue
fi fi
if [[ "$need_sudo" == "true" ]]; then if [[ "$need_sudo" == "true" ]]; then
sudo launchctl unload "$plist_file" 2>/dev/null || true sudo launchctl unload "$plist_file" 2> /dev/null || true
# remove the plist # remove the plist
safe_sudo_remove "$plist_file" safe_sudo_remove "$plist_file"
# AND remove the helper binary if it exists and is not protected # AND remove the helper binary if it exists and is not protected
if [[ -n "$program" && -f "$program" ]]; then if [[ -n "$program" && -f "$program" ]]; then
safe_sudo_remove "$program" safe_sudo_remove "$program"
fi fi
((broken_count++)) ((broken_count++))
echo -e " ${GREEN}${NC} Removed orphaned helper: $(basename "$program")" echo -e " ${GREEN}${NC} Removed orphaned helper: $(basename "$program")"
else else
launchctl unload "$plist_file" 2>/dev/null || true launchctl unload "$plist_file" 2> /dev/null || true
safe_remove "$plist_file" true safe_remove "$plist_file" true
if [[ -n "$program" && -f "$program" ]]; then if [[ -n "$program" && -f "$program" ]]; then
safe_remove "$program" true safe_remove "$program" true
fi fi
((broken_count++)) ((broken_count++))
echo -e " ${GREEN}${NC} Removed orphaned helper: $(basename "$program")" echo -e " ${GREEN}${NC} Removed orphaned helper: $(basename "$program")"
fi fi
continue continue
fi fi
@@ -432,14 +432,14 @@ opt_startup_items_cleanup() {
fi fi
if [[ "$need_sudo" == "true" ]]; then if [[ "$need_sudo" == "true" ]]; then
sudo launchctl unload "$plist_file" 2>/dev/null || true sudo launchctl unload "$plist_file" 2> /dev/null || true
if safe_sudo_remove "$plist_file"; then if safe_sudo_remove "$plist_file"; then
((broken_count++)) ((broken_count++))
else else
echo -e " ${YELLOW}!${NC} Failed to remove (sudo) $plist_file" echo -e " ${YELLOW}!${NC} Failed to remove (sudo) $plist_file"
fi fi
else else
launchctl unload "$plist_file" 2>/dev/null || true launchctl unload "$plist_file" 2> /dev/null || true
if safe_remove "$plist_file" true; then if safe_remove "$plist_file" true; then
((broken_count++)) ((broken_count++))
else else
@@ -447,7 +447,7 @@ opt_startup_items_cleanup() {
fi fi
fi fi
fi fi
done < <("${find_cmd[@]}" "$dir" -maxdepth 1 -name "*.plist" -type f 2>/dev/null || true) done < <("${find_cmd[@]}" "$dir" -maxdepth 1 -name "*.plist" -type f 2> /dev/null || true)
done done
if [[ $broken_count -gt 0 ]]; then if [[ $broken_count -gt 0 ]]; then
@@ -475,7 +475,7 @@ opt_dyld_cache_update() {
local dyld_cache_path="/var/db/dyld/dyld_shared_cache_$(uname -m)" local dyld_cache_path="/var/db/dyld/dyld_shared_cache_$(uname -m)"
if [[ -e "$dyld_cache_path" ]]; then if [[ -e "$dyld_cache_path" ]]; then
local cache_mtime local cache_mtime
cache_mtime=$(stat -f "%m" "$dyld_cache_path" 2>/dev/null || echo "0") cache_mtime=$(stat -f "%m" "$dyld_cache_path" 2> /dev/null || echo "0")
local current_time local current_time
current_time=$(date +%s) current_time=$(date +%s)
local time_diff=$((current_time - cache_mtime)) local time_diff=$((current_time - cache_mtime))
@@ -522,22 +522,22 @@ opt_system_services_refresh() {
local -a restarted_services=() local -a restarted_services=()
# cfprefsd - Preferences cache daemon (ensures fixed preferences take effect) # cfprefsd - Preferences cache daemon (ensures fixed preferences take effect)
if killall -HUP cfprefsd 2>/dev/null; then if killall -HUP cfprefsd 2> /dev/null; then
restarted_services+=("Preferences") restarted_services+=("Preferences")
fi fi
# lsd - LaunchServices daemon (ensures rebuild takes effect) # lsd - LaunchServices daemon (ensures rebuild takes effect)
if killall lsd 2>/dev/null; then if killall lsd 2> /dev/null; then
restarted_services+=("LaunchServices") restarted_services+=("LaunchServices")
fi fi
# iconservicesagent - Icon services (ensures cache refresh takes effect) # iconservicesagent - Icon services (ensures cache refresh takes effect)
if killall iconservicesagent 2>/dev/null; then if killall iconservicesagent 2> /dev/null; then
restarted_services+=("Icon Services") restarted_services+=("Icon Services")
fi fi
# fontd - Font server (ensures font cache refresh takes effect) # fontd - Font server (ensures font cache refresh takes effect)
if killall fontd 2>/dev/null; then if killall fontd 2> /dev/null; then
restarted_services+=("Font Server") restarted_services+=("Font Server")
fi fi
@@ -563,18 +563,18 @@ opt_dock_refresh() {
if [[ -f "$db_file" ]]; then if [[ -f "$db_file" ]]; then
safe_remove "$db_file" true > /dev/null 2>&1 && refreshed=true safe_remove "$db_file" true > /dev/null 2>&1 && refreshed=true
fi fi
done < <(find "$dock_support" -name "*.db" -type f 2>/dev/null || true) done < <(find "$dock_support" -name "*.db" -type f 2> /dev/null || true)
fi fi
# Also clear Dock plist cache # Also clear Dock plist cache
local dock_plist="$HOME/Library/Preferences/com.apple.dock.plist" local dock_plist="$HOME/Library/Preferences/com.apple.dock.plist"
if [[ -f "$dock_plist" ]]; then if [[ -f "$dock_plist" ]]; then
# Just touch to invalidate cache, don't delete (preserves user settings) # Just touch to invalidate cache, don't delete (preserves user settings)
touch "$dock_plist" 2>/dev/null || true touch "$dock_plist" 2> /dev/null || true
fi fi
# Restart Dock to apply changes # Restart Dock to apply changes
killall Dock 2>/dev/null || true killall Dock 2> /dev/null || true
if [[ "$refreshed" == "true" ]]; then if [[ "$refreshed" == "true" ]]; then
echo -e " ${GREEN}${NC} Dock cache cleared" echo -e " ${GREEN}${NC} Dock cache cleared"
@@ -582,7 +582,6 @@ opt_dock_refresh() {
echo -e " ${GREEN}${NC} Dock refreshed" echo -e " ${GREEN}${NC} Dock refreshed"
} }
# Execute optimization by action name # Execute optimization by action name
execute_optimization() { execute_optimization() {
local action="$1" local action="$1"