Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/renderer/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ import {
import { clearState, loadState, saveState } from '../utils/storage';
import {
DEFAULT_DAY_COLOR_SCHEME,
DEFAULT_DAY_HIGH_CONTRAST_COLOR_SCHEME,
DEFAULT_NIGHT_COLOR_SCHEME,
DEFAULT_NIGHT_HIGH_CONTRAST_COLOR_SCHEME,
mapThemeModeToColorMode,
mapThemeModeToColorScheme,
} from '../utils/theme';
Expand Down Expand Up @@ -276,8 +278,18 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
);

setColorMode(colorMode);
setDayScheme(colorScheme ?? DEFAULT_DAY_COLOR_SCHEME);
setNightScheme(colorScheme ?? DEFAULT_NIGHT_COLOR_SCHEME);

// When colorScheme is null (System theme), use appropriate fallbacks
// based on whether high contrast is enabled
const dayFallback = settings.increaseContrast
? DEFAULT_DAY_HIGH_CONTRAST_COLOR_SCHEME
: DEFAULT_DAY_COLOR_SCHEME;
const nightFallback = settings.increaseContrast
? DEFAULT_NIGHT_HIGH_CONTRAST_COLOR_SCHEME
: DEFAULT_NIGHT_COLOR_SCHEME;

setDayScheme(colorScheme ?? dayFallback);
setNightScheme(colorScheme ?? nightFallback);
}, [
settings.theme,
settings.increaseContrast,
Expand Down
20 changes: 19 additions & 1 deletion src/renderer/utils/theme.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Theme } from '../types';
import { mapThemeModeToColorMode, mapThemeModeToColorScheme } from './theme';
import {
DEFAULT_DAY_COLOR_SCHEME,
DEFAULT_DAY_HIGH_CONTRAST_COLOR_SCHEME,
DEFAULT_NIGHT_COLOR_SCHEME,
DEFAULT_NIGHT_HIGH_CONTRAST_COLOR_SCHEME,
mapThemeModeToColorMode,
mapThemeModeToColorScheme,
} from './theme';

describe('renderer/utils/theme.ts', () => {
it('should map theme mode to github primer color mode', () => {
Expand Down Expand Up @@ -53,5 +60,16 @@ describe('renderer/utils/theme.ts', () => {
'dark_dimmed_high_contrast',
);
expect(mapThemeModeToColorScheme(Theme.SYSTEM, false)).toBe(null);
expect(mapThemeModeToColorScheme(Theme.SYSTEM, true)).toBe(null);
});

it('should export high contrast color scheme constants', () => {
expect(DEFAULT_DAY_HIGH_CONTRAST_COLOR_SCHEME).toBe('light_high_contrast');
expect(DEFAULT_NIGHT_HIGH_CONTRAST_COLOR_SCHEME).toBe('dark_high_contrast');
});

it('should export default color scheme constants', () => {
expect(DEFAULT_DAY_COLOR_SCHEME).toBe('light');
expect(DEFAULT_NIGHT_COLOR_SCHEME).toBe('dark');
});
});
2 changes: 2 additions & 0 deletions src/renderer/utils/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Theme } from '../types';

export const DEFAULT_DAY_COLOR_SCHEME = 'light';
export const DEFAULT_NIGHT_COLOR_SCHEME = 'dark';
export const DEFAULT_DAY_HIGH_CONTRAST_COLOR_SCHEME = 'light_high_contrast';
export const DEFAULT_NIGHT_HIGH_CONTRAST_COLOR_SCHEME = 'dark_high_contrast';

export function mapThemeModeToColorMode(themeMode: Theme): ColorModeWithAuto {
switch (themeMode) {
Expand Down