Skip to content

Commit

Permalink
Begin tracking window size
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed Sep 23, 2018
1 parent 0eec0c8 commit 11d72d4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion js/actionCreators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export {
toggleMainWindowShadeMode,
windowsHaveBeenCentered,
centerWindowsIfNeeded,
ensureWindowsAreOnScreen
browserWindowSizeChanged
} from "./windows";
export {
play,
Expand Down
11 changes: 6 additions & 5 deletions js/actionCreators/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TOGGLE_WINDOW_SHADE_MODE,
SET_WINDOW_VISIBILITY,
WINDOWS_HAVE_BEEN_CENTERED,
RESET_WINDOW_LAYOUT
BROWSER_WINDOW_SIZE_CHANGED
} from "../actionTypes";

import { getPositionDiff, SizeDiff } from "../resizeUtils";
Expand Down Expand Up @@ -115,10 +115,6 @@ export function windowsHaveBeenCentered(): Dispatchable {
return { type: WINDOWS_HAVE_BEEN_CENTERED };
}

export function resetWindowLayout(): Dispatchable {
return { type: RESET_WINDOW_LAYOUT };
}

export function centerWindowsIfNeeded(container: HTMLElement): Dispatchable {
return (dispatch, getState) => {
const state = getState();
Expand Down Expand Up @@ -187,6 +183,11 @@ export function centerWindowsIfNeeded(container: HTMLElement): Dispatchable {
};
}

export function browserWindowSizeChanged() {
const { height, width } = Utils.getWindowSize();
return { type: BROWSER_WINDOW_SIZE_CHANGED, height, width };
}

export function ensureWindowsAreOnScreen(): Dispatchable {
return (dispatch, getState) => {
const state = getState();
Expand Down
1 change: 1 addition & 0 deletions js/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ export const CLOSE_REQUESTED = "CLOSE_REQUESTED";
export const LOAD_SERIALIZED_STATE = "LOAD_SERIALIZED_STATE";
export const WINDOWS_HAVE_BEEN_CENTERED = "WINDOWS_HAVE_BEEN_CENTERED";
export const RESET_WINDOW_LAYOUT = "RESET_WINDOW_LAYOUT";
export const BROWSER_WINDOW_SIZE_CHANGED = "BROWSER_WINDOW_SIZE_CHANGED";
12 changes: 10 additions & 2 deletions js/reducers/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
WINDOW_SIZE_CHANGED,
TOGGLE_WINDOW_SHADE_MODE,
LOAD_SERIALIZED_STATE,
RESET_WINDOW_LAYOUT
RESET_WINDOW_LAYOUT,
BROWSER_WINDOW_SIZE_CHANGED
} from "../actionTypes";
import * as Utils from "../utils";

Expand All @@ -19,6 +20,7 @@ export interface WindowsState {
centerRequested: boolean;
genWindows: { [name: string]: WebampWindow };
positions: WindowPositions;
browserWindowSize: { height: number; width: number } | null;
}

interface SerializedWindow {
Expand Down Expand Up @@ -77,7 +79,8 @@ const defaultWindowsState: WindowsState = {
hotkey: "Alt+E"
}
},
positions: {}
positions: {},
browserWindowSize: null
};

const windows = (
Expand Down Expand Up @@ -224,6 +227,11 @@ const windows = (
focused
};
}
case BROWSER_WINDOW_SIZE_CHANGED:
return {
...state,
browserWindowSize: { height: action.height, width: action.width }
};

default:
return state;
Expand Down
3 changes: 2 additions & 1 deletion js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ export type Action =
type: "LOAD_SERIALIZED_STATE";
serializedState: SerializedStateV1;
}
| { type: "RESET_WINDOW_LAYOUT" };
| { type: "RESET_WINDOW_LAYOUT" }
| { type: "BROWSER_WINDOW_SIZE_CHANGED"; height: number; width: number };

export interface WebampWindow {
title: string;
Expand Down
5 changes: 4 additions & 1 deletion js/webampLazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
setWindowSize,
updateWindowPositions,
loadSerializedState,
ensureWindowsAreOnScreen
ensureWindowsAreOnScreen,
browserWindowSizeChanged
} from "./actionCreators";
import { LOAD_STYLE } from "./constants";
import * as Utils from "./utils";
Expand Down Expand Up @@ -124,8 +125,10 @@ class Winamp {
this.store.dispatch({ type: NETWORK_DISCONNECTED })
);

this.store.dispatch(browserWindowSizeChanged());
window.addEventListener("resize", () => {
this.store.dispatch(ensureWindowsAreOnScreen());
this.store.dispatch(browserWindowSizeChanged());
});

if (initialSkin) {
Expand Down

0 comments on commit 11d72d4

Please sign in to comment.