diff --git a/js/actionCreators/index.js b/js/actionCreators/index.js index 833e15fa..52a7ba44 100644 --- a/js/actionCreators/index.js +++ b/js/actionCreators/index.js @@ -5,6 +5,7 @@ export { toggleEqualizerShadeMode, togglePlaylistShadeMode, closeWindow, + hideWindow, setWindowSize, toggleWindow, updateWindowPositions, diff --git a/js/actionCreators/windows.js b/js/actionCreators/windows.js index c6797ed6..34404221 100644 --- a/js/actionCreators/windows.js +++ b/js/actionCreators/windows.js @@ -11,7 +11,8 @@ import { WINDOW_SIZE_CHANGED, TOGGLE_WINDOW, CLOSE_WINDOW, - TOGGLE_WINDOW_SHADE_MODE + TOGGLE_WINDOW_SHADE_MODE, + HIDE_WINDOW } from "../actionTypes"; import { getPositionDiff } from "../resizeUtils"; @@ -82,6 +83,9 @@ export function closeWindow(windowId) { return { type: CLOSE_WINDOW, windowId }; } +export function hideWindow(windowId) { + return { type: HIDE_WINDOW, windowId }; +} export function setWindowSize(windowId, size) { return { type: WINDOW_SIZE_CHANGED, windowId, size }; } diff --git a/js/components/MilkdropWindow/index.js b/js/components/MilkdropWindow/index.js index 22d13187..9b4f5c4d 100644 --- a/js/components/MilkdropWindow/index.js +++ b/js/components/MilkdropWindow/index.js @@ -1,7 +1,9 @@ import React from "react"; +import { connect } from "react-redux"; import screenfull from "screenfull"; import ContextMenuWrapper from "../ContextMenuWrapper"; import GenWindow from "../GenWindow"; +import { hideWindow } from "../../actionCreators"; import MilkdropContextMenu from "./MilkdropContextMenu"; import Desktop from "./Desktop"; @@ -14,7 +16,7 @@ import "../../../css/milkdrop-window.css"; // This component is just responsible for loading dependencies. // This simplifies the inner component, by allowing // it to alwasy assume that it has its dependencies. -export default class PresetsLoader extends React.Component { +class PresetsLoader extends React.Component { constructor() { super(); this.state = { @@ -28,6 +30,10 @@ export default class PresetsLoader extends React.Component { this._enableDesktop = this._enableDesktop.bind(this); } + isHidden() { + return this.state.desktop; + } + async componentDidMount() { const { butterchurn, @@ -55,6 +61,7 @@ export default class PresetsLoader extends React.Component { } _enableDesktop() { + this.props.hideWindow(this.props.windowId); this.setState({ desktop: true }); } @@ -159,3 +166,13 @@ async function loadNonMinimalPresets() { ); }); } + +const mapStateToProps = () => ({}); +const mapDispatchProps = { + hideWindow +}; + +export default connect( + mapStateToProps, + mapDispatchProps +)(PresetsLoader); diff --git a/js/components/WindowManager.js b/js/components/WindowManager.js index f26231a2..a8248cf5 100644 --- a/js/components/WindowManager.js +++ b/js/components/WindowManager.js @@ -11,7 +11,7 @@ import { applyDiff, applyMultipleDiffs } from "../snapUtils"; -import { getWindowsInfo } from "../selectors"; +import { getWindowsInfo, getWindowHidden } from "../selectors"; import { updateWindowPositions } from "../actionCreators"; import { WINDOW_HEIGHT, WINDOW_WIDTH } from "../constants"; import { calculateBoundingBox } from "../utils"; @@ -84,7 +84,8 @@ class WindowManager extends React.Component { movingAndStationaryNodes(key) { const windows = this.props.windowsInfo.filter( - w => this.props.windows[w.key] != null + w => + this.props.windows[w.key] != null && !this.props.getWindowHidden(w.key) ); const targetNode = windows.find(node => node.key === key); @@ -214,7 +215,8 @@ WindowManager.propTypes = { }; const mapStateToProps = state => ({ - windowsInfo: getWindowsInfo(state) + windowsInfo: getWindowsInfo(state), + getWindowHidden: getWindowHidden(state) }); const mapDispatchToProps = { diff --git a/js/reducers/windows.js b/js/reducers/windows.js index ecdac57d..6c480993 100644 --- a/js/reducers/windows.js +++ b/js/reducers/windows.js @@ -3,6 +3,7 @@ import { SET_FOCUSED_WINDOW, TOGGLE_WINDOW, CLOSE_WINDOW, + HIDE_WINDOW, ADD_GEN_WINDOW, UPDATE_WINDOW_POSITIONS, WINDOW_SIZE_CHANGED, @@ -17,6 +18,7 @@ const defaultWindowsState = { title: "Main Window", size: [0, 0], open: true, + hidden: false, shade: false, canResize: false, canShade: true, @@ -28,6 +30,7 @@ const defaultWindowsState = { title: "Equalizer", size: [0, 0], open: true, + hidden: false, shade: false, canResize: false, canShade: true, @@ -39,6 +42,7 @@ const defaultWindowsState = { title: "Playlist Editor", size: [0, 0], open: true, + hidden: false, shade: false, canResize: true, canShade: true, @@ -94,6 +98,17 @@ const windows = (state = defaultWindowsState, action) => { } } }; + case HIDE_WINDOW: + return { + ...state, + genWindows: { + ...state.genWindows, + [action.windowId]: { + ...state.genWindows[action.windowId], + hidden: true + } + } + }; case ADD_GEN_WINDOW: return { ...state, @@ -102,6 +117,7 @@ const windows = (state = defaultWindowsState, action) => { [action.windowId]: { title: action.title, open: true, + hidden: false, size: [0, 0], canShade: false, canResize: true, diff --git a/js/selectors.js b/js/selectors.js index 9d733fbc..28146d1b 100644 --- a/js/selectors.js +++ b/js/selectors.js @@ -279,6 +279,10 @@ export function getWindowShade(state, windowId) { return state.windows.genWindows[windowId].shade; } +export function getWindowHidden(state) { + return windowId => state.windows.genWindows[windowId].hidden; +} + export const getGenWindows = state => { return state.windows.genWindows; };