diff --git a/src/renderer/library/components/catalog/AboutThoriumButton.tsx b/src/renderer/library/components/catalog/AboutThoriumButton.tsx index 190e092a1..090825dc6 100644 --- a/src/renderer/library/components/catalog/AboutThoriumButton.tsx +++ b/src/renderer/library/components/catalog/AboutThoriumButton.tsx @@ -9,26 +9,26 @@ import * as stylesFooter from "readium-desktop/renderer/assets/styles/components import * as stylesGlobal from "readium-desktop/renderer/assets/styles/global.scss"; import { shell } from "electron"; -import { existsSync, promises } from "fs"; -import * as path from "path"; +// import { existsSync, promises } from "fs"; +// import * as path from "path"; import * as React from "react"; import { connect } from "react-redux"; -import { ABOUT_BOOK_TITLE_PREFIX } from "readium-desktop/common/constant"; -import { readerActions } from "readium-desktop/common/redux/actions"; -import { PublicationView } from "readium-desktop/common/views/publication"; +// import { ABOUT_BOOK_TITLE_PREFIX } from "readium-desktop/common/constant"; +// import { readerActions } from "readium-desktop/common/redux/actions"; +// import { PublicationView } from "readium-desktop/common/views/publication"; import { _APP_NAME, _APP_VERSION, _PACKAGING } from "readium-desktop/preprocessor-directives"; import { TranslatorProps, withTranslator, } from "readium-desktop/renderer/common/components/hoc/translator"; import { TDispatch } from "readium-desktop/typings/redux"; -import { findMimeTypeWithExtension, mimeTypes } from "readium-desktop/utils/mimeTypes"; +// import { findMimeTypeWithExtension, mimeTypes } from "readium-desktop/utils/mimeTypes"; -import { TaJsonSerialize } from "@r2-lcp-js/serializable"; -import { Metadata } from "@r2-shared-js/models/metadata"; -import { Publication as R2Publication } from "@r2-shared-js/models/publication"; -import { Link } from "@r2-shared-js/models/publication-link"; +// import { TaJsonSerialize } from "@r2-lcp-js/serializable"; +// import { Metadata } from "@r2-shared-js/models/metadata"; +// import { Publication as R2Publication } from "@r2-shared-js/models/publication"; +// import { Link } from "@r2-shared-js/models/publication-link"; -import { apiAction } from "../../apiAction"; +// import { apiAction } from "../../apiAction"; import { ILibraryRootState } from "readium-desktop/common/redux/states/renderer/libraryRootState"; import * as EdrlabLogo from "readium-desktop/renderer/assets/icons/logo_edrlab.svg"; import SVG from "readium-desktop/renderer/common/components/SVG"; @@ -53,7 +53,7 @@ interface IState { class AboutThoriumButton extends React.Component { - private manifestView: PublicationView; + // private manifestView: PublicationView; constructor(props: IProps) { super(props); @@ -102,9 +102,9 @@ class AboutThoriumButton extends React.Component {

{`v${_APP_VERSION}`}

- { + { ev.preventDefault(); // necessary because href="", CSS must also ensure hyperlink visited style - this.about(); + await shell.openExternal("https://thorium.edrlab.org/en/about/"); // TODO: not link to the english thorium hyperlink }} tabIndex={0}>{__("catalog.about.title", { appName: capitalizedAppName })}
@@ -114,94 +114,94 @@ class AboutThoriumButton extends React.Component { ); } - private about = async () => { - const { locale } = this.props; - const infoFolderRelativePath = "assets/md/information/"; // final / is important - const imagesFolder = "images"; - - let aboutLocale = locale.toLowerCase(); - - const setTitle = (l: string) => `${ABOUT_BOOK_TITLE_PREFIX}${_APP_VERSION}${l}`; - try { - - let title = setTitle(aboutLocale); - - let [pubView] = await apiAction("publication/searchEqTitle", title); - if (pubView) { - console.log("pubView already exist no need to generate a new one"); - console.log(pubView); - - this.manifestView = pubView; - - return; // see finally {} below - } - console.log("pubView not found, need to generate a new one: ", title); - - let folderPath = path.join((global as any).__dirname, infoFolderRelativePath); - if (_PACKAGING === "0") { - folderPath = path.join(process.cwd(), "dist", infoFolderRelativePath); - } - - let htmlFile = `${aboutLocale}.xhtml`; - { - const filePath = path.join(folderPath, `${aboutLocale}.xhtml`); - - if (!existsSync(filePath)) { - console.log("about XHTML does not exist (english fallback) ", filePath); - aboutLocale = "en"; - } - htmlFile = `${aboutLocale}.xhtml`; - title = setTitle(aboutLocale); - } - - [pubView] = await apiAction("publication/searchEqTitle", title); - if (pubView) { - console.log("pubView already exist no need to generate a new one"); - console.log(pubView); - - this.manifestView = pubView; - - return; // see finally {} below - } - console.log("pubView again not found, need to generate a new one: ", title); - - const publication = new R2Publication(); - publication.Context = ["https://readium.org/webpub-manifest/context.jsonld"]; - publication.Metadata = new Metadata(); - publication.Metadata.Title = title; - - const link = new Link(); - link.Href = htmlFile; - link.TypeLink = mimeTypes.xhtml; - link.Title = aboutLocale; - publication.Spine = [link]; - - const imgPath = path.join(folderPath, imagesFolder); - const imgArray = await promises.readdir(imgPath); - publication.Resources = imgArray.map((i) => { - const l = new Link(); - l.Href = `${imagesFolder}/${i}`; // path.join() backslash on Windows - l.TypeLink = findMimeTypeWithExtension(path.extname(l.Href)); - - return l; - }); - - const publicationSerialize = TaJsonSerialize(publication); - const publicationStr = JSON.stringify(publicationSerialize); - - this.manifestView = await apiAction("publication/importFromString", - publicationStr, - "file://" + folderPath.replace(/\\/g, "/")); - - } catch (e) { - console.log("error to import about", aboutLocale, e); - - } finally { - if (this.manifestView) { - this.props.openReader(this.manifestView); - } - } - }; + // private about = async () => { + // const { locale } = this.props; + // const infoFolderRelativePath = "assets/md/information/"; // final / is important + // const imagesFolder = "images"; + + // let aboutLocale = locale.toLowerCase(); + + // const setTitle = (l: string) => `${ABOUT_BOOK_TITLE_PREFIX}${_APP_VERSION}${l}`; + // try { + + // let title = setTitle(aboutLocale); + + // let [pubView] = await apiAction("publication/searchEqTitle", title); + // if (pubView) { + // console.log("pubView already exist no need to generate a new one"); + // console.log(pubView); + + // this.manifestView = pubView; + + // return; // see finally {} below + // } + // console.log("pubView not found, need to generate a new one: ", title); + + // let folderPath = path.join((global as any).__dirname, infoFolderRelativePath); + // if (_PACKAGING === "0") { + // folderPath = path.join(process.cwd(), "dist", infoFolderRelativePath); + // } + + // let htmlFile = `${aboutLocale}.xhtml`; + // { + // const filePath = path.join(folderPath, `${aboutLocale}.xhtml`); + + // if (!existsSync(filePath)) { + // console.log("about XHTML does not exist (english fallback) ", filePath); + // aboutLocale = "en"; + // } + // htmlFile = `${aboutLocale}.xhtml`; + // title = setTitle(aboutLocale); + // } + + // [pubView] = await apiAction("publication/searchEqTitle", title); + // if (pubView) { + // console.log("pubView already exist no need to generate a new one"); + // console.log(pubView); + + // this.manifestView = pubView; + + // return; // see finally {} below + // } + // console.log("pubView again not found, need to generate a new one: ", title); + + // const publication = new R2Publication(); + // publication.Context = ["https://readium.org/webpub-manifest/context.jsonld"]; + // publication.Metadata = new Metadata(); + // publication.Metadata.Title = title; + + // const link = new Link(); + // link.Href = htmlFile; + // link.TypeLink = mimeTypes.xhtml; + // link.Title = aboutLocale; + // publication.Spine = [link]; + + // const imgPath = path.join(folderPath, imagesFolder); + // const imgArray = await promises.readdir(imgPath); + // publication.Resources = imgArray.map((i) => { + // const l = new Link(); + // l.Href = `${imagesFolder}/${i}`; // path.join() backslash on Windows + // l.TypeLink = findMimeTypeWithExtension(path.extname(l.Href)); + + // return l; + // }); + + // const publicationSerialize = TaJsonSerialize(publication); + // const publicationStr = JSON.stringify(publicationSerialize); + + // this.manifestView = await apiAction("publication/importFromString", + // publicationStr, + // "file://" + folderPath.replace(/\\/g, "/")); + + // } catch (e) { + // console.log("error to import about", aboutLocale, e); + + // } finally { + // if (this.manifestView) { + // this.props.openReader(this.manifestView); + // } + // } + // }; } const mapStateToProps = (state: ILibraryRootState, _props: IBaseProps) => { @@ -214,11 +214,11 @@ const mapStateToProps = (state: ILibraryRootState, _props: IBaseProps) => { }; }; -const mapDispatchToProps = (dispatch: TDispatch, _props: IBaseProps) => { +const mapDispatchToProps = (__dispatch: TDispatch, _props: IBaseProps) => { return { - openReader: (publicationView: PublicationView) => { - dispatch(readerActions.openRequest.build(publicationView.identifier)); - }, + // openReader: (publicationView: PublicationView) => { + // dispatch(readerActions.openRequest.build(publicationView.identifier)); + // }, }; };