fix(electron): system theme (#2237)
This commit is contained in:
@@ -2,17 +2,19 @@ import type { ThemeProviderProps } from '@affine/component';
|
|||||||
import { ThemeProvider as NextThemeProvider, useTheme } 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';
|
import { memo, useRef } from 'react';
|
||||||
|
|
||||||
const themes = ['dark', 'light'];
|
const themes = ['dark', 'light'];
|
||||||
|
|
||||||
const DesktopThemeSync = memo(function DesktopThemeSync() {
|
const DesktopThemeSync = memo(function DesktopThemeSync() {
|
||||||
const { resolvedTheme } = useTheme();
|
const { theme } = useTheme();
|
||||||
useEffect(() => {
|
const lastThemeRef = useRef(theme);
|
||||||
if (environment.isDesktop) {
|
if (lastThemeRef.current !== theme) {
|
||||||
window.apis?.onThemeChange(resolvedTheme === 'dark' ? 'dark' : 'light');
|
if (environment.isDesktop && theme) {
|
||||||
|
window.apis?.onThemeChange(theme);
|
||||||
|
}
|
||||||
|
lastThemeRef.current = theme;
|
||||||
}
|
}
|
||||||
}, [resolvedTheme]);
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user