From 483f681400709105f6bb8622a7f744317c58f141 Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Sun, 9 Feb 2014 21:58:45 +0330 Subject: [PATCH] Update check --- Web/js/main.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/Web/js/main.js b/Web/js/main.js index 4255a37..816cbc7 100644 --- a/Web/js/main.js +++ b/Web/js/main.js @@ -93,20 +93,25 @@ $(document).ready(function() { request.onsuccess = function() { var app = this.result[0]; var latest = $.ajax({url:'manifest-web.webapp'}); - latest.onload = function() { - if( this.response ) { - var lapp = JSON.parse(this.response); - alert(lapp.version); - alert(app.manifest.version); - if( lapp.version != app.manifest.version && - confirm('A new version of this app is available, do you want to update? ' + app.manifest.version + ' to ' + lapp.version )) { - 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') - console.log(this.error); + var selfApp = navigator.mozApps.getSelf(); + selfApp.onsuccess = function() { + if(this.result) { + latest.onload = function() { + if( this.response ) { + var lapp = JSON.parse(this.response); + alert(lapp.version); + alert(app.manifest.version); + if( lapp.version != app.manifest.version && + confirm('A new version of this app is available, do you want to update? ' + app.manifest.version + ' to ' + lapp.version )) { + 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') + console.log(this.error); + } + } } } }