Undocumented Code

I recently developed two gadgets for my employer, a Newspaper Stand (gadget showing the front pages of Greek newspapers) and a Custom Calendar that displays information about TV Shows, currently playing shows, events etc. from the Greek portal www.in.gr.


The problem I faced during development was that I had no way of daily refreshing the content assuming that the user didn’t turn off the computer e.g. computer was put into sleep or hibernation mode during inactivity. The MSDN gadget development reference did not mention anything that could help me resolve these issues, so I ended up checking manually for date changes each time a timer’s interval was met. Even this way thow when the user opened the computer on the morning though, he/she had to wait for the first timer’s interval to see the current content.


Looking around for a while I finally found the information I was looking on the Sidebar Gadget Blog. There is actually an event System.Gadget.visibilityChanged which occurs when:



  • The gadget is docked to the sidebar and has been scrolled off-screen.

  • The gadget is docked to the sidebar and the sidebar has been minimized.

  • The workstation is locked or the user has “fast-user-switched” to another session on the console.

  • The power management timeout for the monitor has elapsed and the monitor is turned off.

And a property System.Gadget.visible which returns true if the gadget is visible. So using a simple code like:
function onload()
{
  System.Gadget.visibilityChanged = checkVisibility;
}
function checkVisibility()
{
  if(System.Gadget.visible)
  {
    updateFunction();
  }
}

you can update the content of your gadget the moment it becomes visible.


P.S. Anyone knows a reason or have a good explanation for this information not being in the Gadget Development Reference?


 

 
Comments

No comments yet.

Leave a Reply