alienator88 / Pearcleaner

A free, source-available and fair-code licensed mac app cleaner
https://itsalin.com/appInfo/?id=pearcleaner
Other
3.71k stars 85 forks source link

[FR] Option to auto run brew uninstall <app> in the background upon removing an app using Pearcleaner #154

Closed Risinggoblin closed 1 week ago

Risinggoblin commented 1 week ago

Is your feature request related to a problem? Please describe.

When removing an application installed via Homebrew using Pearcleaner, Homebrew is not updated to reflect this action. This can cause discrepancies where Homebrew continues to list the app as installed, potentially leading to issues during updates or re-installations.

Describe the solution you’d like

It would be great if Pearcleaner could detect whether an application was installed via Homebrew and execute the brew uninstall <app> command in the background when the app is removed. This would ensure Homebrew’s local package database remains accurate and up-to-date, eliminating the need for manually running brew uninstall <app>

Describe alternatives you’ve considered • Manually running brew uninstall <app> after using Pearcleaner to remove an application.

Additional context

Pearcleaner could include a pre-check to confirm whether the app is listed in Homebrew before executing the command. Additionally, this can be an optional setting which can be toggled on or off based on user preference

alienator88 commented 1 week ago

Out of curiosity, does the brew cleanup function not work for you?

Screenshot 2024-11-19 at 11 58 52 AM

Risinggoblin commented 1 week ago

This was my bad, apologies. I had missed the "allow terminal acess" MacOS pop-up. Once I allow, this works well. Apologies again

alienator88 commented 1 week ago

No worries, glad it works now :)

L1cardo commented 3 days ago

There is not "allow terminal access" MacOS pop-up on my Mac, and I can not find any option to turn it on. I can only find "Finder" access for Pearcleaner, not the terminal access. macOS 15.1.1 image

alienator88 commented 1 day ago

There shouldn't be a terminal access permission under Automation settings page. It should only have Finder and System Events. The app uses apple script to tell terminal to launch indirectly. image

L1cardo commented 1 day ago

image Somehow it shows Terminal access now, but it does not run terminal automatically to do the brew uninstall.

I don't have that Systems Events access

alienator88 commented 1 day ago

Can you run this in a separate Terminal window:

log stream --level debug --style compact --predicate 'subsystem == "com.alienator88.Pearcleaner"'

Then attempt to uninstall an app that is also installed via homebrew. See if it spits out any errors in the terminal window.

L1cardo commented 1 day ago

image Nothing special. That Matlab app is not what I was trying to uninstall

alienator88 commented 1 day ago

That's odd..what app are you trying to remove? Can you show me a screenshot of it and the files it finds for it?

L1cardo commented 1 day ago

That's odd..what app are you trying to remove? Can you show me a screenshot of it and the files it finds for it?

https://github.com/mangerlahn/Latest

image

alienator88 commented 1 day ago

Hmm..I can't reproduce the issue. I installed Latest from homebrew, opened it and clicked around a bit to generate some cache files. Then I uninstalled from Pearcleaner and the Terminal popped up and ran through the cleanup process.. I ran it in debug mode in Xcode and got absolutely zero errors, so it might be something environmental to your OS regarding permissions. I'm also on 15.1.1 Sequoia so not exactly sure what's going on.

L1cardo commented 1 day ago

Hmm..I can't reproduce the issue. I installed Latest from homebrew, opened it and clicked around a bit to generate some cache files. Then I uninstalled from Pearcleaner and the Terminal popped up and ran through the cleanup process.. I ran it in debug mode in Xcode and got absolutely zero errors, so it might be something environmental to your OS regarding permissions. I'm also on 15.1.1 Sequoia so not exactly sure what's going on.

It is a newly bought MacBook a week ago, so I don't know what is wrong with my OS environment. Can you trigger some command to let it access System Events ?

alienator88 commented 1 day ago

So Pearcleaner checks permissions on launch. It executes an apple script command to request system events.

This other user had a similar issue and theirs was resolved after reinstalling the OS. I think just strange Sequoia problems: https://github.com/alienator88/Pearcleaner/issues/115#issuecomment-2393120444

L1cardo commented 1 day ago

Below is the app that I developed, it also uses AppleScript, it can successfully trigger System Events, I may have to take a look when I get some time. https://github.com/Bigwig-Club/Account-Switcher

alienator88 commented 1 day ago

I looked more into this and I don't think the System Events permission is an issue here.

I use System Events for the Cmd+Z function when you delete files to undo the deletion via Finder. Maybe you haven't used it yet to have it ask for that permission: https://github.com/alienator88/Pearcleaner/blob/8ed2de96be381a76e68f1f7f60083b2b153521d7/Pearcleaner/Logic/Logic.swift#L275

This is where I use Terminal to run the cleanup task: https://github.com/alienator88/Pearcleaner/blob/8ed2de96be381a76e68f1f7f60083b2b153521d7/Pearcleaner/Logic/Logic.swift#L539

L1cardo commented 1 day ago

Yeah, it now has system events permissions after I pressed CMD + Z, but still no terminal pops up to do brew uninstall command

alienator88 commented 1 day ago

I'll make a custom build for you tomorrow with a button to trigger a simple Terminal command via AppleScript. I'll have it print logs with debugging to see if it's an issue with the command or something else.

L1cardo commented 1 day ago

I'll make a custom build for you tomorrow with a button to trigger a simple Terminal command via AppleScript. I'll have it print logs with debugging to see if it's an issue with the command or something else.

No hurry, take your time and big thanks!

alienator88 commented 1 day ago

Something I'm curious about to see if it's an issue with Pearcleaner or something else, let's try automating terminal outside of my app. Open Script Editor on your Mac and run this:

tell application "Terminal"
    activate
    do script "echo 'Test'"
end tell

Does the Terminal window open?

L1cardo commented 1 day ago

image Terminal window open successfully

alienator88 commented 1 day ago

Cool, I'll follow up tomorrow

alienator88 commented 12 hours ago

Try this build, there's a Terminal button in the middle of the app, can't miss it: Pearcleaner.zip

It should run the same command you tested in Script Editor. If it fails to open the window, run it with that debug command from before in terminal and see if it captures any logs.

L1cardo commented 12 hours ago

OK, I now fully understand what is causing the issue, and it is nothing to do with your test build.

If the close after uninstall option is on, the auto brew uninstall command won't execute. image

Also I have found some other bugs:

  1. CLI support can't be enabled, and here is the error log image image
  2. close after uninstall says it will only affect when Pearcleaner is opened via Finder extension, but if I open the app normally , it will also close itself after uninstall. image
alienator88 commented 12 hours ago

Nice find! Would you be able to add these as a new issue so I can track them better? I think I know why at least 2 of those happen.