
In this context, you cannot use window.require to require any module in your Angular-CLI application, but you can load any module that you had set in your Electron application.įor this example we will expose the ipc as an Angular service, and will create it using angular-cli.A dynamic link library (DLL) initialization routine failed.

So we can just use window.require in any part of our application and it would work as expected. The window object by default will have all the global variables, including require. There is actually another way to access a global variable, that's with the window object. That's because, as I also told, Webpack will try to resolve the module requirement. But I just told that require is a function that Electron injects in the global context. No, we won't call ipcRenderer in the global context, although we could make this works, it's not ideal. To use ipcRenderer in our Angular-CLI app, we will leverage on the global scope.
Electron api call how to#
How to use ipcRenderer in a Angular-CLI application? (Or any application bundle with Webpack) So, although it may seems like the same function, it is not. You may guessed it, Electron injects its own version of require function in the global scope of the renderer process when it loads the page. So, now that we know that require is actually a function injected by Node, then how is require able to work in Electron renderer process. Later, module builders will look for import and require and will try to resolve modules, assuming that's what you want. TL DR: A require function is injected for every file, allowing Node to resolve the dependencies. With the integration of import and export keywords in Node, several articles was written to explain how the require function currently works.

But still is one of the most misunderstand functions in modern web development. Require as been with us for a while, since the first version of Node back in 2008, almost 10 years.

Angular-CLI underneath uses Webpack, and thus the latter will find the require key word, interpret as a call for the Node.js' require function, and will try to resolve the 'electron' module. This will invoke the callback function in the main thread.īut, this won't work in the Angular-CLI application. Use ipcMain is a simple as require it, and use one of the functions that are able for us.Įnter fullscreen mode Exit fullscreen mode Likewise, for the renderer process you would like to use the ipcRenderer. To send and receive messages in the main thread you would have to use the ipcMain function property. With that you can send messages between your web application and the main thread application. IPC is the inter-process communication module of Electron. In this post I'll try to explain how to get a real integrating between Angular and Electron, and be able to communicate using Electron's IPC. So far, this would allow a simple Angular application being packed as a Electron application, but there is no way for us to interact with Electron's main thread. In the previous sections and stories, I explained how to integrate an Angular-CLI generated application with Electron, and also how to write the same Electron application in Typescript.
