help with notifications

29 views
Skip to first unread message

Rob McBroom

unread,
Mar 21, 2012, 3:48:07 PM3/21/12
to quicksilver-...@googlegroups.com
I have begun the unpleasant chore of updating the Spotlight plug-in, but I’m stuck on something. Here’s a work-in-progress branch:

https://github.com/skurfer/Spotlight-qsplugin/tree/notifications

All you need to be looking at is QSSpotlightObjectSource. I’ve tried scanning a source dozens of times, but the `arrayLoaded:` method has only been called two or three times and I can’t figure out why. I’ve done the same searches in another stand-alone project and it finishes and sends the notification quickly and consistently.

Any ideas why it almost never sees the notification? Searching suggests that `startQuery` has to be run on the main thread, but as you can see, I’ve done that.

Probably not related to my problem, but I’m also not sure about having a single NSMetadataQuery object for the class. If I’m not mistaken, one instance of the class will handle all entries of that type, so I probably need an NSMetadataQuery for each entry and not just the class, right? But for testing purposes, I’ve removed all but one Spotlight entry and it still isn’t working as expected.

--
Rob McBroom
<http://www.skurfer.com/>

Patrick Robertson

unread,
Mar 21, 2012, 4:04:23 PM3/21/12
to quicksilver-...@googlegroups.com
A very quick thought off the top of my head: Is the notification send by Quicksilver, or the OS? So should you be using NSDistributedNotificationCenter?
(actually, after doing some googling, I don't think you need that)

Have you seen this:

Rob McBroom

unread,
Mar 22, 2012, 1:28:02 PM3/22/12
to quicksilver-...@googlegroups.com
On Mar 21, 2012, at 4:04 PM, Patrick Robertson wrote:

A very quick thought off the top of my head: Is the notification send by Quicksilver, or the OS? So should you be using NSDistributedNotificationCenter?

I don’t know. All of the examples are like that (including the link you referred me to). :-) Time to RTFM.

Some progress has been made. I got it working by not specifically starting the query on he main thread. (Surely the first thing I tried, but anyway.) But my suspicion was correct that an NSMetadataQuery iVar for the object wasn’t enough. Each entry needs it’s own, so I put them in a dictionary instead. This broke it again. (I read somewhere that the query object needs to be an iVar. Apparently true, and apparently being in a dictionary iVar doesn’t cut it.) Adding the CFRunLoop() business got it working again, but I’m really not comfortable leaving that in there until I understand what it’s doing, so more R’ing of TFM awaits.

The main roadblock now appears to be quirky behavior in the core application itself. :-) I’ve noticed this in the past, but never really worried about it. Long story short, the behavior when scanning catalog entries is not at all consistent. In order from most to least broken, these ways to trigger a scan all behave a little differently:
  1. Manually rescanning with the arrow in the preferences
  2. Scanning with the “Rescan Catalog Entry” action
  3. Allowing the scan to happen normally in the background
  4. Enabling the entry by checking the box next to it
I could probably work around it in the plug-in, but I’ll more likely investigate and attempt to fix it.

Rob McBroom

unread,
Mar 25, 2012, 2:05:55 PM3/25/12
to quicksilver-...@googlegroups.com
On Mar 22, 2012, at 1:28 PM, Rob McBroom wrote:

Adding the CFRunLoop() business got it working again, but I’m really not comfortable leaving that in there until I understand what it’s doing, so more R’ing of TFM awaits.

OK, I’m pretty comfortable with what’s going on now. I got it working for the object source, but then generalized it as a category. Thankfully, the hacky business of the object source calling scanForced:YES on itself is gone. See https://github.com/skurfer/Spotlight-qsplugin/blob/master/NSMetadataQuery%2BSynchronous.h and the corresponding implementation file.

I plan on using this in the Yojimbo plug-in. I had always wanted to use Spotlight there instead of chasing a changing directory structure all the time and now I finally can. I think we could also use Spotlight to fix the Mail plug-in on Lion for the same reason.

If that happens, we’d have three plug-ins using this, so I wonder if it should just be added to Quicksilver. Thoughts?

Long story short, the behavior when scanning catalog entries is not at all consistent. In order from most to least broken, these ways to trigger a scan all behave a little differently:
  1. Manually rescanning with the arrow in the preferences
  2. Scanning with the “Rescan Catalog Entry” action
  3. Allowing the scan to happen normally in the background
  4. Enabling the entry by checking the box next to it
A lot of this turned out to be side-effects of the previously discussed self rescanning behavior of the Spotlight object source, but there was one bug I found and fixed in #765.
Reply all
Reply to author
Forward
0 new messages