mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
fix: theme not being persisted issue (#2283)
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
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'];
|
||||
|
||||
// a workaround to sync theme to electron
|
||||
let firstRender = true;
|
||||
|
||||
const DesktopThemeSync = memo(function DesktopThemeSync() {
|
||||
const { theme } = useTheme();
|
||||
const lastThemeRef = useRef(theme);
|
||||
if (lastThemeRef.current !== theme) {
|
||||
if (lastThemeRef.current !== theme || firstRender) {
|
||||
if (environment.isDesktop && theme) {
|
||||
window.apis?.ui.handleThemeChange(theme as 'dark' | 'light' | 'system');
|
||||
}
|
||||
lastThemeRef.current = theme;
|
||||
firstRender = false;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user