Skip to content

Commit

Permalink
Add realtime BTC price in menu bar
Browse files Browse the repository at this point in the history
  • Loading branch information
harshjv committed Dec 10, 2016
1 parent 13c4163 commit dd3fdc1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/app/components/Coin.jsx
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 (
<li className={listClass} ref={(ref) => this.coinRef = ref}>
<li className={listClass} ref={(ref) => { this.coinRef = ref }}>
<i className={iconClass} />
<div className='media-body'>
<strong>
Expand Down
12 changes: 9 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -39,6 +47,4 @@ if (platform === 'darwin' || platform === 'win32') {
})
}

ipcMain.on('quit', () => {
app.quit()
})
ipcMain.on('quit', () => app.quit())

0 comments on commit dd3fdc1

Please sign in to comment.