How to implement the wakeFromSleep function in javascript.
First some variable declarations:
Code:
var time = new Date();
var savedTime = time;
This is how Yahoo widget would have implemented the wakeFromSleep function
Code:
//==============================
// reload after sleep
//==============================
//widget.onWakeFromSleep = function () {
// lprint("onWakeFromSleep");
// reloadWidget();
//};
This is the Xwidget code that is called from a timer called sleepTimer
Code:
// timer to check sleep once a minute
// sets a value, check the value and if the difference is
// greater than three minutes then assume the PC has been
// asleep and restart the widget.
//==============================
// reload after sleep
//==============================
function sleepTimerOnUpdate(Sender)
{
var theDate = new Date();
secsDif = parseInt(theDate.getTime() / 1000, 10) - parseInt((savedTime) / 1000, 10);
if (secsDif >= 180) { // 3 mins pause causes a restart
print("Running the sleep timer - the difference is an abnormal " + secsDif + " secs");
//widget.cmd("!Reload"); // does not work FFS
savedTime = new Date();
startup(); // have to call the startup function as there is no working reload function in Xwidget
} else {
//print("Running the sleep timer - the difference is " + secsDif + " secs");
savedTime = new Date();
}
}
//=====================
//End function
//=====================