I spent a few days last week re-acquainting myself with Windows Sidebar, a widget engine introduced in Windows Vista and carried over into Windows 7. My goal was to create a Concerto widget similar in functionality to the screensaver so people who don’t use a screensaver as much could still get some Concerto content delivered locally. While Windows Sidebar doesn’t support Windows XP natively, having native support for Vista & 7 should be sufficient for now.
Luckily, there is no secret sauce behind widgets… not on Windows, not on OS X… they’re all just HTML which is really convenient for a web-based system like Concerto. I started with a really simple design, copying almost all of the code to rotate content from Concerto mini-screen we introduced in our 1.9 update. I had to tweak the javascript slightly to pull the XML/JSON from a different domain. For some reason, jQuery’s AJAX methods couldn’t handle the cross-domain request so I had to switch to the manual method: Internet Explorer’s XMLHttpRequest. It wasn’t very painful to substitute in for the .ajax call, and I was still able to use jQuery for all my selectors and iterators.
I got the widget working, but it kept freezing up on me in very strange ways. The text in a div that displayed the content name would keep rotating, but the image above would freeze. For the life of me I couldn’t figure out why this was happening, especially since the text rotation was setup to be handled when the image rotation had completed. I decided to pull out my watch and see if the widget kept freezing at the same time, surprisingly it did. I adjusted the time each image was to be displayed and tested again, measuring the same number of image rotations. It seemed that after X image rotations the image’s ability to fadeOut, fadeIn, or have it’s src changed were getting stopped by some unknown process. Time to fire up taskmgr where I could get a slightly better look at what was going on.
The memory used for the widgets (I had multiple open at a time) kept growing and growing which seemed to correlate with the sudden freezing of the image rotation. I wasn’t totally surprised by the memory issues, the internal workings of jQuery’s chaining and binding have never been very clear to me. While I don’t know the details, it looks like jQuery was attaching a completely new set of functions to each image when it was loaded. Since there were functions attached to the image maybe it didn’t get garbage collected out of memory like it should… or maybe the duplicate functions activated some sort of nasty recursion chaining… I really don’t know. I was a bit surprised we didn’t notice this earlier, since the same code was used on the Concerto mini-screen which was pretty much copy and pasted from the actual javascript used on our screens. Internet Explorer, Firefox, and Chrome all showed a steady growth in memory when left on the mini-screen for a period of time. We hadn’t noticed the leak before because all those big web browsers have much higher memory limits per tab, its not nearly as low as the allocation for 1 widget. I also suspect we didn’t spend time running the mini-screen for a very long time. The average person stays on that page for only a few seconds before clicking off to login, visit the wall, or download the screensaver, so stability over time wasn’t critical during the design phase. Upon further inspection. it looks like we left out the line in the JavaScript from our screen code that destroys everything in the field….
Now the widget is ready to be passed off to someone with a bit more graphical design & CSS skill than I. I suspect my background-color: red; will get stripped away in favor or something that flows better with Concerto.
You can check out the code here: http://dev.studentsenate.rpi.edu/svn/svn-senate/extras/concerto.gadget/

