2019-05-09 00:47:39 +02:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
2019-11-25 06:17:38 +01:00
|
|
|
import Villain from 'villain-react';
|
|
|
|
import 'villain-react/dist/style.css';
|
2019-05-09 00:47:39 +02:00
|
|
|
|
|
|
|
type Props = {
|
2019-11-25 06:17:38 +01:00
|
|
|
theme: string,
|
2019-05-09 00:47:39 +02:00
|
|
|
source: {
|
|
|
|
fileType: string,
|
2019-05-16 08:32:53 +02:00
|
|
|
downloadPath: string,
|
2019-05-09 00:47:39 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-11-25 06:17:38 +01:00
|
|
|
let workerUrl = 'webworkers/worker-bundle.js';
|
|
|
|
|
2019-06-04 20:32:42 +02:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
// Don't add a leading slash in production because electron treats it as an absolute path
|
2019-11-25 06:17:38 +01:00
|
|
|
workerUrl = `/${workerUrl}`;
|
2019-06-04 20:32:42 +02:00
|
|
|
}
|
|
|
|
|
2019-05-16 08:32:53 +02:00
|
|
|
class ComicBookViewer extends React.PureComponent<Props> {
|
2019-05-09 00:47:39 +02:00
|
|
|
render() {
|
2019-05-16 08:32:53 +02:00
|
|
|
const { downloadPath } = this.props.source || {};
|
2019-11-25 06:17:38 +01:00
|
|
|
// Archive source
|
2019-05-16 08:32:53 +02:00
|
|
|
const file = `file://${downloadPath}`;
|
2019-11-25 06:17:38 +01:00
|
|
|
// Villain options
|
|
|
|
const opts = {
|
|
|
|
theme: this.props.theme === 'dark' ? 'Dark' : 'Light',
|
|
|
|
allowFullScreen: true,
|
|
|
|
autoHideControls: false,
|
|
|
|
allowGlobalShortcuts: true,
|
|
|
|
};
|
2019-05-16 08:32:53 +02:00
|
|
|
|
2020-04-16 05:33:43 +02:00
|
|
|
return <Villain source={file} style={{ width: '100%', height: '100%' }} options={opts} workerUrl={workerUrl} />;
|
2019-05-09 00:47:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ComicBookViewer;
|