electron-vite / electron-vite-react

:electron: Electron + Vite + React + Sass boilerplate.
https://electron-vite.github.io
MIT License
1.85k stars 218 forks source link

How to setup auto reload the app when the files of main process are updated? #172

Open MiniSuperDev opened 1 year ago

MiniSuperDev commented 1 year ago

For example I'm using IPC, but when change an implementation of a method of the IPC, this change is not showed in real time like when do a change in the renderer, currently I do manually restart to see the changes in the app.

Example: https://github.com/MiniSuperDev/electron-vite-react-main-reload/tree/main

  1. Click this button image
  2. Check the message image
  3. Change the implementation in the main process

Change this:

https://github.com/MiniSuperDev/electron-vite-react-main-reload/blob/main/electron/main/index.ts#L123-L128

For this:

ipcMain.handle("getDate", () => {
  return `Other String:` + `${Date.now()}`;
});
  1. Save and click the button again image

You notice that the message is the previous.

  1. Restart the app to see the new implementation image

I think it should restart the app, or do a hot reload if possible. Thanks

RSS1102 commented 1 year ago

Please provide a minimum demo. thanks

MiniSuperDev commented 1 year ago

@RSS1102 Hi, I update the issue with an example

RSS1102 commented 1 year ago
ipcMain.handle("getDate", () => {
  return `Other String:` + `${Date.now()}`;
})

This is the code for the Electron process. When you try to change the code here and save it, the program will reload.. This is inevitable

https://github.com/electron-vite/electron-vite-react/assets/81673017/a324c528-f7f7-470e-92f7-2a150eb95c4c

MiniSuperDev commented 1 year ago

@RSS1102 I see, in my VS Code, when save it, it not reload the app, so I need to restart manually

RSS1102 commented 1 year ago

@RSS1102 I see, in my VS Code, when save it, it not reload the app, so I need to restart manually

I'm not quite sure about this, maybe it's because of your vscode? If possible, you can try changing to a different computer.

MiniSuperDev commented 1 year ago

@RSS1102 I checked, it works when you run from npm run dev But the error happens (not reload) when launch using the vs code launch Debug App (F5)

https://github.com/MiniSuperDev/electron-vite-react-main-reload/blob/2793a6831a87a5da20a279a0b549aa3c53858249/.vscode/launch.json#L8

kudorgyozo commented 5 months ago

I have the same problem (I think, it's a bit hard to understand). When I change something in src\main\index.ts for example ipcMain.on('ping', () => console.log('ponggggg')) I need to stop and start the application again. there is no hot reload or anything for the main process. I'm just using npm run dev nothing else.