Don't center windows when restoring from serialized state

This commit is contained in:
Jordan Eldredge 2018-09-19 21:43:56 -07:00
parent 777d482e73
commit ca1cfe3dc6
8 changed files with 62 additions and 23 deletions

View file

@ -19,7 +19,8 @@ export {
setWindowSize,
toggleWindow,
updateWindowPositions,
toggleMainWindowShadeMode
toggleMainWindowShadeMode,
windowsHaveBeenCentered
} from "./windows";
export {
play,

View file

@ -12,7 +12,8 @@ import {
TOGGLE_WINDOW,
CLOSE_WINDOW,
TOGGLE_WINDOW_SHADE_MODE,
SET_WINDOW_VISIBILITY
SET_WINDOW_VISIBILITY,
WINDOWS_HAVE_BEEN_CENTERED
} from "../actionTypes";
import { getPositionDiff, SizeDiff } from "../resizeUtils";
@ -51,7 +52,7 @@ function withWindowGraphIntegrity(action: Action): Dispatchable {
applyDiff(position, positionDiff[key])
);
dispatch(updateWindowPositions(newPositions));
dispatch(updateWindowPositions(newPositions, false));
};
}
@ -104,7 +105,12 @@ export function toggleWindow(windowId: WindowId): Dispatchable {
}
export function updateWindowPositions(
positions: WindowPositions
positions: WindowPositions,
center: boolean
): Dispatchable {
return { type: UPDATE_WINDOW_POSITIONS, positions };
return { type: UPDATE_WINDOW_POSITIONS, positions, center };
}
export function windowsHaveBeenCentered() {
return { type: WINDOWS_HAVE_BEEN_CENTERED };
}

View file

@ -72,3 +72,4 @@ export const SET_WINDOW_VISIBILITY = "SET_WINDOW_VISIBILITY";
export const LOADING = "LOADING";
export const CLOSE_REQUESTED = "CLOSE_REQUESTED";
export const LOAD_SERIALIZED_STATE = "LOAD_SERIALIZED_STATE";
export const WINDOWS_HAVE_BEEN_CENTERED = "WINDOWS_HAVE_BEEN_CENTERED";

View file

@ -11,8 +11,16 @@ import {
applyDiff,
applyMultipleDiffs
} from "../snapUtils";
import { getWindowsInfo, getWindowHidden, getWindowOpen } from "../selectors";
import { updateWindowPositions } from "../actionCreators";
import {
getWindowsInfo,
getWindowHidden,
getWindowOpen,
getCenterRequested
} from "../selectors";
import {
updateWindowPositions,
windowsHaveBeenCentered
} from "../actionCreators";
import { WINDOW_HEIGHT, WINDOW_WIDTH } from "../constants";
import { calculateBoundingBox } from "../utils";
@ -25,11 +33,14 @@ const abuts = (a, b) => {
class WindowManager extends React.Component {
componentDidMount() {
this.centerWindows();
this.centerWindowsIfNeeded();
}
centerWindows = () => {
const { container } = this.props;
centerWindowsIfNeeded = () => {
const { container, centerRequested } = this.props;
if (!centerRequested) {
return;
}
const rect = container.getBoundingClientRect();
const offsetLeft = rect.left + window.scrollX;
@ -78,6 +89,7 @@ class WindowManager extends React.Component {
this.props.updateWindowPositions(newPositions);
}
this.props.windowsHaveBeenCentered();
};
movingAndStationaryNodes(key) {
@ -210,11 +222,16 @@ WindowManager.propTypes = {
const mapStateToProps = state => ({
windowsInfo: getWindowsInfo(state),
getWindowHidden: getWindowHidden(state),
getWindowOpen: getWindowOpen(state)
getWindowOpen: getWindowOpen(state),
centerRequested: getCenterRequested(state)
});
const mapDispatchToProps = {
updateWindowPositions
const mapDispatchToProps = dispatch => {
return {
updateWindowPositions: positions =>
dispatch(updateWindowPositions(positions)),
windowsHaveBeenCentered: () => dispatch(windowsHaveBeenCentered())
};
};
export default connect(

View file

@ -15,6 +15,7 @@ import { objectMap } from "../utils";
export interface WindowsState {
focused: string;
centerRequested: boolean;
genWindows: { [name: string]: WebampWindow };
positions: WindowPositions;
}
@ -28,11 +29,13 @@ interface SerializedWindow {
export interface WindowsSerializedStateV1 {
genWindows: { [windowId: string]: SerializedWindow };
centerRequested: boolean;
positions: WindowPositions;
}
const defaultWindowsState: WindowsState = {
focused: WINDOWS.MAIN,
centerRequested: false,
genWindows: {
// TODO: Remove static capabilites and derive them from ids/generic
main: {
@ -174,12 +177,17 @@ const windows = (
case UPDATE_WINDOW_POSITIONS:
return {
...state,
positions: { ...state.positions, ...action.positions }
positions: {
...state.positions,
...action.positions
},
centerRequested: action.center
};
case LOAD_SERIALIZED_STATE: {
const {
genWindows: serializedWindows,
positions: serializedPositions
positions: serializedPositions,
centerRequested: serializedCenterRequested
} = action.serializedState.windows;
return {
...state,
@ -196,7 +204,8 @@ const windows = (
return position;
}
return serializedPosition;
})
}),
centerRequested: serializedCenterRequested
};
}
@ -217,7 +226,8 @@ export function getSerializedState(
shade: w.shade || false
};
}),
positions: state.positions
positions: state.positions,
centerRequested: state.centerRequested
};
}

View file

@ -427,3 +427,7 @@ export function getBalance(state: AppState): number {
export function getEqualizerEnabled(state: AppState): boolean {
return state.equalizer.on;
}
export function getCenterRequested(state: AppState): boolean {
return state.windows.centerRequested;
}

View file

@ -256,6 +256,7 @@ export type Action =
| {
type: "UPDATE_WINDOW_POSITIONS";
positions: WindowPositions;
center: boolean;
}
| {
type: "CLICKED_TRACK";

View file

@ -16,7 +16,8 @@ import {
seekBackward,
seekForward,
next,
previous
previous,
updateWindowPositions
} from "./actionCreators";
import { LOAD_STYLE } from "./constants";
import { uniqueId, objectMap, objectForEach } from "./utils";
@ -28,7 +29,6 @@ import {
CLOSE_WINAMP,
MINIMIZE_WINAMP,
ADD_GEN_WINDOW,
UPDATE_WINDOW_POSITIONS,
LOADED,
REGISTER_VISUALIZER,
SET_Z_INDEX,
@ -155,10 +155,9 @@ class Winamp {
this.store.dispatch(setWindowSize(windowId, w.size));
}
});
this.store.dispatch({
type: UPDATE_WINDOW_POSITIONS,
positions: objectMap(layout, w => w.position)
});
this.store.dispatch(
updateWindowPositions(objectMap(layout, w => w.position), true)
);
}
if (enableHotkeys) {