mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-23 13:29:02 +08:00
@@ -0,0 +1,25 @@
|
||||
import { DesktopApiService } from '@affine/core/modules/desktop-api/service';
|
||||
import { useService } from '@toeverything/infra';
|
||||
import { useTheme } from 'next-themes';
|
||||
import { useRef } from 'react';
|
||||
|
||||
export const DesktopThemeSync = () => {
|
||||
const { theme } = useTheme();
|
||||
const lastThemeRef = useRef(theme);
|
||||
const onceRef = useRef(false);
|
||||
|
||||
const handler = useService(DesktopApiService).api.handler;
|
||||
|
||||
if (lastThemeRef.current !== theme || !onceRef.current) {
|
||||
if (BUILD_CONFIG.isElectron && theme) {
|
||||
handler.ui
|
||||
.handleThemeChange(theme as 'dark' | 'light' | 'system')
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
lastThemeRef.current = theme;
|
||||
onceRef.current = true;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Reference in New Issue
Block a user