From dd3fdc1355c768ba4f965145f37662cba5c55950 Mon Sep 17 00:00:00 2001 From: Harsh Vakharia Date: Sat, 10 Dec 2016 13:27:51 +0530 Subject: [PATCH] Add realtime BTC price in menu bar --- src/app/components/Coin.jsx | 13 ++++++++++--- src/main.js | 12 +++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/app/components/Coin.jsx b/src/app/components/Coin.jsx index 99fe64c..6479099 100644 --- a/src/app/components/Coin.jsx +++ b/src/app/components/Coin.jsx @@ -1,12 +1,18 @@ import React from 'react' import classNames from 'classnames' +const { ipcRenderer } = window.require('electron') + import CoinStore from '../stores/CoinStore' import CurrencyStore from '../stores/CurrencyStore' import * as CoinUtil from '../utils/coin' import * as FormatUtil from '../utils/format' +function updateTitle (price, currency) { + ipcRenderer.send('update-btc-price', `${price} ${currency}`) +} + export default class Coin extends React.Component { constructor (props) { super(props) @@ -62,8 +68,7 @@ export default class Coin extends React.Component { const { shouldFlash, selectedCurrency, selectedCurrencyValue } = this.state const { long, short, price, perc, volume, cap24hrChange } = this.state.coin - let safePrice = price - if (isNaN(price)) safePrice = 0 + const safePrice = isNaN(price) ? 0 : price const iconClass = CoinUtil.getCoinClass(short) const positiveChangeInPrice = FormatUtil.isPositive(perc) @@ -95,8 +100,10 @@ export default class Coin extends React.Component { const formattedChangeInPercentage = FormatUtil.getFormattedPercentage(perc) const formattedVolume = FormatUtil.getFormattedVolume(volume) + if (short === 'BTC') updateTitle(formattedCurrencyPrice, selectedCurrency) + return ( -
  • this.coinRef = ref}> +
  • { this.coinRef = ref }}>
    diff --git a/src/main.js b/src/main.js index 0dfdb4c..e2f8ece 100644 --- a/src/main.js +++ b/src/main.js @@ -19,6 +19,14 @@ if (platform === 'darwin' || platform === 'win32') { }) mb.on('after-create-window', () => mb.window.setResizable(false)) + + app.on('ready', () => { + mb.tray.setTitle('Donut') + + ipcMain.on('update-btc-price', (event, price) => { + mb.tray.setTitle(price) + }) + }) } else { const { BrowserWindow } = require('electron') @@ -39,6 +47,4 @@ if (platform === 'darwin' || platform === 'win32') { }) } -ipcMain.on('quit', () => { - app.quit() -}) +ipcMain.on('quit', () => app.quit())