-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
getViewBounds.ts
35 lines (31 loc) · 1.15 KB
/
getViewBounds.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { isMac } from '@/helpers/system';
import { container } from '@services/container';
import type { IPreferenceService } from '@services/preferences/interface';
import serviceIdentifier from '@services/serviceIdentifier';
export default async function getViewBounds(
contentSize: [number, number],
findInPage = false,
height?: number,
width?: number,
): Promise<{ height: number; width: number; x: number; y: number }> {
const preferencesService = container.get<IPreferenceService>(serviceIdentifier.Preference);
const showSidebar = await preferencesService.get('sidebar');
const x = showSidebar ? 68 : 0;
/** add title bar height, move down 28px https://github.com/electron/electron/pull/34713 */
const y = isMac ? 28 : 0;
if (findInPage) {
const FIND_IN_PAGE_HEIGHT = 42;
return {
x,
y: y + FIND_IN_PAGE_HEIGHT,
height: height !== undefined ? height : contentSize[1] - FIND_IN_PAGE_HEIGHT,
width: width !== undefined ? width : contentSize[0] - x,
};
}
return {
x,
y,
height: height !== undefined ? height : contentSize[1],
width: width !== undefined ? width : contentSize[0] - x,
};
}