-
Notifications
You must be signed in to change notification settings - Fork 0
/
external-window-snapshot.js
40 lines (35 loc) · 1.32 KB
/
external-window-snapshot.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
async function getExternalWindowByNameTitle(name, title) {
const externalWindows = await fin.System.getAllExternalWindows();
const externalWin = externalWindows.find(w => (w.name === name && w.title == title));
if (externalWin) {
return await fin.ExternalWindow.wrap(externalWin);
} else {
return void 0;
}
}
async function getExternalWindowInfo(name, title) {
const exWin = await getExternalWindowByNameTitle(name, title);
if (exWin) {
return await exWin.getInfo();
} else {
return void 0;
}
}
async function generateExternalWindowSnapshot(externalWins) {
return await Promise.all(externalWins.map(async (i) => await getExternalWindowInfo(i.name, i.title)));
}
async function restoreExternalWindowPositionAndState(info) {
const exWin = await getExternalWindowByNameTitle(info.name, info.title);
if (exWin) {
const bounds = Object.assign({top: info.bounds.y, left: info.bounds.x}, info.bounds);
if (info.maximized) {
await exWin.maximize();
} if (info.minimized) {
await exWin.minimize();
} if (!info.maximized && !info.minimized) {
await exWin.restore();
}
await exWin.setBounds(bounds);
}
}
export { generateExternalWindowSnapshot, restoreExternalWindowPositionAndState };