diff --git a/js/actionCreators.js b/js/actionCreators.js index 7d1bf6ed..fb636ec9 100644 --- a/js/actionCreators.js +++ b/js/actionCreators.js @@ -5,14 +5,17 @@ import {BANDS} from './constants'; import {clamp} from './utils'; import { CLOSE_WINAMP, + LOAD_AUDIO_FILE, + LOAD_AUDIO_URL, + OPEN_FILE_DIALOG, SET_BALANCE, SET_BAND_VALUE, SET_SKIN_DATA, SET_VOLUME, START_LOADING, + STOP, TOGGLE_REPEAT, - TOGGLE_SHUFFLE, - STOP + TOGGLE_SHUFFLE } from './actionTypes'; export function play() { @@ -75,6 +78,25 @@ export function toggleShuffle() { return {type: TOGGLE_SHUFFLE}; } +const SKIN_FILENAME_MATCHER = new RegExp('(wsz|zip)$', 'i'); +export function loadFileFromReference(fileReference) { + return (dispatch) => { + const file = new MyFile(); + file.setFileReference(fileReference); + if (SKIN_FILENAME_MATCHER.test(fileReference.name)) { + dispatch(setSkinFromFile(file)); + } else { + dispatch({type: LOAD_AUDIO_FILE, file}); + } + }; +} + +export function loadMediaFromUrl(url, name) { + return (dispatch) => { + dispatch({type: LOAD_AUDIO_URL, url, name}); + }; +} + export function setSkinFromFile(skinFile) { return (dispatch) => { dispatch({type: START_LOADING}); @@ -98,8 +120,10 @@ export function setSkinFromFilename(filename) { return setSkinFromUrl(url); } -export function openFileDialog(winamp) { - winamp.openFileDialog(); +export function openFileDialog(fileInput) { + fileInput.click(); + // No reducers currently respond to this. + return {type: OPEN_FILE_DIALOG}; } export function setEqBand(band, value) { diff --git a/js/actionTypes.js b/js/actionTypes.js index c8a77db8..0203c95a 100644 --- a/js/actionTypes.js +++ b/js/actionTypes.js @@ -1,7 +1,10 @@ +export const LOAD_AUDIO_URL = 'LOAD_AUDIO_URL'; +export const LOAD_AUDIO_FILE = 'LOAD_AUDIO_FILE'; export const CLOSE_CONTEXT_MENU = 'CLOSE_CONTEXT_MENU'; export const CLOSE_WINAMP = 'CLOSE_WINAMP'; export const IS_PLAYING = 'IS_PLAYING'; export const IS_STOPPED = 'IS_STOPPED'; +export const OPEN_FILE_DIALOG = 'OPEN_FILE_DIALOG'; export const PAUSE = 'PAUSE'; export const PLAY = 'PLAY'; export const SEEK_TO_PERCENT_COMPLETE = 'SEEK_TO_PERCENT_COMPLETE'; diff --git a/js/components/ContextMenu.jsx b/js/components/ContextMenu.jsx index 18c808a4..2f6b9c40 100644 --- a/js/components/ContextMenu.jsx +++ b/js/components/ContextMenu.jsx @@ -63,7 +63,7 @@ const mapDispatchToProps = (dispatch, ownProps) => ({ dispatch({type: TOGGLE_CONTEXT_MENU}); e.stopPropagation(); }, - openFileDialog: () => openFileDialog(ownProps.winamp), + openFileDialog: () => dispatch(openFileDialog(ownProps.fileInput)), setSkin: (filename) => dispatch(setSkinFromFilename(filename)) }); diff --git a/js/components/Eject.jsx b/js/components/Eject.jsx index 68e3cf64..211ffc3b 100644 --- a/js/components/Eject.jsx +++ b/js/components/Eject.jsx @@ -3,23 +3,15 @@ import {connect} from 'react-redux'; import {openFileDialog} from '../actionCreators'; +const Eject = (props) => ( +
+); -class Eject extends React.Component { - constructor(props) { - super(props); - this.handleClick = this.handleClick.bind(this); - } - handleClick() { - openFileDialog(this.props.winamp); - } - render() { - return ( -
- ); - } -} +const mapDispatchToProps = (dispatch, ownProps) => ({ + openFileDialog: () => dispatch(openFileDialog(ownProps.fileInput)) +}); -module.exports = connect()(Eject); +module.exports = connect(() => ({}), mapDispatchToProps)(Eject); diff --git a/js/components/MainWindow.jsx b/js/components/MainWindow.jsx index def8da7d..cb2dd375 100644 --- a/js/components/MainWindow.jsx +++ b/js/components/MainWindow.jsx @@ -29,6 +29,8 @@ import { SET_FOCUSED_WINDOW } from '../actionTypes'; +import {loadFileFromReference} from '../actionCreators'; + import '../../css/main-window.css'; export class MainWindow extends React.Component { @@ -51,7 +53,7 @@ export class MainWindow extends React.Component { this.supress(e); const {files} = e.dataTransfer; // TODO: Move this to an actionCreator - this.props.winamp.loadFromFileReference(files[0]); + this.props.dispatch(loadFileFromReference(files[0])); } render() { @@ -85,7 +87,7 @@ export class MainWindow extends React.Component { >
Loading...
- +
@@ -112,7 +114,7 @@ export class MainWindow extends React.Component {
- +
diff --git a/js/hotkeys.js b/js/hotkeys.js index edfb44c9..5dd80591 100644 --- a/js/hotkeys.js +++ b/js/hotkeys.js @@ -59,7 +59,7 @@ module.exports = function(winamp, {dispatch}) { dispatch(pause()); break; case 76: // L - openFileDialog(winamp); + dispatch(openFileDialog(winamp.fileInput)); break; case 82: // R dispatch(toggleRepeat()); @@ -77,7 +77,7 @@ module.exports = function(winamp, {dispatch}) { winamp.previous(); break; case 96: // numpad 0 - openFileDialog(winamp); + dispatch(openFileDialog(winamp.fileInput)); break; case 97: // numpad 1 winamp.previous(10); diff --git a/js/index.js b/js/index.js index 38f6c1b9..230a8bd9 100644 --- a/js/index.js +++ b/js/index.js @@ -30,7 +30,7 @@ if (new Browser(window).isCompatible) { the , but browsers don't really care... */} - + { playlist ? : '' } { equalizer ? : '' } diff --git a/js/media.js b/js/media.js index e061f038..d83279dd 100644 --- a/js/media.js +++ b/js/media.js @@ -1,5 +1,6 @@ /* Emulate the native