-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
36 lines (28 loc) · 927 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const { app, Menu, Tray } = require('electron');
const request = require('request');
const moment = require('moment');
let tray = null;
app.on('ready', () => {
const updatePrice = () => {
request({
url: 'https://api.coinbase.com/v2/prices/ETH-USD/spot',
headers: { 'CB-VERSION': '2017-08-04' },
}, (err, res, body) => {
if (err) {
tray.setToolTip('Error getting market price.');
} else {
const amount = JSON.parse(body).data.amount;
const timestamp = moment().format('YYYY-MM-DD HH:mm');
tray.setToolTip(`$${amount} as of ${timestamp}`);
}
});
};
const contextMenu = Menu.buildFromTemplate([
{ label: 'Update', click: updatePrice },
{ label: 'Quit', click: () => { app.quit(); } },
]);
tray = new Tray('ethereum-logo.ico');
tray.setToolTip('Getting market price...');
tray.setContextMenu(contextMenu);
updatePrice();
});