Add "cycle profiles" hotkey
This commit is contained in:
@@ -851,6 +851,7 @@
|
|||||||
"offset_spread_pages": "Toggle offset spread pages",
|
"offset_spread_pages": "Toggle offset spread pages",
|
||||||
"previous_chapter": "Previous chapter",
|
"previous_chapter": "Previous chapter",
|
||||||
"previous_page": "Previous page",
|
"previous_page": "Previous page",
|
||||||
|
"profiles": "Cycle profiles",
|
||||||
"scale_type": "Cycle image scale type",
|
"scale_type": "Cycle image scale type",
|
||||||
"scroll_backward": "Scroll backward",
|
"scroll_backward": "Scroll backward",
|
||||||
"scroll_forward": "Scroll forward",
|
"scroll_forward": "Scroll forward",
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { useEffect } from 'react';
|
|||||||
import { useTheme } from '@mui/material/styles';
|
import { useTheme } from '@mui/material/styles';
|
||||||
import { HOTKEY_SCOPES } from '@/modules/hotkeys/Hotkeys.constants.ts';
|
import { HOTKEY_SCOPES } from '@/modules/hotkeys/Hotkeys.constants.ts';
|
||||||
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
|
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
|
||||||
import { ReaderHotkey, ReadingMode } from '@/modules/reader/types/Reader.types.ts';
|
import { IReaderSettings, ReaderHotkey, ReadingMode } from '@/modules/reader/types/Reader.types.ts';
|
||||||
import { useReaderOverlayContext } from '@/modules/reader/contexts/ReaderOverlayContext.tsx';
|
import { useReaderOverlayContext } from '@/modules/reader/contexts/ReaderOverlayContext.tsx';
|
||||||
import { getNextRotationValue } from '@/modules/core/utils/ValueRotationButton.utils.ts';
|
import { getNextRotationValue } from '@/modules/core/utils/ValueRotationButton.utils.ts';
|
||||||
import {
|
import {
|
||||||
@@ -30,6 +30,31 @@ const useHotkeys = (...args: Parameters<typeof useHotKeysHook>): ReturnType<type
|
|||||||
return useHotKeysHook(keys, callback, { ...options, ...HOTKEY_SCOPES.reader }, dependencies);
|
return useHotKeysHook(keys, callback, { ...options, ...HOTKEY_SCOPES.reader }, dependencies);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateSettingCycleThrough = <Setting extends keyof IReaderSettings>(
|
||||||
|
updateSetting: ReturnType<typeof ReaderService.useCreateUpdateSetting>,
|
||||||
|
deleteSetting: ReturnType<typeof ReaderService.useCreateDeleteSetting>,
|
||||||
|
setting: Setting,
|
||||||
|
value: IReaderSettings[Setting],
|
||||||
|
values: IReaderSettings[Setting][],
|
||||||
|
isDefault: boolean,
|
||||||
|
isDefaultable: boolean,
|
||||||
|
) => {
|
||||||
|
if (isDefault) {
|
||||||
|
updateSetting(setting, values[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextValue = getNextRotationValue(values.indexOf(value), values, isDefaultable);
|
||||||
|
|
||||||
|
const isDefaultNextValue = nextValue === undefined;
|
||||||
|
if (isDefaultNextValue) {
|
||||||
|
deleteSetting(setting);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSetting(setting, nextValue);
|
||||||
|
};
|
||||||
|
|
||||||
const DEFAULT_MANGA: MangaIdInfo = { id: -1 };
|
const DEFAULT_MANGA: MangaIdInfo = { id: -1 };
|
||||||
|
|
||||||
const CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION: Record<ReadingMode, ScrollDirection> = {
|
const CONTINUOUS_READING_MODE_TO_SCROLL_DIRECTION: Record<ReadingMode, ScrollDirection> = {
|
||||||
@@ -49,8 +74,16 @@ export const ReaderHotkeys = ({
|
|||||||
const { enableScope, disableScope } = useHotkeysContext();
|
const { enableScope, disableScope } = useHotkeysContext();
|
||||||
const { manga } = useReaderStateMangaContext();
|
const { manga } = useReaderStateMangaContext();
|
||||||
const { isVisible, setIsVisible } = useReaderOverlayContext();
|
const { isVisible, setIsVisible } = useReaderOverlayContext();
|
||||||
const { hotkeys, pageScaleMode, shouldStretchPage, shouldOffsetDoubleSpreads, readingMode, readingDirection } =
|
const {
|
||||||
ReaderService.useSettings();
|
hotkeys,
|
||||||
|
pageScaleMode,
|
||||||
|
shouldStretchPage,
|
||||||
|
shouldOffsetDoubleSpreads,
|
||||||
|
readingMode,
|
||||||
|
readingDirection,
|
||||||
|
defaultProfile,
|
||||||
|
profiles,
|
||||||
|
} = ReaderService.useSettings();
|
||||||
|
|
||||||
const openChapter = ReaderControls.useOpenChapter();
|
const openChapter = ReaderControls.useOpenChapter();
|
||||||
const openPage = ReaderControls.useOpenPage();
|
const openPage = ReaderControls.useOpenPage();
|
||||||
@@ -108,23 +141,15 @@ export const ReaderHotkeys = ({
|
|||||||
useHotkeys(
|
useHotkeys(
|
||||||
hotkeys[ReaderHotkey.CYCLE_SCALE_TYPE],
|
hotkeys[ReaderHotkey.CYCLE_SCALE_TYPE],
|
||||||
() => {
|
() => {
|
||||||
if (pageScaleMode.isDefault) {
|
updateSettingCycleThrough(
|
||||||
updateSetting('pageScaleMode', READER_PAGE_SCALE_MODE_VALUES[0]);
|
updateSetting,
|
||||||
return;
|
deleteSetting,
|
||||||
}
|
'pageScaleMode',
|
||||||
|
pageScaleMode.value,
|
||||||
const nextValue = getNextRotationValue(
|
|
||||||
READER_PAGE_SCALE_MODE_VALUES.indexOf(pageScaleMode.value),
|
|
||||||
READER_PAGE_SCALE_MODE_VALUES,
|
READER_PAGE_SCALE_MODE_VALUES,
|
||||||
|
pageScaleMode.isDefault,
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (nextValue === undefined) {
|
|
||||||
deleteSetting('pageScaleMode');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateSetting('pageScaleMode', nextValue);
|
|
||||||
},
|
},
|
||||||
[updateSetting, deleteSetting, pageScaleMode],
|
[updateSetting, deleteSetting, pageScaleMode],
|
||||||
);
|
);
|
||||||
@@ -138,6 +163,17 @@ export const ReaderHotkeys = ({
|
|||||||
() => updateSetting('shouldOffsetDoubleSpreads', !shouldOffsetDoubleSpreads.value),
|
() => updateSetting('shouldOffsetDoubleSpreads', !shouldOffsetDoubleSpreads.value),
|
||||||
[updateSetting, shouldOffsetDoubleSpreads.value],
|
[updateSetting, shouldOffsetDoubleSpreads.value],
|
||||||
);
|
);
|
||||||
|
useHotkeys(hotkeys[ReaderHotkey.CYCLE_PROFILES], () => {
|
||||||
|
updateSettingCycleThrough(
|
||||||
|
updateSetting,
|
||||||
|
deleteSetting,
|
||||||
|
'defaultProfile',
|
||||||
|
defaultProfile.value,
|
||||||
|
profiles,
|
||||||
|
defaultProfile.isDefault,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
enableScope(HotkeyScope.READER);
|
enableScope(HotkeyScope.READER);
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const READER_HOTKEY_TO_TITLE: Record<ReaderHotkey, TranslationKey> = {
|
|||||||
[ReaderHotkey.CYCLE_SCALE_TYPE]: 'reader.settings.hotkey.scale_type',
|
[ReaderHotkey.CYCLE_SCALE_TYPE]: 'reader.settings.hotkey.scale_type',
|
||||||
[ReaderHotkey.STRETCH_IMAGE]: 'reader.settings.hotkey.stretch_image',
|
[ReaderHotkey.STRETCH_IMAGE]: 'reader.settings.hotkey.stretch_image',
|
||||||
[ReaderHotkey.OFFSET_SPREAD_PAGES]: 'reader.settings.hotkey.offset_spread_pages',
|
[ReaderHotkey.OFFSET_SPREAD_PAGES]: 'reader.settings.hotkey.offset_spread_pages',
|
||||||
|
[ReaderHotkey.CYCLE_PROFILES]: 'reader.settings.hotkey.profiles',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ReaderSettingHotkey = ({
|
export const ReaderSettingHotkey = ({
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ export const DEFAULT_READER_SETTINGS: IReaderSettings = {
|
|||||||
[ReaderHotkey.CYCLE_SCALE_TYPE]: ['i'],
|
[ReaderHotkey.CYCLE_SCALE_TYPE]: ['i'],
|
||||||
[ReaderHotkey.STRETCH_IMAGE]: ['f'],
|
[ReaderHotkey.STRETCH_IMAGE]: ['f'],
|
||||||
[ReaderHotkey.OFFSET_SPREAD_PAGES]: ['o'],
|
[ReaderHotkey.OFFSET_SPREAD_PAGES]: ['o'],
|
||||||
|
[ReaderHotkey.CYCLE_PROFILES]: ['p'],
|
||||||
},
|
},
|
||||||
imagePreLoadAmount: 5,
|
imagePreLoadAmount: 5,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -206,6 +206,7 @@ export enum ReaderHotkey {
|
|||||||
CYCLE_SCALE_TYPE,
|
CYCLE_SCALE_TYPE,
|
||||||
STRETCH_IMAGE,
|
STRETCH_IMAGE,
|
||||||
OFFSET_SPREAD_PAGES,
|
OFFSET_SPREAD_PAGES,
|
||||||
|
CYCLE_PROFILES,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReaderPagerProps
|
export interface ReaderPagerProps
|
||||||
|
|||||||
Reference in New Issue
Block a user