new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Electron · all subjects

api/both-processes

47 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Both process modules in Electron API

Modules available in both main and renderer processes include: clipboard (non-sandboxed renderers only), crashReporter, nativeImage, and shell (non-sandboxed renderers only).

Share data between renderer processes

To share data between web pages (renderer processes), use HTML5 APIs available in browsers: Storage API, localStorage, sessionStorage, or IndexedDB. Alternatively, use Electron IPC primitives: ipcMain and ipcRenderer to share data between main and renderer processes, or send a MessagePort from one web page to another, possibly via the main process using ipcRenderer.postMessage(). Subsequent communication over message ports is direct and does not detour through the main process.

IPC definition in Electron

IPC stands for inter-process communication. Electron uses IPC to send serialized JSON messages between the main and renderer processes.

Squirrel auto-update framework

Squirrel is an open-source framework that enables Electron apps to update automatically as new versions are released.

Process object availability

In Node.js and Electron, each running process has a process object. This object is a global that provides information about and control over the current process. As a global, it is always available to applications without using require().

Mojo IPC system used by Chromium

Mojo is an IPC system for communicating intra- or inter-process. Chrome uses Mojo because it is keen on being able to split its work into separate processes or not, depending on memory pressures.

nativeImage module available in main and renderer processes

The nativeImage module can be used in both the main process and the renderer process. If calling from a renderer process with context isolation enabled, place the API call in the preload script and expose it using the contextBridge API.

nativeImage.createEmpty()

Creates an empty NativeImage instance. Returns NativeImage.

nativeImage.createThumbnailFromPath(path, size)

Creates a thumbnail from a file. Parameters: path (string) - path to a file to construct a thumbnail from; size (Size) - the desired width and height (positive numbers) of the thumbnail. Available on macOS and Windows. Returns Promise<NativeImage> - fulfilled with the file's thumbnail preview image. Note: Windows implementation will ignore size.height and scale the height according to size.width.

nativeImage.createFromPath(path)

Creates a new NativeImage instance from an image file located at the specified path. Parameters: path (string) - path to a file (e.g., PNG or JPEG). This method returns an empty image if the path does not exist, cannot be read, or is not a valid image. Returns NativeImage.

nativeImage.createFromBuffer(buffer[, options])

Creates a new NativeImage instance from buffer. Tries to decode as PNG or JPEG first. Parameters: buffer (Buffer); options (Object, optional) with width (Integer, optional, required for bitmap buffers), height (Integer, optional, required for bitmap buffers), scaleFactor (Number, optional, defaults to 1.0). Returns NativeImage.

nativeImage.createFromDataURL(dataURL)

Creates a new NativeImage instance from a base 64 encoded Data URL string. Parameters: dataURL (string). Returns NativeImage.

NativeImage.toPNG([options])

Converts NativeImage to PNG encoded data. Parameters: options (Object, optional) with scaleFactor (Number, optional, defaults to 1.0). Returns Buffer containing the image's PNG encoded data.

NativeImage.toJPEG(quality)

Converts NativeImage to JPEG encoded data. Parameters: quality (Integer) between 0 - 100. Returns Buffer containing the image's JPEG encoded data.

NativeImage.toBitmap([options])

Returns raw bitmap pixel data. Parameters: options (Object, optional) with scaleFactor (Number, optional, defaults to 1.0), colorSpace (ColorSpace, optional, the target color space for output pixel data, defaults to sRGB). Returns Buffer containing a copy of the image's raw bitmap pixel data. NativeImage.toBitmap() normalizes pixel data to sRGB by default. Pass the image's original color space to preserve the previous behavior, or another color space to get pixel values in that space.

NativeImage.toDataURL([options])

Converts NativeImage to Data URL. Parameters: options (Object, optional) with scaleFactor (Number, optional, defaults to 1.0). Returns string - the Data URL of the image. nativeImage.toDataURL will preserve PNG colorspace.

NativeImage.getBitmap([options]) deprecated

Legacy alias for image.toBitmap(). Deprecated method. Parameters: options (Object, optional) with scaleFactor (Number, optional, defaults to 1.0), colorSpace (ColorSpace, optional). Returns Buffer.

NativeImage.isEmpty()

Returns boolean indicating whether the image is empty.

NativeImage.getSize([scaleFactor])

Returns the size of the image. Parameters: scaleFactor (Number, optional, defaults to 1.0). If scaleFactor is passed, this will return the size corresponding to the image representation most closely matching the passed value. Returns Size.

NativeImage.setTemplateImage(option)

Marks the image as a macOS template image. Parameters: option (boolean). This marks the image as a template image for macOS.

NativeImage.isTemplateImage()

Returns boolean indicating whether the image is a macOS template image.

NativeImage.crop(rect)

Crops the image. Parameters: rect (Rectangle) - the area of the image to crop. Returns NativeImage - the cropped image.

NativeImage.resize(options)

Resizes the image. Parameters: options (Object) with width (Integer, optional, defaults to the image's width), height (Integer, optional, defaults to the image's height), quality (string, optional, possible values are 'good', 'better', or 'best', default is 'best'). If only height or width are specified, the current aspect ratio will be preserved in the resized image. Returns NativeImage - the resized image.

NativeImage.getAspectRatio([scaleFactor])

Returns the image's aspect ratio (width divided by height). Parameters: scaleFactor (Number, optional, defaults to 1.0). If scaleFactor is passed, this will return the aspect ratio corresponding to the image representation most closely matching the passed value. Returns Number.

NativeImage.getScaleFactors()

Returns an array of all scale factors corresponding to representations for a given NativeImage. Returns Number[].

NativeImage.addRepresentation(options)

Adds an image representation for a specific scale factor. This can be used to programmatically add different scale factor representations to an image and can be called on empty images. Parameters: options (Object) with scaleFactor (Number, optional), width (Integer, optional, defaults to 0, required if a bitmap buffer is specified), height (Integer, optional, defaults to 0, required if a bitmap buffer is specified), buffer (Buffer, optional, containing the raw image data), dataURL (string, optional, containing either a base 64 encoded PNG or JPEG image). Returns undefined.

process object extended in both main and renderer

Electron's process object is an extension of Node.js process object and is available in both the main process and renderer process. It adds Electron-specific events, properties, and methods.

process loaded event

The 'loaded' event is emitted when Electron has loaded its internal initialization script and is beginning to load the web page or the main script.

process.mas property

process.mas is a readonly boolean that is true for Mac App Store builds and undefined for other builds.

process.noDeprecation property

process.noDeprecation is an optional boolean that controls whether deprecation warnings are printed to stderr. Setting it to true will silence deprecation warnings. This property is used instead of the --no-deprecation command line flag.

process.resourcesPath property

process.resourcesPath is a readonly string representing the path to the resources directory.

process.throwDeprecation property

process.throwDeprecation is a boolean that controls whether deprecation warnings will be thrown as exceptions. Setting it to true will throw errors for deprecations. This property is used instead of the --throw-deprecation command line flag.

process.traceDeprecation property

process.traceDeprecation is a boolean that controls whether deprecations printed to stderr include their stack trace. Setting it to true will print stack traces for deprecations. This property is used instead of the --trace-deprecation command line flag.

process.traceProcessWarnings property

process.traceProcessWarnings is a boolean that controls whether process warnings printed to stderr include their stack trace. Setting it to true will print stack traces for process warnings including deprecations. This property is used instead of the --trace-warnings command line flag.

process.versions.chrome property

process.versions.chrome is a readonly string representing Chrome's version string.

process.versions.electron property

process.versions.electron is a readonly string representing Electron's version string.

process.crash() method

process.crash() causes the main thread of the current process to crash.

process.getCreationTime() method

process.getCreationTime() returns number | null. It indicates the creation time of the application as the number of milliseconds since epoch, or null if the information is unavailable.

process.getCPUUsage() method

process.getCPUUsage() returns a CPUUsage object with CPU usage statistics.

process.getHeapStatistics() method returns object

process.getHeapStatistics() returns an object with V8 heap statistics. All statistics are reported in Kilobytes. The object has properties: totalHeapSize (Integer), totalHeapSizeExecutable (Integer), totalPhysicalSize (Integer), totalAvailableSize (Integer), usedHeapSize (Integer), heapSizeLimit (Integer), mallocedMemory (Integer), peakMallocedMemory (Integer), and doesZapGarbage (boolean).

process.getBlinkMemoryInfo() method returns object

process.getBlinkMemoryInfo() returns an object with Blink memory information. The object has properties: allocated (Integer, size of all allocated objects in Kilobytes) and total (Integer, total allocated space in Kilobytes). All values are reported in Kilobytes. It can be useful for debugging rendering / DOM related memory issues.

process.getProcessMemoryInfo() method

process.getProcessMemoryInfo() returns Promise<ProcessMemoryInfo> - resolves with a ProcessMemoryInfo object giving memory usage statistics about the current process. All statistics are reported in Kilobytes. This API should be called after app ready. On macOS, Chromium does not provide residentSet value because macOS performs in-memory compression of pages that haven't been recently used; private memory is more representative of the actual pre-compression memory usage.

process.getSystemMemoryInfo() method returns object

process.getSystemMemoryInfo() returns an object with system memory statistics in Kilobytes. Properties: total (Integer, total physical memory available), free (Integer, memory not being used by applications or disk cache), available (Integer, Linux only, kernel's estimate from /proc/meminfo MemAvailable), fileBacked (Integer, macOS only, memory paged out to storage), purgeable (Integer, macOS only, memory marked as purgeable), swapTotal (Integer, Windows and Linux only), swapFree (Integer, Windows and Linux only).

process.getSystemVersion() method example

process.getSystemVersion() returns a string with the version of the host operating system. Examples: '10.13.6' on macOS, '10.0.17763' on Windows, '4.15.0-45-generic' on Linux. It returns the actual operating system version instead of kernel version on macOS, unlike os.release().

process.takeHeapSnapshot(filePath) method

process.takeHeapSnapshot(filePath) takes a V8 heap snapshot and saves it to filePath. Parameter: filePath (string, required, path to the output file). Returns boolean indicating whether the snapshot has been created successfully.

process.hang() method

process.hang() causes the main thread of the current process to hang.

process.setFdLimit(maxDescriptors) method

process.setFdLimit(maxDescriptors) is available on macOS and Linux. It sets the file descriptor soft limit to maxDescriptors or the OS hard limit, whichever is lower for the current process. Parameter: maxDescriptors (Integer, required).

Give your agent this brain