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 #185 from Storj/develop
Browse files Browse the repository at this point in the history
Update master with the latest develop (tagged at v0.5.1)
  • Loading branch information
littleskunk committed Feb 12, 2016
2 parents be1018b + 761ece5 commit a43b9a3
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 99 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
DriveShare
==========

[![Build Status](https://img.shields.io/travis/Storj/driveshare-gui/master.svg?label=Build-Master)](https://travis-ci.org/Storj/driveshare-gui)
[![Build Status](https://img.shields.io/appveyor/ci/Storj/driveshare-gui/master.svg?label=Build-Master)](https://ci.appveyor.com/project/Storj/driveshare-gui/branch/master)
[![Test Status](https://img.shields.io/travis/Storj/driveshare-gui/master.svg?label=Test-Master)](https://travis-ci.org/Storj/driveshare-gui)
[![Coverage Status](https://img.shields.io/coveralls/Storj/driveshare-gui/master.svg?label=Coverage-Master)](https://coveralls.io/github/Storj/driveshare-gui?branch=master)
[![Build Status](https://img.shields.io/travis/Storj/driveshare-gui/develop.svg?label=Build-Develop)](https://travis-ci.org/Storj/driveshare-gui)
[![Coverage Status](https://img.shields.io/coveralls/Storj/driveshare-gui/develop.svg?label=Coverage-Develop)](https://coveralls.io/github/Storj/driveshare-gui?branch=master)
[![Coverage Status](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Storj/driveshare-gui/blob/master/LICENSE)
[![Build Status](https://img.shields.io/appveyor/ci/Storj/driveshare-gui/develop.svg?label=Build-Master)](https://ci.appveyor.com/project/Storj/driveshare-gui/branch/develop)
[![Test Status](https://img.shields.io/travis/Storj/driveshare-gui/develop.svg?label=Test-Develop)](https://travis-ci.org/Storj/driveshare-gui)
[![Coverage Status](https://img.shields.io/coveralls/Storj/driveshare-gui/develop.svg?label=Coverage-Develop)](https://coveralls.io/github/Storj/driveshare-gui?branch=develop)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Storj/driveshare-gui/blob/master/LICENSE)

DriveShare is a cross-platform desktop application enabling users to earn money
by sharing their extra hard drive space.
Expand Down
12 changes: 7 additions & 5 deletions app/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ var updater = new Vue({
var appSettings = new Vue({
el:'#app-settings',
data: {
appSettings: userdata._parsed.appSettings
userdata: userdata._parsed
},
methods: {
changeSettings: function() {
ipc.send('appSettingsChanged', JSON.stringify(this.$data.appSettings));
ipc.send('appSettingsChanged', JSON.stringify(userdata.toObject()));
userdata.saveConfig(function(err) {
if (err) {
return window.alert(err.message);
Expand All @@ -224,7 +224,7 @@ var appSettings = new Vue({
//check for OS-specific boot launch option
ipc.send('checkBootSettings');
ipc.on('checkAutoLaunchOptions', function(ev, isEnabled) {
self.appSettings.launchOnBoot = isEnabled;
self.userdata.appSettings.launchOnBoot = isEnabled;
userdata.saveConfig(function(err) {
if (err) {
return window.alert(err.message);
Expand Down Expand Up @@ -266,8 +266,8 @@ var main = new Vue({
if (event) {
event.preventDefault();
}

this.showTab(this.userdata.tabs.push(new Tab()) - 1);
ipc.send('appSettingsChanged', JSON.stringify(userdata.toObject()));
},
showTab: function(index) {
var self = this;
Expand Down Expand Up @@ -369,7 +369,7 @@ var main = new Vue({

this.transitioning = true;
tab.wasRunning = true;

ipc.send('appSettingsChanged', JSON.stringify(userdata.toObject()));
userdata.saveConfig(function(err) {
if (err) {
self.transitioning = false;
Expand Down Expand Up @@ -416,6 +416,7 @@ var main = new Vue({
tab._process.kill();
tab._process = null;
}
ipc.send('appSettingsChanged', JSON.stringify(userdata.toObject()));
userdata.saveConfig(function(err) {
if(err) {
return window.alert(err.message);
Expand Down Expand Up @@ -522,6 +523,7 @@ var main = new Vue({
ipc.on('storageDirectorySelected', function(ev, path) {
self.userdata.tabs[self.current].storage.path = path[0];
self.getFreeSpace();
ipc.send('appSettingsChanged', JSON.stringify(userdata.toObject()));
});

ipc.on('toggle_dataserv', function() {
Expand Down
6 changes: 3 additions & 3 deletions app/driveshare.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ <h2 class="title">
</button>
<div class="dropdown-menu pull-right" role="tablist">
<label for="MinToTask">
<input v-model="appSettings.minToTask" v-on:change="changeSettings" id="MinToTask" type="checkbox"> Minimize to Tray
<input v-model="userdata.appSettings.minToTask" v-on:change="changeSettings" id="MinToTask" type="checkbox"> Display in System Tray
</label>
<label for="LaunchOnBoot">
<input v-model="appSettings.launchOnBoot" v-on:change="changeSettings" id="LaunchOnBoot" type="checkbox"> Launch Driveshare at User Login
<input v-model="userdata.appSettings.launchOnBoot" v-on:change="changeSettings" id="LaunchOnBoot" type="checkbox"> Launch Driveshare at User Login
</label>
<label for="RunDrivesOnBoot">
<input v-model="appSettings.runDrivesOnBoot" v-on:change="changeSettings" id="RunDrivesOnBoot" type="checkbox"> Share Previously Running Drives at Launch
<input v-model="userdata.appSettings.runDrivesOnBoot" v-on:change="changeSettings" id="RunDrivesOnBoot" type="checkbox"> Share Previously Running Drives at Launch
</label>
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions app/lib/auto_launch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
'use strict';

var app = require('electron').app;
/* jshint ignore:start */
var win = require('./win');
var mac = require('./mac');
var lin = require('./lin');
/* jshint ignore:end */
const PLATFORM = require('../get_platform');
/**
* Cross-platform interface for Application Boot Options
* @constructor
Expand All @@ -28,9 +31,7 @@ function AutoLaunch(optsObj){
app.getPath('exe')
};

this.api = (/^win/.test(process.platform)) ? win :
(/^darwin/.test(process.platform)) ? mac :
(/^linux/.test(process.platform)) ? lin : null;
this.api = PLATFORM;
}

AutoLaunch.prototype.enable = function() {
Expand Down
7 changes: 7 additions & 0 deletions app/lib/get_platform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @module driveshare-gui/get_platform
*/

module.exports = (/^win/.test(process.platform)) ? 'win' :
(/^darwin/.test(process.platform)) ? 'mac' :
(/^linux/.test(process.platform)) ? 'lin' : null;
91 changes: 58 additions & 33 deletions app/lib/sys_tray_icon.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
/**
* @module driveshare-gui/sysTrayIcon
* @module driveshare-gui/sys_tray_icon
*/

'use strict';
var electron = require('electron');
var Menu = electron.Menu;
var Tray = electron.Tray;
var UserData = require('./userdata');

const PLATFORM = require('./get_platform');
/**
* Dynamically builds system tray context-menu based on application state. Will
* not display until render() is called.
* @constructor
*/
function SysTrayIcon(appRoot, appRootWindow, icoPath) {
function SysTrayIcon(appRoot, appRootWindow, icoPath, userdata) {
if (!(this instanceof SysTrayIcon)) {
return new SysTrayIcon(appRoot, appRootWindow, icoPath);
return new SysTrayIcon(appRoot, appRootWindow, icoPath, userdata);
}
this.userData = userdata;
this.rootWindow = appRootWindow;
this.app = appRoot;
this.contextMenu = null;
this.trayIcon = null;
this.trayIconPath = icoPath;
}

Expand All @@ -30,14 +28,26 @@ function SysTrayIcon(appRoot, appRootWindow, icoPath) {
*/
SysTrayIcon.prototype.render = function() {
var self = this;
this.trayIcon = new Tray(this.trayIconPath);
this.trayIcon.setToolTip('DriveShare');
this.contextMenu = Menu.buildFromTemplate(this._getMenuTemplate());
this.trayIcon.setContextMenu(this.contextMenu);

this.trayIcon.on('click', function() {
self.rootWindow.restore();
});
if(typeof this.trayIcon === 'undefined') {
this.trayIcon = new Tray(this.trayIconPath);
this.trayIcon.setToolTip('DriveShare');

if(PLATFORM === 'win' || PLATFORM === 'mac') {
this.trayIcon.on('click', function() {
restoreAll(self.rootWindow);
});

this.trayIcon.on('right-click', function() {
self.trayIcon.popUpContextMenu(self.contextMenu);
});
}
}

if(PLATFORM === 'lin') {
this.trayIcon.setContextMenu(this.contextMenu);
}
};

/**
Expand All @@ -48,6 +58,7 @@ SysTrayIcon.prototype.destroy = function() {
if(this.trayIcon) {
this.trayIcon.removeAllListeners();
this.trayIcon.destroy();
this.trayIcon = undefined;
}
};

Expand All @@ -58,23 +69,20 @@ SysTrayIcon.prototype.destroy = function() {
SysTrayIcon.prototype._getMenuTemplate = function() {
var restore, quit, drives;
var self = this;
var user = new UserData(this.app.getPath('userData'));

function enumerateDrives(userData) {
var drives = userData._parsed.tabs;
function enumerateDrives() {
var drives = self.userData.tabs;
var drivesArr = [];

drives.forEach(function(elem, ind) {
if(elem.storage.path !== '') {
drivesArr.push({
label: getDriveLabelState(elem.wasRunning) + ': ' + elem.storage.path,
click: function handleDriveSelection() {
self.rootWindow.restore();
self.destroy();
self.rootWindow.webContents.send('selectDriveFromSysTray', ind);
}
});
}
drivesArr.push({
label: getDriveLabelState(elem.wasRunning) + ': ' +
getDriveLabelName(elem.storage.path, ind),
click: function handleDriveSelection() {
restoreAll(self.rootWindow);
self.rootWindow.webContents.send('selectDriveFromSysTray', ind);
}
});
});

return drivesArr;
Expand All @@ -84,26 +92,43 @@ SysTrayIcon.prototype._getMenuTemplate = function() {
return (wasRunning === true) ? 'Running' : 'Stopped';
}

function getDriveLabelName(path, ind) {
if(path !== '' && typeof path === 'string') {
return path;
} else if(typeof ind === 'number') {
return 'Drive #' + ind;
} else {
return 'unknown drive';
}
}

restore = {
label: 'Restore',
click: function handleRestoration() {
self.rootWindow.restore();
restoreAll(self.rootWindow);
}
};

drives = {
label: 'Drives',
submenu: enumerateDrives()
};

quit = {
label: 'Quit',
click: function handleQuit() {
self.app.quit();
}
};

drives = {
label: 'Drives',
submenu: enumerateDrives(user)
};

return [restore, quit, drives];
return [restore, drives, quit];
};

function restoreAll(appWin) {
appWin.show();
if(appWin.isMinimized()) {
appWin.restore();
}
}

module.exports = SysTrayIcon;
20 changes: 17 additions & 3 deletions app/lib/userdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ UserData.DEFAULTS = {
appSettings: {
minToTask: true,
launchOnBoot: false,
runDrivesOnBoot: false
runDrivesOnBoot: true
}
};
/**
Expand Down Expand Up @@ -200,13 +200,27 @@ UserData.prototype.getBalance = function(address, callback) {
* @param {Function} callback
*/
UserData.prototype.saveConfig = function(callback) {
var config = {
try {
fs.writeFileSync(this._path, JSON.stringify(this.toObject(), null, 2));
} catch (err) {
return callback(err);
}

callback();
};

/**
* Save the configuration at the given index
* #toObject
* @returns {Object}
*/
UserData.prototype.toObject = function(){
return {
tabs: this._parsed.tabs.map(function(tab) {
return tab.toObject();
}),
appSettings: this._parsed.appSettings
};
fs.writeFile(this._path, JSON.stringify(config, null, 2), callback);
};

module.exports = UserData;
Loading

0 comments on commit a43b9a3

Please sign in to comment.