fix: move primary color switching into theme switching

pull/2522/head
William Grant 3 years ago
parent 8135c2a861
commit 4758fdc64a

@ -52,7 +52,6 @@ import { getLatestReleaseFromFileServer } from '../../session/apis/file_server_a
import { switchThemeTo } from '../../themes/switchTheme';
import { ThemeStateType } from '../../themes/constants/colors';
import { getTheme } from '../../state/selectors/theme';
import { switchPrimaryColorTo } from '../../themes/switchPrimaryColor';
const Section = (props: { type: SectionType }) => {
const ourNumber = useSelector(getOurNumber);
@ -77,7 +76,6 @@ const Section = (props: { type: SectionType }) => {
await switchThemeTo({
theme: newTheme,
mainWindow: true,
resetPrimaryColor: true,
dispatch,
});
} else if (type === SectionType.PathIndicator) {
@ -164,12 +162,9 @@ const setupTheme = async () => {
await switchThemeTo({
theme,
mainWindow: true,
usePrimaryColor: true,
dispatch: window?.inboxStore?.dispatch || undefined,
});
// Set primary color after the theme is loaded so that it's not overwritten
const primaryColor = window.Events.getPrimaryColorSetting();
await switchPrimaryColorTo(primaryColor, window?.inboxStore?.dispatch || null);
};
// Do this only if we created a new Session ID, or if we already received the initial configuration message

@ -88,7 +88,6 @@ const Themes = () => {
await switchThemeTo({
theme: theme.id,
mainWindow: true,
resetPrimaryColor: true,
dispatch,
});
}}

@ -9,12 +9,12 @@ import { findPrimaryColorId, switchPrimaryColorTo } from './switchPrimaryColor';
type SwitchThemeProps = {
theme: ThemeStateType;
mainWindow?: boolean;
resetPrimaryColor?: boolean;
usePrimaryColor?: boolean;
dispatch?: Dispatch;
};
export async function switchThemeTo(props: SwitchThemeProps) {
const { theme, mainWindow, resetPrimaryColor, dispatch } = props;
const { theme, mainWindow, usePrimaryColor, dispatch } = props;
let newTheme: ThemeStateType | null = null;
switch (theme) {
@ -49,7 +49,12 @@ export async function switchThemeTo(props: SwitchThemeProps) {
if (dispatch) {
dispatch(applyTheme(newTheme));
if (resetPrimaryColor) {
if (usePrimaryColor) {
// Set primary color after the theme is loaded so that it's not overwritten
const primaryColor = window.Events.getPrimaryColorSetting();
await switchPrimaryColorTo(primaryColor, dispatch);
} else {
// By default, when we change themes we want to reset the primary color
const defaultPrimaryColor = findPrimaryColorId(
THEMES[convertThemeStateToName(newTheme)].PRIMARY
);

Loading…
Cancel
Save