-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v2] Prefer using preload script for renderer dependencies - no longer require nodeIntegration #289
Comments
@matmalkowski I've been looking into best practices and experimenting for the past week or so, and I think the best solution is to do what's done in Secure Electron Template and allow users to pass in the necessary dependencies on their own from their own preload script like this https://github.com/reZach/secure-electron-template/blob/master/app/electron/preload.js#L15 And then in the This gets us the benefits of the preload script method without locking users into using preload script provided by electron-redux. As I understand it Electron can only support one preload script, so this is a really important aspect. One thing I'm still pondering though is how to "supporting" I hope that can be achieved, but if not, I would propose a PS: The improvements from v1.x to v2 are astounding! |
I'd like to work on this but I'm a Typescript noob so I'm not sure how useful I'll be. It seems to me that the only dependency we need to bind is The files that use
@matmalkowski what would you think of a JS class file like Bindings.js class Bindings {
register = ipcRenderer => {
this.ipcRenderer = ipcRenderer;
};
ipcRenderer = (funcName, ...args) => this.ipcRenderer[funcName](...args);
}
export const bindings = new Bindings(); |
Oh and maybe #235 should be closed in favor of this issue. |
@slapbox I'm not sure (I got to do some reading myself on that topic) but seems to me like we could just declare our scoped preload script as a module, and expose it as part of the lib, users can still consume it in 2 ways, considering the limitation you mentioned of single preload script:
That would work as well right? |
I myself am not sure but I think you're right. How to architect the library in a DRY way while supporting that eludes me though. I also was wondering if we could do something like: register = ipcRenderer = require('electron').ipcRenderer => {
this.ipcRenderer = ipcRenderer;
}; But, given the fact that Electron itself is moving to eliminate the possibility of using this library without using a preload script (because that would require Maybe Thoughts? |
@Superjo149 I have started to work at this issue, and it seems your change for unified interface for initialisation (end re-use of some of the methods as shared will need to be removed for the favour of security. Problem is that we have to have clear separation between renderer code & main code on build time when it comes to referencing electron (or any other dependencies for that matter). Right now with your changes it will bundle main process related modules into the renderer module because fork is done on runtime. |
@slapbox if I manage to finally write this (and I'm in progress) I don't plan to support the old way with |
Ah, yes I understand. Let's do what's best right 👍 |
@matmalkowski that makes sense! |
@musou1500, @slapbox I managed to get it working, most troublesome part was spectron & e2e tests... I created a draft PR (#300 ☝🏻 ), will still need to update some docs for this & add JSDOC comments to new API, but let me know what do you think, since the feature request came from you 😄 |
Looks promising! Because I (apparently) can't compile TypeScript on Windows it's tough for me to give it a quick test, but I looked over the PR just now! |
As the title suggest, move dependencies to preload script, similar to how it's done in the fork
The text was updated successfully, but these errors were encountered: