Skip to content

Commit

Permalink
fix: use window size smaller than HD resolution if the window size do…
Browse files Browse the repository at this point in the history
…esn't allow for it (100px border allowance)
  • Loading branch information
sircharlo committed Dec 4, 2024
1 parent 8300558 commit ccaea31
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions src-electron/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export const TRUSTED_DOMAINS: string[] = [
'akamaihd.net',
'cloudfront.net',
];
export const HD_RESOLUTION = [1280, 720];
39 changes: 30 additions & 9 deletions src-electron/main/window/window-media.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BrowserWindow } from 'electron';
import type { ScreenPreferences } from 'src/types';

import { PLATFORM } from 'app/src-electron/constants';
import { HD_RESOLUTION, PLATFORM } from 'app/src-electron/constants';
import { captureElectronError } from 'app/src-electron/utils';
import { join, resolve } from 'path';

Expand All @@ -25,7 +25,7 @@ export function createMediaWindow() {
mediaWindow = createWindow('media', {
backgroundColor: 'black',
frame: false,
height: 720,
height: HD_RESOLUTION[1],
icon: resolve(
join(
__dirname,
Expand All @@ -37,7 +37,7 @@ export function createMediaWindow() {
minWidth: 195,
thickFrame: false,
title: 'Media Window',
width: 1280,
width: HD_RESOLUTION[0],
});

// Force aspect ratio
Expand Down Expand Up @@ -196,12 +196,33 @@ const setWindowPosition = (
setWindowBounds(targetScreenBounds, true);
});
} else {
const newBounds = {
height: 720,
width: 1280,
x: targetScreenBounds.x + 50,
y: targetScreenBounds.y + 50,
};
const HD_RESOLUTION_RATIO = HD_RESOLUTION[0] / HD_RESOLUTION[1];

const newBounds = (() => {
// Calculate max width and height while ensuring they don't exceed screen bounds
let maxHeight = Math.min(
targetScreenBounds.height - 100,
HD_RESOLUTION[1],
);
let maxWidth = Math.min(
targetScreenBounds.width - 100,
HD_RESOLUTION[0],
);

// Adjust height and width to maintain a 16:9 ratio
if (maxWidth / HD_RESOLUTION_RATIO <= maxHeight) {
maxHeight = Math.floor(maxWidth / HD_RESOLUTION_RATIO);
} else {
maxWidth = Math.floor(maxHeight * HD_RESOLUTION_RATIO);
}

return {
height: maxHeight,
width: maxWidth,
x: targetScreenBounds.x + 50,
y: targetScreenBounds.y + 50,
};
})();
if (
displayNr !== currentDisplayNr ||
mediaWindowIsFullScreen(targetScreenBounds) ||
Expand Down
6 changes: 3 additions & 3 deletions src-electron/main/window/window-website.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BrowserWindow, Video } from 'electron';
import type { NavigateWebsiteAction } from 'src/types';

import { PLATFORM } from 'app/src-electron/constants';
import { HD_RESOLUTION, PLATFORM } from 'app/src-electron/constants';
import {
askForMediaAccess,
captureElectronError,
Expand Down Expand Up @@ -29,11 +29,11 @@ export async function createWebsiteWindow(lang?: string) {
'website',
{
alwaysOnTop: true,
height: 720,
height: HD_RESOLUTION[1],
show: true,
title: 'Website Stream',
useContentSize: PLATFORM !== 'darwin',
width: 1280,
width: HD_RESOLUTION[0],
},
lang,
);
Expand Down

0 comments on commit ccaea31

Please sign in to comment.