2020-10-10 15:37:05 +02:00
|
|
|
import { TouchBar } from 'electron'
|
|
|
|
import { cryptoFormatter } from '../../utils'
|
|
|
|
import { conversions } from '../../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),
|
2020-03-22 00:49:10 +01: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'
|
|
|
|
) => {
|
2020-03-22 00:49:10 +01:00
|
|
|
const items = pricesNew.map((item) => {
|
2019-05-25 02:33:54 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-10-10 15:37:05 +02:00
|
|
|
export { buildTouchbar, updateTouchbar }
|