cawa-93 / vite-electron-builder

Secure boilerplate for Electron app based on Vite. TypeScript + Vue/React/Angular/Svelte/Vanilla
MIT License
2.34k stars 256 forks source link

Add IPCHash.vue #956

Closed Osiris-Team closed 8 months ago

Osiris-Team commented 1 year ago

I think that IPC/Inter-Process Communication is probably one of the most important things in Electron and that this template should also provide an example Vue component for this.

As base the existing ReactiveHash.vue component can be used, and modified to work via IPC.

cawa-93 commented 1 year ago

The main idea of the ReactiveHash.vue component is to show how to use Node.js API without using IPC.

Osiris-Team commented 1 year ago

@cawa-93

I used that approach and tried to create new objects (in the renderer) that are defined in main and exported in preload, which compiles, but fails at runtime (either Uncaught Error: Class constructor MyClass cannot be invoked without 'new', when creating objects with new or Uncaught TypeError: myClass.myFunc is not a function when trying to run a function of a class)

I also need something that is more like events instead of functions I guess.

Osiris-Team commented 1 year ago

@cawa-93 also, computed() doesnt seem to work with async functions, which is a big issue. Uncaught (in promise) Error: Cannot read properties of undefined (reading 'emit') My bad, had leftovers of ipcMain.

Also found out that you can use watchEffect for async functions instead:

watchEffect(async () => {
}
Osiris-Team commented 1 year ago

@cawa-93 Another thing I noticed, that the function you are exporting in preload cannot access fields or methods from the main process like app.getAppPath() is undefined.

cawa-93 commented 8 months ago

From now on, the template uses native ESMs to resolve modules. I'll close this for now. If the issue is still relevant with the latest changes, feel free to open a new report.