Skip to content

Commit 11d72d4

Browse files
committed
Begin tracking window size
1 parent 0eec0c8 commit 11d72d4

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

js/actionCreators/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export {
2121
toggleMainWindowShadeMode,
2222
windowsHaveBeenCentered,
2323
centerWindowsIfNeeded,
24-
ensureWindowsAreOnScreen
24+
browserWindowSizeChanged
2525
} from "./windows";
2626
export {
2727
play,

js/actionCreators/windows.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
TOGGLE_WINDOW_SHADE_MODE,
1111
SET_WINDOW_VISIBILITY,
1212
WINDOWS_HAVE_BEEN_CENTERED,
13-
RESET_WINDOW_LAYOUT
13+
BROWSER_WINDOW_SIZE_CHANGED
1414
} from "../actionTypes";
1515

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

118-
export function resetWindowLayout(): Dispatchable {
119-
return { type: RESET_WINDOW_LAYOUT };
120-
}
121-
122118
export function centerWindowsIfNeeded(container: HTMLElement): Dispatchable {
123119
return (dispatch, getState) => {
124120
const state = getState();
@@ -187,6 +183,11 @@ export function centerWindowsIfNeeded(container: HTMLElement): Dispatchable {
187183
};
188184
}
189185

186+
export function browserWindowSizeChanged() {
187+
const { height, width } = Utils.getWindowSize();
188+
return { type: BROWSER_WINDOW_SIZE_CHANGED, height, width };
189+
}
190+
190191
export function ensureWindowsAreOnScreen(): Dispatchable {
191192
return (dispatch, getState) => {
192193
const state = getState();

js/actionTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ export const CLOSE_REQUESTED = "CLOSE_REQUESTED";
7474
export const LOAD_SERIALIZED_STATE = "LOAD_SERIALIZED_STATE";
7575
export const WINDOWS_HAVE_BEEN_CENTERED = "WINDOWS_HAVE_BEEN_CENTERED";
7676
export const RESET_WINDOW_LAYOUT = "RESET_WINDOW_LAYOUT";
77+
export const BROWSER_WINDOW_SIZE_CHANGED = "BROWSER_WINDOW_SIZE_CHANGED";

js/reducers/windows.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
WINDOW_SIZE_CHANGED,
1111
TOGGLE_WINDOW_SHADE_MODE,
1212
LOAD_SERIALIZED_STATE,
13-
RESET_WINDOW_LAYOUT
13+
RESET_WINDOW_LAYOUT,
14+
BROWSER_WINDOW_SIZE_CHANGED
1415
} from "../actionTypes";
1516
import * as Utils from "../utils";
1617

@@ -19,6 +20,7 @@ export interface WindowsState {
1920
centerRequested: boolean;
2021
genWindows: { [name: string]: WebampWindow };
2122
positions: WindowPositions;
23+
browserWindowSize: { height: number; width: number } | null;
2224
}
2325

2426
interface SerializedWindow {
@@ -77,7 +79,8 @@ const defaultWindowsState: WindowsState = {
7779
hotkey: "Alt+E"
7880
}
7981
},
80-
positions: {}
82+
positions: {},
83+
browserWindowSize: null
8184
};
8285

8386
const windows = (
@@ -224,6 +227,11 @@ const windows = (
224227
focused
225228
};
226229
}
230+
case BROWSER_WINDOW_SIZE_CHANGED:
231+
return {
232+
...state,
233+
browserWindowSize: { height: action.height, width: action.width }
234+
};
227235

228236
default:
229237
return state;

js/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ export type Action =
350350
type: "LOAD_SERIALIZED_STATE";
351351
serializedState: SerializedStateV1;
352352
}
353-
| { type: "RESET_WINDOW_LAYOUT" };
353+
| { type: "RESET_WINDOW_LAYOUT" }
354+
| { type: "BROWSER_WINDOW_SIZE_CHANGED"; height: number; width: number };
354355

355356
export interface WebampWindow {
356357
title: string;

js/webampLazy.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
setWindowSize,
1414
updateWindowPositions,
1515
loadSerializedState,
16-
ensureWindowsAreOnScreen
16+
ensureWindowsAreOnScreen,
17+
browserWindowSizeChanged
1718
} from "./actionCreators";
1819
import { LOAD_STYLE } from "./constants";
1920
import * as Utils from "./utils";
@@ -124,8 +125,10 @@ class Winamp {
124125
this.store.dispatch({ type: NETWORK_DISCONNECTED })
125126
);
126127

128+
this.store.dispatch(browserWindowSizeChanged());
127129
window.addEventListener("resize", () => {
128130
this.store.dispatch(ensureWindowsAreOnScreen());
131+
this.store.dispatch(browserWindowSizeChanged());
129132
});
130133

131134
if (initialSkin) {

0 commit comments

Comments
 (0)