feat: add options to reset settings in the config dialog, closes #1111 (#1475)

This commit is contained in:
Huang Xin
2025-06-26 15:59:34 +08:00
committed by GitHub
parent 460d37c656
commit bc2c3a2c9a
34 changed files with 372 additions and 92 deletions
@@ -1,8 +1,6 @@
import { useReaderStore } from '@/store/readerStore';
import { useNotebookStore } from '@/store/notebookStore';
import { isTauriAppPlatform } from '@/services/environment';
import useShortcuts from '@/hooks/useShortcuts';
import useBooksManager from './useBooksManager';
import { useSidebarStore } from '@/store/sidebarStore';
import { useSettingsStore } from '@/store/settingsStore';
import { getStyles } from '@/utils/style';
@@ -10,6 +8,8 @@ import { tauriHandleToggleFullScreen, tauriQuitApp } from '@/utils/window';
import { eventDispatcher } from '@/utils/event';
import { MAX_ZOOM_LEVEL, MIN_ZOOM_LEVEL, ZOOM_STEP } from '@/services/constants';
import { viewPagination } from './usePagination';
import useShortcuts from '@/hooks/useShortcuts';
import useBooksManager from './useBooksManager';
interface UseBookShortcutsProps {
sideBarBookKey: string | null;
@@ -0,0 +1,28 @@
import { Dispatch, SetStateAction } from 'react';
import { useEnv } from '@/context/EnvContext';
import { ViewSettings } from '@/types/book';
type SetterKey = keyof ViewSettings;
type SetterValue = SetStateAction<string> & SetStateAction<number> & SetStateAction<boolean>;
type StateSetters = Partial<{
[Key in SetterKey]: Dispatch<SetterValue>;
}>;
export const useResetViewSettings = () => {
const { appService } = useEnv();
const resetToDefaults = (setters: StateSetters) => {
if (!appService) return;
const defaultSettings = appService.getDefaultViewSettings();
Object.entries(setters).forEach(([settingKey, setter]) => {
const freshValue = defaultSettings[settingKey as SetterKey];
if (freshValue !== undefined) {
setter(freshValue as SetterValue);
}
});
};
return resetToDefaults;
};