Fix auto theme mode not working on Foliate view

This commit is contained in:
chrox
2024-11-20 18:14:52 +01:00
parent 8ce4c46b46
commit 7c9ed815ad
2 changed files with 11 additions and 2 deletions
@@ -107,6 +107,13 @@ const FoliateViewer: React.FC<{
onRelocate: progressRelocateHandler,
});
useEffect(() => {
if (viewRef.current) {
const viewSettings = getViewSettings(bookKey)!;
viewRef.current.renderer.setStyles?.(getStyles(viewSettings, themeCode));
}
}, [themeCode]);
useEffect(() => {
if (isViewCreated.current) return;
const openBook = async () => {
@@ -120,6 +127,8 @@ const FoliateViewer: React.FC<{
await view.open(bookDoc);
const viewSettings = getViewSettings(bookKey)!;
view.renderer.setStyles?.(getStyles(viewSettings, themeCode));
const isScrolled = viewSettings.scrolled!;
const marginPx = viewSettings.marginPx!;
const gapPercent = viewSettings.gapPercent!;
@@ -147,7 +156,6 @@ const FoliateViewer: React.FC<{
await view.goToFraction(0);
}
setViewInited(true);
view.renderer.setStyles?.(getStyles(viewSettings, themeCode));
window.addEventListener('message', handleClickTurnPage);
};
+2 -1
View File
@@ -73,6 +73,7 @@ export const useTheme = () => {
localStorage.setItem('themeMode', themeMode);
localStorage.setItem('themeColor', themeColor);
}
const isDarkMode = themeMode === 'dark' || (themeMode === 'auto' && systemIsDarkMode);
const theme = themes.find((t) => t.name === themeColor);
const palette = isDarkMode ? theme!.colors.dark : theme!.colors.light;
setThemeCode({
@@ -80,7 +81,7 @@ export const useTheme = () => {
fg: palette['base-content'],
primary: palette.primary,
});
}, [themeMode, themeColor]);
}, [themeMode, themeColor, isDarkMode]);
const updateThemeMode = (mode: ThemeMode) => setThemeMode(mode);
const updateThemeColor = (color: string) => setThemeColor(color);