diff --git a/lib/core/app_protection.sh b/lib/core/app_protection.sh index 400203b..e8a1163 100755 --- a/lib/core/app_protection.sh +++ b/lib/core/app_protection.sh @@ -1056,6 +1056,31 @@ find_app_files() { files_to_clean+=("$container") done < <(command find ~/Library/Group\ Containers -maxdepth 1 \( -name "*$bundle_id*" \) -print0 2> /dev/null) fi + + # App extensions often use bundle-id-derived directories rather than the + # main bundle id exactly, for example share extensions or file providers. + local -a derived_bundle_roots=( + "$HOME/Library/Application Scripts" + "$HOME/Library/Containers" + "$HOME/Library/Application Support/FileProvider" + ) + local derived_root="" + local derived_path="" + local existing_path="" + local already_added=false + for derived_root in "${derived_bundle_roots[@]}"; do + [[ -d "$derived_root" ]] || continue + while IFS= read -r -d '' derived_path; do + already_added=false + for existing_path in "${files_to_clean[@]}"; do + if [[ "$existing_path" == "$derived_path" ]]; then + already_added=true + break + fi + done + [[ "$already_added" == "true" ]] || files_to_clean+=("$derived_path") + done < <(command find "$derived_root" -maxdepth 1 -type d -name "*$bundle_id*" -print0 2> /dev/null) + done fi # Launch Agents by name (special handling) diff --git a/tests/uninstall_naming_variants.bats b/tests/uninstall_naming_variants.bats index eee48f9..4bccc77 100644 --- a/tests/uninstall_naming_variants.bats +++ b/tests/uninstall_naming_variants.bats @@ -109,6 +109,24 @@ setup() { [[ "$result" =~ .local/share/firefox ]] } +@test "find_app_files detects bundle-id-derived extension leftovers" { + mkdir -p "$HOME/Library/Application Support/FileProvider/com.tencent.xinWeChat.WeChatFileProviderExtension" + mkdir -p "$HOME/Library/Application Scripts/com.tencent.xinWeChat.WeChatMacShare" + mkdir -p "$HOME/Library/Application Scripts/5A4RE8SF68.com.tencent.xinWeChat" + mkdir -p "$HOME/Library/Containers/com.tencent.xinWeChat.WeChatFileProviderExtension" + mkdir -p "$HOME/Library/Group Containers/5A4RE8SF68.com.tencent.xinWeChat" + mkdir -p "$HOME/Library/Containers/com.tencent.otherapp.Helper" + + result=$(find_app_files "com.tencent.xinWeChat" "WeChat") + + [[ "$result" =~ "Library/Application Support/FileProvider/com.tencent.xinWeChat.WeChatFileProviderExtension" ]] + [[ "$result" =~ "Library/Application Scripts/com.tencent.xinWeChat.WeChatMacShare" ]] + [[ "$result" =~ "Library/Application Scripts/5A4RE8SF68.com.tencent.xinWeChat" ]] + [[ "$result" =~ "Library/Containers/com.tencent.xinWeChat.WeChatFileProviderExtension" ]] + [[ "$result" =~ "Library/Group Containers/5A4RE8SF68.com.tencent.xinWeChat" ]] + [[ ! "$result" =~ "Library/Containers/com.tencent.otherapp.Helper" ]] +} + @test "find_app_files does not match empty app name" { mkdir -p "$HOME/Library/Application Support/test"