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-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
|
|
|
|
// @if TARGET='web'
|
|
|
|
console.error('provide stub for shell.openExternal');
|
|
|
|
// @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
|
2018-07-05 04:49:12 +02:00
|
|
|
return (
|
2019-03-20 05:41:51 +01:00
|
|
|
<div className="file-render__viewer file-render--pdf" onContextMenu={stopContextMenu}>
|
|
|
|
<p>
|
2019-05-07 23:38:29 +02:00
|
|
|
{__('PDF opened externally.')} <Button button="link" label={__('Click here')} onClick={this.openFile} />{' '}
|
2019-03-20 05:41:51 +01:00
|
|
|
{__('to open it again.')}
|
|
|
|
</p>
|
2018-07-05 07:24:04 +02:00
|
|
|
</div>
|
2018-07-05 04:49:12 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PdfViewer;
|