diff --git a/src/js/yunohost/controllers/home.js b/src/js/yunohost/controllers/home.js index d3361df6..9038ed76 100644 --- a/src/js/yunohost/controllers/home.js +++ b/src/js/yunohost/controllers/home.js @@ -27,37 +27,33 @@ c.showLoader(); + // We gonna retry 3 times to check if yunohost is installed + if (app.isInstalledTry === undefined) { + app.isInstalledTry = 3; + } + c.checkInstall(function(isInstalled) { + if (isInstalled) { - c.hideLoader(); - // Pass domain to hide form field c.view('login', { 'domain': window.location.hostname }); - } else if (typeof isInstalled === 'undefined') { - if (app.isInstalledTry > 0) { - app.isInstalledTry--; - setTimeout(function() { - c.redirect('#/'); - }, 5000); - } - else { - // Reset count - app.isInstalledTry = 3; + return; + } - // API is not responding after 3 try - $( document ).ajaxError(function( event, request, settings ) { - // Display error if status != 200. - // .ajaxError fire even with status code 200 because json is sometimes not valid. - if (request.status !== 200) c.flash('fail', y18n.t('api_not_responding', [request.status+' '+request.statusText] )); - - // Unbind directly - $(document).off('ajaxError'); - }); - - c.hideLoader(); - } - } else { - c.hideLoader(); + if (typeof isInstalled !== 'undefined') { c.redirect('#/postinstall'); + return; + } + + // If the retry counter is still up, retry this function 5 sec + // later + if (app.isInstalledTry > 0) { + app.isInstalledTry--; + setTimeout(function() { + c.redirect('#/'); + }, 5000); + } + else { + c.flash('fail', y18n.t('api_not_responding')); } }); });