Electron/electron-api-demos - An Electron app that teaches you how to use Electron; hokein/electron-sample-apps - Small demo apps for the various Electron APIs; Programmatic usage. Most people use Electron from the command line, but if you require electron inside your Node app (not your Electron app) it will return the file path to the binary.
Use main process modules from the renderer process.
Process: Renderer
These API calls are not in the app itself, but part of the underlying Electron framework. The detected private API symbols include: CAContext CALayerHost NSAccessibilityRemoteUIElement. . Return Electron hidden gui which parented to CoreGui and undetected table getgenv. Returns global environment in a table table getrenv. Returns Roblox's environment in a table table getreg. Returns Roblox's lua registry in a table table getgc. Returns Roblox's gc functions/table in a table table getallgc. // NPM npm electron:build - -win nsis // YARN yarn electron:build -win nsis Conclusion. The completed application can be found on my GitHub. The official Electron documentation provides information and a guide that helps you customize your desktop app whichever way you want. Some of the things I tried out but aren’t included in this. Api tells the code generator this controller is for a REST style API and that no views should be generated; With the code generation complete the API should be good to go. Over in the Electron project, we need a model to match the data the API is returning.
⚠️ WARNING ⚠️The remote
module is deprecated.Instead of remote
, use ipcRenderer
andipcMain
.
Read more about why the remote
module is deprecated here.
If you still want to use remote
despite the performance and securityconcerns, see @electron/remote.
The remote
module provides a simple way to do inter-process communication(IPC) between the renderer process (web page) and the main process.
In Electron, GUI-related modules (such as dialog
, menu
etc.) are onlyavailable in the main process, not in the renderer process. In order to use themfrom the renderer process, the ipc
module is necessary to send inter-processmessages to the main process. With the remote
module, you can invoke methodsof the main process object without explicitly sending inter-process messages,similar to Java's RMI. An example of creating a browser window from arenderer process:
Note: For the reverse (access the renderer process from the main process),you can use webContents.executeJavaScript.
Note: The remote module can be disabled for security reasons in the following contexts:
BrowserWindow
- by setting theenableRemoteModule
option tofalse
.<webview>
- by setting theenableremotemodule
attribute tofalse
.
Remote Objects
Each object (including functions) returned by the remote
module represents anobject in the main process (we call it a remote object or remote function).When you invoke methods of a remote object, call a remote function, or createa new object with the remote constructor (function), you are actually sendingsynchronous inter-process messages.
In the example above, both BrowserWindow
and win
were remote objects andnew BrowserWindow
didn't create a BrowserWindow
object in the rendererprocess. Instead, it created a BrowserWindow
object in the main process andreturned the corresponding remote object in the renderer process, namely thewin
object.
Note: Only enumerable properties which are presentwhen the remote object is first referenced are accessible via remote.
Note: Arrays and Buffers are copied over IPC when accessed via the remote
module. Modifying them in the renderer process does not modify them in the mainprocess and vice versa.
Microsoft OneNote The digital note-taking app for your. Change Language. Privacy & Cookies Legal Trademarks © 2021 Microsoft.com Legal Trademarks © 2021 Microsoft.com. All Devices Chromebook. Better with Office. OneNote is a member of the Office family you already know. Shape notes with points pulled from Outlook email, or embed an Excel table. Get more done with all your favorite Office apps working together. Connect in the classroom. Create a new notebook. From any page on OneNote for the web, click or tap the Notebook List. Microsoft onenote web clipper.
Lifetime of Remote Objects
Electron makes sure that as long as the remote object in the renderer processlives (in other words, has not been garbage collected), the corresponding objectin the main process will not be released. When the remote object has beengarbage collected, the corresponding object in the main process will bedereferenced.
If the remote object is leaked in the renderer process (e.g. stored in a map butnever freed), the corresponding object in the main process will also be leaked,so you should be very careful not to leak remote objects.
Primary value types like strings and numbers, however, are sent by copy.
Passing callbacks to the main process
Code in the main process can accept callbacks from the renderer - for instancethe remote
module - but you should be extremely careful when using thisfeature.
First, in order to avoid deadlocks, the callbacks passed to the main processare called asynchronously. You should not expect the main process toget the return value of the passed callbacks.
For instance you can't use a function from the renderer process in anArray.map
called in the main process:
As you can see, the renderer callback's synchronous return value was not asexpected, and didn't match the return value of an identical callback that livesin the main process.
Second, the callbacks passed to the main process will persist until themain process garbage-collects them.
Electron Api Request
For example, the following code seems innocent at first glance. It installs acallback for the close
event on a remote object:
But remember the callback is referenced by the main process until youexplicitly uninstall it. If you do not, each time you reload your window thecallback will be installed again, leaking one callback for each restart.
To make things worse, since the context of previously installed callbacks hasbeen released, exceptions will be raised in the main process when the close
event is emitted.
To avoid this problem, ensure you clean up any references to renderer callbackspassed to the main process. This involves cleaning up event handlers, orensuring the main process is explicitly told to dereference callbacks that camefrom a renderer process that is exiting.
Accessing built-in modules in the main process
The built-in modules in the main process are added as getters in the remote
module, so you can use them directly like the electron
module.
Methods
The remote
module has the following methods:
remote.getCurrentWindow()
Returns BrowserWindow
- The window to which this web pagebelongs.
Note: Do not use removeAllListeners
on BrowserWindow
.Use of this can remove all blur
listeners, disable click events on touch bar buttons, and other unintendedconsequences.
remote.getCurrentWebContents()
Returns WebContents
- The web contents of this web page.
remote.getGlobal(name)
name
String
Returns any
- The global variable of name
(e.g. Sql express for mac. global[name]
) in the mainprocess.
Properties
remote.require
A NodeJS.Require
function equivalent to require(module)
in the main process.Modules specified by their relative path will resolve relative to the entrypointof the main process.
e.g.
remote.process
Readonly
A NodeJS.Process
object. The process
object in the main process. This is the same asremote.getGlobal('process')
but is cached.
Retrieve information about screen size, displays, cursor position, etc.
Process: Main
This module cannot be used until the ready
event of the app
module is emitted.
screen
is an EventEmitter.
Note: In the renderer / DevTools, window.screen
is a reserved DOMproperty, so writing let { screen } = require('electron')
will not work.
An example of creating a window that fills the whole screen:
Another example of creating a window in the external display:
Events
The screen
module emits the following events:
Event: 'display-added'
Returns:
event
EventnewDisplay
Display
Emitted when newDisplay
has been added.
Event: 'display-removed'
Returns:
event
EventoldDisplay
Display
Emitted when oldDisplay
has been removed.
Event: 'display-metrics-changed'
Returns:
event
Eventdisplay
DisplaychangedMetrics
String[]
Emitted when one or more metrics change in a display
. The changedMetrics
isan array of strings that describe the changes. Possible changes are bounds
,workArea
, scaleFactor
and rotation
.
Methods
The screen
module has the following methods:
screen.getCursorScreenPoint()
Returns Point
The current absolute position of the mouse pointer.
screen.getPrimaryDisplay()
Returns Display
- The primary display.
screen.getAllDisplays()
Returns Display[]
- An array of displays that are currently available.
screen.getDisplayNearestPoint(point)
point
Point
Returns Display
- The display nearest the specified point.
screen.getDisplayMatching(rect)
rect
Rectangle
Returns Display
- The display that most closelyintersects the provided bounds.
screen.screenToDipPoint(point)
Windows
point
Point
Returns Point
Converts a screen physical point to a screen DIP point.The DPI scale is performed relative to the display containing the physical point.
screen.dipToScreenPoint(point)
Windows
point
Point
Returns Point
Converts a screen DIP point to a screen physical point.The DPI scale is performed relative to the display containing the DIP point.
screen.screenToDipRect(window, rect)
Windows
window
BrowserWindow | nullrect
Rectangle
Electron Api Browserwindow
Returns Rectangle
Electron Api Demons
Converts a screen physical rect to a screen DIP rect.The DPI scale is performed relative to the display nearest to window
.If window
is null, scaling will be performed to the display nearest to rect
.
screen.dipToScreenRect(window, rect)
Windows
window
BrowserWindow | nullrect
Rectangle
Returns Rectangle

Electron Api Demo
Converts a screen DIP rect to a screen physical rect.The DPI scale is performed relative to the display nearest to window
.If window
is null, scaling will be performed to the display nearest to rect
.
