Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save version to redux store persistence #1710

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/redux/middleware/persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const reduxPersistMiddleware: Middleware
lastReadingQueue: prevState.publication.lastReadingQueue,
},
opds: prevState.opds,
version: prevState.version,
};

const persistNextState: PersistRootState = {
Expand All @@ -47,6 +48,7 @@ export const reduxPersistMiddleware: Middleware
lastReadingQueue: nextState.publication.lastReadingQueue,
},
opds: nextState.opds,
version: nextState.version,
};

const ops = createPatch(persistPrevState, persistNextState);
Expand Down
4 changes: 3 additions & 1 deletion src/main/redux/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { RootState } from "readium-desktop/main/redux/states";
import { priorityQueueReducer } from "readium-desktop/utils/redux-reducers/pqueue.reducer";
import { combineReducers } from "redux";

import { publicationActions, winActions } from "../actions";
import { appActions, publicationActions, winActions } from "../actions";
import { lcpReducer } from "./lcp";
import { readerDefaultConfigReducer } from "./reader/defaultConfig";
import { sessionReducer } from "./session";
Expand All @@ -23,6 +23,7 @@ import { winSessionReaderReducer } from "./win/session/reader";
import { winModeReducer } from "../../../common/redux/reducers/winModeReducer";
import { publicationDbReducers } from "./publication/db";
import { opdsDbReducers } from "./opds/db";
import { _APP_VERSION } from "readium-desktop/preprocessor-directives";

export const rootReducer = combineReducers<RootState>({
session: sessionReducer,
Expand Down Expand Up @@ -70,4 +71,5 @@ export const rootReducer = combineReducers<RootState>({
opds: combineReducers({
catalog: opdsDbReducers,
}),
version: (state, action) => action.type === appActions.initSuccess.ID ? _APP_VERSION : (state === undefined ? null : state),
});
3 changes: 3 additions & 0 deletions src/main/redux/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as persist from "./persist";
import * as reader from "./reader";
import * as streamer from "./streamer";
import * as win from "./win";
import * as telemetry from "./telemetry";

// Logger
const filename_ = "readium-desktop:main:saga:app";
Expand Down Expand Up @@ -63,6 +64,8 @@ export function* rootSaga() {
yield api.saga();
// yield spawnLeading(api.watchers, (e) => error("main:rootSaga:api", e));

yield telemetry.saga();

yield streamer.saga();
// yield spawnLeading(streamer.watchers, (e) => error("main:rootSaga:streamer", e));

Expand Down
1 change: 1 addition & 0 deletions src/main/redux/sagas/persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const persistStateToFs = async (nextState: RootState) => {
session: nextState.session,
i18n: nextState.i18n,
opds: nextState.opds,
version: nextState.version,
};

await fsp.writeFile(stateFilePath, JSON.stringify(value), {encoding: "utf8"});
Expand Down
24 changes: 24 additions & 0 deletions src/main/redux/sagas/telemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ==LICENSE-BEGIN==
// Copyright 2017 European Digital Reading Lab. All rights reserved.
// Licensed to the Readium Foundation under one or more contributor license agreements.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file exposed on Github (readium) in the project repository.
// ==LICENSE-END==

import * as debug_ from "debug";
import { _APP_VERSION } from "readium-desktop/preprocessor-directives";
import { select } from "typed-redux-saga";
import { RootState } from "../states";

// Logger
const filename_ = "readium-desktop:main:redux:sagas:telemetry";
const debug = debug_(filename_);

export function* saga() {

const version = yield* select((state: RootState) => state.version);

if (_APP_VERSION !== version) {
debug("VERSION MISMATCH", _APP_VERSION, "vs", version);
}
}
5 changes: 3 additions & 2 deletions src/main/redux/states/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ export interface RootState {
keyboard: KeyboardState;
opds: {
catalog: OpdsFeedDocument[];
}
},
version: string;
}


export type PersistRootState = Pick<RootState, "win" | "publication" | "reader" | "session" | "i18n" | "opds">;
export type PersistRootState = Pick<RootState, "win" | "publication" | "reader" | "session" | "i18n" | "opds" | "version">;