fix(electron): theme sync (#2231)

This commit is contained in:
Himself65
2023-05-04 21:00:05 -05:00
committed by GitHub
parent 33c48eed79
commit 1b12972afd
2 changed files with 13 additions and 7 deletions

View File

@@ -1,6 +1,5 @@
import { DarkModeIcon, LightModeIcon } from '@blocksuite/icons';
import { useTheme } from 'next-themes';
import { useEffect } from 'react';
import {
StyledSwitchItem,
@@ -13,11 +12,6 @@ import {
export const MenuThemeModeSwitch = () => {
const { setTheme, resolvedTheme, theme } = useTheme();
useEffect(() => {
if (environment.isDesktop) {
window.apis?.onThemeChange(resolvedTheme === 'dark' ? 'dark' : 'light');
}
}, [resolvedTheme]);
return (
<StyledThemeModeContainer>
<StyledThemeModeSwitch data-testid="change-theme-container" inMenu={true}>

View File

@@ -1,10 +1,21 @@
import type { ThemeProviderProps } from '@affine/component';
import { ThemeProvider as NextThemeProvider } from 'next-themes';
import { ThemeProvider as NextThemeProvider, useTheme } from 'next-themes';
import type { PropsWithChildren } from 'react';
import type React from 'react';
import { memo, useEffect } from 'react';
const themes = ['dark', 'light'];
const DesktopThemeSync = memo(function DesktopThemeSync() {
const { resolvedTheme } = useTheme();
useEffect(() => {
if (environment.isDesktop) {
window.apis?.onThemeChange(resolvedTheme === 'dark' ? 'dark' : 'light');
}
}, [resolvedTheme]);
return null;
});
export const ThemeProvider = ({
children,
...props
@@ -12,6 +23,7 @@ export const ThemeProvider = ({
return (
<NextThemeProvider themes={themes} enableSystem={true} {...props}>
{children}
<DesktopThemeSync />
</NextThemeProvider>
);
};