From 4758fdc64aac6d0542d76e447675ef0193d88278 Mon Sep 17 00:00:00 2001 From: William Grant Date: Tue, 11 Oct 2022 11:58:18 +1100 Subject: [PATCH] fix: move primary color switching into theme switching --- ts/components/leftpane/ActionsPanel.tsx | 7 +------ ts/components/settings/SettingsThemeSwitcher.tsx | 1 - ts/themes/switchTheme.tsx | 11 ++++++++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ts/components/leftpane/ActionsPanel.tsx b/ts/components/leftpane/ActionsPanel.tsx index 43f23ca0d..c17088ca1 100644 --- a/ts/components/leftpane/ActionsPanel.tsx +++ b/ts/components/leftpane/ActionsPanel.tsx @@ -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 diff --git a/ts/components/settings/SettingsThemeSwitcher.tsx b/ts/components/settings/SettingsThemeSwitcher.tsx index c5549786c..697a8646b 100644 --- a/ts/components/settings/SettingsThemeSwitcher.tsx +++ b/ts/components/settings/SettingsThemeSwitcher.tsx @@ -88,7 +88,6 @@ const Themes = () => { await switchThemeTo({ theme: theme.id, mainWindow: true, - resetPrimaryColor: true, dispatch, }); }} diff --git a/ts/themes/switchTheme.tsx b/ts/themes/switchTheme.tsx index fecb0b225..8ffa29e80 100644 --- a/ts/themes/switchTheme.tsx +++ b/ts/themes/switchTheme.tsx @@ -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 );