-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
48 lines (40 loc) · 1.37 KB
/
index.js
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
const {convertWidth, convertHeight} = require("./columnRow.js");
const CONFIG_KEY = "hyperWindowSize";
const DEFAULT_WIDTH = 540;
const DEFAULT_HEIGHT = 380;
const DEFAULT_POS_X = 50;
const DEFAULT_POS_Y = 50;
let width = null;
let height = null;
let startX = null;
let startY = null;
let browserWindowSingleton = null;
const trySetSize = () => {
if (browserWindowSingleton && !browserWindowSingleton.isDestroyed()) {
if (typeof height === "number" && typeof width === "number") {
browserWindowSingleton.setSize(width, height);
}
if (typeof startX === "number" && typeof startY === "number") {
browserWindowSingleton.setPosition(startX, startY);
}
}
};
module.exports.decorateConfig = config => {
if (config[CONFIG_KEY].transform === true) {
width = convertWidth(config[CONFIG_KEY].width);
height = convertHeight(config[CONFIG_KEY].height);
} else if (config[CONFIG_KEY].width || config[CONFIG_KEY].height) {
width = config[CONFIG_KEY].width || DEFAULT_WIDTH;
height = config[CONFIG_KEY].height || DEFAULT_HEIGHT;
}
if (config[CONFIG_KEY].startX || config[CONFIG_KEY].startY) {
startX = config[CONFIG_KEY].startX || DEFAULT_POS_X;
startY = config[CONFIG_KEY].startY || DEFAULT_POS_Y;
}
trySetSize();
return config;
};
module.exports.onWindow = browserWindow => {
browserWindowSingleton = browserWindow;
trySetSize();
};