From 9f5c20d4133fc32cd455e322ac83e19831861aa8 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sun, 21 Oct 2018 15:49:54 -0700 Subject: [PATCH] Require load style always be explicit Fixes #687 --- js/actionCreators/files.ts | 11 ++++++----- js/components/PlaylistWindow/index.tsx | 10 +++++++++- js/constants.ts | 3 ++- js/types.ts | 2 +- js/webampLazy.js | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/js/actionCreators/files.ts b/js/actionCreators/files.ts index 013cb5a5..456de26d 100644 --- a/js/actionCreators/files.ts +++ b/js/actionCreators/files.ts @@ -56,7 +56,7 @@ const loadQueue = new LoadQueue({ threads: 4 }); export function addTracksFromReferences( fileReferences: FileList, - loadStyle: LoadStyle | null, + loadStyle: LoadStyle, atIndex: number | undefined ): Dispatchable { const tracks: Track[] = Array.from(fileReferences).map(file => ({ @@ -70,7 +70,7 @@ const SKIN_FILENAME_MATCHER = new RegExp("(wsz|zip)$", "i"); const EQF_FILENAME_MATCHER = new RegExp("eqf$", "i"); export function loadFilesFromReferences( fileReferences: FileList, - loadStyle: LoadStyle | null = LOAD_STYLE.PLAY, + loadStyle: LoadStyle = LOAD_STYLE.PLAY, atIndex: number | undefined = undefined ): Dispatchable { return dispatch => { @@ -206,7 +206,7 @@ export function fetchMediaDuration(url: string, id: number): Dispatchable { export function loadMediaFiles( tracks: Track[], - loadStyle: LoadStyle | null = null, + loadStyle: LoadStyle = LOAD_STYLE.NONE, atIndex = 0 ): Dispatchable { return dispatch => { @@ -216,7 +216,7 @@ export function loadMediaFiles( dispatch(removeAllTracks()); } tracks.forEach((track, i) => { - const priority = i === 0 && loadStyle != null ? loadStyle : null; + const priority = i === 0 ? loadStyle : LOAD_STYLE.NONE; dispatch(loadMediaFile(track, priority, atIndex + i)); }); }; @@ -224,7 +224,7 @@ export function loadMediaFiles( export function loadMediaFile( track: Track, - priority: LoadStyle | null = null, + priority: LoadStyle = LOAD_STYLE.NONE, atIndex = 0 ): Dispatchable { return dispatch => { @@ -253,6 +253,7 @@ export function loadMediaFile( case LOAD_STYLE.PLAY: dispatch({ type: PLAY_TRACK, id }); break; + case LOAD_STYLE.NONE: default: // If we're not going to load this right away, // we should set duration on our own diff --git a/js/components/PlaylistWindow/index.tsx b/js/components/PlaylistWindow/index.tsx index 58b46b0a..7a8c4e35 100644 --- a/js/components/PlaylistWindow/index.tsx +++ b/js/components/PlaylistWindow/index.tsx @@ -21,6 +21,8 @@ import { getSkinPlaylistStyle } from "../../selectors"; +import { LOAD_STYLE } from "../../constants"; + import { clamp } from "../../utils"; import DropTarget from "../DropTarget"; import Visualizer from "../Visualizer"; @@ -200,7 +202,13 @@ const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => { scrollUpFourTracks: () => dispatch(scrollUpFourTracks()), scrollDownFourTracks: () => dispatch(scrollDownFourTracks()), loadFilesFromReferences: (e, startIndex) => - dispatch(loadFilesFromReferences(e.dataTransfer.files, null, startIndex)), + dispatch( + loadFilesFromReferences( + e.dataTransfer.files, + LOAD_STYLE.NONE, + startIndex + ) + ), scrollVolume: e => dispatch(scrollVolume(e)) }; }; diff --git a/js/constants.ts b/js/constants.ts index cbdfff7d..3e903d62 100644 --- a/js/constants.ts +++ b/js/constants.ts @@ -28,7 +28,8 @@ export const WINDOWS = { export const LOAD_STYLE: Record = { BUFFER: "BUFFER", - PLAY: "PLAY" + PLAY: "PLAY", + NONE: "NONE" }; // TODO: Make this an enum? diff --git a/js/types.ts b/js/types.ts index 57605171..4c0eb4c5 100644 --- a/js/types.ts +++ b/js/types.ts @@ -424,7 +424,7 @@ export type MediaTagRequestStatus = export type MediaStatus = "PLAYING" | "STOPPED" | "PAUSED"; -export type LoadStyle = "BUFFER" | "PLAY"; +export type LoadStyle = "BUFFER" | "PLAY" | "NONE"; export type TimeMode = "ELAPSED" | "REMAINING"; diff --git a/js/webampLazy.js b/js/webampLazy.js index dbd2eee8..3841b88c 100644 --- a/js/webampLazy.js +++ b/js/webampLazy.js @@ -192,7 +192,7 @@ class Winamp { appendTracks(tracks) { const nextIndex = Selectors.getTrackCount(this.store.getState()); this.store.dispatch( - Actions.loadMediaFiles(tracks, LOAD_STYLE.BUFFER, nextIndex) + Actions.loadMediaFiles(tracks, LOAD_STYLE.NONE, nextIndex) ); }