mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 18:26:05 +08:00
feat: forced file naming format (#2270)
This commit is contained in:
31
apps/web/src/providers/theme-provider.tsx
Normal file
31
apps/web/src/providers/theme-provider.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { ThemeProviderProps } from '@affine/component';
|
||||
import { ThemeProvider as NextThemeProvider, useTheme } from 'next-themes';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import type React from 'react';
|
||||
import { memo, useRef } from 'react';
|
||||
|
||||
const themes = ['dark', 'light'];
|
||||
|
||||
const DesktopThemeSync = memo(function DesktopThemeSync() {
|
||||
const { theme } = useTheme();
|
||||
const lastThemeRef = useRef(theme);
|
||||
if (lastThemeRef.current !== theme) {
|
||||
if (environment.isDesktop && theme) {
|
||||
window.apis?.onThemeChange(theme);
|
||||
}
|
||||
lastThemeRef.current = theme;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
export const ThemeProvider = ({
|
||||
children,
|
||||
...props
|
||||
}: PropsWithChildren<ThemeProviderProps>) => {
|
||||
return (
|
||||
<NextThemeProvider themes={themes} enableSystem={true} {...props}>
|
||||
{children}
|
||||
<DesktopThemeSync />
|
||||
</NextThemeProvider>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user