maximegris/angular-electron

Add DesktopCapturer to ElectronService

julien1709 opened this issue · 2 comments

Hello,

I wanted to know how to import others functionality of Electron in the electron.service.ts,

I tried this but desktopCapturer is undefined :

In electron.service.ts :

import { ipcRenderer, webFrame, desktopCapturer } from 'electron';
import * as childProcess from 'child_process';
import * as fs from 'fs';

@Injectable({
providedIn: 'root'
})
export class ElectronService {
ipcRenderer!: typeof ipcRenderer;
webFrame!: typeof webFrame;
desktopCapturer!: typeof desktopCapturer;
childProcess!: typeof childProcess;
fs!: typeof fs;
constructor() {
// Conditional imports
if (this.isElectron) {
this.ipcRenderer = (window as any).require('electron').ipcRenderer;
this.webFrame = (window as any).require('electron').webFrame;
this.desktopCapturer = (window as any).require('electron').desktopCapturer;
this.fs = (window as any).require('fs');

  console.log(this.desktopCapturer)

same here, can it be fixed ?

Electron does not provide deskstopCapturer on the renderer side (Angular).

Here the official documentation of DeskstopCapturer
https://www.electronjs.org/docs/latest/api/desktop-capturer

If you want to use DeskstopCapturer, I think you should use ipcRenderer.send from Angular and listen to this event inside the main process (Electron) with ipcMain.on