fix(electron): theme sync (#2231)
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { DarkModeIcon, LightModeIcon } from '@blocksuite/icons';
|
import { DarkModeIcon, LightModeIcon } from '@blocksuite/icons';
|
||||||
import { useTheme } from 'next-themes';
|
import { useTheme } from 'next-themes';
|
||||||
import { useEffect } from 'react';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
StyledSwitchItem,
|
StyledSwitchItem,
|
||||||
@@ -13,11 +12,6 @@ import {
|
|||||||
|
|
||||||
export const MenuThemeModeSwitch = () => {
|
export const MenuThemeModeSwitch = () => {
|
||||||
const { setTheme, resolvedTheme, theme } = useTheme();
|
const { setTheme, resolvedTheme, theme } = useTheme();
|
||||||
useEffect(() => {
|
|
||||||
if (environment.isDesktop) {
|
|
||||||
window.apis?.onThemeChange(resolvedTheme === 'dark' ? 'dark' : 'light');
|
|
||||||
}
|
|
||||||
}, [resolvedTheme]);
|
|
||||||
return (
|
return (
|
||||||
<StyledThemeModeContainer>
|
<StyledThemeModeContainer>
|
||||||
<StyledThemeModeSwitch data-testid="change-theme-container" inMenu={true}>
|
<StyledThemeModeSwitch data-testid="change-theme-container" inMenu={true}>
|
||||||
|
|||||||
@@ -1,10 +1,21 @@
|
|||||||
import type { ThemeProviderProps } from '@affine/component';
|
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 { PropsWithChildren } from 'react';
|
||||||
import type React from 'react';
|
import type React from 'react';
|
||||||
|
import { memo, useEffect } from 'react';
|
||||||
|
|
||||||
const themes = ['dark', 'light'];
|
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 = ({
|
export const ThemeProvider = ({
|
||||||
children,
|
children,
|
||||||
...props
|
...props
|
||||||
@@ -12,6 +23,7 @@ export const ThemeProvider = ({
|
|||||||
return (
|
return (
|
||||||
<NextThemeProvider themes={themes} enableSystem={true} {...props}>
|
<NextThemeProvider themes={themes} enableSystem={true} {...props}>
|
||||||
{children}
|
{children}
|
||||||
|
<DesktopThemeSync />
|
||||||
</NextThemeProvider>
|
</NextThemeProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user