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 { switchThemeTo } from '../../themes/switchTheme';
import { ThemeStateType } from '../../themes/constants/colors'; import { ThemeStateType } from '../../themes/constants/colors';
import { getTheme } from '../../state/selectors/theme'; import { getTheme } from '../../state/selectors/theme';
import { switchPrimaryColorTo } from '../../themes/switchPrimaryColor';
const Section = (props: { type: SectionType }) => { const Section = (props: { type: SectionType }) => {
const ourNumber = useSelector(getOurNumber); const ourNumber = useSelector(getOurNumber);
@ -77,7 +76,6 @@ const Section = (props: { type: SectionType }) => {
await switchThemeTo({ await switchThemeTo({
theme: newTheme, theme: newTheme,
mainWindow: true, mainWindow: true,
resetPrimaryColor: true,
dispatch, dispatch,
}); });
} else if (type === SectionType.PathIndicator) { } else if (type === SectionType.PathIndicator) {
@ -164,12 +162,9 @@ const setupTheme = async () => {
await switchThemeTo({ await switchThemeTo({
theme, theme,
mainWindow: true, mainWindow: true,
usePrimaryColor: true,
dispatch: window?.inboxStore?.dispatch || undefined, 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 // 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({ await switchThemeTo({
theme: theme.id, theme: theme.id,
mainWindow: true, mainWindow: true,
resetPrimaryColor: true,
dispatch, dispatch,
}); });
}} }}

@ -9,12 +9,12 @@ import { findPrimaryColorId, switchPrimaryColorTo } from './switchPrimaryColor';
type SwitchThemeProps = { type SwitchThemeProps = {
theme: ThemeStateType; theme: ThemeStateType;
mainWindow?: boolean; mainWindow?: boolean;
resetPrimaryColor?: boolean; usePrimaryColor?: boolean;
dispatch?: Dispatch; dispatch?: Dispatch;
}; };
export async function switchThemeTo(props: SwitchThemeProps) { export async function switchThemeTo(props: SwitchThemeProps) {
const { theme, mainWindow, resetPrimaryColor, dispatch } = props; const { theme, mainWindow, usePrimaryColor, dispatch } = props;
let newTheme: ThemeStateType | null = null; let newTheme: ThemeStateType | null = null;
switch (theme) { switch (theme) {
@ -49,7 +49,12 @@ export async function switchThemeTo(props: SwitchThemeProps) {
if (dispatch) { if (dispatch) {
dispatch(applyTheme(newTheme)); 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( const defaultPrimaryColor = findPrimaryColorId(
THEMES[convertThemeStateToName(newTheme)].PRIMARY THEMES[convertThemeStateToName(newTheme)].PRIMARY
); );

Loading…
Cancel
Save