mirror of
https://github.com/kremalicious/blowfish.git
synced 2024-12-29 16:17:52 +01:00
change primary color based on system accent color
This commit is contained in:
parent
ae42e4da68
commit
c041f2007f
@ -42,7 +42,7 @@
|
|||||||
"babel-loader": "^8.0.6",
|
"babel-loader": "^8.0.6",
|
||||||
"copy-webpack-plugin": "^5.0.3",
|
"copy-webpack-plugin": "^5.0.3",
|
||||||
"css-loader": "^2.1.1",
|
"css-loader": "^2.1.1",
|
||||||
"electron": "^5.0.1",
|
"electron": "^6.0.0-beta.3",
|
||||||
"electron-builder": "^20.40.2",
|
"electron-builder": "^20.40.2",
|
||||||
"electron-devtools-installer": "^2.2.4",
|
"electron-devtools-installer": "^2.2.4",
|
||||||
"electron-store": "^3.2.0",
|
"electron-store": "^3.2.0",
|
||||||
|
@ -58,9 +58,10 @@ h5 {
|
|||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a,
|
||||||
color: #f6388a;
|
button {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
|
||||||
a h1 {
|
a h1 {
|
||||||
|
@ -31,24 +31,6 @@
|
|||||||
border-color: #303030;
|
border-color: #303030;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ticker button:not(:disabled):hover {
|
|
||||||
border-color: #f6388a;
|
|
||||||
color: #f6388a;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ticker button.active,
|
|
||||||
.ticker button.active:hover {
|
|
||||||
border-color: #e2e2e2;
|
|
||||||
background: #f6388a;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dark .ticker button.active,
|
|
||||||
.dark .ticker button.active:hover {
|
|
||||||
border-color: #303030;
|
|
||||||
color: #fff !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.label--price {
|
.label--price {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
font-size: .95rem;
|
font-size: .95rem;
|
||||||
|
@ -12,7 +12,19 @@ export default class Ticker extends PureComponent {
|
|||||||
static contextType = AppContext
|
static contextType = AppContext
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { toggleCurrencies, needsConfig, currency, prices } = this.context
|
const {
|
||||||
|
toggleCurrencies,
|
||||||
|
needsConfig,
|
||||||
|
currency,
|
||||||
|
prices,
|
||||||
|
accentColor
|
||||||
|
} = this.context
|
||||||
|
|
||||||
|
const activeStyle = {
|
||||||
|
backgroundColor: accentColor,
|
||||||
|
color: '#fff',
|
||||||
|
borderColor: accentColor
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<footer className="number-unit-wrap ticker" {...this.props}>
|
<footer className="number-unit-wrap ticker" {...this.props}>
|
||||||
@ -20,11 +32,10 @@ export default class Ticker extends PureComponent {
|
|||||||
{Object.keys(prices).map((key, i) => (
|
{Object.keys(prices).map((key, i) => (
|
||||||
<Item key={i} className="number-unit">
|
<Item key={i} className="number-unit">
|
||||||
<button
|
<button
|
||||||
className={`label label--price ${key === currency &&
|
className="label label--price"
|
||||||
!needsConfig &&
|
|
||||||
'active'}`}
|
|
||||||
onClick={() => toggleCurrencies(key)}
|
onClick={() => toggleCurrencies(key)}
|
||||||
disabled={needsConfig}
|
disabled={needsConfig}
|
||||||
|
style={key === currency && !needsConfig ? activeStyle : {}}
|
||||||
>
|
>
|
||||||
{formatCurrency(prices[key], key.toUpperCase(), locale)
|
{formatCurrency(prices[key], key.toUpperCase(), locale)
|
||||||
.replace(/BTC/, 'Ƀ')
|
.replace(/BTC/, 'Ƀ')
|
||||||
|
@ -5,12 +5,12 @@ import { locale } from '../util/moneyFormatter'
|
|||||||
import { formatCurrency } from '@coingecko/cryptoformat'
|
import { formatCurrency } from '@coingecko/cryptoformat'
|
||||||
import { AppContext } from '../store/createContext'
|
import { AppContext } from '../store/createContext'
|
||||||
|
|
||||||
const TouchbarItems = ({ prices, currency, toggleCurrencies }) => (
|
const TouchbarItems = ({ prices, currency, toggleCurrencies, accentColor }) => (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
label={formatCurrency(1, 'OCEAN', locale).replace(/OCEAN/, 'Ọ')}
|
label={formatCurrency(1, 'OCEAN', locale).replace(/OCEAN/, 'Ọ')}
|
||||||
onClick={() => toggleCurrencies('ocean')}
|
onClick={() => toggleCurrencies('ocean')}
|
||||||
backgroundColor={currency === 'ocean' ? '#f6388a' : '#141414'}
|
backgroundColor={currency === 'ocean' ? accentColor : '#141414'}
|
||||||
/>
|
/>
|
||||||
{Object.keys(prices).map(key => (
|
{Object.keys(prices).map(key => (
|
||||||
<Button
|
<Button
|
||||||
@ -20,7 +20,7 @@ const TouchbarItems = ({ prices, currency, toggleCurrencies }) => (
|
|||||||
.replace(/ETH/, 'Ξ')}
|
.replace(/ETH/, 'Ξ')}
|
||||||
onClick={() => toggleCurrencies(key)}
|
onClick={() => toggleCurrencies(key)}
|
||||||
backgroundColor={
|
backgroundColor={
|
||||||
currency !== 'ocean' && currency === key ? '#f6388a' : '#141414'
|
currency !== 'ocean' && currency === key ? accentColor : '#141414'
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
@ -30,7 +30,8 @@ const TouchbarItems = ({ prices, currency, toggleCurrencies }) => (
|
|||||||
TouchbarItems.propTypes = {
|
TouchbarItems.propTypes = {
|
||||||
prices: PropTypes.object.isRequired,
|
prices: PropTypes.object.isRequired,
|
||||||
currency: PropTypes.string.isRequired,
|
currency: PropTypes.string.isRequired,
|
||||||
toggleCurrencies: PropTypes.func.isRequired
|
toggleCurrencies: PropTypes.func.isRequired,
|
||||||
|
accentColor: PropTypes.string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Touchbar extends PureComponent {
|
export default class Touchbar extends PureComponent {
|
||||||
@ -41,6 +42,7 @@ export default class Touchbar extends PureComponent {
|
|||||||
prices={this.context.prices}
|
prices={this.context.prices}
|
||||||
currency={this.context.currency}
|
currency={this.context.currency}
|
||||||
toggleCurrencies={this.context.toggleCurrencies}
|
toggleCurrencies={this.context.toggleCurrencies}
|
||||||
|
accentColor={this.context.accentColor}
|
||||||
/>
|
/>
|
||||||
</TouchBar>
|
</TouchBar>
|
||||||
)
|
)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
margin-top: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome svg {
|
.welcome svg {
|
||||||
|
@ -2,11 +2,18 @@ import React from 'react'
|
|||||||
import { Link } from '@reach/router'
|
import { Link } from '@reach/router'
|
||||||
import IconRocket from '../images/rocket.svg'
|
import IconRocket from '../images/rocket.svg'
|
||||||
import './Welcome.css'
|
import './Welcome.css'
|
||||||
|
import { AppContext } from '../store/createContext'
|
||||||
|
|
||||||
const Welcome = () => (
|
const Welcome = () => (
|
||||||
<div className="welcome">
|
<div className="welcome">
|
||||||
<IconRocket />
|
<IconRocket />
|
||||||
<Link to="preferences">Add your first address to get started.</Link>
|
<AppContext.Consumer>
|
||||||
|
{context => (
|
||||||
|
<Link style={{ color: context.accentColor }} to="preferences">
|
||||||
|
Add your first address to get started.
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</AppContext.Consumer>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,19 +20,11 @@
|
|||||||
height: 1.25rem;
|
height: 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preferences-link:hover svg {
|
|
||||||
fill: #41474e;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dark .preferences-link svg {
|
.dark .preferences-link svg {
|
||||||
fill: #8b98a9;
|
fill: #8b98a9;
|
||||||
opacity: .5;
|
opacity: .5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark .preferences-link:hover svg {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.number-unit-wrap {
|
.number-unit-wrap {
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -58,10 +50,6 @@
|
|||||||
transition: color .2s ease-out;
|
transition: color .2s ease-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
.number-unit:not(.number-unit--main) .label:not(:disabled):hover {
|
|
||||||
color: #f6388a;
|
|
||||||
}
|
|
||||||
|
|
||||||
.number-unit-wrap--accounts {
|
.number-unit-wrap--accounts {
|
||||||
min-height: 55px;
|
min-height: 55px;
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,6 @@
|
|||||||
color: #8b98a9;
|
color: #8b98a9;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preferences__close:hover {
|
|
||||||
color: #f6388a;
|
|
||||||
}
|
|
||||||
|
|
||||||
.preference__list {
|
.preference__list {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
border-top: 1px solid #e2e2e2;
|
border-top: 1px solid #e2e2e2;
|
||||||
@ -58,7 +54,6 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
outline: 0;
|
outline: 0;
|
||||||
color: #f6388a;
|
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,10 +65,6 @@ button.delete {
|
|||||||
transition: color .5s ease-out;
|
transition: color .5s ease-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
button.delete:hover {
|
|
||||||
color: #f6388a;
|
|
||||||
}
|
|
||||||
|
|
||||||
.preference {
|
.preference {
|
||||||
-webkit-app-region: none;
|
-webkit-app-region: none;
|
||||||
-webkit-user-select: text;
|
-webkit-user-select: text;
|
||||||
|
@ -112,9 +112,11 @@ export default class Preferences extends PureComponent {
|
|||||||
onChange={this.handleInputChange}
|
onChange={this.handleInputChange}
|
||||||
className="preference__input"
|
className="preference__input"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
className="preference__input__add"
|
className="preference__input__add"
|
||||||
onClick={e => this.handleSave(e)}
|
onClick={e => this.handleSave(e)}
|
||||||
|
style={{ color: this.context.accentColor }}
|
||||||
>
|
>
|
||||||
Add
|
Add
|
||||||
</button>
|
</button>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React, { PureComponent } from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import ms from 'ms'
|
import ms from 'ms'
|
||||||
|
import { ipcRenderer } from 'electron'
|
||||||
import Store from 'electron-store'
|
import Store from 'electron-store'
|
||||||
import { AppContext } from './createContext'
|
import { AppContext } from './createContext'
|
||||||
import fetchData from '../util/fetch'
|
import fetchData from '../util/fetch'
|
||||||
@ -20,10 +21,15 @@ export default class AppProvider extends PureComponent {
|
|||||||
needsConfig: false,
|
needsConfig: false,
|
||||||
prices: Object.assign(...prices.map(key => ({ [key]: 0 }))),
|
prices: Object.assign(...prices.map(key => ({ [key]: 0 }))),
|
||||||
toggleCurrencies: currency => this.setState({ currency }),
|
toggleCurrencies: currency => this.setState({ currency }),
|
||||||
setBalances: () => this.setBalances()
|
setBalances: () => this.setBalances(),
|
||||||
|
accentColor: ''
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
|
ipcRenderer.on('accent-color', (event, accentColor) => {
|
||||||
|
this.setState({ accentColor })
|
||||||
|
})
|
||||||
|
|
||||||
await this.fetchAndSetPrices()
|
await this.fetchAndSetPrices()
|
||||||
await this.setBalances()
|
await this.setBalances()
|
||||||
|
|
||||||
|
38
src/main.js
38
src/main.js
@ -3,6 +3,7 @@ const { app, BrowserWindow, systemPreferences } = require('electron')
|
|||||||
const { touchBarWrapper } = require('react-touchbar-electron')
|
const { touchBarWrapper } = require('react-touchbar-electron')
|
||||||
const pkg = require('../package.json')
|
const pkg = require('../package.json')
|
||||||
const buildMenu = require('./menu')
|
const buildMenu = require('./menu')
|
||||||
|
const { rgbaToHex } = require('./utils')
|
||||||
|
|
||||||
let mainWindow
|
let mainWindow
|
||||||
|
|
||||||
@ -105,19 +106,22 @@ const createWindow = async () => {
|
|||||||
mainWindow.setSize(width, height, true)
|
mainWindow.setSize(width, height, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
switchTheme()
|
// Load menubar
|
||||||
|
|
||||||
// Load menubar menu items
|
|
||||||
buildMenu(mainWindow)
|
buildMenu(mainWindow)
|
||||||
|
|
||||||
|
// Load touchbar
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
touchBarWrapper(mainWindow)
|
touchBarWrapper(mainWindow)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
createWindow()
|
createWindow()
|
||||||
|
|
||||||
// Switch to user theme on start, and on reload
|
mainWindow.webContents.on('dom-ready', () => {
|
||||||
mainWindow.webContents.on('dom-ready', () => switchTheme())
|
switchTheme()
|
||||||
|
switchAccentColor()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// Quit when all windows are closed.
|
||||||
@ -133,6 +137,28 @@ app.on('activate', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
//
|
||||||
|
// Accent color setting
|
||||||
|
// macOS & Windows
|
||||||
|
//
|
||||||
|
const switchAccentColor = () => {
|
||||||
|
const systemAccentColor = systemPreferences.getAccentColor()
|
||||||
|
const accentColor = rgbaToHex(systemAccentColor)
|
||||||
|
mainWindow.webContents.send('accent-color', accentColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Listen for accent color changes in System Preferences
|
||||||
|
// macOS
|
||||||
|
systemPreferences.subscribeNotification('AppleAquaColorVariantChanged', () =>
|
||||||
|
switchAccentColor()
|
||||||
|
)
|
||||||
|
// Windows
|
||||||
|
systemPreferences.on('accent-color-changed', () => switchAccentColor())
|
||||||
|
|
||||||
|
//
|
||||||
|
// Appearance setting
|
||||||
|
// macOS
|
||||||
|
//
|
||||||
const switchTheme = () => {
|
const switchTheme = () => {
|
||||||
const isDarkMode = systemPreferences.isDarkMode()
|
const isDarkMode = systemPreferences.isDarkMode()
|
||||||
|
|
||||||
@ -145,7 +171,7 @@ const switchTheme = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen for theme changes in System Preferences
|
// Listen for appearance changes in System Preferences
|
||||||
systemPreferences.subscribeNotification(
|
systemPreferences.subscribeNotification(
|
||||||
'AppleInterfaceThemeChangedNotification',
|
'AppleInterfaceThemeChangedNotification',
|
||||||
() => switchTheme()
|
() => switchTheme()
|
||||||
|
11
src/utils.js
11
src/utils.js
@ -4,4 +4,13 @@ const openUrl = url => {
|
|||||||
shell.openExternal(url)
|
shell.openExternal(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { openUrl }
|
const rgbaToHex = color => {
|
||||||
|
const r = color.substr(0, 2)
|
||||||
|
const g = color.substr(2, 2)
|
||||||
|
const b = color.substr(4, 2)
|
||||||
|
// const a = color.substr(6, 2)
|
||||||
|
|
||||||
|
return '#' + r + g + b
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { openUrl, rgbaToHex }
|
||||||
|
Loading…
Reference in New Issue
Block a user