Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
Change in UUID fetching for first launches (#13419)
Browse files Browse the repository at this point in the history
* Fixing Mac compilation errors

* Removing console message

* Fixing linter errors in this file.
  • Loading branch information
nethip authored and saurabh95 committed Jun 15, 2017
1 parent 3df3963 commit f4dd55c
Showing 1 changed file with 40 additions and 22 deletions.
62 changes: 40 additions & 22 deletions src/extensions/default/HealthData/HealthDataManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*
*/

/*global define, $, brackets,navigator, console, appshell */
define(function (require, exports, module) {
"use strict";

Expand All @@ -30,20 +31,18 @@ define(function (require, exports, module) {
UrlParams = brackets.getModule("utils/UrlParams").UrlParams,
Strings = brackets.getModule("strings"),
HealthDataUtils = require("HealthDataUtils"),
uuid = require("thirdparty/uuid");

var prefs = PreferencesManager.getExtensionPrefs("healthData");
uuid = require("thirdparty/uuid"),
prefs = PreferencesManager.getExtensionPrefs("healthData"),
params = new UrlParams(),
ONE_MINUTE = 60 * 1000,
ONE_DAY = 24 * 60 * ONE_MINUTE,
FIRST_LAUNCH_SEND_DELAY = 30 * ONE_MINUTE,
timeoutVar;

prefs.definePreference("healthDataTracking", "boolean", true, {
description: Strings.DESCRIPTION_HEALTH_DATA_TRACKING
});

var ONE_MINUTE = 60 * 1000,
ONE_DAY = 24 * 60 * ONE_MINUTE,
FIRST_LAUNCH_SEND_DELAY = 30 * ONE_MINUTE,
timeoutVar;

var params = new UrlParams();
params.parse();

/**
Expand All @@ -53,14 +52,6 @@ define(function (require, exports, module) {
var result = new $.Deferred(),
oneTimeHealthData = {};

var userUuid = PreferencesManager.getViewState("UUID");

if (!userUuid) {
userUuid = uuid.v4();
PreferencesManager.setViewState("UUID", userUuid);
}

oneTimeHealthData.uuid = userUuid;
oneTimeHealthData.snapshotTime = Date.now();
oneTimeHealthData.os = brackets.platform;
oneTimeHealthData.userAgent = window.navigator.userAgent;
Expand All @@ -79,7 +70,31 @@ define(function (require, exports, module) {
oneTimeHealthData.bracketsTheme = bracketsTheme;
})
.always(function () {
return result.resolve(oneTimeHealthData);
var userUuid = PreferencesManager.getViewState("UUID");

if (!userUuid) {

// For first launch, we are now going to
// rely on the macine Hash.
appshell.app.getMachineHash(function (err, macHash) {
// In case of error, use the older algorithm
if (err) {
userUuid = uuid.v4();
} else {
userUuid = macHash;
}

PreferencesManager.setViewState("UUID", userUuid);

oneTimeHealthData.uuid = userUuid;
return result.resolve(oneTimeHealthData);
});

} else {
oneTimeHealthData.uuid = userUuid;
return result.resolve(oneTimeHealthData);
}

});

});
Expand Down Expand Up @@ -127,13 +142,16 @@ define(function (require, exports, module) {
* for opt-out/in is closed.
*/
function checkHealthDataSend() {
var result = new $.Deferred(),
isHDTracking = prefs.get("healthDataTracking");
var result = new $.Deferred(),
isHDTracking = prefs.get("healthDataTracking"),
nextTimeToSend,
currentTime;

HealthLogger.setHealthLogsEnabled(isHDTracking);
window.clearTimeout(timeoutVar);
if (isHDTracking) {
var nextTimeToSend = PreferencesManager.getViewState("nextHealthDataSendTime"),
currentTime = Date.now();
nextTimeToSend = PreferencesManager.getViewState("nextHealthDataSendTime");
currentTime = Date.now();

// Never send data before FIRST_LAUNCH_SEND_DELAY has ellapsed on a fresh install. This gives the user time to read the notification
// popup, learn more, and opt out if desired
Expand Down

0 comments on commit f4dd55c

Please sign in to comment.