mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-28 20:40:39 +00:00
Handle case where there are no windows and thus no sensible bounding box
Resolves Sentry issue WINAMP2-JS-PROD-GC
This commit is contained in:
parent
e57a958613
commit
328e9f8074
2 changed files with 26 additions and 14 deletions
|
|
@ -159,6 +159,11 @@ export function centerWindows(box: {
|
|||
windowsInfo.filter(w => getOpen(w.key))
|
||||
);
|
||||
|
||||
if (bounding == null) {
|
||||
// There are no windows to center
|
||||
return;
|
||||
}
|
||||
|
||||
const boxHeight = bounding.bottom - bounding.top;
|
||||
const boxWidth = bounding.right - bounding.left;
|
||||
|
||||
|
|
@ -211,6 +216,10 @@ export function ensureWindowsAreOnScreen(): Thunk {
|
|||
const bounding = Utils.calculateBoundingBox(
|
||||
windowsInfo.filter(w => getOpen(w.key))
|
||||
);
|
||||
if (bounding == null) {
|
||||
// There are no windows visible, so there's no work to do.
|
||||
return;
|
||||
}
|
||||
const positions = Selectors.getWindowPositions(state);
|
||||
|
||||
// Are we good?
|
||||
|
|
|
|||
31
js/utils.ts
31
js/utils.ts
|
|
@ -336,20 +336,23 @@ export function objectFilter<V>(
|
|||
}, {});
|
||||
}
|
||||
|
||||
export const calculateBoundingBox = (windows: WindowInfo[]) =>
|
||||
windows
|
||||
.map(w => ({
|
||||
left: w.x,
|
||||
top: w.y,
|
||||
bottom: w.y + w.height,
|
||||
right: w.x + w.width,
|
||||
}))
|
||||
.reduce((b, w) => ({
|
||||
left: Math.min(b.left, w.left),
|
||||
top: Math.min(b.top, w.top),
|
||||
bottom: Math.max(b.bottom, w.bottom),
|
||||
right: Math.max(b.right, w.right),
|
||||
}));
|
||||
export const calculateBoundingBox = (windows: WindowInfo[]) => {
|
||||
if (windows.length === 0) {
|
||||
return null;
|
||||
}
|
||||
const windowSizes = windows.map(w => ({
|
||||
left: w.x,
|
||||
top: w.y,
|
||||
bottom: w.y + w.height,
|
||||
right: w.x + w.width,
|
||||
}));
|
||||
return windowSizes.reduce((b, w) => ({
|
||||
left: Math.min(b.left, w.left),
|
||||
top: Math.min(b.top, w.top),
|
||||
bottom: Math.max(b.bottom, w.bottom),
|
||||
right: Math.max(b.right, w.right),
|
||||
}));
|
||||
};
|
||||
|
||||
export function findLastIndex<T>(arr: T[], cb: (val: T) => boolean) {
|
||||
for (let i = arr.length - 1; i >= 0; i--) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue