From f1d1f9e15509b40fa3f76ca9e30b453d16999732 Mon Sep 17 00:00:00 2001 From: Jeff Morgan Date: Wed, 10 Dec 2014 17:29:37 -0800 Subject: [PATCH] Changing to leveldb --- meteor/client/lib/metrics.js | 40 +++++++++++++++++++++--------------- meteor/client/lib/util.js | 4 ++++ package.json | 4 +++- script/setup.sh | 4 ++-- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/meteor/client/lib/metrics.js b/meteor/client/lib/metrics.js index 2934c20933..41e42ff8ba 100644 --- a/meteor/client/lib/metrics.js +++ b/meteor/client/lib/metrics.js @@ -1,8 +1,10 @@ var remote = require('remote'); var app = remote.require('app'); var crypto = require('crypto'); -var getmac = require('getmac'); 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 = {}; @@ -11,24 +13,28 @@ Metrics.trackEvent = function (name) { return; } var uuid = localStorage.getItem('metrics.uuid'); - if (localStorage.getItem('metrics.enabled') && uuid) { - mixpanel.track('docker_gui ' + name, { - distinct_id: uuid, - version: app.getVersion() - }); - } + db.get('metrics.enabled', function (err, value) { + if (!err && uuid) { + mixpanel.track('docker_gui ' + name, { + distinct_id: uuid, + version: app.getVersion() + }); + } + }); }; Metrics.prepareTracking = function () { - if (localStorage.getItem('metrics.enabled') === null) { - var settings = Settings.findOne(); - if (settings && settings.tracking) { - localStorage.setItem('metrics.enabled', !!settings.tracking); - } else { - localStorage.setItem('metrics.enabled', true); + db.get('metrics.enabled', function (err, value) { + if (err && err.notFound) { + var settings = Settings.findOne(); + if (settings && settings.tracking) { + db.put('metrics.enabled', !!settings.tracking); + } else { + db.put('metrics.enabled', true); + } } - } - if (!localStorage.getItem('metrics.uuid')) { - localStorage.setItem('metrics.uuid', uuid.v4()); - } + db.get('metrics.uuid', function (err, value) { + db.put('metrics.uuid', uuid.v4()); + }); + }); }; diff --git a/meteor/client/lib/util.js b/meteor/client/lib/util.js index 9973e812d4..c55302344c 100755 --- a/meteor/client/lib/util.js +++ b/meteor/client/lib/util.js @@ -21,6 +21,10 @@ Util.getResourceDir = function () { 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_TAR_PATH = path.join(Util.KITE_PATH, '.tar'); Util.KITE_IMAGES_PATH = path.join(Util.KITE_PATH, '.images'); diff --git a/package.json b/package.json index 9c494709f2..4f65cc6e98 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "request": "2.42.0", "request-progress": "0.3.1", "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" } } diff --git a/script/setup.sh b/script/setup.sh index e551d46bda..c9cf1e70fa 100755 --- a/script/setup.sh +++ b/script/setup.sh @@ -56,7 +56,7 @@ cd $BASE # Build NPM modules NPM="$BASE/cache/node/bin/npm" export npm_config_disturl=https://gh-contractor-zcbenz.s3.amazonaws.com/atom-shell/dist -export npm_config_target=ATOM_SHELL_VERSION -export npm_config_arch=ia32 +export npm_config_target=$ATOM_SHELL_VERSION +export npm_config_arch=ia64 HOME=~/.atom-shell-gyp $NPM install