lbry-desktop/src/ui/component/viewers/pdfViewer.jsx

45 lines
1 KiB
React
Raw Normal View History

// @flow
2018-10-15 08:26:46 +02:00
import * as React from 'react';
2018-11-21 22:20:55 +01:00
import { stopContextMenu } from 'util/context-menu';
2019-03-20 05:41:51 +01:00
import Button from 'component/button';
import { shell } from 'electron';
type Props = {
source: string,
};
class PdfViewer extends React.PureComponent<Props> {
2019-03-20 05:41:51 +01:00
constructor() {
super();
(this: any).openFile = this.openFile.bind(this);
}
componentDidMount() {
this.openFile();
}
openFile() {
const { source } = this.props;
2019-03-20 05:41:51 +01:00
const path = `file://${source}`;
shell.openExternal(path);
}
render() {
// We used to be able to just render a webview and display the pdf inside the app
// This was disabled on electron@3
// https://github.com/electron/electron/issues/12337
return (
2019-03-20 05:41:51 +01:00
<div className="file-render__viewer file-render--pdf" onContextMenu={stopContextMenu}>
<p>
{__('PDF opened externally.')}{' '}
<Button button="link" label={__('Click here')} onClick={this.openFile} />{' '}
{__('to open it again.')}
</p>
</div>
);
}
}
export default PdfViewer;