Skip to content

Commit

Permalink
feat: use system accent color
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Dec 15, 2020
1 parent 030005c commit a173ea2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion main/lib/theme.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { ipcMain, nativeTheme } = require('electron')
const { ipcMain, nativeTheme, systemPreferences } = require('electron')
const memoize = require('lodash/memoize')
const { toRGBA, toCSSColor, toElectronColor, isDarkColor, mix } = require('../utils/color')
const { resources, userData } = require('../utils/directory')
Expand Down Expand Up @@ -53,6 +53,8 @@ async function loadTheme() {
if (!theme.cursorAccent) {
theme.cursorAccent = theme.background
}
const accentColor = systemPreferences.getAccentColor()
theme.systemAccent = accentColor ? `#${accentColor.slice(0, 6)}` : ''
setThemeOptions({
backgroundColor: toElectronColor({ ...backgroundRGBA, a: 0 }),
vibrancy: opacity === 0 ? 'tooltip' : null,
Expand Down
1 change: 1 addition & 0 deletions renderer/components/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ body {
color: var(--theme-foreground, transparent);
background: var(--theme-backdrop);
transition: background 0.2s;
--system-accent: var(--design-blue);
}
.app.opaque {
background: var(--theme-background);
Expand Down
2 changes: 1 addition & 1 deletion renderer/components/basic/switch-control.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default {
transition: transform 0.2s;
}
.switch-control input:checked + .switch-content::before {
background: var(--design-blue);
background: var(--system-accent);
opacity: 1;
}
.switch-control input:checked + .switch-content::after {
Expand Down
5 changes: 4 additions & 1 deletion renderer/hooks/theme.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ export const useTheme = memoize(() => {
})

const themeStyleRef = computed(() => {
const property = {
systemAccent: '--system-accent',
}
const theme = unref(useTheme())
return Object.fromEntries(
Object.entries(theme).filter(([key, value]) => value)
.map(([key, value]) => [`--theme-${key.toLowerCase()}`, value])
.map(([key, value]) => [property[key] ?? `--theme-${key.toLowerCase()}`, value])
)
})

Expand Down

0 comments on commit a173ea2

Please sign in to comment.