electron-vite-react icon indicating copy to clipboard operation
electron-vite-react copied to clipboard

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

Open MiniSuperDev opened this issue 2 years ago • 7 comments

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

MiniSuperDev avatar Sep 26 '23 14:09 MiniSuperDev

Please provide a minimum demo. thanks

RSS1102 avatar Sep 26 '23 16:09 RSS1102

@RSS1102 Hi, I update the issue with an example

MiniSuperDev avatar Sep 26 '23 18:09 MiniSuperDev

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

RSS1102 avatar Sep 26 '23 18:09 RSS1102

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

MiniSuperDev avatar Sep 26 '23 19:09 MiniSuperDev

@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.

RSS1102 avatar Sep 26 '23 19:09 RSS1102

@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

MiniSuperDev avatar Sep 26 '23 21:09 MiniSuperDev

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.

kudorgyozo avatar Apr 14 '24 16:04 kudorgyozo