diff --git a/src/main.js b/src/main.js index af61376..9c18476 100644 --- a/src/main.js +++ b/src/main.js @@ -109,12 +109,12 @@ const createWindow = async () => { // Load menubar buildMenu(mainWindow) // Load touchbar - process.platform === 'darwin' && - const systemAccentColor = systemPreferences.getAccentColor() - buildTouchbar(prices, mainWindow, systemAccentColor) + if (process.platform === 'darwin') { + const accentColor = getAccentColor() + buildTouchbar(prices, mainWindow, accentColor) ipcMain.on('prices-updated', (event, pricesNew) => { - updateTouchbar(pricesNew, mainWindow, systemAccentColor) + updateTouchbar(pricesNew, mainWindow, accentColor) }) } } @@ -145,9 +145,13 @@ app.on('activate', () => { // Accent color setting // macOS & Windows // -const switchAccentColor = () => { +const getAccentColor = () => { const systemAccentColor = systemPreferences.getAccentColor() - const accentColor = rgbaToHex(systemAccentColor) + return rgbaToHex(systemAccentColor) +} + +const switchAccentColor = () => { + const accentColor = getAccentColor() mainWindow.webContents.send('accent-color', accentColor) } diff --git a/src/touchbar.js b/src/touchbar.js index deb9d05..b856eef 100644 --- a/src/touchbar.js +++ b/src/touchbar.js @@ -6,32 +6,33 @@ const { TouchBarButton } = TouchBar // const currency = ipc... // const prices = ipc... -const createButton = (value, key, mainWindow, systemAccentColor) => - new TouchBarButton({ +const createButton = (value, key, mainWindow, accentColor) => { + return new TouchBarButton({ label: cryptoFormatter(value, key.toUpperCase()), click: () => mainWindow.webContents.send('setCurrency', key), - backgroundColor: key === 'ocean' ? systemAccentColor : '#141414' + backgroundColor: key === 'ocean' ? accentColor : '#141414' }) +} -const buildTouchbar = (prices, mainWindow, systemAccentColor) => { +const buildTouchbar = (prices, mainWindow, accentColor) => { const touchBar = new TouchBar({ items: [ - createButton(1, 'ocean', mainWindow, systemAccentColor), - ...prices.map(key => createButton(0, key, mainWindow, systemAccentColor)) + createButton(1, 'ocean', mainWindow, accentColor), + ...prices.map(key => createButton(0, key, mainWindow, accentColor)) ] }) mainWindow.setTouchBar(touchBar) } -const updateTouchbar = (prices, mainWindow, systemAccentColor) => { +const updateTouchbar = (prices, mainWindow, accentColor) => { const touchBar = new TouchBar({ items: [ - createButton(1, 'ocean', mainWindow, systemAccentColor), + createButton(1, 'ocean', mainWindow, accentColor), ...Object.entries(prices) .filter(([key]) => key !== 'ocean') .map(([key, value]) => - createButton(value, key, mainWindow, systemAccentColor) + createButton(value, key, mainWindow, accentColor) ) ] })