maximegris / angular-electron

Ultra-fast bootstrapping with Angular and Electron :speedboat:
https://www.maximegris.fr/angular-electron/
MIT License
5.66k stars 1.37k forks source link

ipcRenderer is undefined #663

Closed andyrue closed 2 years ago

andyrue commented 2 years ago

I cloned a new project, added a simple function call to the ipcRenderer and it comes back as undefined. Not sure what I'm doing wrong.

import { Component, OnInit } from '@angular/core';
import { ElectronService } from '../core/services';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {

  constructor(
    private electronService: ElectronService
    ) { }

  ngOnInit(): void {
  }

  test() {
    console.log('testing call (client)')
    this.electronService.ipcRenderer.send('test');
  }

}

ERROR TypeError: Cannot read properties of undefined (reading 'send')

maximegris commented 2 years ago

You have to test if you are in an electron context before calling ipcRenderer

Have a look at app.component.ts