Skip to content

Commit

Permalink
Merge pull request #19 from lionsharecapital/ms-taskbar
Browse files Browse the repository at this point in the history
Taskbar prices
  • Loading branch information
jorilallo committed Jan 24, 2017
2 parents 59a820e + d61598f commit cd9f292
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
12 changes: 11 additions & 1 deletion desktop/application.js
@@ -1,4 +1,5 @@
import electron from 'electron';
import { ipcMain } from 'electron';
import path from 'path';
import url from 'url';
import isDev from 'electron-is-dev';
Expand Down Expand Up @@ -84,7 +85,7 @@ app.on('ready', () => {
mainWindow = createMainWindow();
if (isDev) mainWindow.webContents.openDevTools({ mode: 'detach' });
if (!isDev) scheduleUpdates();
createTray(mainWindow);
const tray = createTray(mainWindow);
createMenu(app, mainWindow);

const page = mainWindow.webContents;
Expand All @@ -96,8 +97,17 @@ app.on('ready', () => {
app.on('activate', () => {
mainWindow.show();
});

ipcMain.on('priceUpdate', (_event, change) => {
if (config.get('priceSetting')) {
tray.setTitle(change);
} else {
tray.setTitle('');
}
});
});


app.on('before-quit', () => {
isQuitting = true;
config.set('lastWindowState', mainWindow.getBounds());
Expand Down
14 changes: 14 additions & 0 deletions desktop/menu.js
@@ -1,4 +1,5 @@
import { Menu, shell } from 'electron';
import config from './config';

const createMenu = (app, mainWindow) => {
const template = [
Expand Down Expand Up @@ -110,6 +111,19 @@ const createMenu = (app, mainWindow) => {
{
type: 'separator',
},
{
label: 'Show Profit/Loss in Taskbar',
type: 'checkbox',
checked: config.get('priceSetting'),
click() {
const setting = !config.get('priceSetting');
config.set('priceSetting', setting);
mainWindow.webContents.send('priceSetting', setting);
},
},
{
type: 'separator',
},
{
label: 'Bring All to Front',
role: 'front',
Expand Down
1 change: 1 addition & 0 deletions desktop/tray.js
Expand Up @@ -30,6 +30,7 @@ const create = win => {
});
tray.on('right-click', () => tray.popUpContextMenu(contextMenu));
tray.on('double-click', () => toggleWin());
return tray;
};

export {
Expand Down
21 changes: 20 additions & 1 deletion src/scenes/Portfolio/PortfolioStore.js
@@ -1,7 +1,9 @@
import { observable, computed, action, asMap, autorun } from 'mobx';
import _ from 'lodash';
import { ipcRenderer } from 'electron';

import { currencyData } from 'utils/currencies';
import { formatNumber } from 'utils/formatting';

const PORTFOLIO_KEY = 'PORTFOLIO_KEY';

Expand Down Expand Up @@ -199,9 +201,26 @@ class PortfolioStore {
this.isEditing = true;
}

// Persist store to localStorage
ipcRenderer.on('priceSetting', (_event, setting) => {
if (setting) {
ipcRenderer.send('priceUpdate', formatNumber(this.totalChange, 'USD', {
directionSymbol: true,
minPrecision: true,
}));
} else {
ipcRenderer.send('priceUpdate', '');
}
});

autorun(() => {
// Persist store to localStorage
localStorage.setItem(PORTFOLIO_KEY, this.toJSON());
// Taskbar change updates
const trayChange = formatNumber(this.totalChange, 'USD', {
directionSymbol: true,
minPrecision: true,
});
ipcRenderer.send('priceUpdate', trayChange);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/scenes/Prices/components/PriceList/PriceList.js
Expand Up @@ -10,8 +10,8 @@ import ChangeHighlight from 'components/ChangeHighlight';
import ColoredChange from 'components/ColoredChange';

import classNames from 'classnames/bind';
const cx = classNames.bind(styles);
import styles from './PriceList.scss';
const cx = classNames.bind(styles);

const PriceList = ({ assets, visibleCurrencies }) => {
const includedAssets = assets.filter(asset => visibleCurrencies.includes(asset.symbol));
Expand Down
1 change: 0 additions & 1 deletion src/utils/formatting.js
@@ -1,7 +1,6 @@
import numeral from 'numeral';

const formatNumber = (amount, currency, options = {}) => {

if (!(options.maximumFractionDigits || options.maximumFractionDigits === 0)) {
options.maximumFractionDigits = 7 - parseInt(amount, 10).toString().length;
}
Expand Down

0 comments on commit cd9f292

Please sign in to comment.