Skip to content

Commit

Permalink
feat(GUI): use resin-raven in AnalyticsService
Browse files Browse the repository at this point in the history
This commit also removes bower.

Change-Type: patch
Fixes: #1027
  • Loading branch information
stefan-mihaila committed Mar 27, 2017
1 parent 180802b commit 09b0250
Show file tree
Hide file tree
Showing 18 changed files with 893 additions and 2,487 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ install:
./scripts/build/docker/run-command.sh -r ${TARGET_ARCH} -s ${PWD} -c "make info && make electron-develop";
else
pip install codespell==1.9.2 awscli;
npm install -g bower asar;
npm install -g asar;
brew install afsctool jq;
make info;
make electron-develop;
Expand Down
9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,13 @@ $(BUILD_DIRECTORY)/node-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies/node_modu
-t node \
-s "$(TARGET_PLATFORM)"

$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies/bower_components: bower.json \
| $(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies
./scripts/build/dependencies-bower.sh -p -x $|

$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(APPLICATION_VERSION)-$(TARGET_ARCH)-app: \
$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies/node_modules \
$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies/bower_components \
| $(BUILD_DIRECTORY)
./scripts/build/electron-create-resources-app.sh -s . -o $@ \
-v $(APPLICATION_VERSION) \
-f "$(APPLICATION_FILES)"
$(foreach prerequisite,$^,$(call execute-command,cp -RLf $(prerequisite) $@))
cp -Rlf $< $@

$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(APPLICATION_VERSION)-$(TARGET_ARCH)-app.asar: \
$(BUILD_DIRECTORY)/electron-$(TARGET_PLATFORM)-$(APPLICATION_VERSION)-$(TARGET_ARCH)-app \
Expand Down Expand Up @@ -484,7 +479,6 @@ electron-develop:
-v "$(ELECTRON_VERSION)" \
-t electron \
-s "$(TARGET_PLATFORM)"
./scripts/build/dependencies-bower.sh

help:
@echo "Available targets: $(TARGETS)"
Expand All @@ -509,6 +503,5 @@ clean:

distclean: clean
rm -rf node_modules
rm -rf bower_components

.DEFAULT_GOAL = help
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ environment:

install:
- ps: Install-Product node $env:nodejs_version x64
- npm install -g bower rimraf asar
- npm install -g rimraf asar
- choco install nsis -version 2.51
- choco install jq
- choco install curl
Expand Down
13 changes: 0 additions & 13 deletions bower.json

This file was deleted.

1 change: 0 additions & 1 deletion docs/RUNNING-LOCALLY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Prerequisites
### Common

- [NodeJS](https://nodejs.org) (at least v6)
- [Bower](http://bower.io)
- [Python](https://www.python.org)
- [jq](https://stedolan.github.io/jq/)
- [Asar](https://github.com/electron/asar)
Expand Down
11 changes: 0 additions & 11 deletions lib/gui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@
<!-- See https://github.com/visionmedia/debug#browser-support -->
<script>window.localStorage.debug = '*';</script>

<script>
window._trackJs = {
token: '032448bc3d9e4cffb1e9b43d29d6c142',
application: 'etcher',
console: {
error: false
}
};
</script>
<script src="../../node_modules/trackjs/tracker.js"></script>

<script src="./app.js"></script>
</head>
<body ng-app="Etcher">
Expand Down
143 changes: 41 additions & 102 deletions lib/gui/modules/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,108 +20,44 @@
* @module Etcher.Modules.Analytics
*/

const _ = require('lodash');
const angular = require('angular');
const username = require('username');
const isRunningInAsar = require('electron-is-running-in-asar');
const errors = require('../../shared/errors');
const os = require('os');
const resinCorvus = require('resin-corvus/browser');
const packageJSON = require('../../../package.json');
const arch = require('arch');
const utils = require('../../shared/utils');

// Force Mixpanel snippet to load Mixpanel locally
// instead of using a CDN for performance reasons
window.MIXPANEL_CUSTOM_LIB_URL = '../../bower_components/mixpanel/mixpanel.js';

require('../../../bower_components/mixpanel/mixpanel-jslib-snippet.js');
require('../../../bower_components/angular-mixpanel/src/angular-mixpanel');
const MODULE_NAME = 'Etcher.Modules.Analytics';
const analytics = angular.module(MODULE_NAME, [
'analytics.mixpanel',
require('../models/settings')
]);

/**
* @summary Get host architecture
* @function
* @private
*
* @description
* We need this because node's os.arch() returns the process architecture
* See: https://github.com/nodejs/node-v0.x-archive/issues/2862
*
* @returns {String} Host architecture
*
* @example
* if (getHostArchitecture() === 'x64') {
* console.log('Host architecture is x64');
* }
*/
const getHostArchitecture = () => {
return _.includes([ 'ia32', 'x64' ], process.arch) ? _.replace(arch(), 'x86', 'ia32') : process.arch;
};

// Mixpanel integration
// https://github.com/kuhnza/angular-mixpanel

analytics.config(($mixpanelProvider) => {
$mixpanelProvider.apiKey('63e5fc4563e00928da67d1226364dd4c');

$mixpanelProvider.superProperties({
electron: process.versions.electron,
node: process.version,
arch: process.arch,
version: packageJSON.version,
osPlatform: os.platform(),
hostArch: getHostArchitecture(),
osRelease: os.release(),
cpuCores: os.cpus().length,
totalMemory: os.totalmem(),
startFreeMemory: os.freemem()
});
});

// TrackJS integration
// http://docs.trackjs.com/tracker/framework-integrations

analytics.run(($window) => {

// Don't configure TrackJS when
// running inside the test suite
if (window.mocha) {
return;
}

$window.trackJs.configure({
userId: username.sync(),
version: packageJSON.version
analytics.config(() => {
resinCorvus.install({
services: {
sentry: process.env.SENTRY_DSN,
mixpanel: process.env.MIXPANEL_TOKEN
},
options: {
release: packageJSON.version
}
});
});

analytics.service('AnalyticsService', function($log, $window, $mixpanel, SettingsModel) {
analytics.service('AnalyticsService', function() {

/**
* @summary Log a debug message
* @function
* @public
*
* @description
* This function sends the debug message to TrackJS only.
* This function sends the debug message to error reporting / product analytics services.
*
* @param {String} message - message
*
* @example
* AnalyticsService.log('Hello World');
*/
this.logDebug = (message) => {
const debugMessage = `${new Date()} ${message}`;

if (SettingsModel.get('errorReporting') && isRunningInAsar()) {
$window.trackJs.console.debug(debugMessage);
}

$log.debug(debugMessage);
resinCorvus.logDebug(message);
};

/**
Expand All @@ -130,7 +66,7 @@ analytics.service('AnalyticsService', function($log, $window, $mixpanel, Setting
* @public
*
* @description
* This function sends the debug message to TrackJS and Mixpanel.
* This function sends the debug message to product analytics services.
*
* @param {String} message - message
* @param {Object} [data] - event data
Expand All @@ -141,21 +77,8 @@ analytics.service('AnalyticsService', function($log, $window, $mixpanel, Setting
* });
*/
this.logEvent = (message, data) => {
const debugData = utils.hideAbsolutePathsInObject(utils.makeFlatStartCaseObject(data));

if (SettingsModel.get('errorReporting') && isRunningInAsar()) {
$mixpanel.track(message, debugData);
}

const debugMessage = _.attempt(() => {
if (debugData) {
return `${message} (${JSON.stringify(debugData)})`;
}

return message;
});

this.logDebug(debugMessage);
console.log(resinCorvus.isEnabled());
resinCorvus.logEvent(message, data);
};

/**
Expand All @@ -164,23 +87,39 @@ analytics.service('AnalyticsService', function($log, $window, $mixpanel, Setting
* @public
*
* @description
* This function logs an exception in TrackJS.
* This function logs an exception to error reporting services.
*
* @param {Error} exception - exception
*
* @example
* AnalyticsService.logException(new Error('Something happened'));
*/
this.logException = (exception) => {
if (_.every([
SettingsModel.get('errorReporting'),
isRunningInAsar(),
errors.shouldReport(exception)
])) {
$window.trackJs.track(exception);
}
resinCorvus.logException(exception);
};

/**
* @summary Enable analytics
* @function
* @public
*
* @example
* AnalyticsService.enable()
*/
this.enable = () => {
resinCorvus.enable();
};

$log.error(exception);
/**
* @summary Disable analytics
* @function
* @public
*
* @example
* AnalyticsService.disable()
*/
this.disable = () => {
resinCorvus.disable();
};

});
Expand Down
8 changes: 8 additions & 0 deletions lib/gui/pages/settings/controllers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ module.exports = function(WarningModalService, SettingsModel, ErrorService, Anal
dangerous
});

if (setting === 'errorReporting') {
if (value) {
AnalyticsService.enable();
} else {
AnalyticsService.disable();
}
}

if (!value || !dangerous) {
return this.model.set(setting, value);
}
Expand Down
23 changes: 0 additions & 23 deletions lib/shared/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,6 @@ const getUserFriendlyMessageProperty = (error, property) => {
return _.invoke(exports.HUMAN_FRIENDLY, [ code, property ], error);
};

/**
* @summary Check whether an error should be reported to TrackJS
* @function
* @public
*
* @description
* In order to determine whether the error should be reported, we
* check a property called `report`. For backwards compatibility, and
* to properly handle errors that we don't control, an error without
* this property is reported automatically.
*
* @param {Error} error - error
* @returns {Boolean} whether the error should be reported
*
* @example
* if (errors.shouldReport(new Error('foo'))) {
* console.log('We should report this error');
* }
*/
exports.shouldReport = (error) => {
return !_.has(error, [ 'report' ]) || Boolean(error.report);
};

/**
* @summary Check if a string is blank
* @function
Expand Down
Loading

0 comments on commit 09b0250

Please sign in to comment.