saltyshiomix / nextron

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

app.quit() using JavaScript. #396

Closed pixkk closed 8 months ago

pixkk commented 9 months ago

For example, i want use next code (client side render):

const {ipcRenderer} = require('electron');
const closeApp = document.getElementById('closeApp');
closeApp.addEventListener('click', () => {
    ipcRenderer.send('close-me')
});

Any mention of "require('electron')" in the page code generates the error "./node_modules/electron/index.js:1:0 Module not found: Can't resolve 'fs'" (module FS installed and used in another file successfully)

Is it possible quit app by JavaScript?

PS.: it can bypassed by window.close(), but is it best method of closing app?

makeusabrew commented 8 months ago

Look into exposing a minimal subset of the electron API to your renderer process via a context bridge and invoking an IPC send from methods you expose via that bridge. This section of the official Electron docs covers the pattern you're after: https://www.electronjs.org/docs/latest/tutorial/ipc#pattern-2-renderer-to-main-two-way

pixkk commented 8 months ago

Look into exposing a minimal subset of the electron API to your renderer process via a context bridge and invoking an IPC send from methods you expose via that bridge. This section of the official Electron docs covers the pattern you're after: https://www.electronjs.org/docs/latest/tutorial/ipc#pattern-2-renderer-to-main-two-way

Thanks for the answer. It seems like I solved the problem a long time ago, so I’ll write an answer for those who came here.

Play with the renderer settings (examples/........./renderer/next.config.js, config.target option). If you have a problem using IPC, look at the settings from the project template where IPC is used.

Mrx-dev commented 8 months ago

what should I change in (renderer/next.config.js) ?

Edit: I look through (examples/ipc-communication/renderer/next.config.js) settings its the same settings that i have in renderer folder and i still go the same error any idea how to fix it?

Error: Module not found: Can't resolve 'fs'