Skip to content

Commit

Permalink
Don't center windows when restoring from serialized state
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed Oct 1, 2018
1 parent 777d482 commit ca1cfe3
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 23 deletions.
3 changes: 2 additions & 1 deletion js/actionCreators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export {
setWindowSize,
toggleWindow,
updateWindowPositions,
toggleMainWindowShadeMode
toggleMainWindowShadeMode,
windowsHaveBeenCentered
} from "./windows";
export {
play,
Expand Down
14 changes: 10 additions & 4 deletions js/actionCreators/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -51,7 +52,7 @@ function withWindowGraphIntegrity(action: Action): Dispatchable {
applyDiff(position, positionDiff[key])
);

dispatch(updateWindowPositions(newPositions));
dispatch(updateWindowPositions(newPositions, false));
};
}

Expand Down Expand Up @@ -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 };
}
1 change: 1 addition & 0 deletions js/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
33 changes: 25 additions & 8 deletions js/components/WindowManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;
Expand Down Expand Up @@ -78,6 +89,7 @@ class WindowManager extends React.Component {

this.props.updateWindowPositions(newPositions);
}
this.props.windowsHaveBeenCentered();
};

movingAndStationaryNodes(key) {
Expand Down Expand Up @@ -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(
Expand Down
18 changes: 14 additions & 4 deletions js/reducers/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { objectMap } from "../utils";

export interface WindowsState {
focused: string;
centerRequested: boolean;
genWindows: { [name: string]: WebampWindow };
positions: WindowPositions;
}
Expand All @@ -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: {
Expand Down Expand Up @@ -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,
Expand All @@ -196,7 +204,8 @@ const windows = (
return position;
}
return serializedPosition;
})
}),
centerRequested: serializedCenterRequested
};
}

Expand All @@ -217,7 +226,8 @@ export function getSerializedState(
shade: w.shade || false
};
}),
positions: state.positions
positions: state.positions,
centerRequested: state.centerRequested
};
}

Expand Down
4 changes: 4 additions & 0 deletions js/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export type Action =
| {
type: "UPDATE_WINDOW_POSITIONS";
positions: WindowPositions;
center: boolean;
}
| {
type: "CLICKED_TRACK";
Expand Down
11 changes: 5 additions & 6 deletions js/webampLazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
seekBackward,
seekForward,
next,
previous
previous,
updateWindowPositions
} from "./actionCreators";
import { LOAD_STYLE } from "./constants";
import { uniqueId, objectMap, objectForEach } from "./utils";
Expand All @@ -28,7 +29,6 @@ import {
CLOSE_WINAMP,
MINIMIZE_WINAMP,
ADD_GEN_WINDOW,
UPDATE_WINDOW_POSITIONS,
LOADED,
REGISTER_VISUALIZER,
SET_Z_INDEX,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ca1cfe3

Please sign in to comment.