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: 3 additions & 1 deletion src/common/redux/actions/toast/openRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ export const ID = "TOAST_OPEN_REQUEST";
export interface Payload {
type: ToastType;
data: string | undefined;
title: string | undefined;
publicationIdentifier: string | undefined;
}

export function build(type: ToastType, data: string, publicationIdentifier?: string):
export function build(type: ToastType, data: string, title?: string, publicationIdentifier?: string):
Action<typeof ID, Payload> {

return {
type: ID,
payload: {
type,
data,
title,
publicationIdentifier,
},
};
Expand Down
2 changes: 2 additions & 0 deletions src/common/redux/reducers/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const initialState: ToastState = {
open: false,
type: ToastType.Success,
data: undefined,
title: undefined,
publicationIdentifier: undefined,
};

Expand All @@ -35,6 +36,7 @@ function toastReducer_(
open: true,
type: action.payload.type,
data: action.payload.data,
title: action.payload.title,
publicationIdentifier: action.payload.publicationIdentifier,
},
);
Expand Down
1 change: 1 addition & 0 deletions src/common/redux/states/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export interface ToastState {
open: boolean;
type: ToastType;
data: string;
title?: string;
publicationIdentifier: string | undefined;
}
36 changes: 18 additions & 18 deletions src/main/redux/sagas/api/publication/import/importLcplFromFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import * as fs from "fs";
import moment from "moment";
import * as path from "path";
import { lcpLicenseIsNotWellFormed } from "readium-desktop/common/lcp";
import { ToastType } from "readium-desktop/common/models/toast";
import { toastActions } from "readium-desktop/common/redux/actions";
// import { ToastType } from "readium-desktop/common/models/toast";
// import { toastActions } from "readium-desktop/common/redux/actions";
import { extractCrc32OnZip } from "readium-desktop/main/tools/crc";
import { PublicationDocument } from "readium-desktop/main/db/document/publication";
import { diMainGet } from "readium-desktop/main/di";
// eslint-disable-next-line local-rules/typed-redux-saga-use-typed-effects
import { call, put } from "redux-saga/effects";
import { call } from "redux-saga/effects";
import { SagaGenerator } from "typed-redux-saga";
import { call as callTyped } from "typed-redux-saga/macro";

Expand All @@ -25,10 +25,13 @@ import { TaJsonDeserialize } from "@r2-lcp-js/serializable";

import { downloader } from "../../../downloader";
import { importPublicationFromFS } from "./importPublicationFromFs";
// import { getTranslator } from "readium-desktop/common/services/translator";

// Logger
const debug = debug_("readium-desktop:main#saga/api/publication/import/publicationLcplFromFs");

// const translate = getTranslator().translate;

export function* importLcplFromFS(
filePath: string,
lcpHashedPassphrase?: string,
Expand All @@ -47,7 +50,6 @@ export function* importLcplFromFS(
const r2LCP = TaJsonDeserialize(r2LCPJson, LCP);
r2LCP.JsonSource = r2LCPStr;
r2LCP.init();

// LCP license checks to avoid unnecessary download:
// CERTIFICATE_SIGNATURE_INVALID = 102
// CERTIFICATE_REVOKED = 101
Expand All @@ -74,13 +76,12 @@ export function* importLcplFromFS(
debug(err);
}
if (res) {
const msg = lcpManager.convertUnlockPublicationResultToString(res, r2LCP.Issued?.toISOString() || "");
yield put(
toastActions.openRequest.build(
ToastType.Error, msg,
),
);
throw new Error(`[${msg}] (${filePath})`);
const msg = lcpManager.convertUnlockPublicationResultToString(res, r2LCP.Issued?.toISOString() || "");
// yield put(
// toastActions.openRequest.build(
// ToastType.Error, msg, title)
// );
throw new Error(msg);
}
}

Expand All @@ -94,20 +95,19 @@ export function* importLcplFromFS(
// LICENSE_CERTIFICATE_DATE_INVALID (was LICENSE_SIGNATURE_DATE_INVALID) = 111
// LICENSE_SIGNATURE_INVALID = 112
const msg = lcpManager.convertUnlockPublicationResultToString(err, r2LCP.Issued?.toISOString() || "");
yield put(
toastActions.openRequest.build(
ToastType.Error, msg,
),
);
throw new Error(`[${msg}] (${filePath})`);
// yield put(
// toastActions.openRequest.build(
// ToastType.Error, msg, title
// ),
// );
throw new Error(msg);
}
}
}

const link = r2LCP?.Links?.reduce((pv, cv) => cv.Rel === "publication" ? cv : pv);

if (link?.Href) {

const title = link.Title || path.basename(filePath);
const [downloadFilePath] = yield* callTyped(downloader, [{ href: link.Href, type: link.Type }], title);

Expand Down
10 changes: 6 additions & 4 deletions src/main/redux/sagas/api/publication/import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function* importFromLink(
toastActions.openRequest.build(
ToastType.Error,
translate("message.import.fail",
{ path: link.url, err: e?.toString() }),
{ title: link.title, err: e?.toString() }),
),
);
}
Expand Down Expand Up @@ -231,11 +231,13 @@ export function* importFromFs(
} catch (error) {

debug("importFromFs (hash + import) fail with :" + filePath, error);

const fileTitle = fpath.split("/").at(-1);
const title = translate("message.import.fail", { title: fileTitle });
const msg = error?.message;
yield put(
toastActions.openRequest.build(
ToastType.Error,
translate("message.import.fail",
{ path: filePath, err: error?.toString() }),
ToastType.Error, msg, title,
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/redux/sagas/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function* readerOpenRequest(action: readerActions.openRequest.TAction) {

} catch (e) {

const errMsg = e.toString();
const errMsg = e.message;
if (errMsg === ERROR_MESSAGE_ENCRYPTED_NO_LICENSE) {
yield put(
toastActions.openRequest.build(
Expand Down
3 changes: 2 additions & 1 deletion src/main/storage/publication-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export class PublicationStorage {
}

debug("Error GetPublicationEpubPath not found with", identifier, "Throw new Error");
throw new Error(`getPublicationEpubPath() FAIL ${identifier} (cannot find book.epub|audiobook|etc.)`);
// throw new Error(`getPublicationEpubPath() FAIL ${identifier} (cannot find book.epub|audiobook|etc.)`);
throw new Error("This publication is missing in the storage folder.");
}

public async getPublicationFilename(publicationView: PublicationView) {
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/assets/styles/components/toasts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
padding: 1rem;
border: 1px var(--color-success-text) solid;
border-radius: 6px;
width: 15rem;
width: 23rem;
height: fit-content;
background: white;
display: flex;
Expand Down Expand Up @@ -85,7 +85,7 @@
}

.leave {
transform: translateX(-100%);
transform: translateX(calc(-100% - 20px));
transition: transform 0.5s;
}

Expand All @@ -100,7 +100,7 @@

@keyframes start {
from {
transform: translateX(-100%);
transform: translateX(calc(-100% - 20px));
}

to {
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/common/components/toast/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface IBaseProps extends TranslatorProps {
message?: string;
displaySystemNotification?: boolean;
type?: ToastType;
title?: string;
}

// IProps may typically extend:
Expand Down Expand Up @@ -85,7 +86,7 @@ export class Toast extends React.Component<IProps, IState> {
this.timer = window.setTimeout(() => {
this.timer = undefined;
this.handleClose();
}, fast ? 500 : 5000);
}, fast ? 500 : 8000);
}

public componentDidMount() {
Expand Down Expand Up @@ -155,10 +156,13 @@ export class Toast extends React.Component<IProps, IState> {
toRemove && stylesToasts.toRemove,
typeClassName,
)}
style={{display: "flex", flexDirection: "column", alignItems: "flex-start"}}
>
{
// icon && <SVG className={styles.icon} svg={icon} />
}
{this.props.title ?
<h5 style={{fontWeight: "bold", fontSize: "12px", margin: "0 0 5px"}}>{this.props.title}</h5> : <></>}
<p
aria-live="assertive"
aria-relevant="all"
Expand Down
1 change: 1 addition & 0 deletions src/renderer/common/components/toast/ToastManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class ToastManager extends React.Component<IProps, IState> {
close={ () => this.close(id) }
type={toast.type}
displaySystemNotification={false}
title={toast.title}
/>;
default:
return (<></>);
Expand Down
30 changes: 15 additions & 15 deletions src/resources/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,15 @@
"success": "Import completed successfully."
},
"download": {
"error": "Downloading [{{- title}}] failed: [{{- err}}]"
"error": "Downloading \"{{- title}}\" failed: [{{- err}}]"
},
"import": {
"alreadyImport": "[{{- title}}] was already imported.",
"fail": "Importing [{{- path}}] failed: [{{- err}}]",
"success": "Importing [{{- title}}] completed."
"alreadyImport": "\"{{- title}}\" was already imported.",
"fail": "Error while importing \"{{- title}}.\"",
"success": "\"{{- title}}\" successfully imported."
},
"open": {
"error": "Loading publication failed: [{{- err}}]"
"error": "{{- err}}."
},
"wipeData": "Login data was cleared (access tokens and cookies)"
},
Expand Down Expand Up @@ -606,9 +606,9 @@
"tracks": "Tracks"
},
"author": "Author",
"cancelledLcp": "This publication's LCP license is cancelled.",
"certificateRevoked": "Revoked LCP license certificate.",
"certificateSignatureInvalid": "Invalid LCP license certificate signature.",
"cancelledLcp": "Your license to read this publication has been cancelled.",
"certificateRevoked": "This publication cannot be opened (X509 cert was revoked).",
"certificateSignatureInvalid": "This publication cannot be opened (invalid X509 cert signature).",
"cover": {
"img": "cover image"
},
Expand All @@ -617,18 +617,18 @@
"duration": {
"title": "Duration"
},
"encryptedNoLicense": "Publication is encrypted but lacks an LCP license!",
"encryptedNoLicense": "This publication cannot be opened (no license in encrypted file).",
"expired": "Loan expired",
"expiredLcp": "This publication's LCP license is expired.",
"expiredLcp": "Your license to read this publication has expired.",
"incorrectPassphrase": "No stored passphrase fits the publication, or the entered passphrase is wrong.",
"lcpEnd": "End",
"lcpRightsCopy": "Copied characters",
"lcpRightsPrint": "Printed pages",
"lcpStart": "Start",
"licenceLCP": "License (LCP)",
"licenseCertificateDateInvalid": "The LCP provider certificate expired before the license issue date ({{- dateTime}}).",
"licenseOutOfDate": "Out of date LCP License.",
"licenseSignatureInvalid": "Invalid LCP license signature.",
"licenseCertificateDateInvalid": "This publication cannot be opened (X509 cert expired before license issue date).",
"licenseOutOfDate": "Your license to read this publication has expired or has not started.",
"licenseSignatureInvalid": "This publication cannot be opened (invalid license signature).",
"licensed": "Licensed",
"markAsRead": "Mark as read",
"notStarted": "Not Started",
Expand All @@ -640,8 +640,8 @@
"remainingTime": "Loan (remaining time)",
"renewButton": "Renew",
"returnButton": "Return",
"returnedLcp": "This LCP-protected publication is returned.",
"revokedLcp": "This publication's LCP license is revoked.",
"returnedLcp": "You already have returned this publication.",
"revokedLcp": "Your license to read this publication has been revoked.",
"seeLess": "See less",
"seeMore": "See more",
"timeLeft": "Remaining time",
Expand Down
10 changes: 5 additions & 5 deletions src/resources/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@
"success": "Importation réussie"
},
"download": {
"error": "Le téléchargement de {{- title}} a échoué: [{{- err}}]"
"error": "Le téléchargement de '{{- title}}' a échoué: [{{- err}}]"
},
"import": {
"alreadyImport": "{{- title}} a déjà été ajouté.",
"fail": "L'ajout de {{- path}} a échoué. {{- err}}",
"success": "L'ajout de {{- title}} est achevé."
"alreadyImport": "\"{{- title}}\" a déjà été importé.",
"fail": "Erreur lors de l'import de \"{{- title}}\".",
"success": "\"{{- title}}\" importé avec succès."
},
"open": {
"error": "Le livre ne peut pas être ouvert : {{- err}}"
"error": "{{- err}}."
},
"wipeData": "Données d'authentification supprimées avec succès !"
},
Expand Down
Loading