Changing to leveldb

This commit is contained in:
Jeff Morgan 2014-12-10 17:29:37 -08:00
parent d524cb756c
commit f1d1f9e155
4 changed files with 32 additions and 20 deletions

View File

@ -1,8 +1,10 @@
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 = {};
@ -11,24 +13,28 @@ Metrics.trackEvent = function (name) {
return; return;
} }
var uuid = localStorage.getItem('metrics.uuid'); var uuid = localStorage.getItem('metrics.uuid');
if (localStorage.getItem('metrics.enabled') && uuid) { db.get('metrics.enabled', function (err, value) {
if (!err && uuid) {
mixpanel.track('docker_gui ' + name, { mixpanel.track('docker_gui ' + name, {
distinct_id: uuid, distinct_id: uuid,
version: app.getVersion() version: app.getVersion()
}); });
} }
});
}; };
Metrics.prepareTracking = function () { Metrics.prepareTracking = function () {
if (localStorage.getItem('metrics.enabled') === null) { db.get('metrics.enabled', function (err, value) {
if (err && err.notFound) {
var settings = Settings.findOne(); var settings = Settings.findOne();
if (settings && settings.tracking) { if (settings && settings.tracking) {
localStorage.setItem('metrics.enabled', !!settings.tracking); db.put('metrics.enabled', !!settings.tracking);
} else { } else {
localStorage.setItem('metrics.enabled', true); db.put('metrics.enabled', true);
} }
} }
if (!localStorage.getItem('metrics.uuid')) { db.get('metrics.uuid', function (err, value) {
localStorage.setItem('metrics.uuid', uuid.v4()); db.put('metrics.uuid', uuid.v4());
} });
});
}; };

View File

@ -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');

View File

@ -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"
} }
} }

View File

@ -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