Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

Can anyone help me with the update function - it won't work

Author Message
albi



Joined: 21 Jun 2005
Posts: 9

Posted: Thu Oct 11, 2007 - 12:47 pm    Post subject: Can anyone help me with the update function - it won't work Reply with quote

got a widget with the update notification function from sebastian mentioned here in the forum.

everything runs fine in the widget. but the update causes some headache:


- here is my txt on a webserver
http://www.christen.ch/widget.txt it shows "1.1"


- then in the info.plist is something like:
Code:
   <key>CFBundleVersion</key>
   <string>1.0</string>



- in the html in the bodytag is
Code:
<body onload="setup();">



- the setupfunction looks like this:
Code:
function setup()
{
   some extra stuff. nothing to mention here.

   currentVersion = trim(getPlistProperty("Info", "CFBundleVersion"));
   checkForUpdate();
}



- and now - here is the javascript:
Code:
var newVerURL = 'http://www.christen.ch/widget.txt';

// Removes leading whitespaces
function LTrim( value ) {
   var re = /\s*((\S+\s*)*)/;
   return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
   var re = /((\s*\S+)*)\s*/;
   return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
   return LTrim(RTrim(value));
}

/* Thanks to Sebastien Vallon see here : http://www.dashboardwidgets.com/forums/viewtopic.php?t=1178
   I've made changes to make it check against my own page
*/

function checkForUpdate() {
    var req = new XMLHttpRequest();
    req.onreadystatechange = function() {compareVersion(req)};
    req.open("GET", newVerURL, true);
    req.setRequestHeader("Cache-Control", ;no-cache");
   req.send();
}

function compareVersion(request) {
    if (request.readyState == 4) {
        if (request.status == 200) {
         var serverVersion = trim(request.responseText);
         if ((currentVersion < serverVersion) && !isNaN(parseFloat(serverVersion))) {
            needUpdate(serverVersion);
         } else {
            dontNeedUpdate();
         }
        }
    }
}

var setzeupdate = document.getElementById('updateMessage');

function needUpdate(serverVersion) {
   setzeupdate.innerHTML = '<p>update signal</p>';
}

function dontNeedUpdate() {
   setzeupdate.innerHTML = '';
}

function getPlistProperty(filename, property){
   
   // check the parameters
   if( (filename == null) || (filename == "") ){ return null; }
   if( (property == null) || (property == "") ){ return null; }
   
   // retrieve the value with the defaults command
   return trim(widget.system('/bin/sh -c "defaults read `pwd`/'+ filename + ' ' + property + '"',null).outputString);
}

function inputKeyPress (event) {
   switch (event.keyCode) {
      case 13: // return
      case 3:  // enter
         getSiteList();
      break;
      case 9:  // tab
      break;
   }
}

function getLocalizedString (key) {
    try {
        var ret = localizedStrings[key];
        if (ret === undefined)
            ret = key;
        return ret;
    } catch (ex) {}
 
    return key;
}



i do not see anything that is wrong. but the widget shows the update

forgot to mention that ther is a div with the id "updateMessage;
View user's profile Send private message Send e-mail Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group