On 06/08/2011, at 06:48, cocoa-dev-requ...@lists.apple.com wrote:
> From: Jens Alfke <j...@mooseyard.com>
> Date: 6 de agosto de 2011 02:07:48 BRT
> 
> On Aug 5, 2011, at 8:04 AM, Carl Harris wrote:
> 
>> I have a Cocoa app that (among other things) installs an agent in launchd 
>> that runs in the background.  The agent installation happens when the app is 
>> first launched after install.
>> I'd like to support the drag-to-trash approach to uninstalling.  Can my 
>> background agent listen for some notification that would allow me to detect 
>> that the app bundle has been dragged to the trash, so I can clean up 
>> properly?
> 
> Interesting question. I’m not aware of any such notification.
> 
> The best thing I can think of is to have your agent process periodically 
> check whether its file still exists, and exit if it doesn’t (or if it’s now 
> inside the trash).

What I do in a similar situation is having the agent watch its own executable 
(as well as the containing app's bundle) with a kqueue (using EVFILT_VNODE and 
checking fro the flags NOTE_DELETE|NOTE_RENAME), and if this event occurs it 
unloads itself and exits. Works for me.

Note that moving a running application to anywhere (not just the Trash) can 
lead to all sorts of path-dependent operations failing, so it's best to exit 
fast here.

HTH,
--
Rainer Brockerhoff  <rai...@brockerhoff.net>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
Weblog: http://www.brockerhoff.net/blog

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to