cherry-studio/src/renderer/src/hooks/useUserTheme.ts
kangfenmao a6bb58bb45 feat(DisplaySettings): add theme color presets and zoom settings
- Introduced a new color selection feature in DisplaySettings, allowing users to choose from predefined theme color presets.
- Added a dedicated section for zoom settings in the DisplaySettings component, enhancing user customization options.
- Updated localization files to include new zoom settings titles in multiple languages.
2025-05-29 15:35:32 +08:00

30 lines
905 B
TypeScript

import { useAppDispatch, useAppSelector } from '@renderer/store'
import { setUserTheme, UserTheme } from '@renderer/store/settings'
import Color from 'color'
export default function useUserTheme() {
const userTheme = useAppSelector((state) => state.settings.userTheme)
const dispatch = useAppDispatch()
const initUserTheme = (theme: UserTheme = userTheme) => {
const colorPrimary = Color(theme.colorPrimary)
document.body.style.setProperty('--color-primary', colorPrimary.toString())
document.body.style.setProperty('--color-primary-soft', colorPrimary.alpha(0.6).toString())
document.body.style.setProperty('--color-primary-mute', colorPrimary.alpha(0.3).toString())
}
return {
colorPrimary: Color(userTheme.colorPrimary),
initUserTheme,
setUserTheme(userTheme: UserTheme) {
dispatch(setUserTheme(userTheme))
initUserTheme(userTheme)
}
}
}