ThorstenHans / ngx-electron

A simple Angular wrapper for electron's Renderer API
MIT License
429 stars 86 forks source link

Send Variable from main.js to Angular 2 directly #19

Closed ameagol closed 5 years ago

ameagol commented 6 years ago

Hi, I've already tested the ping/pong with success, but I have to trigger from main.js (MENU), then click in a button associated with the method playPingPong() .

Please let me know if is possible to transmit a variable, directly from main.js to Angular like:

main.js => angular component

My Idea would be like below, but is not receiveing anything from angular.

main.js

const menuTemplate = [
      { 
        label:'View User Profile',
        click: () => {    
          ipcMain.on('Router', (event, arg) => { 
            event.sender.send('Router', 'users/profile')
          }) 
        }
   ]

service.ts

ngOnInit() {

    this._electronService.ipcRenderer.on('Router', (event, arg) => {
       this.router.navigate([arg]);
    }) 

}
Frixoe commented 6 years ago

Have you tried using the remote module instead?

There’s a function on it called getGlobal(string) where the string is a variable in your main process.

FYI: I have not experimented with this method.

walkingriver commented 6 years ago

I have not tried that, no.

ThorstenHans commented 5 years ago

@walkingriver the code listing above is wrong. in the main, you've to do window.webContents.send in order to send a message

see https://electronjs.org/docs/api/web-contents#contentssendchannel-arg1-arg2- for further instructions

Feel free to re-open the issue if the problem still exists