2019-05-19 13:46:43 +02:00
|
|
|
const { TouchBar } = require('electron')
|
2019-05-25 03:16:53 +02:00
|
|
|
const { cryptoFormatter } = require('../utils')
|
|
|
|
const { conversions } = require('../config')
|
2019-05-19 13:46:43 +02:00
|
|
|
|
|
|
|
const { TouchBarButton } = TouchBar
|
|
|
|
|
2019-05-23 00:20:50 +02:00
|
|
|
const createButton = (
|
|
|
|
value,
|
|
|
|
key,
|
|
|
|
mainWindow,
|
2020-02-09 21:45:59 +01:00
|
|
|
accentColor = '#f6388a',
|
2019-05-23 00:20:50 +02:00
|
|
|
currentCurrency = 'ocean'
|
|
|
|
) =>
|
|
|
|
new TouchBarButton({
|
|
|
|
label: cryptoFormatter(value, key),
|
2019-05-20 03:35:19 +02:00
|
|
|
click: () => mainWindow.webContents.send('setCurrency', key),
|
2019-05-23 00:20:50 +02:00
|
|
|
backgroundColor: key === currentCurrency ? accentColor : '#141414'
|
2019-05-19 13:46:43 +02:00
|
|
|
})
|
2019-05-20 03:35:19 +02:00
|
|
|
|
2019-05-25 02:33:54 +02:00
|
|
|
const buildTouchbar = (mainWindow, accentColor) => {
|
2019-05-20 03:35:19 +02:00
|
|
|
const touchBar = new TouchBar({
|
|
|
|
items: [
|
2019-05-20 20:14:15 +02:00
|
|
|
createButton(1, 'ocean', mainWindow, accentColor),
|
2019-05-25 02:33:54 +02:00
|
|
|
...conversions.map(key => createButton(0, key, mainWindow, accentColor))
|
2019-05-20 03:35:19 +02:00
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
mainWindow.setTouchBar(touchBar)
|
2019-05-19 13:46:43 +02:00
|
|
|
}
|
|
|
|
|
2019-05-23 00:20:50 +02:00
|
|
|
const updateTouchbar = (
|
2019-05-25 02:33:54 +02:00
|
|
|
pricesNew,
|
2019-05-23 00:20:50 +02:00
|
|
|
mainWindow,
|
|
|
|
accentColor,
|
|
|
|
currentCurrency = 'ocean'
|
|
|
|
) => {
|
2019-05-25 02:33:54 +02:00
|
|
|
const items = pricesNew.map(item => {
|
|
|
|
return createButton(
|
|
|
|
item[1],
|
|
|
|
item[0],
|
|
|
|
mainWindow,
|
|
|
|
accentColor,
|
|
|
|
currentCurrency
|
2019-05-23 00:20:50 +02:00
|
|
|
)
|
2019-05-25 02:33:54 +02:00
|
|
|
})
|
2019-05-23 00:20:50 +02:00
|
|
|
|
2019-05-19 13:46:43 +02:00
|
|
|
const touchBar = new TouchBar({
|
2019-05-25 02:33:54 +02:00
|
|
|
items: [...items]
|
2019-05-19 13:46:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
mainWindow.setTouchBar(touchBar)
|
|
|
|
}
|
|
|
|
|
2019-05-20 03:35:19 +02:00
|
|
|
module.exports = { buildTouchbar, updateTouchbar }
|