Skip to content

Commit

Permalink
fix: readerDefaultConfig locally and across the app
Browse files Browse the repository at this point in the history
disable ttsVoice global readerConfig persistence

I also create a fresh copy of annotation_defaultColor on
READER_DEFAULT_CONFIG_SET_REQUEST action
  • Loading branch information
panaC committed Dec 3, 2024
1 parent 815077d commit 6570a30
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/common/redux/actions/reader/configSetDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { ReaderConfig } from "readium-desktop/common/models/reader";
import { Action } from "readium-desktop/common/models/redux";
import { readerConfigInitialState } from "../../states/reader";
import { isNotNil } from "readium-desktop/utils/nil";

export const ID = "READER_DEFAULT_CONFIG_SET_REQUEST";

Expand All @@ -18,6 +19,15 @@ export interface Payload {
export function build(config: ReaderConfig = readerConfigInitialState):
Action<typeof ID, Payload> {

const configCopy = {
...config,
};
if (isNotNil(configCopy["ttsVoice"])) {
configCopy["ttsVoice"] = null;
}
if (isNotNil(configCopy["annotation_defaultColor"])) {
configCopy["annotation_defaultColor"] = { ...configCopy["annotation_defaultColor"] };
}
return {
type: ID,
payload: {
Expand Down
5 changes: 4 additions & 1 deletion src/main/redux/sagas/win/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ function* winOpen(action: winActions.reader.openSucess.TAction) {
reader: {
...reader?.reduxState || {},
// see issue https://github.com/edrlab/thorium-reader/issues/2532
defaultConfig: readerDefaultConfig,
defaultConfig: {
...readerDefaultConfig,
ttsVoice: null, // disable ttsVoice global preference for readium/speech lib
},
transientConfig: {
font: transientConfigMerge.font,
fontSize: transientConfigMerge.fontSize,
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/common/hooks/useReaderConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ export const useDiffBoolBetweenReaderConfigAndDefaultConfig = () => {
const diff = React.useMemo(() => {

for (const v of ObjectKeys(config)) {

if (v === "ttsVoice") {
// skip ttsVoice with readium/speech
continue ;
}
if (!equals(config[v], defaultConfig[v])) {
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/reader/components/ReaderSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,8 @@ const SaveResetApplyPreset = () => {

const cb = React.useCallback(() => {

setReaderConfig(readerDefaultConfig);
const { ttsVoice: __ttsVoice, ...readerDefaultConfigCopy} = readerDefaultConfig;
setReaderConfig(readerDefaultConfigCopy);

if (allowCustomCheckboxChecked) {
if (publisherConfigOverrided) {
Expand Down

0 comments on commit 6570a30

Please sign in to comment.