From d61598f9eb0df73f257e2160192cd2a426e53b23 Mon Sep 17 00:00:00 2001 From: Maksim Stepanenko Date: Mon, 23 Jan 2017 21:25:02 -0800 Subject: [PATCH] Taskbar prices --- desktop/application.js | 12 ++++++++++- desktop/menu.js | 14 +++++++++++++ desktop/tray.js | 1 + src/scenes/Portfolio/PortfolioStore.js | 21 ++++++++++++++++++- .../Prices/components/PriceList/PriceList.js | 2 +- src/utils/formatting.js | 1 - 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/desktop/application.js b/desktop/application.js index a434b21..2782d0a 100644 --- a/desktop/application.js +++ b/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'; @@ -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; @@ -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()); diff --git a/desktop/menu.js b/desktop/menu.js index 21bb02d..22d1b9d 100644 --- a/desktop/menu.js +++ b/desktop/menu.js @@ -1,4 +1,5 @@ import { Menu, shell } from 'electron'; +import config from './config'; const createMenu = (app, mainWindow) => { const template = [ @@ -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', diff --git a/desktop/tray.js b/desktop/tray.js index 6c38536..efa17f5 100644 --- a/desktop/tray.js +++ b/desktop/tray.js @@ -30,6 +30,7 @@ const create = win => { }); tray.on('right-click', () => tray.popUpContextMenu(contextMenu)); tray.on('double-click', () => toggleWin()); + return tray; }; export { diff --git a/src/scenes/Portfolio/PortfolioStore.js b/src/scenes/Portfolio/PortfolioStore.js index 1c9f604..cae1199 100644 --- a/src/scenes/Portfolio/PortfolioStore.js +++ b/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'; @@ -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); }); } } diff --git a/src/scenes/Prices/components/PriceList/PriceList.js b/src/scenes/Prices/components/PriceList/PriceList.js index 9345566..efb7cd9 100644 --- a/src/scenes/Prices/components/PriceList/PriceList.js +++ b/src/scenes/Prices/components/PriceList/PriceList.js @@ -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)); diff --git a/src/utils/formatting.js b/src/utils/formatting.js index f1814ce..b8c10c9 100644 --- a/src/utils/formatting.js +++ b/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; }