mirror of https://github.com/docker/docs.git
Merge pull request #135 from kitematic/jmorgan_fix_metrics
Change localstore data to leveldb
This commit is contained in:
commit
0d3846b6fc
|
@ -1,34 +1,65 @@
|
||||||
var remote = require('remote');
|
var remote = require('remote');
|
||||||
var app = remote.require('app');
|
var app = remote.require('app');
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
var getmac = require('getmac');
|
|
||||||
var uuid = require('node-uuid');
|
var uuid = require('node-uuid');
|
||||||
|
var level = require('levelup');
|
||||||
|
var path = require('path');
|
||||||
|
var db = level(path.join(process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'], 'Library/Application Support/Kitematic/data', 'db'));
|
||||||
|
|
||||||
Metrics = {};
|
Metrics = {};
|
||||||
|
|
||||||
|
Metrics.enable = function () {
|
||||||
|
db.put('metrics.enabled', true);
|
||||||
|
};
|
||||||
|
|
||||||
|
Metrics.disable = function () {
|
||||||
|
db.put('metrics.enabled', false);
|
||||||
|
};
|
||||||
|
|
||||||
|
Metrics.enabled = function (callback) {
|
||||||
|
db.get('metrics.enabled', function (err, value) {
|
||||||
|
if (err) {
|
||||||
|
callback(false);
|
||||||
|
} else {
|
||||||
|
callback(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Metrics.trackEvent = function (name) {
|
Metrics.trackEvent = function (name) {
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var uuid = localStorage.getItem('metrics.uuid');
|
db.get('metrics.enabled', function (err, value) {
|
||||||
if (localStorage.getItem('metrics.enabled') && uuid) {
|
if (err || !value) {
|
||||||
mixpanel.track('docker_gui ' + name, {
|
return;
|
||||||
distinct_id: uuid,
|
}
|
||||||
version: app.getVersion()
|
db.get('metrics.uuid', function (err, uuid) {
|
||||||
|
if (err) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mixpanel.track('docker_gui ' + name, {
|
||||||
|
distinct_id: uuid,
|
||||||
|
version: app.getVersion()
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Metrics.prepareTracking = function () {
|
Metrics.prepareTracking = function () {
|
||||||
if (localStorage.getItem('metrics.enabled') === null) {
|
db.get('metrics.enabled', function (err, value) {
|
||||||
var settings = Settings.findOne();
|
if (err && err.notFound) {
|
||||||
if (settings && settings.tracking) {
|
var settings = Settings.findOne();
|
||||||
localStorage.setItem('metrics.enabled', !!settings.tracking);
|
if (settings && settings.tracking) {
|
||||||
} else {
|
db.put('metrics.enabled', !!settings.tracking);
|
||||||
localStorage.setItem('metrics.enabled', true);
|
} else {
|
||||||
|
db.put('metrics.enabled', true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
db.get('metrics.uuid', function (err, value) {
|
||||||
if (!localStorage.getItem('metrics.uuid')) {
|
if (err && err.notFound) {
|
||||||
localStorage.setItem('metrics.uuid', uuid.v4());
|
db.put('metrics.uuid', uuid.v4());
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,10 @@ Util.getResourceDir = function () {
|
||||||
return path.join(Util.getHomePath(), 'Library/Application Support/Kitematic/Resources');
|
return path.join(Util.getHomePath(), 'Library/Application Support/Kitematic/Resources');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Util.getDataDir = function () {
|
||||||
|
return path.join(Util.getHomePath(), 'Library/Application Support/Kitematic/data');
|
||||||
|
};
|
||||||
|
|
||||||
Util.KITE_PATH = path.join(Util.getHomePath(), 'Kitematic');
|
Util.KITE_PATH = path.join(Util.getHomePath(), 'Kitematic');
|
||||||
Util.KITE_TAR_PATH = path.join(Util.KITE_PATH, '.tar');
|
Util.KITE_TAR_PATH = path.join(Util.KITE_PATH, '.tar');
|
||||||
Util.KITE_IMAGES_PATH = path.join(Util.KITE_PATH, '.images');
|
Util.KITE_IMAGES_PATH = path.join(Util.KITE_PATH, '.images');
|
||||||
|
|
|
@ -3,11 +3,11 @@ var dialog = remote.require('dialog');
|
||||||
|
|
||||||
Template.dashboardSettings.events({
|
Template.dashboardSettings.events({
|
||||||
'click .btn-usage-analytics-on': function () {
|
'click .btn-usage-analytics-on': function () {
|
||||||
localStorage.setItem('metrics.enabled', true);
|
Metrics.enable();
|
||||||
Session.set('metrics.enabled', true);
|
Session.set('metrics.enabled', true);
|
||||||
},
|
},
|
||||||
'click .btn-usage-analytics-off': function () {
|
'click .btn-usage-analytics-off': function () {
|
||||||
localStorage.setItem('metrics.enabled', false);
|
Metrics.disable();
|
||||||
Session.set('metrics.enabled', false);
|
Session.set('metrics.enabled', false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -15,7 +15,9 @@ Template.dashboardSettings.events({
|
||||||
Template.dashboardSettings.helpers({
|
Template.dashboardSettings.helpers({
|
||||||
metricsEnabled: function () {
|
metricsEnabled: function () {
|
||||||
if (Session.get('metrics.enabled') === undefined) {
|
if (Session.get('metrics.enabled') === undefined) {
|
||||||
Session.set('metrics.enabled', localStorage.getItem('metrics.enabled'));
|
Metrics.enabled(function (value) {
|
||||||
|
Session.set('metrics.enabled', value);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return Session.get('metrics.enabled');
|
return Session.get('metrics.enabled');
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
"request": "2.42.0",
|
"request": "2.42.0",
|
||||||
"request-progress": "0.3.1",
|
"request-progress": "0.3.1",
|
||||||
"tar": "0.1.20",
|
"tar": "0.1.20",
|
||||||
"node-uuid": "1.4.1"
|
"node-uuid": "1.4.1",
|
||||||
|
"leveldown": "^1.0.0",
|
||||||
|
"levelup": "git+https://github.com/kitematic/node-levelup.git"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ cd $BASE
|
||||||
# Build NPM modules
|
# Build NPM modules
|
||||||
NPM="$BASE/cache/node/bin/npm"
|
NPM="$BASE/cache/node/bin/npm"
|
||||||
export npm_config_disturl=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist
|
export npm_config_disturl=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist
|
||||||
export npm_config_target=ATOM_SHELL_VERSION
|
export npm_config_target=$ATOM_SHELL_VERSION
|
||||||
export npm_config_arch=ia32
|
export npm_config_arch=ia64
|
||||||
HOME=~/.atom-shell-gyp $NPM install
|
HOME=~/.atom-shell-gyp $NPM install
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue