Question

I'm writing a Dashboard widget in Dashcode, and I'd like to add some sort of check-for-updates functionality. I already looked into Sparkle, but AFAICT it's not applicable to widgets like this. Is there a commonly-used library to do update checking, or will I have to develop my own system?

I only need a very simple setup... automatically checking for new versions would be a plus, but if the user had to click a button in order to check that would be OK with me.

Was it helpful?

Solution

Inasmuch as "is there a function that will..." then i have not come across it.

What i did was as follows

In the plist there is the version of the widget and you put the number in there, lets say 1.0. Which you should be able to access and use. (see code) For reason i didn't and added this global var widget_version = "1.4"; and then updated that when the widget updated.

Then on a server accessible by the web you create a php (or whatever) file that has the number of current version of the widget. Again lets say 1.1.

Then you write a javascript function than will check this current widget version against the server version and display a graphic or message to tell the user. It is best to let the user decide if they want to upgrade rather than making it automatic.

Following is the code i used. Please copy and or hack as you wish.

function getSoftwareUpdate() {

// so use the built in CURL to do a REST call n.b. in widget preference you will need to check 'allow network access'
var softwareUpdate = widget.system("/usr/bin/curl  'http://api.yourserver.com/widget/wfccupdate.php'", null).outputString;

//alert(softwareUpdate); // tells you the function has been called
//alert("the update number from the REST " + softwareUpdate); // for debugging will show the key

// in main.js add this line
// var widget_version = "1.4"; // this is changed when you update the widget code for  new release
// yes it's a global variable and bad but i was in a hurry
// the following line should get the widget number but for some reason i didn't do it
// localVersion = widget.preferenceForKey(preferenceForKey);
//alert("the internal preference key " + widget_version);

// then check to see if they match
    if(softwareUpdate == widget_version)
    { hide_update('softwareupdate')
    }
    else
    {show_update('softwareupdate')
    }
}

function hide_update(el) { // hide the update graphic
    if(document.getElementById(el)) 
    {
        if(document.getElementById(el).style.display != "none") 
        document.getElementById(el).style.display = "none";
    }
}
function show_update(el) { // show the update graphic
    if(document.getElementById(el)) {
        if(document.getElementById(el).style.display == "none") 
        document.getElementById(el).style.display = "block"; 
        }
    }



// this is the php that is called by curl and acts as REST

<?php
// data
$UPDATE_database = <<<_UPDATE_
<?xml version="1.0" encoding="utf-8" ?>
<update>
    <widgetversion>1.1</widgetversion>
</update>
_UPDATE_;

// load data
$xml = simplexml_load_string($UPDATE_database);
$result = $xml->xpath("widgetversion");
print $result[0];
?>

Hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top