forked from nullxx/electron-active-window
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·47 lines (46 loc) · 1.87 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
const activeWindows = require('./build/Release/wm');
const os = require('os');
const exec = require('child_process').exec;
const fs = require('fs');
const path = require('path');
const mac_d = path.join(__dirname, '/mac/window');
module.exports = () => {
if (os.platform() == 'darwin'){
return{
getActiveWindow: () => {
return new Promise((res, rej) => {
if (!fs.existsSync(mac_d)) return rej("Mac binary not found")
exec(mac_d, (error, stdout, stderr) => {
if (error) return rej(error);
const r = stdout || stderr;
var json; try {json = JSON.parse(r);}catch(err){rej(error)}
res({
os: 'macos',
windowClass: json.bundleIdentifier,
windowName: json.name,
windowDesktop: null,
windowType: null,
windowPid: json["PID"],
atTime: json.time,
launchDate: json.launchDate,
isTerminated: json.isTerminated
})
});
})
}
}
}else{
return{
getActiveWindow: () => {
return new Promise((res, rej) => {
const win = activeWindows.getActiveWindow();
if (win != null && win.error != null){
rej(win.error);
}else{
res(win);
}
})
}
}
}
}