Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into feat/i18n-first-…
Browse files Browse the repository at this point in the history
…launch

* upstream/develop:
  feat (reader): save/apply/reset preferred reading settings (Fixes edrlab#2530 Fixes edrlab#2532 PR edrlab#2533)
  fix (main): initialize missing keys from reader.defaultConfig in memory.ts preloadedState
  chore (refactor): comment session.state unused and disable the force reset of the global defaultConfig at start
  • Loading branch information
ddfreiling committed Sep 16, 2024
2 parents 37cfdcc + f1e531a commit 201de6e
Show file tree
Hide file tree
Showing 20 changed files with 342 additions and 235 deletions.
30 changes: 15 additions & 15 deletions src/common/redux/actions/session/enable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof ID, Payload> {
// export function build(value: boolean): Action<typeof ID, Payload> {

return {
type: ID,
payload: {
value,
},
};
}
build.toString = () => ID; // Redux StringableActionCreator
export type TAction = ReturnType<typeof build>;
// return {
// type: ID,
// payload: {
// value,
// },
// };
// }
// build.toString = () => ID; // Redux StringableActionCreator
// export type TAction = ReturnType<typeof build>;
4 changes: 2 additions & 2 deletions src/common/redux/actions/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
16 changes: 8 additions & 8 deletions src/common/redux/reducers/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/common/redux/states/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
// ==LICENSE-END==

export interface ISessionState {
state: boolean;
// state: boolean;
save: boolean;
}
6 changes: 4 additions & 2 deletions src/main/redux/actions/win/session/registerReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -42,15 +43,16 @@ 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)
? manifestUrl : convertHttpUrlToCustomScheme(manifestUrl);

reduxStateReader = {
...{
config: readerConfigDefault,
// see issue https://github.com/edrlab/thorium-reader/issues/2532
config: readerConfigInitialState,
disableRTLFlip,
locator: locatorInitialState,
},
Expand Down
2 changes: 1 addition & 1 deletion src/main/redux/middleware/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
19 changes: 10 additions & 9 deletions src/main/redux/sagas/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 6 additions & 5 deletions src/main/redux/sagas/win/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
Expand Down Expand Up @@ -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);
Expand All @@ -224,7 +225,7 @@ function* winClose(_action: winActions.library.closed.TAction) {
// );
// debug("result:", messageValue.response);
// value = messageValue.response;
}
// }

yield all(
readersArray.map(
Expand Down
11 changes: 8 additions & 3 deletions src/main/redux/sagas/win/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
47 changes: 31 additions & 16 deletions src/main/redux/store/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ 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;
Expand Down Expand Up @@ -212,22 +211,38 @@ export async function initStore()
debug("REDUX STATE VALUE :: ", typeof reduxState, reduxState ? Object.keys(reduxState) : "nil");
// debug(reduxState);

const forceDisableReaderDefaultConfigAndSessionForTheNewUI: Partial<PersistRootState> = {
reader: {
defaultConfig: readerConfigInitialState,
disableRTLFlip: reduxState?.reader?.disableRTLFlip || { disabled: defaultDisableRTLFLip },
},
session: {
state: true,
save: reduxState?.session?.save || false,
},
};
const preloadedState = reduxState ? {
// const forceDisableReaderDefaultConfigAndSessionForTheNewUI: Partial<PersistRootState> = {
// 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: Partial<PersistRootState> = reduxState ? {
...reduxState,
...forceDisableReaderDefaultConfigAndSessionForTheNewUI,
} : {
...forceDisableReaderDefaultConfigAndSessionForTheNewUI,
};
} : {};

// 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();

Expand Down
Loading

0 comments on commit 201de6e

Please sign in to comment.