ElectronNET / Electron.NET

:electron: Build cross platform desktop apps with ASP.NET Core (Razor Pages, MVC, Blazor).

Home Page:https://gitter.im/ElectronNET/community

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding and calling custom javscript to electron .net app

domingoladron opened this issue · comments

Hey there,

I want to hook right into the electron engine via Javascript using npm etc. How do I

  1. Add code which should be loaded and run by the base electron system?
  2. Ensure this code is loaded up when the app is built / started?
  3. Call such custom code from the electron.net APIs?

I have been trying to piece it all together, but so many moving parts and I just would like a bit of clarity so I can do this right.

Cheers

For this, we have the HostHook feature, which needs to be activated via the Electron.NET-CLI with the following command: electronize add hosthook

This will create an ElectronHostHook directory in your project. Ideally, you can now open this with Visual Studio Code. Install NPM packages and communicate with the actual application.

Our Electron.NET API Demo App and its source code will show you exactly how to do this:
https://github.com/ElectronNET/electron.net-api-demos

https://github.com/ElectronNET/electron.net-api-demos/blob/master/ElectronNET-API-Demos/Controllers/HostHookController.cs

https://github.com/ElectronNET/electron.net-api-demos/tree/master/ElectronNET-API-Demos/ElectronHostHook

Was I able to assist you with this?

That's exactly what I was after. Thanks so much.

Once I get my head around it and am able to do the basics, would y'all be amenable to a documentation PR with details on how to do this for others? This seems like a useful scenario for devs, as some stuff is just easier to do in javascript / typescript / electron than in Blazor.

If a documentation PR would be acceptable, do you have a preferred place (README.md?) for such docs?

Let me know and cheers for the assist