active-window-listener
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -34,22 +34,12 @@ "use strict"; | ||
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); | ||
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; | ||
}); | ||
if (started) { | ||
if (newOpenedProcesses.length) { | ||
this.eventEmitter.emit('changed', newOpenedProcesses[0]); | ||
this.activeWindow = newOpenedProcesses[0]; | ||
} | ||
} | ||
}).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) { | ||
closedProgramsArr.forEach(cp => { | ||
@@ -68,2 +58,14 @@ var _a; | ||
}); | ||
} | ||
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 { | ||
if (started) { | ||
if (newOpenedProcesses.length) { | ||
this.eventEmitter.emit('changed', newOpenedProcesses[0]); | ||
this.activeWindow = newOpenedProcesses[0]; | ||
} | ||
} | ||
this.openedProcesses = newOpenedProcesses; | ||
@@ -70,0 +72,0 @@ } |
61
index.ts
import {Window, windowManager} from 'node-window-manager'; | ||
import { Window, windowManager } from 'node-window-manager'; | ||
import EventEmitter from 'events'; | ||
@@ -22,3 +22,3 @@ | ||
clearEvent(){ | ||
clearEvent() { | ||
this.eventEmitter.removeAllListeners('changed') | ||
@@ -38,28 +38,16 @@ this.stopLoop = true; | ||
const activeWindow = windowManager.getActiveWindow(); | ||
const processes = windowManager.getWindows(); | ||
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(); | ||
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 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]; | ||
} | ||
} | ||
const closedProgramsArr = this.openedProcesses.filter(x => { | ||
return !newOpenedProcesses.find(a => a?.path === x.path) | ||
}); | ||
if (!started) { | ||
closedProgramsArr.forEach(cp => { | ||
@@ -76,4 +64,19 @@ if (cp.path === this.activeWindow?.path) { | ||
}) | ||
} | ||
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 { | ||
if (started) { | ||
if (newOpenedProcesses.length) { | ||
this.eventEmitter.emit('changed', newOpenedProcesses[0]); | ||
this.activeWindow = newOpenedProcesses[0]; | ||
} | ||
} | ||
this.openedProcesses = newOpenedProcesses as Window[]; | ||
@@ -87,3 +90,3 @@ } | ||
export function getWindows () { | ||
export function getWindows() { | ||
const filteredFolder = ["Windows"]; | ||
@@ -102,5 +105,5 @@ | ||
arr.push(window); | ||
} | ||
} | ||
return arr; | ||
} |
{ | ||
"name": "active-window-listener", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"description": "Listen to active windows by specifying them", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
15255
256