Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Commit

Permalink
Merge pull request #369 from aleitner/master
Browse files Browse the repository at this point in the history
v2.0.7
  • Loading branch information
bookchin authored Oct 3, 2016
2 parents 38fd2a4 + 558cfdf commit fa6b006
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 600 deletions.
64 changes: 38 additions & 26 deletions app/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var Updater = require('./lib/updater');
var UserData = require('./lib/userdata');
var Tab = require('./lib/tab');
var diskspace = require('fd-diskspace').diskSpace;
var storj = require('storj');
var storj = require('storj-lib');
var Monitor = storj.Monitor;
var SpeedTest = require('myspeed').Client;
var userdata = new UserData(app.getPath('userData'));
Expand Down Expand Up @@ -119,14 +119,14 @@ var main = new Vue({
data: {
userdata: userdata._parsed,
current: 0,
transitioning: false,
freespace: {size: 0, unit: 'B'},
balance: {
sjcx: 0,
sjct: 0,
qualified: false
},
logwindow: '',
error: {drive: '', message: ''},
telemetry: {},
telemetryWarningDismissed: localStorage.getItem('telemetryWarningDismissed')
},
Expand Down Expand Up @@ -155,8 +155,6 @@ var main = new Vue({
self.userdata.tabs[self.current].active = false;
}

self.transitioning = false;

if (index === -1) {
this.current = 0;

Expand Down Expand Up @@ -224,50 +222,56 @@ var main = new Vue({
return window.alert(err.message);
}

this.transitioning = true;
tab.transitioning = true;
tab.telemetry = { enabled: appSettings.reportTelemetry };

var storageAdapter = storj.EmbeddedStorageAdapter(tab.storage.path);
var logger = new Logger(Number(appSettings.logLevel));
var reporter = new TelemetryReporter(
'https://status.storj.io',
storj.KeyPair(tab.key)
);
var farmerconf = {
keypair: storj.KeyPair(tab.key),
payment: { address: tab.getAddress() },
storage: tab.storage,
address: tab.network.hostname,
port: Number(tab.network.port),
noforward: tab.network.nat === 'false',
keyPair: storj.KeyPair(tab.key),
paymentAddress: tab.getAddress(),
storageManager: storj.StorageManager(storageAdapter, {
maxCapacity: storj.utils.toNumberBytes(
tab.storage.size,
tab.storage.unit
)
}),
rpcAddress: tab.network.hostname,
rpcPort: Number(tab.network.port),
doNotTraverseNat: tab.network.nat === 'false',
logger: logger,
tunport: Number(tab.tunnels.tcpPort),
tunnels: Number(tab.tunnels.numConnections),
gateways: {
tunnelServerPort: Number(tab.tunnels.tcpPort),
maxTunnels: Number(tab.tunnels.numConnections),
tunnelGatewayRange: {
min: Number(tab.tunnels.startPort),
max: Number(tab.tunnels.endPort)
},
seeds: tab.network.seed ? [tab.network.seed] : []
seedList: tab.network.seed ? [tab.network.seed] : []
};
var farmer = new storj.FarmerInterface(farmerconf);

this.contractCounter(tab, farmer, function(err) {

if (err) {
logger.error(err.message);
self.transitioning = false;
tab.transitioning = false;
return window.alert(err.message);
}

// Update by drive
var contractCountKey = 'contractCount_' + tab.id;
farmer.manager._storage.on('add',function(item){
farmer.storageManager._storage.on('add',function(item){
var contracts = Number(localStorage.getItem(contractCountKey));
contracts += Object.keys(item.contracts).length;
localStorage.setItem(contractCountKey, contracts.toString());
tab.contracts.total = contracts;
});

farmer.manager._storage.on('update',function(previous, next){
farmer.storageManager._storage.on('update',function(previous, next){
var contracts = Number(localStorage.getItem(contractCountKey));
previous = Object.keys(previous.contracts).length;
next = Object.keys(next.contracts).length;
Expand All @@ -276,7 +280,7 @@ var main = new Vue({
tab.contracts.total = contracts;
});

farmer.manager._storage.on('delete',function(item){
farmer.storageManager._storage.on('delete',function(item){
var contracts = Number(localStorage.getItem(contractCountKey));
contracts -= Object.keys(item.contracts).length;
localStorage.setItem(contractCountKey, contracts.toString());
Expand All @@ -300,18 +304,26 @@ var main = new Vue({

userdata.saveConfig(function(err) {
if (err) {
self.transitioning = false;
tab.transitioning = false;
return window.alert(err.message);
}

farmer.join(function(err) {
self.transitioning = false;
tab.transitioning = false;

if (self.userdata.appSettings.reportTelemetry) {
self.startReportingTelemetry(tab);
}

if (err) {
self.stopFarming(null, tab);
self.error.message = err;
self.error.drive = tab.shortId;
$('#error').modal({
backdrop: 'static',
keyboard: false,
show: true}
);
logger.error(err.message);
}
});
Expand Down Expand Up @@ -346,25 +358,25 @@ var main = new Vue({
return callback();
}
},
stopFarming: function(event) {
stopFarming: function(event, tab) {
var self = this;

if (event) {
event.preventDefault();
}

var tab = this.userdata.tabs[this.current];
tab = (!tab) ? this.userdata.tabs[this.current]: tab;

if (tab.farmer) {
if (self.userdata.appSettings.reportTelemetry) {
self.stopReportingTelemetry(tab);
}

tab.wasRunning = false;
self.transitioning = true;
tab.transitioning = true;

tab.farmer().leave(function() {
self.transitioning = false;
tab.transitioning = false;
tab.farmer = null;
});
}
Expand Down Expand Up @@ -523,7 +535,7 @@ var main = new Vue({
}

Monitor.getPaymentAddressBalances({
keypair: storj.KeyPair(tab.key),
keyPair: storj.KeyPair(tab.key),
_options: { payment: { address: tab.getAddress() } }
}, function(err, stats) {
self.balance.sjcx = stats.payments.balances.sjcx || 0;
Expand Down
7 changes: 4 additions & 3 deletions app/lib/autolaunch/lin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs');
var mkdirp = require('mkdirp');
var untildify = require('untildify');
var configDir = untildify('~/.config/autostart/');
var utils = require('./../utils');

module.exports = {
enable: function(opts) {
Expand Down Expand Up @@ -37,8 +38,8 @@ module.exports = {
disable: function(opts) {
var file = configDir + opts.appName + '.desktop';
var promise = new Promise(function(resolve) {
if(fs.existsSync(file)) {
fs.unlinkSync(file);
if(utils.existsSync(file)) {
utils.unlinkSync(file);
return resolve();
}
});
Expand All @@ -47,7 +48,7 @@ module.exports = {
isEnabled: function(opts) {
var file = configDir + opts.appName + '.desktop';
var promise = new Promise(function(resolve) {
if(fs.existsSync(file)) {
if(utils.existsSync(file)) {
return resolve(true);
}
else {
Expand Down
Loading

0 comments on commit fa6b006

Please sign in to comment.