I am currently having some issues receiving an constant stream of active windows from my main process to my renderer process (in Angular). I know receiving second-by-second updates will break my app as it does, so I am trying to throttle it a bit using setTimeout. But this still doesn't work. How can I fix this?
renderer - component in Angular
ipc: IpcRenderer | undefined | null;
constructor(private electronService: ElectronService) { }
ngAfterViewInit(): void {
this.getActiveWindow();
}
getActiveWindow() {
while(this.electronService.isElectronApp) {
this.ipc = this.electronService.ipcRenderer;
this.ipc.send('get-active-window');
this.ipc.on('get-active-window-reply', (_event, reply) => {
console.log(reply);
});
}
}
main.js
const activeWindows = require('electron-active-window');
ipcMain.on('get-active-window', (_event, _arg) => {
let i = 0;
setTimeout(function () {
activeWindows().getActiveWindow().then((result) => {
win.webContents.send("get-active-window-reply", result)
})
}, 10000 * i)
});
So far I've tried the following, but this only displays the active window once. I'd like to keep track of all the changes:
renderer - component in Angular
ngOnInit(): void {
this.getActiveWindow();
}
getActiveWindow() {
if(this.electronService.isElectronApp) {
this.ipc = this.electronService.ipcRenderer;
this.ipc.send('get-active-window');
this.ipc.on('get-active-window-reply', (_event, reply) => {
console.log(reply);
});
}
}
main.js
ipcMain.on('get-active-window', (_event, _arg) => {
activeWindows().getActiveWindow().then((result) => {
win.webContents.send("get-active-window-reply", result)
});
});