You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			TypeScript
		
	
import { ipcRenderer } from 'electron';
 | 
						|
import React from 'react';
 | 
						|
import { createGlobalStyle } from 'styled-components';
 | 
						|
import { switchThemeTo } from './switchTheme';
 | 
						|
import { classicDark } from './classicDark';
 | 
						|
import { getOppositeTheme, isThemeMismatched } from '../util/theme';
 | 
						|
import { declareCSSVariables, THEME_GLOBALS } from './globals';
 | 
						|
 | 
						|
// Defaults to Classic Dark theme
 | 
						|
const SessionGlobalStyles = createGlobalStyle`
 | 
						|
  html {
 | 
						|
    ${declareCSSVariables(THEME_GLOBALS)}
 | 
						|
    ${declareCSSVariables(classicDark)}
 | 
						|
  };
 | 
						|
`;
 | 
						|
 | 
						|
export const SessionTheme = ({ children }: { children: any }) => (
 | 
						|
  <>
 | 
						|
    <SessionGlobalStyles />
 | 
						|
    {children}
 | 
						|
  </>
 | 
						|
);
 | 
						|
 | 
						|
export async function ensureThemeConsistency(): Promise<boolean> {
 | 
						|
  const theme = window.Events.getThemeSetting();
 | 
						|
 | 
						|
  return new Promise(resolve => {
 | 
						|
    ipcRenderer.send('get-native-theme');
 | 
						|
    ipcRenderer.once('send-native-theme', (_, shouldUseDarkColors) => {
 | 
						|
      const isMismatchedTheme = isThemeMismatched(theme, shouldUseDarkColors);
 | 
						|
      if (isMismatchedTheme) {
 | 
						|
        const newTheme = getOppositeTheme(theme);
 | 
						|
        void switchThemeTo({
 | 
						|
          theme: newTheme,
 | 
						|
          mainWindow: true,
 | 
						|
          usePrimaryColor: true,
 | 
						|
          dispatch: window?.inboxStore?.dispatch,
 | 
						|
        });
 | 
						|
        resolve(true); // Theme was switched
 | 
						|
      } else {
 | 
						|
        resolve(false); // Theme was not switched
 | 
						|
      }
 | 
						|
    });
 | 
						|
  });
 | 
						|
}
 |