Skip to content
Draft
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
4 changes: 0 additions & 4 deletions src/main/redux/actions/win/library/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
// ==LICENSE-END==

import * as closed from "./closed";
import * as openRequest from "./openRequest";
import * as openSucess from "./openSucess";

export {
closed,
openSucess,
openRequest,
};
26 changes: 0 additions & 26 deletions src/main/redux/actions/win/library/openRequest.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/main/redux/actions/win/library/openSucess.ts

This file was deleted.

11 changes: 5 additions & 6 deletions src/main/redux/actions/win/session/registerLibrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import { BrowserWindow } from "electron";
import { Action } from "readium-desktop/common/models/redux";
import { ok } from "readium-desktop/common/utils/assert";
import { saveLibraryWindowInDi } from "readium-desktop/main/di";
import { v4 as uuidv4 } from "uuid";

export const ID = "WIN_SESSION_REGISTER_LIBRARY";

export interface Payload {
win: BrowserWindow;
identifier: string;
libraryWindow: BrowserWindow;
windowIdentifier: string;
winBound: Electron.Rectangle;
}

export function build(win: BrowserWindow, winBound: Electron.Rectangle):
export function build(win: BrowserWindow, winBound: Electron.Rectangle, windowIdentifier: string):
Action<typeof ID, Payload> {

ok(win, "lib win not defined");
Expand All @@ -29,9 +28,9 @@ export function build(win: BrowserWindow, winBound: Electron.Rectangle):
return {
type: ID,
payload: {
win,
libraryWindow: win,
winBound,
identifier: uuidv4(),
windowIdentifier,
},
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/redux/reducers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { type Reducer } from "redux";
import { appActions } from "readium-desktop/main/redux/actions";
import { AppState, AppStatus } from "readium-desktop/main/redux/states/app";

// TODO: not used, can be safely removed

const initialState: AppState = {
status: AppStatus.Unknown,
};
Expand Down
4 changes: 2 additions & 2 deletions src/main/redux/reducers/win/session/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function winSessionLibraryReducer_(
return {
...state,
...{
browserWindowId: action.payload.win.id,
identifier: action.payload.identifier,
browserWindowId: action.payload.libraryWindow.id,
identifier: action.payload.windowIdentifier,
windowBound: action.payload.winBound,
},
};
Expand Down
28 changes: 16 additions & 12 deletions src/main/redux/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import { keyboardActions, versionUpdateActions } from "readium-desktop/common/re
import { keyboardShortcuts } from "readium-desktop/main/keyboard";
// eslint-disable-next-line local-rules/typed-redux-saga-use-typed-effects
import { all, call, put, take } from "redux-saga/effects";
import { select as selectTyped, call as callTyped, spawn as spawnTyped} from "typed-redux-saga/macro";
import { select as selectTyped, call as callTyped, spawn as spawnTyped, join as joinTyped } from "typed-redux-saga/macro";
import { RootState } from "../states";
import { _APP_VERSION, _APP_NAME, _PACK_NAME } from "readium-desktop/preprocessor-directives";
// import { THttpGetCallback } from "readium-desktop/common/utils/http";
// import { Headers } from "node-fetch";
import { httpGet } from "readium-desktop/main/network/http";
import * as semver from "semver";
import { ContentType, parseContentType } from "readium-desktop/utils/contentType";
import { appActions, winActions } from "../actions";
import { appActions } from "../actions";
import * as api from "./api";
import * as appSaga from "./app";
import * as auth from "./auth";
Expand All @@ -42,6 +42,7 @@ import { sagaCustomizationProfileProvisioning } from "./customization";
import isURL from "validator/lib/isURL";
import { publicationIntegrityChecker } from "./publication/checker";
import { error } from "readium-desktop/main/tools/error";
import { createLibraryWindow } from "./win/browserWindow/createLibraryWindow";

// Logger
const filename_ = "readium-desktop:main:saga:app";
Expand Down Expand Up @@ -162,28 +163,31 @@ export function* rootSaga() {
yield put(keyboardActions.setShortcuts.build(keyboardShortcuts.getAll(), false));

// enjoy the app !
yield put(winActions.library.openRequest.build());
// yield put(winActions.library.openRequest.build());

// TODO
const createLibraryWindowTask = yield* callTyped(createLibraryWindow);

// spawn telemetry after library window ready and initialized
// but with the hydrated reduxState version before his update from the appActions.initSuccess action with _APP_VERSION
const versionFromHydratedGlobalState = yield* selectTyped((state: RootState) => state.version);

// app initialized
yield put(appActions.initSuccess.build());

// wait library window fully opened before to throw events
yield take(winActions.library.openSucess.ID);

// open reader from CLI or open-file event on MACOS
yield events.saga();

// spawn appVersion update checker in background
if (!process.windowsStore && _APP_NAME === "Thorium" && _PACK_NAME === "EDRLab.ThoriumReader") {
yield* spawnTyped(checkAppVersionUpdate);
}

// spawn telemetry in background
yield* spawnTyped(telemetry.collectSaveAndSend, versionFromHydratedGlobalState);

yield* joinTyped(createLibraryWindowTask);

// app initialized
// TODO: not used anymore
yield put(appActions.initSuccess.build());

// open reader from CLI or open-file event on MACOS
yield events.saga();
}

function* checkAppVersionUpdate() {
Expand Down
26 changes: 13 additions & 13 deletions src/main/redux/sagas/publication/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
// ==LICENSE-END==

import debug_ from "debug";
import { SagaGenerator, call as callTyped, delay as delayTyped, put as putTyped, take as takeTyped } from "typed-redux-saga/macro";
import { SagaGenerator, call as callTyped, delay as delayTyped } from "typed-redux-saga/macro";
import { diMainGet } from "readium-desktop/main/di";
import * as fs from "node:fs";
import * as path from "node:path";
import { _APP_NAME, _APP_VERSION, _PACK_NAME } from "readium-desktop/preprocessor-directives";
import { USER_DATA_FOLDER, FORCE_PROD_DB_IN_DEV } from "readium-desktop/common/constant";
import { IPublicationCheckerState } from "readium-desktop/common/redux/states/publicationsChecker";
import { publicationActions } from "readium-desktop/common/redux/actions";
import { winActions } from "../../actions";
// import { IPublicationCheckerState } from "readium-desktop/common/redux/states/publicationsChecker";
// import { publicationActions } from "readium-desktop/common/redux/actions";
import { tryCatch } from "readium-desktop/utils/tryCatch";

// TODO: use app.getPath("logs"); instead
Expand Down Expand Up @@ -126,12 +125,12 @@ export function* publicationIntegrityChecker(): SagaGenerator<void> {
}
yield* delayTyped(1);

const publicationCheckerState: IPublicationCheckerState = {
publicationIdentifierDataBase,
// publicationIdentifierDisk = [...approvedPublicationIdentifierDisk, ...rejectedPublicationIdentifierDisk];
approvedPublicationIdentifierDisk, rejectedPublicationIdentifierDisk,
dump,
};
// const publicationCheckerState: IPublicationCheckerState = {
// publicationIdentifierDataBase,
// // publicationIdentifierDisk = [...approvedPublicationIdentifierDisk, ...rejectedPublicationIdentifierDisk];
// approvedPublicationIdentifierDisk, rejectedPublicationIdentifierDisk,
// dump,
// };

yield* delayTyped(1);
dump += `Process: ${JSON.stringify({
Expand All @@ -149,9 +148,10 @@ export function* publicationIntegrityChecker(): SagaGenerator<void> {
if (dumpLogs) {
yield* callTyped(() => fs.promises.appendFile(appLogs, dump));

yield* takeTyped(winActions.library.openSucess.ID);
yield* delayTyped(1000); // 1s
yield* putTyped(publicationActions.checker.build(publicationCheckerState));
// TODO: not a valid way to wait libraryWindow, if libWin is ready before this event, publicationChecker will be never send
// yield* takeTyped(winActions.library.openSucess.ID);
// yield* delayTyped(1000); // 1s
// yield* putTyped(publicationActions.checker.build(publicationCheckerState));
}

}
Loading