From aba73a08c6e223d5ec8e169324d649dea4e00c35 Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Sun, 9 Feb 2014 21:12:55 +0330 Subject: [PATCH] Update check --- Web/js/main.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Web/js/main.js b/Web/js/main.js index 7d45789..cbf5d8e 100644 --- a/Web/js/main.js +++ b/Web/js/main.js @@ -91,20 +91,24 @@ $(document).ready(function() { var request = navigator.mozApps.getInstalled(); request.onsuccess = function() { - var update; - var selfApp = navigator.mozApps.getSelf(); - selfApp.onsuccess = function() { - if( this.result ) update = true; - else update = false; - } - selfApp.onsuccess = function() { - update = false; - } var app = this.result[0]; - if( !app ) { - if( update ) confirm('A new version is available, do you want to update?') - else confirm('Do you want to Install this app?'); - + var latest = $.ajax({url:'manifest-web.webapp'}); + latest.onsuccess = function() { + if( this.response ) { + var lapp = JSON.parse(this.response); + if( lapp.version != app.manifest.version && + confirm('A new version of this app is available, do you want to update?')) { + var ins = navigator.mozApps.install('http://mdibaiee.github.io/Sketchy/Web/manifest-web.webapp'); + ins.onsuccess = function() { + alert('The app was installed successfuly'); + } + ins.onerror = function() { + alert('There was an error installing app') + } + } + } + } + if( !app && confirm('Do you want to Install this app?') ) { var ins = navigator.mozApps.install('http://mdibaiee.github.io/Sketchy/Web/manifest-web.webapp'); ins.onsuccess = function() { alert('The app was installed successfuly');