Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / shared / lib / helpers / initElectronClassnames.ts
blobe9b6a3d69848b4f152d68c27ab124e8cb182b738
1 import { canGetInboxDesktopInfo, getInboxDesktopInfo, hasInboxDesktopFeature } from '../desktop/ipcHelpers';
2 import type { ThemeSetting } from '../themes/themes';
3 import { ColorScheme, ThemeModeSetting, electronAppTheme, getDarkThemes } from '../themes/themes';
4 import { isElectronApp, isElectronOnMac, isElectronOnWindows } from './desktop';
6 export const updateElectronThemeModeClassnames = (theme: ThemeSetting) => {
7     let prefersDark = false;
9     if (theme.Mode === ThemeModeSetting.Dark) {
10         prefersDark = true;
11     } else if (theme.Mode === ThemeModeSetting.Auto) {
12         if (canGetInboxDesktopInfo && hasInboxDesktopFeature('FullTheme')) {
13             prefersDark = getInboxDesktopInfo('colorScheme') === ColorScheme.Dark;
14         } else {
15             prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
16         }
17     }
19     const selectedTheme = prefersDark ? theme.DarkTheme : theme.LightTheme;
20     const isUsingDarkTheme = getDarkThemes().includes(selectedTheme);
22     if (isUsingDarkTheme) {
23         document.body.classList.add('is-electron-dark');
24         document.body.classList.remove('is-electron-light');
25     } else {
26         document.body.classList.remove('is-electron-dark');
27         document.body.classList.add('is-electron-light');
28     }
31 export const initElectronClassnames = () => {
32     if (isElectronApp) {
33         document.body.classList.add('is-electron');
35         if (hasInboxDesktopFeature('ThemeSelection') && canGetInboxDesktopInfo) {
36             updateElectronThemeModeClassnames(getInboxDesktopInfo('theme'));
37         } else {
38             updateElectronThemeModeClassnames(electronAppTheme);
39         }
40     }
42     if (isElectronOnMac) {
43         document.body.classList.add('is-electron-mac');
44     }
46     if (isElectronOnWindows) {
47         document.body.classList.add('is-electron-windows');
48     }