mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
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 type { PropsWithChildren } from 'react';
|
||||
import type React from 'react';
|
||||
import { memo, useEffect } from 'react';
|
||||
import { memo, useRef } 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');
|
||||
const { theme } = useTheme();
|
||||
const lastThemeRef = useRef(theme);
|
||||
if (lastThemeRef.current !== theme) {
|
||||
if (environment.isDesktop && theme) {
|
||||
window.apis?.onThemeChange(theme);
|
||||
}
|
||||
}, [resolvedTheme]);
|
||||
lastThemeRef.current = theme;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user