From 5e98635237a4e2b3d6b9a73354840d812ca913c6 Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Sun, 9 Feb 2014 19:57:14 +0330 Subject: [PATCH] Update check --- Web/js/main.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Web/js/main.js b/Web/js/main.js index 8b294e4..7d45789 100644 --- a/Web/js/main.js +++ b/Web/js/main.js @@ -91,9 +91,21 @@ $(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 && confirm('A new version is available, do you want to update?') ) { - var ins = navigator.mozApps.install('mdibaiee.github.io/Sketchy/Web/manifest-web.webapp'); + 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 ins = navigator.mozApps.install('http://mdibaiee.github.io/Sketchy/Web/manifest-web.webapp'); ins.onsuccess = function() { alert('The app was installed successfuly'); }