From 173c44072678fc15c1d292596b175ae21601cd20 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Sun, 9 Nov 2025 09:30:35 +0800 Subject: [PATCH 1/4] Supports cleaning the cache of various AI browsers --- bin/clean.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/bin/clean.sh b/bin/clean.sh index ebbdf58..34fe296 100755 --- a/bin/clean.sh +++ b/bin/clean.sh @@ -21,6 +21,13 @@ IS_M_SERIES=$([ "$(uname -m)" = "arm64" ] && echo "true" || echo "false") readonly MAX_PARALLEL_JOBS=15 # Maximum parallel background jobs readonly TEMP_FILE_AGE_DAYS=7 # Age threshold for temp file cleanup readonly ORPHAN_AGE_DAYS=60 # Age threshold for orphaned data + +# Protected Service Worker domains (web-based editing tools) +readonly PROTECTED_SW_DOMAINS=( + "capcut.com" + "photopea.com" + "pixlr.com" +) # Default whitelist patterns (preselected, user can disable) declare -a DEFAULT_WHITELIST_PATTERNS=( "$HOME/Library/Caches/ms-playwright*" @@ -444,6 +451,56 @@ start_cleanup() { fi } +# Clean Service Worker CacheStorage with domain protection +clean_service_worker_cache() { + local browser_name="$1" + local cache_path="$2" + + [[ ! -d "$cache_path" ]] && return 0 + + local total_size=0 + local cleaned_size=0 + local protected_count=0 + + # Find all cache directories and calculate sizes + while IFS= read -r cache_dir; do + [[ ! -d "$cache_dir" ]] && continue + + # Extract domain from path + local domain=$(basename "$cache_dir" | grep -oE '[a-zA-Z0-9][-a-zA-Z0-9]*\.[a-zA-Z]{2,}' | head -1 || echo "") + local size=$(du -sk "$cache_dir" 2>/dev/null | awk '{print $1}') + total_size=$((total_size + size)) + + # Check if domain is protected + local is_protected=false + for protected_domain in "${PROTECTED_SW_DOMAINS[@]}"; do + if [[ "$domain" == *"$protected_domain"* ]]; then + is_protected=true + protected_count=$((protected_count + 1)) + break + fi + done + + # Clean if not protected + if [[ "$is_protected" == "false" ]]; then + if [[ "$DRY_RUN" != "true" ]]; then + rm -rf "$cache_dir" 2>/dev/null || true + fi + cleaned_size=$((cleaned_size + size)) + fi + done < <(find "$cache_path" -type d -depth 2 2>/dev/null) + + if [[ $cleaned_size -gt 0 ]]; then + local cleaned_mb=$((cleaned_size / 1024)) + if [[ "$DRY_RUN" != "true" ]]; then + echo -e " ${GREEN}${ICON_SUCCESS}${NC} $browser_name Service Worker cache (${cleaned_mb}MB cleaned, $protected_count protected)" + else + echo -e " ${YELLOW}→${NC} $browser_name Service Worker cache (would clean ${cleaned_mb}MB, $protected_count protected)" + fi + note_activity + fi +} + perform_cleanup() { echo -e "${BLUE}${ICON_ADMIN}${NC} $(detect_architecture) | Free space: $(get_free_space)" @@ -576,11 +633,21 @@ perform_cleanup() { safe_clean ~/Library/Caches/com.microsoft.edgemac/* "Edge cache" safe_clean ~/Library/Caches/company.thebrowser.Browser/* "Arc cache" + safe_clean ~/Library/Caches/company.thebrowser.dia/* "Dia cache" safe_clean ~/Library/Caches/BraveSoftware/Brave-Browser/* "Brave cache" safe_clean ~/Library/Caches/Firefox/* "Firefox cache" safe_clean ~/Library/Caches/com.operasoftware.Opera/* "Opera cache" safe_clean ~/Library/Caches/com.vivaldi.Vivaldi/* "Vivaldi cache" + safe_clean ~/Library/Caches/Comet/* "Comet cache" + safe_clean ~/Library/Caches/com.kagi.kagimacOS/* "Orion cache" + safe_clean ~/Library/Caches/zen/* "Zen cache" safe_clean ~/Library/Application\ Support/Firefox/Profiles/*/cache2/* "Firefox profile cache" + + # Service Worker CacheStorage + clean_service_worker_cache "Chrome" "$HOME/Library/Application Support/Google/Chrome/Default/Service Worker/CacheStorage" + clean_service_worker_cache "Edge" "$HOME/Library/Application Support/Microsoft Edge/Default/Service Worker/CacheStorage" + clean_service_worker_cache "Brave" "$HOME/Library/Application Support/BraveSoftware/Brave-Browser/Default/Service Worker/CacheStorage" + clean_service_worker_cache "Arc" "$HOME/Library/Application Support/Arc/User Data/Default/Service Worker/CacheStorage" end_section # ===== 6. Cloud Storage ===== From d7abb42dacf91d5948a9c66f7b6df10a9312c431 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Sun, 9 Nov 2025 09:47:02 +0800 Subject: [PATCH 2/4] Support the quick use of Raycast, Alfred and Shortcuts --- README.md | 10 +++++ integrations/README.md | 43 ++++++++++++++++++++++ integrations/raycast/mole-clean-dry-run.sh | 32 ++++++++++++++++ integrations/raycast/mole-clean.sh | 32 ++++++++++++++++ integrations/raycast/mole-uninstall.sh | 32 ++++++++++++++++ integrations/setup-raycast.sh | 31 ++++++++++++++++ 6 files changed, 180 insertions(+) create mode 100644 integrations/README.md create mode 100755 integrations/raycast/mole-clean-dry-run.sh create mode 100755 integrations/raycast/mole-clean.sh create mode 100755 integrations/raycast/mole-uninstall.sh create mode 100755 integrations/setup-raycast.sh diff --git a/README.md b/README.md index 1b89b7f..510dffc 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,16 @@ mo --version # Show installed version - Protect caches with `mo clean --whitelist`; defaults cover Playwright, HuggingFace, and Maven paths. - Use `mo touchid` to approve sudo with Touch ID instead of typing your password. +## Quick Launchers + +Install Raycast integration with one command: + +```bash +curl -fsSL https://raw.githubusercontent.com/tw93/mole/main/integrations/setup-raycast.sh | bash +``` + +For Alfred and macOS Shortcuts, see [integrations/README.md](integrations/README.md). + ## Features in Detail ### Deep System Cleanup diff --git a/integrations/README.md b/integrations/README.md new file mode 100644 index 0000000..46cf4bf --- /dev/null +++ b/integrations/README.md @@ -0,0 +1,43 @@ +# Mole Integrations + +Quick launcher integrations for Mole. + +## Raycast + +One command install: + +```bash +curl -fsSL https://raw.githubusercontent.com/tw93/Mole/main/integrations/setup-raycast.sh | bash +``` + +Then open Raycast and search "Reload Script Commands". + +Available commands: `clean mac`, `dry run`, `uninstall apps` + +## Alfred + +Add a workflow with keyword `clean` and script: + +```bash +mo clean +``` + +For dry-run: `mo clean --dry-run` + +For uninstall: `mo uninstall` + +## macOS Shortcuts + +Create a shortcut with "Run Shell Script": + +```bash +mo clean +``` + +Then add to Menu Bar or assign a keyboard shortcut. + +## Uninstall + +```bash +rm -rf ~/Library/Application\ Support/Raycast/script-commands/mole-*.sh +``` diff --git a/integrations/raycast/mole-clean-dry-run.sh b/integrations/raycast/mole-clean-dry-run.sh new file mode 100755 index 0000000..a6f12be --- /dev/null +++ b/integrations/raycast/mole-clean-dry-run.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Clean Mac (Dry Run) +# @raycast.mode fullOutput +# @raycast.packageName Mole + +# Optional parameters: +# @raycast.icon 👀 +# @raycast.needsConfirmation false + +# Documentation: +# @raycast.description Preview what Mole would clean without making changes +# @raycast.author tw93 +# @raycast.authorURL https://github.com/tw93/Mole + +# Detect mo/mole installation +if command -v mo >/dev/null 2>&1; then + MO_BIN="mo" +elif command -v mole >/dev/null 2>&1; then + MO_BIN="mole" +else + echo "❌ Mole not found. Install from:" + echo " https://github.com/tw93/Mole" + exit 1 +fi + +# Run dry-run +echo "👀 Previewing cleanup..." +echo "" +"$MO_BIN" clean --dry-run diff --git a/integrations/raycast/mole-clean.sh b/integrations/raycast/mole-clean.sh new file mode 100755 index 0000000..7ee0261 --- /dev/null +++ b/integrations/raycast/mole-clean.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Clean Mac +# @raycast.mode fullOutput +# @raycast.packageName Mole + +# Optional parameters: +# @raycast.icon 🐹 +# @raycast.needsConfirmation true + +# Documentation: +# @raycast.description Deep clean your Mac using Mole +# @raycast.author tw93 +# @raycast.authorURL https://github.com/tw93/Mole + +# Detect mo/mole installation +if command -v mo >/dev/null 2>&1; then + MO_BIN="mo" +elif command -v mole >/dev/null 2>&1; then + MO_BIN="mole" +else + echo "❌ Mole not found. Install from:" + echo " https://github.com/tw93/Mole" + exit 1 +fi + +# Run cleanup +echo "🐹 Starting cleanup..." +echo "" +"$MO_BIN" clean diff --git a/integrations/raycast/mole-uninstall.sh b/integrations/raycast/mole-uninstall.sh new file mode 100755 index 0000000..8ae9b37 --- /dev/null +++ b/integrations/raycast/mole-uninstall.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Uninstall Apps +# @raycast.mode fullOutput +# @raycast.packageName Mole + +# Optional parameters: +# @raycast.icon 🗑️ +# @raycast.needsConfirmation true + +# Documentation: +# @raycast.description Completely uninstall apps using Mole +# @raycast.author tw93 +# @raycast.authorURL https://github.com/tw93/Mole + +# Detect mo/mole installation +if command -v mo >/dev/null 2>&1; then + MO_BIN="mo" +elif command -v mole >/dev/null 2>&1; then + MO_BIN="mole" +else + echo "❌ Mole not found. Install from:" + echo " https://github.com/tw93/Mole" + exit 1 +fi + +# Run uninstall +echo "🗑️ Starting app uninstaller..." +echo "" +"$MO_BIN" uninstall diff --git a/integrations/setup-raycast.sh b/integrations/setup-raycast.sh new file mode 100755 index 0000000..07e67b6 --- /dev/null +++ b/integrations/setup-raycast.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# One-line Raycast integration installer +# Usage: curl -fsSL https://raw.githubusercontent.com/tw93/Mole/main/integrations/setup-raycast.sh | bash + +set -euo pipefail + +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +RAYCAST_DIR="$HOME/Library/Application Support/Raycast/script-commands" +BASE_URL="https://raw.githubusercontent.com/tw93/Mole/main/integrations/raycast" + +# Check Raycast +if [[ ! -d "$HOME/Library/Application Support/Raycast" ]]; then + echo -e "${YELLOW}Raycast not found. Install from: https://raycast.com${NC}" + exit 1 +fi + +echo "Installing Mole commands for Raycast..." +mkdir -p "$RAYCAST_DIR" + +# Download scripts +for script in mole-clean.sh mole-clean-dry-run.sh mole-uninstall.sh; do + curl -fsSL "$BASE_URL/$script" -o "$RAYCAST_DIR/$script" + chmod +x "$RAYCAST_DIR/$script" +done + +echo -e "${GREEN}✓${NC} Installed! Open Raycast and search: 'Reload Script Commands'" +echo "" +echo "Then search for: 'Clean Mac'" From f2279d340a160e67e7258c8b1222130bebb284d6 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Sun, 9 Nov 2025 09:59:12 +0800 Subject: [PATCH 3/4] Supports browser multi-profile cleaning --- bin/clean.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/clean.sh b/bin/clean.sh index 34fe296..6ed9baf 100755 --- a/bin/clean.sh +++ b/bin/clean.sh @@ -458,7 +458,6 @@ clean_service_worker_cache() { [[ ! -d "$cache_path" ]] && return 0 - local total_size=0 local cleaned_size=0 local protected_count=0 @@ -469,7 +468,6 @@ clean_service_worker_cache() { # Extract domain from path local domain=$(basename "$cache_dir" | grep -oE '[a-zA-Z0-9][-a-zA-Z0-9]*\.[a-zA-Z]{2,}' | head -1 || echo "") local size=$(du -sk "$cache_dir" 2>/dev/null | awk '{print $1}') - total_size=$((total_size + size)) # Check if domain is protected local is_protected=false @@ -643,11 +641,20 @@ perform_cleanup() { safe_clean ~/Library/Caches/zen/* "Zen cache" safe_clean ~/Library/Application\ Support/Firefox/Profiles/*/cache2/* "Firefox profile cache" - # Service Worker CacheStorage - clean_service_worker_cache "Chrome" "$HOME/Library/Application Support/Google/Chrome/Default/Service Worker/CacheStorage" - clean_service_worker_cache "Edge" "$HOME/Library/Application Support/Microsoft Edge/Default/Service Worker/CacheStorage" - clean_service_worker_cache "Brave" "$HOME/Library/Application Support/BraveSoftware/Brave-Browser/Default/Service Worker/CacheStorage" - clean_service_worker_cache "Arc" "$HOME/Library/Application Support/Arc/User Data/Default/Service Worker/CacheStorage" + # Service Worker CacheStorage (all profiles) + while IFS= read -r sw_path; do + local profile_name=$(basename "$(dirname "$(dirname "$sw_path")")") + local browser_name="Chrome" + [[ "$sw_path" == *"Microsoft Edge"* ]] && browser_name="Edge" + [[ "$sw_path" == *"Brave"* ]] && browser_name="Brave" + [[ "$sw_path" == *"Arc"* ]] && browser_name="Arc" + [[ "$profile_name" != "Default" ]] && browser_name="$browser_name ($profile_name)" + clean_service_worker_cache "$browser_name" "$sw_path" + done < <(find "$HOME/Library/Application Support/Google/Chrome" \ + "$HOME/Library/Application Support/Microsoft Edge" \ + "$HOME/Library/Application Support/BraveSoftware/Brave-Browser" \ + "$HOME/Library/Application Support/Arc/User Data" \ + -type d -name "CacheStorage" -path "*/Service Worker/*" 2>/dev/null) end_section # ===== 6. Cloud Storage ===== From ead56c457549af66e2ae3fe80fcd5f8389ed65b3 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Sun, 9 Nov 2025 10:03:07 +0800 Subject: [PATCH 4/4] Increase the cleaning of uncommon software --- bin/clean.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/clean.sh b/bin/clean.sh index 6ed9baf..e41c448 100755 --- a/bin/clean.sh +++ b/bin/clean.sh @@ -926,6 +926,9 @@ perform_cleanup() { safe_clean ~/Library/Caches/com.sketchup.*/* "SketchUp cache" safe_clean ~/Library/Caches/com.raycast.macos/* "Raycast cache" safe_clean ~/Library/Caches/com.tw93.MiaoYan/* "MiaoYan cache" + safe_clean ~/Library/Caches/com.klee.desktop/* "Klee cache" + safe_clean ~/Library/Caches/klee_desktop/* "Klee desktop cache" + safe_clean ~/Library/Caches/com.orabrowser.app/* "Ora browser cache" safe_clean ~/Library/Caches/com.filo.client/* "Filo cache" safe_clean ~/Library/Caches/com.flomoapp.mac/* "Flomo cache" safe_clean ~/Library/Caches/com.spotify.client/* "Spotify cache"