diff --git a/src/renderer/component/fileViewer/view.jsx b/src/renderer/component/fileViewer/view.jsx index 0a16d9f92..406c25186 100644 --- a/src/renderer/component/fileViewer/view.jsx +++ b/src/renderer/component/fileViewer/view.jsx @@ -17,6 +17,9 @@ type Props = { download_path: string, completed: boolean, }, + fileInfoErrors: ?{ + [string]: boolean, + }, metadata: ?{ nsfw: boolean, thumbnail: string, @@ -55,14 +58,17 @@ class FileViewer extends React.PureComponent { window.addEventListener('keydown', this.handleKeyDown); } - componentWillReceiveProps(nextProps: Props) { + componentDidUpdate(prev: Props) { if ( - this.props.autoplay !== nextProps.autoplay || - this.props.fileInfo !== nextProps.fileInfo || - this.props.isDownloading !== nextProps.isDownloading || - this.props.playingUri !== nextProps.playingUri + this.props.autoplay !== prev.autoplay || + this.props.fileInfo !== prev.fileInfo || + this.props.isDownloading !== prev.isDownloading || + this.props.playingUri !== prev.playingUri ) { - this.handleAutoplay(nextProps); + // suppress autoplay after download error + if (!(this.props.uri in this.props.fileInfoErrors)) { + this.handleAutoplay(this.props); + } } } @@ -79,22 +85,10 @@ class FileViewer extends React.PureComponent { } } - // do not play when state.content.errors[uri] handleAutoplay = (props: Props) => { - const { - autoplay, - playingUri, - fileInfo, - costInfo, - isDownloading, - uri, - play, - metadata, - fileInfoErrors, - } = props; + const { autoplay, playingUri, fileInfo, costInfo, isDownloading, uri, play, metadata } = props; - const playable = - autoplay && playingUri !== uri && metadata && !metadata.nsfw && !(uri in fileInfoErrors); + const playable = autoplay && playingUri !== uri && metadata && !metadata.nsfw; if (playable && costInfo && costInfo.cost === 0 && !fileInfo && !isDownloading) { play(uri);