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
Goto page 1, 2  Next

Check for updates code...

Author Message
prezet



Joined: 02 May 2005
Posts: 25

Posted: Thu May 19, 2005 - 5:13 am    Post subject: Check for updates code... Reply with quote

Hi all

Wonder if anyone can point me in the right direction to creating a piece of code that checks for updates to a widget.

The first thing I thought is to do it via XMLhttpRequest to check a txt file on my server which shows the latest version number, and if it differs from the current version installed to alert the user that a new version is available.

I'm not sure if this is the cleanest way of doing it as I've never done this before. I've seen other OSX apps using CURL to check, which is another option, but I'm not sure how to implement it.

Any suggestions appreciated.
View user's profile Send private message Send e-mail AIM Address Widgets
zzen



Joined: 21 Apr 2005
Posts: 43
Location: Czech Republic

Posted: Thu May 19, 2005 - 7:52 am    Post subject: Re: Check for updates code... Reply with quote

prezet wrote:
The first thing I thought is to do it via XMLhttpRequest
[...]
I'm not sure if this is the cleanest way of doing it


Good idea, nice question, prezet. I haven't thought of doing updates checks, but I think I'll implement them now that you pointed it out.

Even though I haven't done the update checks myself yet, I don't see anything wrong with XMLHttpRequest (be sure to set pragma no-cache as some other poster here warned!).
Code:
widget.system('curl http://my.updates.server/widget-version.txt',null)
is another option, I think both are perfectly OK, so it's rather up to you which one makes you feel more comfortable. Both should work.

I'll post my experience if I have any problems once I get around to implement update checking myself.
View user's profile Send private message Send e-mail Widgets
prezet



Joined: 02 May 2005
Posts: 25

Posted: Thu May 19, 2005 - 9:05 am    Post subject: Reply with quote

thanks - can you explain the pragma no-cache thing? can't seem to find anything about it.

hmmm, checking for updates now I come to think of it shouldn't really interfere with the use experience, wonder if apple should have any guidelines on how to alert a user to a new version being available.
View user's profile Send private message Send e-mail AIM Address Widgets
sean



Joined: 22 Apr 2005
Posts: 67
Location: Duluth, MN

Posted: Thu May 19, 2005 - 9:56 am    Post subject: Reply with quote

The only problem I can see with using XMLHttpRequest is that it'll tie up the widget while it checks for updates. Usually this won't be a problem, but if your server happens to be down, the widget will freeze while it looks for the server. An asynchronous call to curl would probably be the better way to do it, because your widget will never freeze waiting for a response, but it'll trigger a function when it gets that response.

I think a new version should be alerted to the user quietly, like a small image or text that shows up (clickable, of course) preferably on the back, but the front would be alright depending on the widget.
View user's profile Send private message Send e-mail Visit poster's website Widgets
thornrag



Joined: 02 May 2005
Posts: 1

Posted: Thu May 19, 2005 - 1:52 pm    Post subject: Reply with quote

XMLHttpRequest can be used asynchronously:

http://developer.apple.com/internet/webcontent/xmlhttpreq.html
View user's profile Send private message Send e-mail Visit poster's website Widgets
zzen



Joined: 21 Apr 2005
Posts: 43
Location: Czech Republic

Posted: Thu May 19, 2005 - 6:27 pm    Post subject: Further questions Reply with quote

Yes, XMLHttpRequest can be used asynchronously very well, so tying up the widget is not the problem. I've been pondering about the idea for a while though, and came with other questions which I present, along with my humble answers. I'd be happy to hear more ideas from you.

  • when should we conduct the check? Options:
    a) on widget opening (dragging out of dashboard bar)
    b) on widget activation (ditto+upon showing the dashboard layer when the widget is opened)
    c) on periodic time intervals (x days) even when dashboard is in background
    My vote? A + C. Not sure though.
  • How should we notify the user? Javascript pop up alerts do not work in Dashboard IIRC. So should we just straight fire up the browser with web page saying there is an update? That seems intrusive. Or should we somehow signal that in the widget? How?
    (I suggest showing a previously hidden overlay sheet with text info of new version dynamically included and a button to click to automatically download the new version.)
  • How do we check for the new version? I suggest the SourceVersion tag of version.plist, but is there a way to extract this data while inside the widget? Any mapping to window.widget DOM object or something?
View user's profile Send private message Send e-mail Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Fri May 20, 2005 - 7:14 am    Post subject: Re: Further questions Reply with quote

zzen wrote:

When should we conduct the check? Options:
a) on widget opening (dragging out of dashboard bar)
b) on widget activation (ditto+upon showing the dashboard layer when the widget is opened)
c) on periodic time intervals (x days) even when dashboard is in background
My vote? A + C. Not sure though.


Yeah, I'd go for A and C too.

zzen wrote:
How should we notify the user? Javascript pop up alerts do not work in Dashboard IIRC. So should we just straight fire up the browser with web page saying there is an update? That seems intrusive. Or should we somehow signal that in the widget? How?
(I suggest showing a previously hidden overlay sheet with text info of new version dynamically included and a button to click to automatically download the new version.)


I'd go for the hidden notification layer also. It's less intrusive and let's the user know what's going on (and also gives them the choice to ignore the update).

zzen wrote:
How do we check for the new version? I suggest the SourceVersion tag of version.plist, but is there a way to extract this data while inside the widget? Any mapping to window.widget DOM object or something?


Well, you can just use XMLHttpRequest, I suppose.

Something like:
Code:

function getKeyValue(plist, key) {
   var xml_http = new XMLHttpRequest();
   xml_http.open("GET", plist, false);
   xml_http.send(null);
   
   var xml = xml_http.responseXML;
   var keys = xml.getElementsByTagName("key");
   var vals = xml.getElementsByTagName("string");
   var key_value;
   
   for (var i=0; i < keys.length; i++) {
      if (keys[i].firstChild.data == key) {
         key_value = vals[i].firstChild.data;
         break;
      }
   }
   
   return key_value;
}


then to get the version number, just

var bundle_version = getKeyValue("version.plist", "CFBundleVersion");

for example. Of course, that's not a full proof plist parser, since key values aren't always strings. I just knocked that up in 2 minutes as an example Smile
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
zzen



Joined: 21 Apr 2005
Posts: 43
Location: Czech Republic

Posted: Fri May 20, 2005 - 9:12 am    Post subject: Re: Further questions Reply with quote

Chris wrote:
Well, you can just use XMLHttpRequest, I suppose.

then to get the version number, just

var bundle_version = getKeyValue("version.plist", "CFBundleVersion");


Your getKeyValue code is quite nifty, but that would work for retrieval of a remote XML document. For the remote document, I was thinking of a X(HT?)ML file, which would feature:
  • the current CFBundleVersion, or even SourceVersion
  • a short description of new widget features/fixes
  • a download link
This would be then used to construct the contents of the notification sheet.

However, the widget needs to compare the version number obtained from server with it's own version number. I was wondering if there was any way to get to the CFBundleVersion stored in version.plist. You cannot use XMLHttpRequest for local files, can you? After all, you need a HTTP server to get to the files...[/list]
View user's profile Send private message Send e-mail Widgets
Mayhem



Joined: 18 May 2005
Posts: 63
Location: Stockholm, Sweden

Posted: Fri May 20, 2005 - 9:34 am    Post subject: Re: Further questions Reply with quote

zzen wrote:
However, the widget needs to compare the version number obtained from server with it's own version number. I was wondering if there was any way to get to the CFBundleVersion stored in version.plist. You cannot use XMLHttpRequest for local files, can you? After all, you need a HTTP server to get to the files...

XMLHttpRequest works fine for local files as well, just supply a relative URL and you should be able to get to any file inside your widget bundle. Like so:
Code:
function displayInfoPlist()
{
   var infoPlist = new XMLHttpRequest();
   infoPlist.open("GET", "Info.plist", false);
   infoPlist.send(null);
   alert(infoPlist.responseText);
}

Naturally one will also receive a responseXML object from which it should be trivial to extract the values required for version checking.
_________________
Give me one more medicated peaceful moment
View user's profile Send private message Send e-mail Visit poster's website MSN MessengerWidgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Fri May 20, 2005 - 9:34 am    Post subject: Reply with quote

Nono, you can use XMLHttpRequest for local files. That's why I posted the stuff in my last post Smile

Just plug it in and have a look - it'll return the widget's version number. You can then use that to compare versions on a remote server.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
sean



Joined: 22 Apr 2005
Posts: 67
Location: Duluth, MN

Posted: Fri May 20, 2005 - 10:08 am    Post subject: Reply with quote

thornrag wrote:
XMLHttpRequest can be used asynchronously:

http://developer.apple.com/internet/webcontent/xmlhttpreq.html


Well, would you look at thaaat, I guess it can. Why the hell did I go through the trouble of using curl then?
View user's profile Send private message Send e-mail Visit poster's website Widgets
zzen



Joined: 21 Apr 2005
Posts: 43
Location: Czech Republic

Posted: Fri May 20, 2005 - 10:11 am    Post subject: Cool! Reply with quote

Chris wrote:
Nono, you can use XMLHttpRequest for local files.


Cool! Cool This comes from being lazy to actually try out the posted code. I was sort of expecting XMLHttpRequest to be able to produce just that -- HTTP requests. Heh, you never stop to learn, I guess... Wink
View user's profile Send private message Send e-mail Widgets
sean



Joined: 22 Apr 2005
Posts: 67
Location: Duluth, MN

Posted: Tue May 24, 2005 - 9:56 am    Post subject: Reply with quote

Hey Chris,

Just wanted to let you know that I used the bit of code you posted for version checking in the latest version of my wikipedia widget and it works great. Thanks. It checks on launch, then on dashboard hiding. I was going to check when the dashboard is shown, but I would rather not cause even the slightest slowdown when the user wants to search for something quickly. I just added a small 'update available' in the bottom left of the front side; clicks jump to the widget's page on my server.
View user's profile Send private message Send e-mail Visit poster's website Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Tue May 24, 2005 - 1:11 pm    Post subject: Reply with quote

sean wrote:
Hey Chris,

Just wanted to let you know that I used the bit of code you posted for version checking in the latest version of my wikipedia widget and it works great. Thanks. It checks on launch, then on dashboard hiding. I was going to check when the dashboard is shown, but I would rather not cause even the slightest slowdown when the user wants to search for something quickly. I just added a small 'update available' in the bottom left of the front side; clicks jump to the widget's page on my server.


I noticed that whilst perusing the code for your widget yesterday Wink
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
Ludge



Joined: 09 May 2005
Posts: 98
Location: UK

Posted: Tue May 24, 2005 - 4:13 pm    Post subject: Reply with quote

Can anyone clear up why we should send the no-cache header? I'm using XMLHttpRequest without it and it seems to work fine.
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Goto page 1, 2  Next
Powered by phpBB © 2001, 2002 phpBB Group