May 27th, 2009 by Mike Fulton
Categories: Microsoft, Web Design & Programming, Windows
NVIDIA Graphics Gadget

NVIDIA Graphics Gadget

I first got involved in creating Vista Sidebar gadgets back when Windows Vista was still in beta release.  I was asked by NVIDIA to create a gadget that would display the type of graphics card you have installed, the current NVIDIA driver version, how much graphics memory was on the card, and the current operating temperature.  And if you had two cards working in NVIDIA’s SLI mode, it needed to show the separate information for each of the installed cards.  Lastly, it had to be able to generate an alarm if the temperature got too hot.

It sounds like it’s really not that hard, provided you have a means of collecting those various tidbits of information about the installed graphics card(s), but it was still a challenging project in some ways.  For one thing, when I started the project, the documentation about creating gadgets was brand new and still undergoing occasional changes.   The first few weeks I was working on the gadget, the documentation changed 3 times.

Also, there were really no samples to look at except for those gadgets included with the Vista beta.   Some decent gadgets are included there, but none of them were created with the goal of being sample code for developers.  Between the lack of samples and the shifting documentation, there were a lot of questions about “Can you do xxx in a gadget?” that nobody seemed able to answer quite yet.

What Is A Gadget?

Gadgets are basically small, specialized webpages that exist independently of any visible browser.  Windows Vista isn’t the first system to have such an animal.  The Macintosh OS X has the Dashboard and “widgets”, and Yahoo has their Yahoo Widget Engine, previously known as Konfabulator.  All of these are slightly differnet flavors of the same idea.  They are all created with a mix of browser-compatible artwork, HTML, CSS, and your favorite scripting language. Generally, they can do almost anything you can do on a regular webpage, but are typically designed to show a specific and limited amount of information.

There’s usually some manifest file gluing it all together.   For Windows Sidebar Gadgets, there’s an XML document that specifies all the information needed by the system.

Gadget Scripting

Most gadgets need to allow for some interactivity with the user, or with web servers, database servers, or who knows what.  To manage this, you can use any client-side scripting language that is supported natively by Internet Explorer.  That means Javascript or VBScript for most people.  The good news is, you don’t have to worry about targetting 14 different combinations of browser type and version. 

Javascript code running in a gadget has some additional restrictions compared to code running in a standard browser.  Certain things just don’t work, such as alerts or input prompts.   And you’re not able to open new windows.

On the other hand, gadgets also have some additional capabilities available through Javascript compared to code running in a standard browser.  For example, they have access to a special system object class that provides access to variety of things that Javascript would ordinarily not be able to access.

Gadget Security

Gadgets have to live within a security model that’s more or less similar to what a regular webpage has, but there are some important differences.  The main example is that the System.Gadget object class allows your script code to access to the local file system and a variety of other things that Javascript would ordinarily not be able to access.

Another nice thing is that because gadgets are based locally instead of coming from a web server, the usual security restrictions for not allowing cross-domain script access have been lifted.  Your Javascript code can make Ajax requests of any domain as desired.

The NVIDIA Status Gadget

The NVIDIA Status Gadget needed to be able to display information that could only be obtained from one source: directly from the NVIDIA graphics drivers.  Since it was not possible to access the drivers directly from the gadget’s Javascript code, I needed an alternative way to get the information.  So what I did was to create an Active-X control that implemented an object that was accessible from Javascript.  This control was basically just a wrapper for the calls in the NVIDIA drivers that returned the desired information.

This got the job done, ultimately, but it did complicate development at first.  Before I could write the gadget, I needed the Active-X object, and before I could really test that the Active-X object was working right, I needed the gadget as a client.  Ultimately, the Active-X control wasn’t really that complicated, as such things go, but it was an added task that most gadgets don’t have to worry about.