forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
56 lines (50 loc) · 1.94 KB
/
utils.js
File metadata and controls
56 lines (50 loc) · 1.94 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { screen } from 'electron'
import { isLinux } from '../config'
export const zoomIn = win => {
const { webContents } = win
const zoom = webContents.getZoomFactor()
// WORKAROUND: We need to set zoom on the browser window due to Electron#16018.
webContents.send('mt::window-zoom', Math.min(2.0, zoom + 0.125))
}
export const zoomOut = win => {
const { webContents } = win
const zoom = webContents.getZoomFactor()
// WORKAROUND: We need to set zoom on the browser window due to Electron#16018.
webContents.send('mt::window-zoom', Math.max(0.5, zoom - 0.125))
}
export const centerWindowOptions = options => {
// "workArea" doesn't work on Linux
const { bounds, workArea } = screen.getDisplayNearestPoint(screen.getCursorScreenPoint())
const screenArea = isLinux ? bounds : workArea
const { width, height } = options
options.x = Math.ceil(screenArea.x + (screenArea.width - width) / 2)
options.y = Math.ceil(screenArea.y + (screenArea.height - height) / 2)
}
export const ensureWindowPosition = windowState => {
// "workArea" doesn't work on Linux
const { bounds, workArea } = screen.getPrimaryDisplay()
const screenArea = isLinux ? bounds : workArea
let { x, y, width, height } = windowState
let center = false
if (x === undefined || y === undefined) {
center = true
// First app start; check whether window size is larger than screen size
if (screenArea.width < width) width = screenArea.width
if (screenArea.height < height) height = screenArea.height
} else {
center = !screen.getAllDisplays().map(display =>
x >= display.bounds.x && x <= display.bounds.x + display.bounds.width &&
y >= display.bounds.y && y <= display.bounds.y + display.bounds.height)
.some(display => display)
}
if (center) {
x = Math.ceil(screenArea.x + (screenArea.width - width) / 2)
y = Math.ceil(screenArea.y + (screenArea.height - height) / 2)
}
return {
x,
y,
width,
height
}
}