fix(GUI): ensure settings are loaded before bootstrapping application (#1879)

We load localStorage settings into the Redux store in an asynchronous
way. This means that user settings might not be loaded by the time the
application starts, resulting in Mixpanel sending a few tracking events
before Etcher realises that the user opted out from anonoymous analytics
and error reporting.

In order to fix that, we remove `ng-app` and we manually bootstrap the
Angular.js application *after* the local settings are loaded.

Change-Type: patch
Changelog-Entry: Don't send initial Mixpanel events before "Anonymous Tracking" settings are loaded.
Fixes: https://github.com/resin-io/etcher/issues/1772
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
This commit is contained in:
Juan Cruz Viotti 2017-12-05 11:04:52 -04:00 committed by GitHub
parent 19b7ce0668
commit 618440e38f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 61 deletions

View File

@ -102,7 +102,6 @@ app.run(() => {
version: currentVersion version: currentVersion
}) })
settings.load().then(() => {
const shouldCheckForUpdates = updateNotifier.shouldCheckForUpdates({ const shouldCheckForUpdates = updateNotifier.shouldCheckForUpdates({
currentVersion, currentVersion,
lastSleptUpdateNotifier: settings.get('lastSleptUpdateNotifier'), lastSleptUpdateNotifier: settings.get('lastSleptUpdateNotifier'),
@ -173,7 +172,6 @@ app.run(() => {
title: errors.getTitle(error), title: errors.getTitle(error),
description: errors.getDescription(error) description: errors.getDescription(error)
}) })
})
}).catch(exceptionReporter.report) }).catch(exceptionReporter.report)
}) })
@ -347,3 +345,11 @@ app.controller('StateController', function ($rootScope, $scope) {
*/ */
this.currentName = null this.currentName = null
}) })
// Ensure user settings are loaded before
// we bootstrap the Angular.js application
angular.element(document).ready(() => {
settings.load().then(() => {
angular.bootstrap(document, [ 'Etcher' ])
}).catch(exceptionReporter.report)
})

View File

@ -8,7 +8,7 @@
<link rel="stylesheet" type="text/css" href="css/angular.css"> <link rel="stylesheet" type="text/css" href="css/angular.css">
<script src="./app.js"></script> <script src="./app.js"></script>
</head> </head>
<body ng-app="Etcher"> <body>
<header class="section-header" ng-controller="HeaderController as header"> <header class="section-header" ng-controller="HeaderController as header">
<button class="button button-link" <button class="button button-link"
ng-click="header.openHelpPage()" ng-click="header.openHelpPage()"