2018-07-05 04:49:12 +02:00
|
|
|
// @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';
|
2019-12-10 20:49:00 +01:00
|
|
|
import I18nMessage from 'component/i18nMessage';
|
2019-03-22 05:51:27 +01:00
|
|
|
// @if TARGET='app'
|
2019-03-20 05:41:51 +01:00
|
|
|
import { shell } from 'electron';
|
2019-03-22 05:51:27 +01:00
|
|
|
// @endif
|
2018-07-05 04:49:12 +02:00
|
|
|
|
|
|
|
type Props = {
|
2018-08-02 02:53:38 +02:00
|
|
|
source: string,
|
2018-07-05 04:49:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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() {
|
2018-07-05 04:49:12 +02:00
|
|
|
const { source } = this.props;
|
2019-03-20 05:41:51 +01:00
|
|
|
const path = `file://${source}`;
|
2019-03-22 05:51:27 +01:00
|
|
|
// @if TARGET='app'
|
2019-03-20 05:41:51 +01:00
|
|
|
shell.openExternal(path);
|
2019-03-22 05:51:27 +01:00
|
|
|
// @endif
|
2019-03-20 05:41:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2019-11-26 20:08:34 +01:00
|
|
|
const { source } = this.props;
|
2018-07-05 04:49:12 +02:00
|
|
|
return (
|
2019-08-13 07:35:13 +02:00
|
|
|
<div className="file-render__viewer--pdf" onContextMenu={stopContextMenu}>
|
2019-11-26 20:08:34 +01:00
|
|
|
{/* @if TARGET='app' */}
|
2019-03-20 05:41:51 +01:00
|
|
|
<p>
|
2019-12-10 20:49:00 +01:00
|
|
|
<I18nMessage
|
|
|
|
tokens={{ click_here: <Button button="link" label={__('Click here')} onClick={this.openFile} /> }}
|
|
|
|
>
|
|
|
|
PDF opened externally. %click_here% to open it again.
|
|
|
|
</I18nMessage>
|
2019-03-20 05:41:51 +01:00
|
|
|
</p>
|
2019-11-26 20:08:34 +01:00
|
|
|
{/* @endif */}
|
|
|
|
|
|
|
|
{/* @if TARGET='web' */}
|
|
|
|
<div className="file-render__viewer">
|
|
|
|
<iframe title={__('File preview')} src={source} />
|
|
|
|
</div>
|
|
|
|
{/* @endif */}
|
2018-07-05 07:24:04 +02:00
|
|
|
</div>
|
2018-07-05 04:49:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PdfViewer;
|