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); + } + } } } }