mirror of
https://github.com/tw93/Mole.git
synced 2026-02-15 10:30:06 +00:00
fix: improve Dock cleanup path handling
- Add control character validation - Use canonical paths (pwd -P) for better resolution - Strengthen fallback logic for deleted applications - Add empty path guards
This commit is contained in:
@@ -43,9 +43,9 @@ update_via_homebrew() {
|
|||||||
echo "Updating Homebrew..."
|
echo "Updating Homebrew..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
brew update > "$temp_update" 2>&1 &
|
brew update >"$temp_update" 2>&1 &
|
||||||
local update_pid=$!
|
local update_pid=$!
|
||||||
wait $update_pid 2> /dev/null || true # Continue even if brew update fails
|
wait $update_pid 2>/dev/null || true # Continue even if brew update fails
|
||||||
|
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
stop_inline_spinner
|
stop_inline_spinner
|
||||||
@@ -58,9 +58,9 @@ update_via_homebrew() {
|
|||||||
echo "Upgrading Mole..."
|
echo "Upgrading Mole..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
brew upgrade mole > "$temp_upgrade" 2>&1 &
|
brew upgrade mole >"$temp_upgrade" 2>&1 &
|
||||||
local upgrade_pid=$!
|
local upgrade_pid=$!
|
||||||
wait $upgrade_pid 2> /dev/null || true # Continue even if brew upgrade fails
|
wait $upgrade_pid 2>/dev/null || true # Continue even if brew upgrade fails
|
||||||
|
|
||||||
local upgrade_output
|
local upgrade_output
|
||||||
upgrade_output=$(cat "$temp_upgrade")
|
upgrade_output=$(cat "$temp_upgrade")
|
||||||
@@ -78,7 +78,7 @@ update_via_homebrew() {
|
|||||||
|
|
||||||
if echo "$upgrade_output" | grep -q "already installed"; then
|
if echo "$upgrade_output" | grep -q "already installed"; then
|
||||||
local installed_version
|
local installed_version
|
||||||
installed_version=$(brew list --versions mole 2> /dev/null | awk '{print $2}')
|
installed_version=$(brew list --versions mole 2>/dev/null | awk '{print $2}')
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${GREEN}${ICON_SUCCESS}${NC} Already on latest version (${installed_version:-$current_version})"
|
echo -e "${GREEN}${ICON_SUCCESS}${NC} Already on latest version (${installed_version:-$current_version})"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -89,14 +89,14 @@ update_via_homebrew() {
|
|||||||
else
|
else
|
||||||
echo "$upgrade_output" | grep -Ev "^(==>|Updating Homebrew|Warning:)" || true
|
echo "$upgrade_output" | grep -Ev "^(==>|Updating Homebrew|Warning:)" || true
|
||||||
local new_version
|
local new_version
|
||||||
new_version=$(brew list --versions mole 2> /dev/null | awk '{print $2}')
|
new_version=$(brew list --versions mole 2>/dev/null | awk '{print $2}')
|
||||||
echo ""
|
echo ""
|
||||||
echo -e "${GREEN}${ICON_SUCCESS}${NC} Updated to latest version (${new_version:-$current_version})"
|
echo -e "${GREEN}${ICON_SUCCESS}${NC} Updated to latest version (${new_version:-$current_version})"
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Clear update cache (suppress errors if cache doesn't exist or is locked)
|
# Clear update cache (suppress errors if cache doesn't exist or is locked)
|
||||||
rm -f "$HOME/.cache/mole/version_check" "$HOME/.cache/mole/update_message" 2> /dev/null || true
|
rm -f "$HOME/.cache/mole/version_check" "$HOME/.cache/mole/update_message" 2>/dev/null || true
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove applications from Dock
|
# Remove applications from Dock
|
||||||
@@ -125,35 +125,40 @@ remove_apps_from_dock() {
|
|||||||
local changed=false
|
local changed=false
|
||||||
for target in "${targets[@]}"; do
|
for target in "${targets[@]}"; do
|
||||||
local app_path="$target"
|
local app_path="$target"
|
||||||
# Normalize path for comparison - use original path if app already deleted
|
local full_path=""
|
||||||
local full_path
|
|
||||||
if full_path=$(cd "$(dirname "$app_path")" 2> /dev/null && pwd); then
|
if [[ "$app_path" =~ [[:cntrl:]] ]]; then
|
||||||
full_path="$full_path/$(basename "$app_path")"
|
debug_log "Skipping dock removal for path with control chars: $app_path"
|
||||||
else
|
continue
|
||||||
# App already deleted - use the original path as-is
|
|
||||||
# Remove ~/ prefix and expand to full path if needed
|
|
||||||
if [[ "$app_path" == ~/* ]]; then
|
|
||||||
full_path="$HOME/${app_path#~/}"
|
|
||||||
elif [[ "$app_path" != /* ]]; then
|
|
||||||
# Relative path - skip this entry
|
|
||||||
continue
|
|
||||||
else
|
|
||||||
full_path="$app_path"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# URL-encode the path for matching against Dock URLs (spaces -> %20)
|
if [[ -e "$app_path" ]]; then
|
||||||
|
if full_path=$(cd "$(dirname "$app_path")" 2>/dev/null && pwd -P); then
|
||||||
|
full_path="$full_path/$(basename "$app_path")"
|
||||||
|
else
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
case "$app_path" in
|
||||||
|
~/*) full_path="$HOME/${app_path#~/}" ;;
|
||||||
|
/*) full_path="$app_path" ;;
|
||||||
|
*) continue ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ -z "$full_path" ]] && continue
|
||||||
|
|
||||||
local encoded_path="${full_path// /%20}"
|
local encoded_path="${full_path// /%20}"
|
||||||
|
|
||||||
# Find the index of the app in persistent-apps
|
# Find the index of the app in persistent-apps
|
||||||
local i=0
|
local i=0
|
||||||
while true; do
|
while true; do
|
||||||
local label
|
local label
|
||||||
label=$(/usr/libexec/PlistBuddy -c "Print :persistent-apps:$i:tile-data:file-label" "$plist" 2> /dev/null || echo "")
|
label=$(/usr/libexec/PlistBuddy -c "Print :persistent-apps:$i:tile-data:file-label" "$plist" 2>/dev/null || echo "")
|
||||||
[[ -z "$label" ]] && break
|
[[ -z "$label" ]] && break
|
||||||
|
|
||||||
local url
|
local url
|
||||||
url=$(/usr/libexec/PlistBuddy -c "Print :persistent-apps:$i:tile-data:file-data:_CFURLString" "$plist" 2> /dev/null || echo "")
|
url=$(/usr/libexec/PlistBuddy -c "Print :persistent-apps:$i:tile-data:file-data:_CFURLString" "$plist" 2>/dev/null || echo "")
|
||||||
[[ -z "$url" ]] && {
|
[[ -z "$url" ]] && {
|
||||||
((i++))
|
((i++))
|
||||||
continue
|
continue
|
||||||
@@ -161,7 +166,7 @@ remove_apps_from_dock() {
|
|||||||
|
|
||||||
# Match by URL-encoded path to handle spaces in app names
|
# Match by URL-encoded path to handle spaces in app names
|
||||||
if [[ -n "$encoded_path" && "$url" == *"$encoded_path"* ]]; then
|
if [[ -n "$encoded_path" && "$url" == *"$encoded_path"* ]]; then
|
||||||
if /usr/libexec/PlistBuddy -c "Delete :persistent-apps:$i" "$plist" 2> /dev/null; then
|
if /usr/libexec/PlistBuddy -c "Delete :persistent-apps:$i" "$plist" 2>/dev/null; then
|
||||||
changed=true
|
changed=true
|
||||||
# After deletion, current index i now points to the next item
|
# After deletion, current index i now points to the next item
|
||||||
continue
|
continue
|
||||||
@@ -173,6 +178,6 @@ remove_apps_from_dock() {
|
|||||||
|
|
||||||
if [[ "$changed" == "true" ]]; then
|
if [[ "$changed" == "true" ]]; then
|
||||||
# Restart Dock to apply changes from the plist
|
# Restart Dock to apply changes from the plist
|
||||||
killall Dock 2> /dev/null || true
|
killall Dock 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user