Weird things with persistentSettings.js

I'm having some difficulties with the persistentSettings Bruce made.

I'm trying to load persistentSettings as my Settings dialog loads, but for some reason nothing gets returned. HOWEVER, if I right afterwards press a button that triggers the same thing (loading value from persistentSettings), it comes up fine!

Here is my code for Settings.js:

//gets called when the Settings windows gets opened or loaded
document.onreadystatechange = function()
{
if(document.readyState == "complete")
{
//fetch current location settings for user
loadStates('US');

getGadgetLocation(); <-- here is the function that gets the saved setting
alertme(g_location); <-- debug stuff, shows me what comes up, i'm using div for this.

if(g_location == "US")
radLocationNation.checked = true;
else if(g_location.length == 2)
radLocationState.checked = true;
else if(g_location.length == 5)
radLocationZip.checked = true;

}
}

function saveGadgetLocation(strSaved)
{
updateLocation(strSaved);
}

function getGadgetLocation()
{
getPersistentSetting( g_LOCATIONPARAM, updateLocationCallback );
}

function updateLocationCallback( value )
{
g_location = value;
}

function updateLocation(value)
{
g_location = value;
setPersistentSetting( g_LOCATIONPARAM, value );
}

Thanks!
Thor.




Answer this question

Weird things with persistentSettings.js

  • Jassim Rahma

    Ahh... makes perfect sense now! One more question though regarding the persistentSettings - is it user dependent That is, if two instances of the same gadget are being used on two different User Profiles in Vista, will those 2 users share saved settings, or will persistentSettings save things seperately for each vista user

    Thanks a lot!
    Thor.



  • Santhosh Pallikara

    Update:

    I tried calling that getGadgetLocation function every 300 ms with a timer as my settings load, and doing that makes it work... so basically i'm just polling the persistentSettings until it returns me a value or null. But this behavior is really odd, it looks like the persistentSetting object isn't ready right after a page loads... it needs some time or something. What do you think Bruce

    Thanks
    Thor.



  • uhclstudent

    Each user will have their own copy of the settings. You could change that if you wanted, though - just identify/create a directory that all users can write to, and modify the persistentSettings.js to put its files there instead of in the gadget's install directory.

    On a mostly-unrelated note - another way to store persistent settings would be in the registry. I don't recall why I didn't code persistentSettings.js that way in the first place - probably just slipped my mind. If you use registry calls, you wouldn't have to deal with the callback architecture that my library has.


  • ONEWORKNGRL

    You are assuming that g_location is set when the call to getGadgetLocation returns. That is not the case - you cannot rely on this value until updateLocationCallback is called and you set it. Recode as follows:

    //gets called when the Settings windows gets opened or loaded
    document.onreadystatechange = function()
    {
    if(document.readyState == "complete")
    {
    //fetch current location settings for user
    loadStates('US');

    getGadgetLocation(); <-- here is the function that gets the saved setting
    }
    }

    function saveGadgetLocation(strSaved)
    {
    updateLocation(strSaved);
    }

    function getGadgetLocation()
    {
    getPersistentSetting( g_LOCATIONPARAM, updateLocationCallback );
    }

    function updateLocationCallback( value )
    {
    g_location = value;

    alertme(g_location); <-- debug stuff, shows me what comes up, i'm using div for this.

    if(g_location == "US")
    radLocationNation.checked = true;
    else if(g_location.length == 2)
    radLocationState.checked = true;
    else if(g_location.length == 5)
    radLocationZip.checked = true;

    }

    function updateLocation(value)
    {
    g_location = value;
    setPersistentSetting( g_LOCATIONPARAM, value );
    }


  • Weird things with persistentSettings.js