# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1551965973 -19800
#      Thu Mar 07 19:09:33 2019 +0530
# Node ID c084b4dda327f0ca2588989634ad0a87825c68c3
# Parent  b429fc603217aab63b70462da023f0fdd9589080
Related to issue 40313 : Show System perfomance Popup before login window

diff -r b429fc603217 -r c084b4dda327 web/org.openbravo.mobile.core/source/component/ob-login.js
--- a/web/org.openbravo.mobile.core/source/component/ob-login.js	Thu Mar 07 08:51:59 2019 +0100
+++ b/web/org.openbravo.mobile.core/source/component/ob-login.js	Thu Mar 07 19:09:33 2019 +0530
@@ -1,32 +1,13 @@
 /*
  ************************************************************************************
- * Copyright (C) 2012-2018 Openbravo S.L.U.
+ * Copyright (C) 2012-2019 Openbravo S.L.U.
  * Licensed under the Openbravo Commercial License version 1.0
  * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
  * or in the legal folder of this module distribution.
  ************************************************************************************
  */
 
-/*global enyo, OB, ServiceWorkerUtil, navigator, setTimeout, _ */
-
-function executeApplication(browserInfo) {
-  OB.MobileApp.model.set('ApplicationSourcesLoaded', true);
-  if (browserInfo.isSupported) {
-    if (!OB.UTIL.Debug.getDebugCauses() || (!OB.UTIL.Debug.getDebugCauses().isInDevelopment && !OB.UTIL.Debug.getDebugCauses().isTestEnvironment)) {
-      if (OB.MobileApp.model.get('shouldExecuteBenchmark') && OB.UTIL.localStorage.getItem('doNotExecuteBenchmark') === null) {
-        if (OB.UTIL.localStorage.getItem('executePerformanceTest') !== 'N') {
-          this.dialog = OB.MobileApp.view.$.confirmationContainer.createComponent({
-            kind: 'OB.UI.ModalBenchmark',
-            name: 'modalBenchmark',
-            context: this
-          });
-          this.dialog.show();
-        }
-      }
-    }
-  }
-}
-
+/*global enyo, OB, navigator, setTimeout, _ */
 
 enyo.kind({
   name: 'OB.OBPOSLogin.UI.UserButton',
@@ -266,27 +247,6 @@
   initComponents: function () {
     var notSupportedBrowserMsg;
 
-    var browserInfo = OB.UTIL.getSupportedBrowserInfo();
-    var permissionSW;
-    if (typeof ServiceWorkerUtil !== 'undefined') {
-      permissionSW = ServiceWorkerUtil.useServiceWorkers;
-    } else {
-      permissionSW = false;
-    }
-    if (permissionSW === true) {
-      OB.UTIL.fetchApplicationSources(function () {
-        executeApplication(browserInfo);
-      }, function () {
-        OB.error("Error in fetching the application sources.");
-        OB.MobileApp.model.set('loadManifeststatus', {
-          type: 'error',
-          reason: 'fail'
-        });
-      });
-    } else {
-      //If preference is not set, we will use AppCache
-      executeApplication(browserInfo);
-    }
     this.inherited(arguments);
 
     OB.MobileApp.view.currentWindow = 'login';
diff -r b429fc603217 -r c084b4dda327 web/org.openbravo.mobile.core/source/component/ob-performancetest.js
--- a/web/org.openbravo.mobile.core/source/component/ob-performancetest.js	Thu Mar 07 08:51:59 2019 +0100
+++ b/web/org.openbravo.mobile.core/source/component/ob-performancetest.js	Thu Mar 07 19:09:33 2019 +0530
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2016 Openbravo S.L.U.
+ * Copyright (C) 2016-2019 Openbravo S.L.U.
  * Licensed under the Openbravo Commercial License version 1.0
  * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
  * or in the legal folder of this module distribution.
@@ -68,12 +68,15 @@
       var finalScore = Math.round(1000000 / OB.Benchmark.ModelResults.get('finalResult'));
       OB.Benchmark.ModelResults.set('finalScore', finalScore);
       OB.UTIL.localStorage.setItem('benchmarkScore', finalScore);
+      if (this.args && this.args.callback && this.args.callback instanceof Function) {
+        this.args.callback();
+      }
       me.hide();
       if (finalScore > 1000) {
         OB.UTIL.showSuccess(OB.I18N.getLabel('OBMOBC_SystemPerformanceIsGood', [finalScore]));
         OB.UTIL.localStorage.setItem('doNotExecuteBenchmark', true);
       } else {
-        me.destroy();
+        this.destroy();
         this.dialog = OB.MobileApp.view.$.confirmationContainer.createComponent({
           kind: 'OB.UI.ModalBenchmarkResult',
           name: 'modalBenchmark',
@@ -81,7 +84,7 @@
         });
         this.dialog.show();
       }
-    });
+    }, this);
 
   }
 });
diff -r b429fc603217 -r c084b4dda327 web/org.openbravo.mobile.core/source/model/ob-terminal-model.js
--- a/web/org.openbravo.mobile.core/source/model/ob-terminal-model.js	Thu Mar 07 08:51:59 2019 +0100
+++ b/web/org.openbravo.mobile.core/source/model/ob-terminal-model.js	Thu Mar 07 19:09:33 2019 +0530
@@ -7,7 +7,7 @@
  ************************************************************************************
  */
 
-/*global OB, _, enyo, Backbone, CryptoJS, Promise */
+/*global OB, _, enyo, Backbone, ServiceWorkerUtil, CryptoJS, Promise */
 
 OB.Model = window.OB.Model || {};
 OB.MobileApp = OB.MobileApp || {};
@@ -1603,11 +1603,65 @@
       OB.Dal.initCache(OB.Model.LogClient, [], null, null);
     }
 
-    OB.MobileApp.view.$.containerWindow.destroyComponents();
-    OB.MobileApp.view.$.containerWindow.createComponent({
-      kind: OB.OBPOSLogin.UI.Login
-    }).render();
-    OB.UTIL.showLoading(false);
+    this.loadApplicationSources(function () {
+      OB.MobileApp.view.$.containerWindow.destroyComponents();
+      OB.MobileApp.view.$.containerWindow.createComponent({
+        kind: OB.OBPOSLogin.UI.Login
+      }).render();
+      OB.UTIL.showLoading(false);
+    });
+  },
+
+  loadApplicationSources: function (callback) {
+    var finalCallback, checkBenchMark, permissionSW, browserInfo = OB.UTIL.getSupportedBrowserInfo();
+
+    finalCallback = function () {
+      if (callback instanceof Function) {
+        callback();
+      }
+    };
+
+    checkBenchMark = function () {
+      OB.MobileApp.model.set('ApplicationSourcesLoaded', true);
+      if (browserInfo.isSupported) {
+        if (!OB.UTIL.Debug.getDebugCauses() || (!OB.UTIL.Debug.getDebugCauses().isInDevelopment && !OB.UTIL.Debug.getDebugCauses().isTestEnvironment)) {
+          if (OB.MobileApp.model.get('shouldExecuteBenchmark') && OB.UTIL.localStorage.getItem('doNotExecuteBenchmark') === null && OB.UTIL.localStorage.getItem('executePerformanceTest') !== 'N') {
+            this.dialog = OB.MobileApp.view.$.confirmationContainer.createComponent({
+              kind: 'OB.UI.ModalBenchmark',
+              name: 'modalBenchmark',
+              context: this
+            });
+            this.dialog.show({
+              callback: finalCallback
+            });
+            return;
+          }
+        }
+      }
+      finalCallback();
+    };
+
+    if (typeof ServiceWorkerUtil !== 'undefined') {
+      permissionSW = ServiceWorkerUtil.useServiceWorkers;
+    } else {
+      permissionSW = false;
+    }
+    if (permissionSW === true) {
+      OB.UTIL.fetchApplicationSources(function () {
+        checkBenchMark();
+      }, function () {
+        OB.error("Error in fetching the application sources.");
+        OB.MobileApp.model.set('loadManifeststatus', {
+          type: 'error',
+          reason: 'fail'
+        });
+        finalCallback();
+      });
+    } else {
+      //If preference is not set, we will use AppCache
+      checkBenchMark();
+    }
+
   },
 
   loadModels: function (windows, incremental, callback) {
