-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathanimate.js
56 lines (38 loc) · 1.34 KB
/
animate.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
49
50
51
52
53
54
55
const animateWindow = (win, slide) => {
return new Promise((res, rej) => {
const { size, bounds } = screen.getPrimaryDisplay();
// get x/y field
const coord = slide.screenEdge == 'Left' || slide.screenEdge == 'Right' ? 'x' : 'y';
const dim = coord == 'x' ? 'width' : 'height';
const winBounds = win.getBounds();
// created window at x/y taking animation into account
let pos = winBounds[coord];
const speedMs = 150;
const timerInterval = 10;
let tick = 0;
const numTicks = parseInt(speedMs / timerInterval);
const offset = slide[dim] / numTicks;
//console.log('numTicks', numTicks, 'widthChunk', offset);
const timer = setInterval(() => {
tick++;
if (tick >= numTicks) {
clearInterval(timer);
res();
}
const winBounds = win.getBounds();
if (slide.screenEdge == 'Right' || slide.screenEdge == 'Down') {
// new position is current position +/- offset
pos = pos - offset;
}
const grownEnough = winBounds[dim] <= slide[dim];
const newDim = grownEnough ?
winBounds[dim] + offset
: winBounds[dim];
const newBounds = {};
newBounds[coord] = parseInt(pos, 10);
newBounds[dim] = parseInt(newDim, 10);
// set new bounds
win.setBounds(newBounds);
}, timerInterval);
});
};