Archive for November, 2009

Default Folder X 4.3.3 is out!

Friday, November 6th, 2009

Default Folder X 4.3.3 is available on the What’s New page, addressing a couple of fairly major issues on Leopard and Tiger.  My apologies for the need for another update so close on the heels of version 4.3.2 – see my earlier blog post about LSSharedFileListAddObserver for the gory details.

To just download the new version, use the link below:

http://www.stclairsoft.com/cgi-bin/dl.cgi?DX

And yes, I’m aware that this would be easier for you if DFX auto-updated using Sparkle.  It’s on my list, but the last couple of releases have had significant fixes that I haven’t wanted to hold up with the oodles of testing necessary to roll out a new update mechanism.

Being careful with LSSharedFileListAddObserver

Friday, November 6th, 2009

So, Apple added this cool little capability to the Launch Services API in Leopard: LSSharedFileListAddObserver will call your observer function whenever there are changes in a number of different file lists maintained by Launch Services. One of those lists is the “Recent Documents” list in the Apple Menu. “Great!” I thought, “I’ll roll this into Default Folder X to ensure that it doesn’t miss any recently used folders.”  It’s a simple API – what could go wrong?  As a long time developer, I should have known better – if you EVER say this (even if you never even say it out loud), you need to poke yourself with something sharp and realize that the consequences will probably hurt quite a bit more than that. “What could go wrong?” indeed.

So yes, here I am apologizing for not having poked myself after I used LSSharedFileListAddObserver without asking more questions – or at least without testing more.  Here’s how Default Folder X ended up using 60% of some users’ CPUs while doing nothing useful:

  1. DFX added itself as an observer for kLSSharedFileListRecentDocumentItems.
  2. The observer function got called by Launch Services because the user double-clicked a document in the Finder.
  3. DFX looked at the list, took the most recent entry in it (the first one), asked Launch Services for the URL of the document, and added the folder enclosing that document to its Recent Folders list.

Pretty simple, right? Yeah, I thought so too. This was tested thoroughly on Snow Leopard and performed fine, and all my Leopard testers reported that it worked well for them too.

So what’s the problem then?  Well, there’s this little “issue”…  If a user has a Windows server mounted on the Desktop, things get a little more interesting.  Normally, when Launch Services calls your observer function, it hands you the file list and you ask for a copy of the list.  The list itself is just a series of ID’s and references – to see what’s in an entry, you have to call LSSharedFileListItemResolve().  And that’s where the interesting part happened.  On Leopard, if the shared file list item lies on a Windows server, the act of calling LSSharedFileListItemResolve actually results in the item being changed, so your observer function gets called again the next time you hit your event loop.  The result of this is that you get called over and over again if you naively use LSSharedFileListItemResolve to get more info about the items that Launch Services is handing you.

So – the warning:  If you use LSSharedFileListAddObserver to watch the list of recent documents, keep a copy of the ID’s from the previous call and ONLY call LSSharedFileListItemResolve if there’s a new ID in the array.  Otherwise do nothing, or work off cached information – otherwise you’ll end up in an infinite loop, sucking down lots of CPU time.  And if you’re doing anything that interacts with the filesystem, make SURE you test with SMB shared volumes too.

Default Folder X high CPU-usage and responsiveness problems

Thursday, November 5th, 2009

Well, there’s definitely a bug in Default Folder X 4.3.2.  When running under Leopard and accessing SMB file servers, DFX will start consuming 20-60% of one CPU and will start to lag or become completely unresponsive.  This may also affect Snow Leopard and / or other types of file servers besides SMB.

I’ve got a test build available with a fix:

http://www.stclairsoft.com/download/DefaultFolderX-4.3.3b1.dmg

If you’re having any trouble with Default Folder X, please download and install it.  It should fix your problems.  If you run into any problems, please let me know as soon as possible at DefaultFolder@stclairsoft.com.

Thanks, and I apologize for the bug (I’ll post the gory details in a few minutes, since it’s an interesting little ‘gotcha’ in the Launch Services API).