active-window-listener
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -33,20 +33,18 @@ "use strict"; | ||
return; | ||
const processes = node_window_manager_1.windowManager.getWindows(); | ||
const newOpenedProcesses = this.processArr.map(pa => { | ||
return processes.find(p => { | ||
return p.path.indexOf(pa, p.path.length - pa.length) != -1; | ||
const activeWindow = node_window_manager_1.windowManager.getActiveWindow(); | ||
if ((!this.activeWindow || this.activeWindow.processId !== activeWindow.processId) && this.processArr.find(pa => activeWindow.path.indexOf(pa, activeWindow.path.length - pa.length) != -1)) { | ||
this.eventEmitter.emit('changed', activeWindow); | ||
this.activeWindow = activeWindow; | ||
} | ||
else { | ||
const processes = node_window_manager_1.windowManager.getWindows(); | ||
const newOpenedProcesses = this.processArr.map(pa => { | ||
return processes.find(p => { | ||
return p.path.indexOf(pa, p.path.length - pa.length) != -1; | ||
}); | ||
}).filter(pa => pa); | ||
const closedProgramsArr = this.openedProcesses.filter(x => { | ||
return !newOpenedProcesses.find(a => (a === null || a === void 0 ? void 0 : a.path) === x.path); | ||
}); | ||
}).filter(pa => pa); | ||
const closedProgramsArr = this.openedProcesses.filter(x => { | ||
return !newOpenedProcesses.find(a => (a === null || a === void 0 ? void 0 : a.path) === x.path); | ||
}); | ||
if (started) { | ||
if (newOpenedProcesses.length) { | ||
this.eventEmitter.emit('changed', newOpenedProcesses[0]); | ||
this.activeWindow = newOpenedProcesses[0]; | ||
} | ||
} | ||
closedProgramsArr.forEach(cp => { | ||
var _a; | ||
if (cp.path === ((_a = this.activeWindow) === null || _a === void 0 ? void 0 : _a.path)) { | ||
if (started) { | ||
if (newOpenedProcesses.length) { | ||
@@ -56,13 +54,17 @@ this.eventEmitter.emit('changed', newOpenedProcesses[0]); | ||
} | ||
else { | ||
this.eventEmitter.emit('changed', undefined); | ||
this.activeWindow = undefined; | ||
} | ||
closedProgramsArr.forEach(cp => { | ||
var _a; | ||
if (cp.path === ((_a = this.activeWindow) === null || _a === void 0 ? void 0 : _a.path)) { | ||
if (newOpenedProcesses.length) { | ||
this.eventEmitter.emit('changed', newOpenedProcesses[0]); | ||
this.activeWindow = newOpenedProcesses[0]; | ||
} | ||
else { | ||
this.eventEmitter.emit('changed', undefined); | ||
this.activeWindow = undefined; | ||
} | ||
} | ||
} | ||
}); | ||
this.openedProcesses = newOpenedProcesses; | ||
const activeWindow = node_window_manager_1.windowManager.getActiveWindow(); | ||
if ((!this.activeWindow || this.activeWindow.processId !== activeWindow.processId) && this.processArr.find(pa => activeWindow.path.indexOf(pa, activeWindow.path.length - pa.length) != -1)) { | ||
this.eventEmitter.emit('changed', activeWindow); | ||
this.activeWindow = activeWindow; | ||
}); | ||
this.openedProcesses = newOpenedProcesses; | ||
} | ||
@@ -69,0 +71,0 @@ setTimeout(() => this.loop(), 5000); |
62
index.ts
@@ -36,41 +36,43 @@ | ||
if (this.stopLoop) return; | ||
const processes = windowManager.getWindows(); | ||
const newOpenedProcesses = this.processArr.map(pa => { | ||
return processes.find(p => { | ||
return p.path.indexOf(pa, p.path.length - pa.length) != -1; | ||
}) | ||
}).filter(pa => pa) | ||
const closedProgramsArr = this.openedProcesses.filter(x => { | ||
return !newOpenedProcesses.find(a => a?.path === x.path) | ||
}); | ||
const activeWindow = windowManager.getActiveWindow(); | ||
if (started) { | ||
if (newOpenedProcesses.length) { | ||
this.eventEmitter.emit('changed', newOpenedProcesses[0]); | ||
this.activeWindow = newOpenedProcesses[0]; | ||
} | ||
} | ||
if ((!this.activeWindow || this.activeWindow.processId !== activeWindow.processId) && this.processArr.find(pa => activeWindow.path.indexOf(pa, activeWindow.path.length - pa.length) != -1)) { | ||
this.eventEmitter.emit('changed', activeWindow); | ||
this.activeWindow = activeWindow; | ||
} else { | ||
const processes = windowManager.getWindows(); | ||
closedProgramsArr.forEach(cp => { | ||
if (cp.path === this.activeWindow?.path) { | ||
const newOpenedProcesses = this.processArr.map(pa => { | ||
return processes.find(p => { | ||
return p.path.indexOf(pa, p.path.length - pa.length) != -1; | ||
}) | ||
}).filter(pa => pa) | ||
const closedProgramsArr = this.openedProcesses.filter(x => { | ||
return !newOpenedProcesses.find(a => a?.path === x.path) | ||
}); | ||
if (started) { | ||
if (newOpenedProcesses.length) { | ||
this.eventEmitter.emit('changed', newOpenedProcesses[0]); | ||
this.activeWindow = newOpenedProcesses[0]; | ||
} else { | ||
this.eventEmitter.emit('changed', undefined); | ||
this.activeWindow = undefined | ||
} | ||
} | ||
}) | ||
this.openedProcesses = newOpenedProcesses as Window[]; | ||
const activeWindow = windowManager.getActiveWindow(); | ||
if ((!this.activeWindow || this.activeWindow.processId !== activeWindow.processId) && this.processArr.find(pa => activeWindow.path.indexOf(pa, activeWindow.path.length - pa.length) != -1)) { | ||
this.eventEmitter.emit('changed', activeWindow); | ||
this.activeWindow = activeWindow; | ||
closedProgramsArr.forEach(cp => { | ||
if (cp.path === this.activeWindow?.path) { | ||
if (newOpenedProcesses.length) { | ||
this.eventEmitter.emit('changed', newOpenedProcesses[0]); | ||
this.activeWindow = newOpenedProcesses[0]; | ||
} else { | ||
this.eventEmitter.emit('changed', undefined); | ||
this.activeWindow = undefined | ||
} | ||
} | ||
}) | ||
this.openedProcesses = newOpenedProcesses as Window[]; | ||
} | ||
@@ -77,0 +79,0 @@ |
{ | ||
"name": "active-window-listener", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Listen to active windows by specifying them", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
15242
252