19
|
1 |
// ////////////////////////////////////////////////////////////////////////////
|
|
2 |
// Symbian Foundation Example Code
|
|
3 |
//
|
|
4 |
// This software is in the public domain. No copyright is claimed, and you
|
|
5 |
// may use it for any purpose without license from the Symbian Foundation.
|
|
6 |
// No warranty for any purpose is expressed or implied by the authors or
|
|
7 |
// the Symbian Foundation.
|
|
8 |
// ////////////////////////////////////////////////////////////////////////////
|
|
9 |
|
|
10 |
var updatePageAjax;
|
|
11 |
var versionURL = "http://developer.symbian.org/wiki/index.php/SEE_2009_Widget";
|
|
12 |
var downloadUrl = "http://developer.symbian.org/wiki/images/7/74/See09Widget.wgz";
|
|
13 |
var myVersion = "1.0rc3";
|
|
14 |
var versionPrefixString = "Current Widget Version is: [";
|
|
15 |
var versionSuffixString = "]";
|
|
16 |
|
|
17 |
function CheckForUpdates() {
|
|
18 |
if (IsHSViewMode()) {
|
|
19 |
setTimeout(function() {CheckForUpdates();}, 600000);
|
|
20 |
return;
|
|
21 |
}
|
|
22 |
|
|
23 |
uiManager.showNotification(-1, "wait", "Checking for updates...", -1);
|
|
24 |
updatePageAjax = new Ajax();
|
|
25 |
updatePageAjax.onreadystatechange = function(){
|
|
26 |
CheckForUpdatesStage2();
|
|
27 |
};
|
|
28 |
updatePageAjax.open('GET', nocache(versionURL), true);
|
|
29 |
updatePageAjax.send(null);
|
|
30 |
}
|
|
31 |
|
|
32 |
function CheckForUpdatesStage2() {
|
|
33 |
if (updatePageAjax.readyState == 4) {
|
|
34 |
// extract version number
|
|
35 |
var content = updatePageAjax.responseText;
|
|
36 |
var ind = content.indexOf(versionPrefixString);
|
|
37 |
if ( ind == -1 ) {
|
|
38 |
uiManager.showNotification(3000, "warning", "Update failed, check manually.");
|
|
39 |
return;
|
|
40 |
}
|
|
41 |
ind += versionPrefixString.length;
|
|
42 |
var ind2 = content.indexOf(versionSuffixString,ind);
|
|
43 |
if ( ind2 == -1 || (ind2-ind) > 10 ) {
|
|
44 |
uiManager.showNotification(3000, "warning", "Update failed, check manually.");
|
|
45 |
return;
|
|
46 |
}
|
|
47 |
var version = content.substring(ind,ind2);
|
|
48 |
// compare to this version
|
|
49 |
if ( version != myVersion ) {
|
|
50 |
var answer = confirm("Install new version " + version + "?");
|
|
51 |
if (answer) {
|
|
52 |
// ok, we have the update
|
|
53 |
uiManager.hideNotification();
|
|
54 |
openURL(nocache(downloadUrl));
|
|
55 |
setTimeout(function () {window.close();}, 1000);
|
|
56 |
} else {
|
|
57 |
uiManager.showNotification(3000, "info", "Update cancelled.");
|
|
58 |
}
|
|
59 |
} else {
|
|
60 |
// No need to show anything
|
|
61 |
uiManager.showNotification(3000, "info", "Up to date!");
|
|
62 |
}
|
|
63 |
}
|
|
64 |
}
|