From a7d5fc650307f0a3cc53985b9c58cf58bc3b789a Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Sat, 24 Feb 2018 19:26:49 -0500 Subject: [PATCH 1/3] Fix macOS badge --- src/renderer/util/setBadge.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/renderer/util/setBadge.js b/src/renderer/util/setBadge.js index ca4c9d358..77e5ee2f2 100644 --- a/src/renderer/util/setBadge.js +++ b/src/renderer/util/setBadge.js @@ -2,10 +2,10 @@ import { remote } from 'electron'; const application = remote.app; const { dock } = application; -const win = remote.BrowserWindow.getFocusedWindow(); +const browserWindow = remote.getCurrentWindow(); const setBadge = text => { if (!dock) return; - if (win.isFocused()) return; + if (browserWindow.isFocused()) return; dock.setBadge(text); }; From 9ad6676a4fd224f12063e3cf640b10bc572a9bc4 Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Sun, 25 Feb 2018 13:27:19 -0500 Subject: [PATCH 2/3] Fix ESLint problems other than type validation --- .../component/video/internal/player.jsx | 117 +++++++++--------- 1 file changed, 56 insertions(+), 61 deletions(-) diff --git a/src/renderer/component/video/internal/player.jsx b/src/renderer/component/video/internal/player.jsx index e938a856f..c6a39026b 100644 --- a/src/renderer/component/video/internal/player.jsx +++ b/src/renderer/component/video/internal/player.jsx @@ -1,5 +1,4 @@ -const { remote } = require('electron'); - +import { remote } from 'electron'; import React from 'react'; import { Thumbnail } from 'component/common'; import player from 'render-media'; @@ -21,33 +20,21 @@ class VideoPlayer extends React.PureComponent { this.togglePlayListener = this.togglePlay.bind(this); } - componentWillReceiveProps(next) { - const el = this.refs.media.children[0]; - if (!this.props.paused && next.paused && !el.paused) el.pause(); - } - componentDidMount() { - const container = this.refs.media; - const { - contentType, - downloadPath, - mediaType, - changeVolume, - volume, - position, - claim, - uri, - } = this.props; + const container = this.media; + const { contentType, changeVolume, volume, position, claim } = this.props; - const loadedMetadata = e => { + const loadedMetadata = () => { this.setState({ hasMetadata: true, startedPlaying: true }); - this.refs.media.children[0].play(); + this.media.children[0].play(); }; - const renderMediaCallback = err => { - if (err) this.setState({ unplayable: true }); + + const renderMediaCallback = error => { + if (error) this.setState({ unplayable: true }); }; + // Handle fullscreen change for the Windows platform - const win32FullScreenChange = e => { + const win32FullScreenChange = () => { const win = remote.BrowserWindow.getFocusedWindow(); if (process.platform === 'win32') { win.setMenu(document.webkitIsFullScreen ? null : remote.Menu.getApplicationMenu()); @@ -67,7 +54,7 @@ class VideoPlayer extends React.PureComponent { } document.addEventListener('keydown', this.togglePlayListener); - const mediaElement = this.refs.media.children[0]; + const mediaElement = this.media.children[0]; if (mediaElement) { mediaElement.currentTime = position || 0; mediaElement.addEventListener('play', () => this.props.doPlay()); @@ -87,29 +74,38 @@ class VideoPlayer extends React.PureComponent { } } + componentWillReceiveProps(next) { + const el = this.media.children[0]; + if (!this.props.paused && next.paused && !el.paused) el.pause(); + } + + componentDidUpdate() { + const { contentType, downloadCompleted } = this.props; + const { startedPlaying } = this.state; + + if (this.playableType() && !startedPlaying && downloadCompleted) { + const container = this.media.children[0]; + + if (VideoPlayer.MP3_CONTENT_TYPES.indexOf(contentType) > -1) { + this.renderAudio(this.media, true); + } else { + player.render(this.file(), container, { + autoplay: true, + controls: true, + }); + } + } + } + componentWillUnmount() { document.removeEventListener('keydown', this.togglePlayListener); - const mediaElement = this.refs.media.children[0]; + const mediaElement = this.media.children[0]; if (mediaElement) { mediaElement.removeEventListener('click', this.togglePlayListener); } this.props.doPause(); } - renderAudio(container, autoplay) { - if (container.firstChild) { - container.firstChild.remove(); - } - - // clear the container - const { downloadPath } = this.props; - const audio = document.createElement('audio'); - audio.autoplay = autoplay; - audio.controls = true; - audio.src = downloadPath; - container.appendChild(audio); - } - togglePlay(event) { // ignore all events except click and spacebar keydown, or input events in a form control if ( @@ -119,7 +115,7 @@ class VideoPlayer extends React.PureComponent { return; } event.preventDefault(); - const mediaElement = this.refs.media.children[0]; + const mediaElement = this.media.children[0]; if (mediaElement) { if (!mediaElement.paused) { mediaElement.pause(); @@ -129,24 +125,6 @@ class VideoPlayer extends React.PureComponent { } } - componentDidUpdate() { - const { contentType, downloadCompleted } = this.props; - const { startedPlaying } = this.state; - - if (this.playableType() && !startedPlaying && downloadCompleted) { - const container = this.refs.media.children[0]; - - if (VideoPlayer.MP3_CONTENT_TYPES.indexOf(contentType) > -1) { - this.renderAudio(this.refs.media, true); - } else { - player.render(this.file(), container, { - autoplay: true, - controls: true, - }); - } - } - } - file() { const { downloadPath, filename } = this.props; @@ -162,14 +140,26 @@ class VideoPlayer extends React.PureComponent { return ['audio', 'video'].indexOf(mediaType) !== -1; } + renderAudio(container, autoplay) { + if (container.firstChild) { + container.firstChild.remove(); + } + + // clear the container + const { downloadPath } = this.props; + const audio = document.createElement('audio'); + audio.autoplay = autoplay; + audio.controls = true; + audio.src = downloadPath; + container.appendChild(audio); + } + render() { const { mediaType, poster } = this.props; const { hasMetadata, unplayable } = this.state; const noMetadataMessage = 'Waiting for metadata.'; const unplayableMessage = "Sorry, looks like we can't play this file."; - const needsMetadata = this.playableType(); - return (
{['audio', 'application'].indexOf(mediaType) !== -1 && @@ -179,7 +169,12 @@ class VideoPlayer extends React.PureComponent { !hasMetadata && !unplayable && } {unplayable && } -
+
{ + this.media = container; + }} + className="media" + />
); } From 019926059ed4a6bf205156487ae8350e99fc1157 Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Sun, 25 Feb 2018 15:18:03 -0500 Subject: [PATCH 3/3] Fix #754 --- src/renderer/component/video/internal/player.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/component/video/internal/player.jsx b/src/renderer/component/video/internal/player.jsx index c6a39026b..8bbf2692f 100644 --- a/src/renderer/component/video/internal/player.jsx +++ b/src/renderer/component/video/internal/player.jsx @@ -48,7 +48,7 @@ class VideoPlayer extends React.PureComponent { player.append( this.file(), container, - { autoplay: false, controls: true }, + { autoplay: true, controls: true }, renderMediaCallback.bind(this) ); }