-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
40 lines (33 loc) · 1.07 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
'use strict';
const path = require('path');
const execa = require('execa');
const electronUtil = require('electron-util/node');
const macosVersion = require('macos-version');
const PCancelable = require('p-cancelable');
const binary = path.join(electronUtil.fixPathForAsarUnpack(__dirname), 'window-select');
const isSupported = macosVersion.isGreaterThanOrEqualTo('10.14.4');
module.exports = ({appsToIgnore} = {appsToIgnore: []}) => new PCancelable(async (resolve, reject, onCancel) => {
if (!isSupported) {
resolve({canceled: false, window: undefined});
}
const worker = execa(binary, [
'select',
'-j',
...appsToIgnore.reduce((acc, app) => [...acc, '-i', app], [])
]);
onCancel(() => {
resolve({canceled: true, window: undefined});
worker.cancel();
});
try {
const {stdout} = await worker;
resolve({canceled: false, window: JSON.parse(stdout).window});
} catch (error) {
if (error.isCanceled || error.stdout === 'canceled') {
resolve({canceled: true, window: undefined});
} else {
reject(error);
}
}
});
module.exports.isSupported = isSupported;