From 87fbb4687d84937dd9cae4411fe02910e980113b Mon Sep 17 00:00:00 2001 From: Pierre Leroux Date: Wed, 4 Sep 2024 22:53:05 +0200 Subject: [PATCH 1/3] chore (refactor): comment session.state unused and disable the force reset of the global defaultConfig at start session.state is Thorium3.0 always enabled, so a hack was to force set to true in main/lib and not set it in reader view. Just commented, the code is easily revertable I commented in memory.ts the reset of the reader.defaultConfig preloadedState, needed to set the default config of a new publication. Now each new publication has the copy of the last publication configuration, thorium freeshly started or not. --- src/common/redux/actions/session/enable.ts | 30 +-- src/common/redux/actions/session/index.ts | 4 +- src/common/redux/reducers/session.ts | 16 +- src/common/redux/states/session.ts | 2 +- src/main/redux/middleware/sync.ts | 2 +- src/main/redux/sagas/reader.ts | 19 +- src/main/redux/sagas/win/library.ts | 11 +- src/main/redux/store/memory.ts | 43 ++-- .../components/settings/SessionSettings.tsx | 186 +++++++++--------- src/renderer/library/redux/middleware/sync.ts | 2 +- src/renderer/reader/components/Reader.tsx | 72 +++---- src/renderer/reader/redux/middleware/sync.ts | 6 +- .../reader/redux/sagas/readerConfig.ts | 8 +- 13 files changed, 207 insertions(+), 194 deletions(-) diff --git a/src/common/redux/actions/session/enable.ts b/src/common/redux/actions/session/enable.ts index d4298058e..075625381 100644 --- a/src/common/redux/actions/session/enable.ts +++ b/src/common/redux/actions/session/enable.ts @@ -5,22 +5,22 @@ // that can be found in the LICENSE file exposed on Github (readium) in the project repository. // ==LICENSE-END== -import { Action } from "readium-desktop/common/models/redux"; +// import { Action } from "readium-desktop/common/models/redux"; -export const ID = "SESSION_ENABLE"; +// export const ID = "SESSION_ENABLE"; -export interface Payload { - value: boolean; -} +// export interface Payload { +// value: boolean; +// } -export function build(value: boolean): Action { +// export function build(value: boolean): Action { - return { - type: ID, - payload: { - value, - }, - }; -} -build.toString = () => ID; // Redux StringableActionCreator -export type TAction = ReturnType; +// return { +// type: ID, +// payload: { +// value, +// }, +// }; +// } +// build.toString = () => ID; // Redux StringableActionCreator +// export type TAction = ReturnType; diff --git a/src/common/redux/actions/session/index.ts b/src/common/redux/actions/session/index.ts index 9a2bd009a..97da2a31c 100644 --- a/src/common/redux/actions/session/index.ts +++ b/src/common/redux/actions/session/index.ts @@ -5,10 +5,10 @@ // that can be found in the LICENSE file exposed on Github (readium) in the project repository. // ==LICENSE-END== -import * as enable from "./enable"; +// import * as enable from "./enable"; import * as save from "./save"; export { save, - enable, + // enable, }; diff --git a/src/common/redux/reducers/session.ts b/src/common/redux/reducers/session.ts index 3a9b9d946..c50729ffc 100644 --- a/src/common/redux/reducers/session.ts +++ b/src/common/redux/reducers/session.ts @@ -11,23 +11,23 @@ import { sessionActions } from "../actions"; import { ISessionState } from "../states/session"; const initialState: ISessionState = { - state: false, + // state: false, save: false, }; function sessionReducer_( state = initialState, - action: sessionActions.enable.TAction | sessionActions.save.TAction, + action: /*sessionActions.enable.TAction |*/ sessionActions.save.TAction, ): ISessionState { switch (action.type) { - case sessionActions.enable.ID: - return { - state: action.payload.value, - save: state.save, - }; + // case sessionActions.enable.ID: + // return { + // state: action.payload.value, + // save: state.save, + // }; case sessionActions.save.ID: return { - state: state.state, + // state: state.state, save: action.payload.value, }; default: diff --git a/src/common/redux/states/session.ts b/src/common/redux/states/session.ts index 4f2c67b41..1d31b25ed 100644 --- a/src/common/redux/states/session.ts +++ b/src/common/redux/states/session.ts @@ -6,6 +6,6 @@ // ==LICENSE-END== export interface ISessionState { - state: boolean; + // state: boolean; save: boolean; } diff --git a/src/main/redux/middleware/sync.ts b/src/main/redux/middleware/sync.ts index aef26cfb5..73cbbda88 100644 --- a/src/main/redux/middleware/sync.ts +++ b/src/main/redux/middleware/sync.ts @@ -55,7 +55,7 @@ const SYNCHRONIZABLE_ACTIONS: string[] = [ // authActions.done.ID, // not used authActions.cancel.ID, - sessionActions.enable.ID, + // sessionActions.enable.ID, lcpActions.unlockPublicationWithPassphrase.ID, diff --git a/src/main/redux/sagas/reader.ts b/src/main/redux/sagas/reader.ts index bf31a6216..1422dfb39 100644 --- a/src/main/redux/sagas/reader.ts +++ b/src/main/redux/sagas/reader.ts @@ -203,15 +203,16 @@ function* readerOpenRequest(action: readerActions.openRequest.TAction) { state.win.registry.reader[publicationIdentifier]?.reduxState || {} as IReaderStateReader, ); - const sessionIsEnabled = yield* selectTyped( - (state: RootState) => state.session.state, - ); - if (!sessionIsEnabled) { - const reduxDefaultConfig = yield* selectTyped( - (state: RootState) => state.reader.defaultConfig, - ); - reduxState.config = reduxDefaultConfig; - } + // session always enabled + // const sessionIsEnabled = yield* selectTyped( + // (state: RootState) => state.session.state, + // ); + // if (!sessionIsEnabled) { + // const reduxDefaultConfig = yield* selectTyped( + // (state: RootState) => state.reader.defaultConfig, + // ); + // reduxState.config = reduxDefaultConfig; + // } const winBound = yield* callTyped(getWinBound, publicationIdentifier); diff --git a/src/main/redux/sagas/win/library.ts b/src/main/redux/sagas/win/library.ts index 72a278587..d16656add 100644 --- a/src/main/redux/sagas/win/library.ts +++ b/src/main/redux/sagas/win/library.ts @@ -107,7 +107,7 @@ function* winOpen(action: winActions.library.openSucess.TAction) { tag: [], }, session: { - state: state.session.state, + // state: state.session.state, save: state.session.save, }, }; @@ -195,9 +195,10 @@ function* winClose(_action: winActions.library.closed.TAction) { if (readersArray.length) { - const sessionIsEnabled = yield* selectTyped((state: RootState) => state.session.state); - debug(sessionIsEnabled ? "session enabled destroy reader" : "session not enabled close reader"); - if (sessionIsEnabled) { + // session always enabled by default + // const sessionIsEnabled = yield* selectTyped((state: RootState) => state.session.state); + // debug(sessionIsEnabled ? "session enabled destroy reader" : "session not enabled close reader"); + // if (sessionIsEnabled) { delay(100); @@ -224,7 +225,7 @@ function* winClose(_action: winActions.library.closed.TAction) { // ); // debug("result:", messageValue.response); // value = messageValue.response; - } + // } yield all( readersArray.map( diff --git a/src/main/redux/store/memory.ts b/src/main/redux/store/memory.ts index 6ae1d5db4..f6e667005 100644 --- a/src/main/redux/store/memory.ts +++ b/src/main/redux/store/memory.ts @@ -22,8 +22,6 @@ import createSagaMiddleware, { SagaMiddleware } from "redux-saga"; import { applyPatch } from "rfc6902"; import { reduxPersistMiddleware } from "../middleware/persistence"; -import { readerConfigInitialState } from "readium-desktop/common/redux/states/reader"; -import { defaultDisableRTLFLip } from "readium-desktop/common/redux/states/renderer/rtlFlip"; // import { composeWithDevTools } from "remote-redux-devtools"; const REDUX_REMOTE_DEVTOOLS_PORT = 7770; @@ -212,22 +210,31 @@ export async function initStore() debug("REDUX STATE VALUE :: ", typeof reduxState, reduxState ? Object.keys(reduxState) : "nil"); // debug(reduxState); - const forceDisableReaderDefaultConfigAndSessionForTheNewUI: Partial = { - reader: { - defaultConfig: readerConfigInitialState, - disableRTLFlip: reduxState?.reader?.disableRTLFlip || { disabled: defaultDisableRTLFLip }, - }, - session: { - state: true, - save: reduxState?.session?.save || false, - }, - }; - const preloadedState = reduxState ? { - ...reduxState, - ...forceDisableReaderDefaultConfigAndSessionForTheNewUI, - } : { - ...forceDisableReaderDefaultConfigAndSessionForTheNewUI, - }; + // const forceDisableReaderDefaultConfigAndSessionForTheNewUI: Partial = { + // reader: { + + // // reader default config could be removed + // // defaultConfig: readerConfigInitialState, + + // // just disableRTLFlip use yet + // disableRTLFlip: reduxState?.reader?.disableRTLFlip || { disabled: defaultDisableRTLFLip }, + // }, + // session: { + + // // not used anymore, just force to true in main and lib, but not declared in reader (false by default) + // // state: true, + + // // save is used to know if the session must be saved at the end + // // save: reduxState?.session?.save || false, + // }, + // }; + // const preloadedState = reduxState ? { + // ...reduxState, + // ...forceDisableReaderDefaultConfigAndSessionForTheNewUI, + // } : { + // ...forceDisableReaderDefaultConfigAndSessionForTheNewUI, + // }; + const preloadedState = reduxState ? { ...reduxState } : {}; const sagaMiddleware = createSagaMiddleware(); diff --git a/src/renderer/library/components/settings/SessionSettings.tsx b/src/renderer/library/components/settings/SessionSettings.tsx index 8705d504b..ecf19f582 100644 --- a/src/renderer/library/components/settings/SessionSettings.tsx +++ b/src/renderer/library/components/settings/SessionSettings.tsx @@ -5,104 +5,104 @@ // that can be found in the LICENSE file exposed on Github (readium) in the project repository. // ==LICENSE-END== -import * as React from "react"; -import { connect } from "react-redux"; -import * as DoneIcon from "readium-desktop/renderer/assets/icons/done.svg"; -import * as stylesGlobal from "readium-desktop/renderer/assets/styles/global.scss"; -import { - TranslatorProps, withTranslator, -} from "readium-desktop/renderer/common/components/hoc/translator"; -import { ILibraryRootState } from "readium-desktop/common/redux/states/renderer/libraryRootState"; -import { TDispatch } from "readium-desktop/typings/redux"; +// import * as React from "react"; +// import { connect } from "react-redux"; +// import * as DoneIcon from "readium-desktop/renderer/assets/icons/done.svg"; +// import * as stylesGlobal from "readium-desktop/renderer/assets/styles/global.scss"; +// import { +// TranslatorProps, withTranslator, +// } from "readium-desktop/renderer/common/components/hoc/translator"; +// import { ILibraryRootState } from "readium-desktop/common/redux/states/renderer/libraryRootState"; +// import { TDispatch } from "readium-desktop/typings/redux"; -import SVG from "../../../common/components/SVG"; -import { sessionActions } from "readium-desktop/common/redux/actions"; +// import SVG from "../../../common/components/SVG"; +// import { sessionActions } from "readium-desktop/common/redux/actions"; -// eslint-disable-next-line @typescript-eslint/no-empty-interface -interface IBaseProps extends TranslatorProps { -} -// IProps may typically extend: -// RouteComponentProps -// ReturnType -// ReturnType -// eslint-disable-next-line @typescript-eslint/no-empty-interface -interface IProps extends IBaseProps, ReturnType, ReturnType { -} +// // eslint-disable-next-line @typescript-eslint/no-empty-interface +// interface IBaseProps extends TranslatorProps { +// } +// // IProps may typically extend: +// // RouteComponentProps +// // ReturnType +// // ReturnType +// // eslint-disable-next-line @typescript-eslint/no-empty-interface +// interface IProps extends IBaseProps, ReturnType, ReturnType { +// } -class SessionSettings extends React.Component { +// class SessionSettings extends React.Component { - constructor(props: IProps) { - super(props); - this.state = { - sessionEnabled: false, - }; - } +// constructor(props: IProps) { +// super(props); +// this.state = { +// sessionEnabled: false, +// }; +// } - public render(): React.ReactElement<{}> { - const { __ } = this.props; - return ( - <> -
-
-

{__("settings.session.title")}

-
-
-
- this.props.setSession(true)} - checked={this.props.session === true} - /> - -
-
- this.props.setSession(false)} - checked={this.props.session === false} - /> - -
-
-
- - ); - } -} +// public render(): React.ReactElement<{}> { +// const { __ } = this.props; +// return ( +// <> +//
+//
+//

{__("settings.session.title")}

+//
+//
+//
+// this.props.setSession(true)} +// checked={this.props.session === true} +// /> +// +//
+//
+// this.props.setSession(false)} +// checked={this.props.session === false} +// /> +// +//
+//
+//
+// +// ); +// } +// } -const mapStateToProps = (state: ILibraryRootState, _props: IBaseProps) => { - return { - locale: state.i18n.locale, - session: state.session.state, - }; -}; +// const mapStateToProps = (state: ILibraryRootState, _props: IBaseProps) => { +// return { +// locale: state.i18n.locale, +// session: state.session.state, +// }; +// }; -const mapDispatchToProps = (dispatch: TDispatch, _props: IBaseProps) => { - return { - setSession: (enable: boolean) => { - dispatch(sessionActions.enable.build(enable)); - }, - }; -}; +// const mapDispatchToProps = (dispatch: TDispatch, _props: IBaseProps) => { +// return { +// setSession: (enable: boolean) => { +// dispatch(sessionActions.enable.build(enable)); +// }, +// }; +// }; -export default connect(mapStateToProps, mapDispatchToProps)(withTranslator(SessionSettings)); +// export default connect(mapStateToProps, mapDispatchToProps)(withTranslator(SessionSettings)); diff --git a/src/renderer/library/redux/middleware/sync.ts b/src/renderer/library/redux/middleware/sync.ts index 5fb6ef6e7..dc1bd313b 100644 --- a/src/renderer/library/redux/middleware/sync.ts +++ b/src/renderer/library/redux/middleware/sync.ts @@ -33,7 +33,7 @@ const SYNCHRONIZABLE_ACTIONS: string[] = [ downloadActions.abort.ID, - sessionActions.enable.ID, + // sessionActions.enable.ID, lcpActions.renewPublicationLicense.ID, lcpActions.returnPublication.ID, diff --git a/src/renderer/reader/components/Reader.tsx b/src/renderer/reader/components/Reader.tsx index acb70717f..fc2108399 100644 --- a/src/renderer/reader/components/Reader.tsx +++ b/src/renderer/reader/components/Reader.tsx @@ -538,31 +538,31 @@ class Reader extends React.Component { console.log(`highlightsClickListen MOUNTER STATE EMPTY -- mounterStateMap: [${JSON.stringify(mounterStateMap, null, 4)}]`); return; } - + const mounterStateItem = mounterStateMap.find(([_uuid, mounterState]) => mounterState.ref.id === highlight.id && mounterState.href === href); - + if (!mounterStateItem) { console.log(`highlightsClickListen CANNOT FIND MOUNTER -- href: [${href}] ref.id: [${highlight.id}] mounterStateMap: [${JSON.stringify(mounterStateMap, null, 4)}]`); return; } - + const [mounterStateItemUuid] = mounterStateItem; // mounterStateItem[0] - + const handlerStateMap = store.getState()?.reader.highlight.handler; if (!handlerStateMap?.length) { console.log(`highlightsClickListen HANDLER STATE EMPTY -- handlerStateMap: [${JSON.stringify(handlerStateMap, null, 4)}]`); return; } - + const handlerStateItem = handlerStateMap.find(([uuid, _handlerState]) => uuid === mounterStateItemUuid); - + if (!handlerStateItem) { console.log(`dispatchClick CANNOT FIND HANDLER -- uuid: [${mounterStateItemUuid}] handlerStateMap: [${JSON.stringify(handlerStateMap, null, 4)}]`); return; } - + const [uuid, handlerState] = handlerStateItem; - + console.log(`dispatchClick CLICK ACTION ... -- uuid: [${uuid}] handlerState: [${JSON.stringify(handlerState, null, 4)}]`); this.handleMenuButtonClick(true, "tab-annotation", true, uuid); @@ -698,7 +698,7 @@ class Reader extends React.Component { // {this.state.bookmarkMessage} // : <>} - + const isAudioBook = isAudiobookFn(this.props.r2Publication); const arrowDisabledNotEpub = isAudioBook || this.props.isPdf || this.props.isDivina; // const isFXL = this.isFixedLayout(); @@ -707,14 +707,14 @@ class Reader extends React.Component { // console.log(arrowDisabledNotEpub, isFXL, isPaginated); // epub non fxl (page) : false false true : true // epub non fxl (scroll) : false false false : false - // epub fxl : false true true : true + // epub fxl : false true true : true // epub fxl (scroll) : false true false : true // pdf : true false true : false // audiobook : true false true : false // divina : true false true : false const arrowEnabled = !arrowDisabledNotEpub /* && (isFXL || isPaginated) */; - + return (
{ disableRTLFlip={this.props.disableRTLFlip} isRTLFlip={this.isRTLFlip} /> - : + : } -
{ this.props.readerConfig.readerDockingMode === "left" ? stylesReader.docked_left_pdf : this.props.readerConfig.readerDockingMode === "right" ? !this.props.readerConfig.paged ? stylesReader.docked_right_scrollable : stylesReader.docked_right_pdf : "" - ) : undefined, - (this.props.searchEnable && !this.props.isPdf) ? stylesReader.isOnSearch - : (this.props.searchEnable && this.props.isPdf) ? stylesReader.isOnSearchPdf + ) : undefined, + (this.props.searchEnable && !this.props.isPdf) ? stylesReader.isOnSearch + : (this.props.searchEnable && this.props.isPdf) ? stylesReader.isOnSearchPdf : "")} ref={this.mainElRef} style={{ inset: isAudioBook || !this.props.readerConfig.paged || this.props.isPdf || this.props.isDivina ? "0" : "75px 50px" }}> @@ -854,7 +854,7 @@ class Reader extends React.Component {
- : + : <>} { @@ -923,7 +923,7 @@ class Reader extends React.Component {
- { !this.state.zenMode ? + { !this.state.zenMode ? { newReaderConfig.annotation_defaultDrawView = newReaderConfig.annotation_defaultDrawView === "annotation" ? "margin" : "annotation"; console.log(`onKeyboardAnnotationMargin : highlight=${newReaderConfig.annotation_defaultDrawView}`); - this.props.setConfig(newReaderConfig, this.props.session); + this.props.setConfig(newReaderConfig); }; private onKeyboardAnnotation = () => { @@ -1210,13 +1210,13 @@ class Reader extends React.Component { newReaderConfig.annotation_popoverNotOpenOnNoteTaking = true; console.log(`onKeyboardQuickAnnotation : popoverNotOpenOnNoteTaking=${annotation_popoverNotOpenOnNoteTaking}`); - this.props.setConfig(newReaderConfig, this.props.session); + this.props.setConfig(newReaderConfig); this.props.triggerAnnotationBtn(); newReaderConfig = {...this.props.readerConfig}; newReaderConfig.annotation_popoverNotOpenOnNoteTaking = annotation_popoverNotOpenOnNoteTaking; - this.props.setConfig(newReaderConfig, this.props.session); + this.props.setConfig(newReaderConfig); }; private onKeyboardAudioStop = () => { @@ -2329,7 +2329,7 @@ class Reader extends React.Component { } private closeMenu() { - + if (this.state.menuOpen) { this.handleMenuButtonClick(false); } @@ -2352,9 +2352,9 @@ class Reader extends React.Component { // // shortcutEnable must be true (see handleMenuButtonClick() above, and this.state.menuOpen)) // console.log("@@@@@@@@@@@@@@@"); // console.log(); - + // console.log("@@@@@@@@@@@@@@@"); - + // this.onKeyboardFocusMain(); // } } @@ -2651,7 +2651,7 @@ class Reader extends React.Component { private handleTTSPlaybackRate(speed: string) { ttsPlaybackRate(parseFloat(speed)); // this.setState({ ttsPlaybackRate: speed }); - this.props.setConfig({ ...this.props.readerConfig, ttsPlaybackRate: speed }, this.props.session); + this.props.setConfig({ ...this.props.readerConfig, ttsPlaybackRate: speed }); } private handleTTSVoice(voice: SpeechSynthesisVoice | null) { // alert(`${voice.name} ${voice.lang} ${voice.default} ${voice.voiceURI} ${voice.localService}`); @@ -2664,7 +2664,7 @@ class Reader extends React.Component { } : null; ttsVoice(v); // this.setState({ ttsVoice: v }); - this.props.setConfig({ ...this.props.readerConfig, ttsVoice: v }, this.props.session); + this.props.setConfig({ ...this.props.readerConfig, ttsVoice: v }); } private handleMediaOverlaysPlay() { @@ -2690,7 +2690,7 @@ class Reader extends React.Component { private handleMediaOverlaysPlaybackRate(speed: string) { mediaOverlaysPlaybackRate(parseFloat(speed)); // this.setState({ mediaOverlaysPlaybackRate: speed }); - this.props.setConfig({ ...this.props.readerConfig, mediaOverlaysPlaybackRate: speed }, this.props.session); + this.props.setConfig({ ...this.props.readerConfig, mediaOverlaysPlaybackRate: speed }); } // private handleSettingsSave(readerConfig: ReaderConfig) { @@ -2718,7 +2718,7 @@ class Reader extends React.Component { // }, 300); // } - // this.props.setConfig(readerConfig, this.props.session); + // this.props.setConfig(readerConfig); // if (this.props.r2Publication) { // readiumCssUpdate(computeReadiumCssJsonMessage(readerConfig)); @@ -2855,7 +2855,7 @@ const mapStateToProps = (state: IReaderRootState, _props: IBaseProps) => { readerMode: state.mode, divinaReadingMode: state.reader.divina.readingMode, locale: state.i18n.locale, - session: state.session.state, + // session: state.session.state, disableRTLFlip: !!state.reader.disableRTLFlip?.disabled, r2PublicationHasMediaOverlays: state.reader.info.navigator.r2PublicationHasMediaOverlays, @@ -2908,14 +2908,14 @@ const mapDispatchToProps = (dispatch: TDispatch, _props: IBaseProps) => { // TODO: quick fix to refresh AllPublication component grid view // when a book is set as finished and then open / readed - // + // // dispatch a stub api endpoint "readingFinishedRefresh" just to trigger // AllPublication grid view, this is a legacy usage of the ReduxApi // originaly developped. Now we should use the react/redux data update mechanism // instead to call a fake IPC API // // So call readingFinishedRefresh API at each call of setLocator function - // trigger too often the refresh, needed only at start or when the book is + // trigger too often the refresh, needed only at start or when the book is // check as set as finished in library/AllPublication compoment during the reading // setLocator is heavealy called with tts enabled or in an audiobook // so we just called readingFinishedRefresh 2 times at start @@ -2928,12 +2928,14 @@ const mapDispatchToProps = (dispatch: TDispatch, _props: IBaseProps) => { apiDispatch(dispatch)()("publication/readingFinishedRefresh")(); } }, - setConfig: (config: ReaderConfig, sessionEnabled: boolean) => { + setConfig: (config: ReaderConfig) => { dispatch(readerLocalActionSetConfig.build(config)); - if (!sessionEnabled) { - dispatch(readerActions.configSetDefault.build(config)); - } + // session never enabled in reader but always in main/lib + // if (!sessionEnabled) { + // called once in the readerConfigChanged saga function triggerd by the readerLocalActionSetConfig action just above. + // dispatch(readerActions.configSetDefault.build(config)); + // } }, addBookmark: (bookmark: IBookmarkStateWithoutUUID) => { dispatch(readerActions.bookmark.push.build(bookmark)); diff --git a/src/renderer/reader/redux/middleware/sync.ts b/src/renderer/reader/redux/middleware/sync.ts index 2a9c0d215..32e3a3196 100644 --- a/src/renderer/reader/redux/middleware/sync.ts +++ b/src/renderer/reader/redux/middleware/sync.ts @@ -6,7 +6,7 @@ // ==LICENSE-END== import { - apiActions, i18nActions, keyboardActions, lcpActions, publicationActions, readerActions, sessionActions, themeActions, + apiActions, i18nActions, keyboardActions, lcpActions, publicationActions, readerActions, themeActions, } from "readium-desktop/common/redux/actions"; import { syncFactory } from "readium-desktop/renderer/common/redux/middleware/syncFactory"; @@ -30,7 +30,7 @@ const SYNCHRONIZABLE_ACTIONS: string[] = [ keyboardActions.showShortcuts.ID, keyboardActions.reloadShortcuts.ID, - sessionActions.enable.ID, + // sessionActions.enable.ID, lcpActions.renewPublicationLicense.ID, lcpActions.returnPublication.ID, @@ -46,7 +46,7 @@ const SYNCHRONIZABLE_ACTIONS: string[] = [ readerActions.annotation.pop.ID, readerActions.annotation.push.ID, - readerActions.annotation.update.ID, + readerActions.annotation.update.ID, ]; export const reduxSyncMiddleware = syncFactory(SYNCHRONIZABLE_ACTIONS); diff --git a/src/renderer/reader/redux/sagas/readerConfig.ts b/src/renderer/reader/redux/sagas/readerConfig.ts index dd64aabc7..71824d3c1 100644 --- a/src/renderer/reader/redux/sagas/readerConfig.ts +++ b/src/renderer/reader/redux/sagas/readerConfig.ts @@ -58,10 +58,12 @@ function* readerConfigChanged(action: readerLocalActionSetConfig.TAction): SagaG } // this.props.setConfig(readerConfig, this.props.session); - const sessionEnabled = yield* select((state: IReaderRootState) => state.session.state); - if (!sessionEnabled) { + // const sessionEnabled = yield* select((state: IReaderRootState) => state.session.state); + + // session never enabled in reader but always in main/lib + // if (!sessionEnabled) { yield* put(readerActions.configSetDefault.build(readerConfig)); - } + // } readiumCssUpdate(computeReadiumCssJsonMessage(readerConfig)); } From 2d76704dd9c4b69d646c91969e8f35f62d551879 Mon Sep 17 00:00:00 2001 From: Pierre Leroux Date: Fri, 6 Sep 2024 11:28:50 +0200 Subject: [PATCH 2/3] fix (main): initialize missing keys from reader.defaultConfig in memory.ts preloadedState default readerConfig migration from older thorium version 2.x, 3.0 --- src/main/redux/store/memory.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/redux/store/memory.ts b/src/main/redux/store/memory.ts index f6e667005..f72a67642 100644 --- a/src/main/redux/store/memory.ts +++ b/src/main/redux/store/memory.ts @@ -22,6 +22,7 @@ import createSagaMiddleware, { SagaMiddleware } from "redux-saga"; import { applyPatch } from "rfc6902"; import { reduxPersistMiddleware } from "../middleware/persistence"; +import { readerConfigInitialState } from "readium-desktop/common/redux/states/reader"; // import { composeWithDevTools } from "remote-redux-devtools"; const REDUX_REMOTE_DEVTOOLS_PORT = 7770; @@ -234,7 +235,14 @@ export async function initStore() // } : { // ...forceDisableReaderDefaultConfigAndSessionForTheNewUI, // }; - const preloadedState = reduxState ? { ...reduxState } : {}; + const preloadedState: Partial = reduxState ? { + ...reduxState, + } : {}; + + // defaultConfig state initialization from older database thorium version 2.x, 3.0 + if (preloadedState?.reader?.defaultConfig) { + preloadedState.reader.defaultConfig = { ...readerConfigInitialState, ...preloadedState.reader.defaultConfig }; + } const sagaMiddleware = createSagaMiddleware(); From f1e531a3287138ce8dc2dc8c2efd11e967c11c97 Mon Sep 17 00:00:00 2001 From: Pierre Leroux Date: Tue, 10 Sep 2024 15:05:21 +0200 Subject: [PATCH 3/3] feat (reader): save/apply/reset preferred reading settings (Fixes #2530 Fixes #2532 PR #2533) --- .../actions/win/session/registerReader.ts | 6 +- src/main/redux/sagas/win/reader.ts | 11 +- .../reader/components/ReaderSettings.tsx | 101 ++++++++++++------ src/renderer/reader/di.ts | 8 +- .../reader/redux/sagas/readerConfig.ts | 4 +- src/resources/locales/en.json | 8 +- src/resources/locales/fr.json | 8 +- src/typings/en.translation.d.ts | 26 ++++- 8 files changed, 129 insertions(+), 43 deletions(-) diff --git a/src/main/redux/actions/win/session/registerReader.ts b/src/main/redux/actions/win/session/registerReader.ts index a47c444cb..f364d96b4 100644 --- a/src/main/redux/actions/win/session/registerReader.ts +++ b/src/main/redux/actions/win/session/registerReader.ts @@ -16,6 +16,7 @@ import { v4 as uuidv4 } from "uuid"; import { convertHttpUrlToCustomScheme, READIUM2_ELECTRON_HTTP_PROTOCOL, } from "@r2-navigator-js/electron/common/sessions"; +import { readerConfigInitialState } from "readium-desktop/common/redux/states/reader"; export const ID = "WIN_SESSION_REGISTER_READER"; @@ -42,7 +43,7 @@ export function build( // we lose purity !! const store = diMainGet("store"); - const readerConfigDefault = store.getState().reader.defaultConfig; + const disableRTLFlip = store.getState().reader.disableRTLFlip; const manifestUrlR2Protocol = manifestUrl.startsWith(READIUM2_ELECTRON_HTTP_PROTOCOL) @@ -50,7 +51,8 @@ export function build( reduxStateReader = { ...{ - config: readerConfigDefault, + // see issue https://github.com/edrlab/thorium-reader/issues/2532 + config: readerConfigInitialState, disableRTLFlip, locator: locatorInitialState, }, diff --git a/src/main/redux/sagas/win/reader.ts b/src/main/redux/sagas/win/reader.ts index 882e7605b..c1a863096 100644 --- a/src/main/redux/sagas/win/reader.ts +++ b/src/main/redux/sagas/win/reader.ts @@ -35,6 +35,7 @@ function* winOpen(action: winActions.reader.openSucess.TAction) { const webContents = readerWin.webContents; const locale = yield* selectTyped((_state: RootState) => _state.i18n.locale); const reader = yield* selectTyped((_state: RootState) => _state.win.session.reader[identifier]); + const readerDefaultConfig = yield* selectTyped((_state: RootState) => _state.reader.defaultConfig); const keyboard = yield* selectTyped((_state: RootState) => _state.keyboard); const mode = yield* selectTyped((state: RootState) => state.mode); const theme = yield* selectTyped((state: RootState) => state.theme); @@ -48,7 +49,11 @@ function* winOpen(action: winActions.reader.openSucess.TAction) { win: { identifier, }, - reader: reader?.reduxState, + reader: { + ...reader?.reduxState || {}, + // see issue https://github.com/edrlab/thorium-reader/issues/2532 + defaultConfig: readerDefaultConfig, + }, keyboard, mode, theme, @@ -93,8 +98,8 @@ function* winClose(action: winActions.reader.closed.TAction) { const mode = yield* selectTyped((state: RootState) => state.mode); if (mode === ReaderMode.Detached) { - - // disabled for the new UI refactoring by choice of the designer + + // disabled for the new UI refactoring by choice of the designer // yield put(readerActions.attachModeRequest.build()); } else { diff --git a/src/renderer/reader/components/ReaderSettings.tsx b/src/renderer/reader/components/ReaderSettings.tsx index ea3a075ad..63818f812 100644 --- a/src/renderer/reader/components/ReaderSettings.tsx +++ b/src/renderer/reader/components/ReaderSettings.tsx @@ -10,6 +10,7 @@ import * as Dialog from "@radix-ui/react-dialog"; import * as Tabs from "@radix-ui/react-tabs"; import * as RadioGroup from "@radix-ui/react-radio-group"; import classNames from "classnames"; +import * as GuearIcon from "readium-desktop/renderer/assets/icons/gear-icon.svg"; import * as QuitIcon from "readium-desktop/renderer/assets/icons/close-icon.svg"; import * as TextAreaIcon from "readium-desktop/renderer/assets/icons/textarea-icon.svg"; import * as LayoutIcon from "readium-desktop/renderer/assets/icons/layout-icon.svg"; @@ -50,6 +51,7 @@ import { useSelector } from "readium-desktop/renderer/common/hooks/useSelector"; import { IReaderRootState } from "readium-desktop/common/redux/states/renderer/readerRootState"; import { readerConfigInitialState } from "readium-desktop/common/redux/states/reader"; import { usePublisherReaderConfig, useReaderConfig, useReaderConfigAll, useSavePublisherReaderConfig, useSavePublisherReaderConfigDebounced, useSaveReaderConfig, useSaveReaderConfigDebounced } from "readium-desktop/renderer/common/hooks/useReaderConfig"; +import { readerActions } from "readium-desktop/common/redux/actions"; // eslint-disable-next-line @typescript-eslint/no-empty-interface interface IBaseProps extends IReaderSettingsProps { @@ -153,10 +155,10 @@ const Theme = () => { ]); - const defaultKey = - theme === "neutral" ? 1 - : theme === "night" ? 4 - : theme === "sepia" ? 2 + const defaultKey = + theme === "neutral" ? 1 + : theme === "night" ? 4 + : theme === "sepia" ? 2 : theme === "contrast1" ? 5 : theme === "paper" ? 3 : theme === "contrast2" ? 6 @@ -171,34 +173,34 @@ const Theme = () => { value={themeOptions.find((theme) => theme.id === defaultKey).value} onValueChange={(option) => set({ theme: option as TTheme })} > - {themeOptions.map((theme) => - + , )} - {/* - - */} @@ -327,7 +329,7 @@ export const FontFamily = () => { } }; - + return (
{ className={stylesGlobal.checkbox_custom_input} />