Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcasting Event with Electron IPC System not working #169

Closed
mho22 opened this issue Aug 10, 2023 · 6 comments
Closed

Broadcasting Event with Electron IPC System not working #169

mho22 opened this issue Aug 10, 2023 · 6 comments
Labels
bug Something isn't working f/broadcasting

Comments

@mho22
Copy link

mho22 commented Aug 10, 2023

What happened?

Two things don't actually work or exist from the NativePHP documentation.

  1. There's no ipcRenderer exported from @electron/remote package. There is only a ipcMain Event Emitter.

-> This could be replaced in the documentation by

import * as remote from 'electron';


remote.ipcMain.on( 'native-php', ( _, data ) => ... );
  1. It seems Vite externalizes all Node modules from browser compatibility. But actually, electron uses it in the node_moidules/electron/index.js` file.
Module "path" has been externalized for browser compatibility. Cannot access "path.join" in client code. 
See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
Uncaught TypeError: path.join is not a function
    at node_modules/electron/index.js (index.js:4:23)
    at __require (chunk-UXIASGQL.js?v=7bde630a:8:50)
    at electron.js?v=7bde630a:5:16

How to reproduce the bug

  1. Install dependency :

npm install @electron/remote

  1. Add in NativeAppServiceProvider :
Menu::new()->appMenu()->subMenu( 'Events', Menu::new()->label( 'Send Event' ) )->register();
  1. Add in Vue Component :
import * as remote from '@electron/remote';

remote.ipcMain.on( 'native-php', () => console.log( 'event listened' ) );
  1. Build
npm run dev

php artisan native:serve

Package Version

0.4.0

PHP Version

8.1.21

Laravel Version

10.18.0

Node Version

18.10.0

Which operating systems does with happen with?

macOS

Notes

I tried to correct the error with vite-plugin-node-polyfills. No more warning but fs was null.

@mho22 mho22 added the bug Something isn't working label Aug 10, 2023
@MarceauKa
Copy link

MarceauKa commented Aug 10, 2023

Can't reproduce since I can't serve my app in 0.4 version but this how I log every events. Hope it'll help somebody :)

window.addEventListener('livewire:load', () => {
    // Sometimes not handled by Native with Livewire 🤷‍
    window.Livewire.addHeaders({
        'X-NativePHP-Secret': '{{ config('nativephp-internal.secret') }}',
    })

    window.Echo.channel('nativephp')
        .subscribed(() => console.info('Subscribed to nativephp channel'))
        .error((error) => console.error(error))
        // Not in Echo public API but works 😉
        .listenToAll((event, payload) => {
            console.log(event, payload)
            // See https://github.com/NativePHP/electron-plugin/blob/main/src/preload/index.ts
            //window.Livewire.emit(event, payload)
        })

    /** @type {Electron} */
    const remote = window.remote;
    // Helps me to keeping track of the window load
    remote.shell.beep()

    remote.ipcMain.on('native-event', (_, data) => {
        console.log(data);
    });
})

@Nuhel
Copy link

Nuhel commented Aug 14, 2023

Can't reproduce since I can't serve my app in 0.4 version but this how I log every events. Hope it'll help somebody :)

window.addEventListener('livewire:load', () => {
    // Sometimes not handled by Native with Livewire 🤷‍
    window.Livewire.addHeaders({
        'X-NativePHP-Secret': '{{ config('nativephp-internal.secret') }}',
    })

    window.Echo.channel('nativephp')
        .subscribed(() => console.info('Subscribed to nativephp channel'))
        .error((error) => console.error(error))
        // Not in Echo public API but works 😉
        .listenToAll((event, payload) => {
            console.log(event, payload)
            // See https://github.com/NativePHP/electron-plugin/blob/main/src/preload/index.ts
            //window.Livewire.emit(event, payload)
        })

    /** @type {Electron} */
    const remote = window.remote;
    // Helps me to keeping track of the window load
    remote.shell.beep()

    remote.ipcMain.on('native-event', (_, data) => {
        console.log(data);
    });
})

Hello, Can you help me?

I want to listen from event from livewire, But it's not working.
Can you help me on this?

@simonhamp simonhamp changed the title [Bug]: Broadcasting Event with Electron IPC System not working Broadcasting Event with Electron IPC System not working May 8, 2024
@simonhamp
Copy link
Member

@mho22 I know this was from a while ago, but can you give some context around what you were trying to achieve?

@mho22
Copy link
Author

mho22 commented May 14, 2024

@simonhamp As I remember, I wanted to catch events from clicking on a subMenu. I remember trying out what is written in this part of the documentation but it didn't work for me.

I think it was related to the DOOM Native PHP side project : I think I was trying to load different games from the menubar.

I can see that the documentation hasn't changed. But I don't know if the issue is outdated or not. I can try to reproduce the issue again in the next days if you want.

@gwleuverink
Copy link
Contributor

Fixed by #367 @simonhamp?

@simonhamp
Copy link
Member

I think it will be. Thanks for digging through related issues @gwleuverink 😇

@mho22 @MarceauKa @Nuhel the PR that Willem linked will be released next week. Please try that out at your leisure. In the meantime, I'm going to close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working f/broadcasting
Projects
None yet
Development

No branches or pull requests

5 participants