saltyshiomix / nextron

⚡ Next.js + Electron ⚡
https://npm.im/nextron
MIT License
3.69k stars 215 forks source link

IPC example #459

Closed yt-dlx closed 1 month ago

yt-dlx commented 1 month ago

Dear Devs,

I hope this message finds you well. I'm currently working with nextron based on Next.js 13.5.6 and I'm facing some challenges incorporating IPC (Inter-Process Communication) into my project. Despite my efforts, I haven't been able to locate any IPC-based examples in your documentation or resources.

Could you please provide some guidance or examples on how to effectively implement IPC within a nextron project? Any assistance you could offer would be greatly appreciated.

Thank you for your time and support.

bm777 commented 1 month ago

@yt-dlx Hi, in this template, you can see how we send data from the frontend, to the js backend via IPC.


In that example:

ipcMain.on('run-sh', async (event, value) => {
  console.log('DEBUG: starting process') // for dev mode
  event.sender.send('log', 'Running...') // for prod mode
  await startProcess(event, value)
})

I hope it helps :)

yt-dlx commented 1 month ago

Capture

what am i doing wrong? I cloned the example folder and ran 'yarn dev'

bm777 commented 1 month ago

@yt-dlx doo you have preload.js file inside the main folder? that might be the cause, it is define and exposed in that file.

And when creating a windows, you should pass it like this:

mainWindow = createWindow('main', {
            width: 1000,
            height: 700,
            webPreferences: {
              preload: path.join(__dirname, 'preload.js'),
            }
          })
yt-dlx commented 1 month ago

@bm777 in this version there was no preload.js 'https://github.com/saltyshiomix/nextron/tree/main/examples/basic-lang-javascript-python'

can i use the preload.js from the repo?

bm777 commented 1 month ago

It should appear if you do:

npx create-nextron-app my-app --example basic-lang-javascript-python

If not, you can copy this preload.js and past it in your main/

yt-dlx commented 1 month ago

I have tried with the preload.js but I am facing the same error. Kindly please help me: https://github.com/yt-dlx/yt-dlx/tree/main/package

image

Psycokwet commented 1 month ago

Instead of cloning to start your working directory, did you create a whole new project from npx create-nextron-app my-app --example basic-lang-javascript-python ? This will help greatly if you don't start from a clone.

yt-dlx commented 1 month ago

@Psycokwet I tried with the yarn create but same error of window.ipc. I have also tried the preload.js.

bm777 commented 1 month ago

@yt-dlx Oh I got the issue: There is a helper folder missing. @Psycokwet is right, you didn't create the project with that template. if you did it, it would have automatically also created that folder. it seems, you are trying to integrate it into your project.

The missing folder is this -> https://github.com/saltyshiomix/nextron/tree/651967d7df3d0f7cb306f7d4296866f994fbeb5d/examples/_template/js/main

yt-dlx commented 1 month ago

@bm777 @Psycokwet

I've implemented the changes using 'yarn create' as suggested, but the issue persists. Would you mind reviewing the details?

You can find the commit with the updates here: https://github.com/yt-dlx/yt-dlx/tree/main/package

Psycokwet commented 1 month ago

If you really did start your project with npx create-nextron-app my-app --example basic-lang-javascript-python You should have this file structure Screenshot 2024-05-23 at 10 20 26

But in your github example, I see that : Screenshot 2024-05-23 at 10 20 07

Those are differents, what did you do ? You still miss at least scripts, but I would start anew instead of trying to fix an install made by hand

Psycokwet commented 1 month ago

Note that a fresh project from

npx create-nextron-app my-app --example basic-lang-javascript-python
cd my-app
npm install && npm run dev

This exact set of command launch the app on my mac

yt-dlx commented 1 month ago

@Psycokwet @bm777

I followed these steps:

Yet the same issues. window.ipc

Tested Environments:

Commit:

Note:

image

yt-dlx commented 1 month ago

Thnks guys. I have fixed the issue using electron-vite