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