pksunkara / electron-plugin-manager

Plugin Manager based on NPM for Electron apps
MIT License
8 stars 3 forks source link

Pattern advice for render/main plugin loading #82

Closed Allow2CEO closed 3 years ago

Allow2CEO commented 3 years ago

Hi Pavan. So having a good time working out my use case. I am trying to build a pluggable framework for an electron app. The intention is to allow people to publish extensions that will have both a main process and a render process component. I have prototyped the load using your module and it's working well.

Now I need to work out how to best facilitate loading/unloading in sync across both processes. So the render side is a react view/display component, which is passed props containing redux sub-state (managed by the main app, which provides callbacks to the main app to update state). The render process is the UI for the plugin and allows users to interact with and configure that specific plugin.

The main app component provides the core functionality based on the state to interact with web services, network, printers, devices, etc. This is the engine side. The engine in the main process plugin part uses triggers off the main app and configurations for the specific plugin to provide the actual plugin functionality.

So the plugin in a single library that I pull in to both the main and the render processes to provide the engine and the interface. The main app acts as the conduit, so changes made to redux store by the ui help to control the engine side and vice-versa. The user can also disable/enable the plugin to "pause" it without uninstalling or deconfiguring it.

I trust the required steps are for me to manage the alignment of loaded/unloaded states between the engine side and the ui side, maybe with a configuration flag which drive appearance on the render side and the "liveness" of the engine side. I don't think it's worth unloading/loading the libraries at this stage in parallel with the enabled/disabled state, but maybe it's something I should consider?

Have you seen this use case (or considered it)? and If so, what advice/pointers could you share?

Also, I am having to not use es6 and jsx, but maybe I should use ondemand transpiling on render side component loading, but I'd need to know how to use your library to do this. I presume we need to extend or modify your library to achieve loading jsx and such at runtime? Have you thought about this? or has there been any demand?

Happy to work with you on any of this if it interests you.

Thanks, Andrew

pksunkara commented 3 years ago

Regarding es6 and jsx, all you need to do is compile it to JS and make a package out of it and put it in plugins folder and it will behave like normal.

Regarding sync, as you can see from here, https://github.com/pksunkara/electron-plugin-manager/blob/master/lib/load.js#L5, it's just calling require, so both the functions are synchronous. You can use ipc to manage this loading on both at the same time. I would recommend load on main.js first. But this is something that is upto you design according to your app's needs.

Allow2CEO commented 3 years ago

Thanks, all makes sense and matches the approach I am taking.